/*****************************************************************************
 List the images (for applications) that need to be prefetched
*****************************************************************************/
var appImgList = [
	'/img/CocoMon.png',
	'/img/FBEvents.png',
	'/img/bombsweeper.png',
	'/img/Alert.png',
	'/img/SoccerParty.png',
	'/img/MinuteMania.png',
	'/img/Acteris.png',
	'/img/FacebookQS.png',	
	'/img/iHonk.png',
	'/img/FCQ.png',
	'/img/SpaceMission.png',
	'/img/SimplerTips.png',
	'/img/TwitterQS.png'
];

var appImgIconList = [
	'/img/CocoMon_icon.png',
	'/img/FBEvents_icon.png',
	'/img/bombsweeper_icon.png',
	'/img/Alert_icon.png',
	'/img/SoccerParty_icon.png',
	'/img/MinuteMania_icon.png',
	'/img/Acteris_icon.png',
	'/img/FacebookQS_icon.png',
	'/img/iHonk_icon.png',
	'/img/FCQ_icon.png',
	'/img/SpaceMission_icon.png',
	'/img/SimplerTips_icon.png',
	'/img/TwitterQS_icon.png'
];
  
var appTitleList = [
  'Air CocoMon',
  'Facebook Events',
  'Bomb Sweeper',
  'ALERT!',
  'Soccer Party',
  'One Minute Mania!',
  'ACTERIS',
  'Facebook Quick Status',
  'iHonk!',
  'Facebook Celebrity Quotes',
  'Aero Space Project',
  'Simpler Tips',
  'All Quick Tweet'
];
  
var appDescList = [
  'Air CocoMon is the newest, most addicting, and fun game available! It is perfect for people in search of a simple game that can provide anywhere from two minutes of fun while waiting in line to hours of fun sitting on the couch trying to beat the latest high score!',
  'The BEST Facebook Events app with full map support, directions, routes, sync events to your calendar, RSVP to your events, and see all your events for one day on the SAME map with annotations so you can easily tell where to go first!',
  'Bomb Sweeper is the newest and most addicting action puzzle game around! You are the hero, trying to move walls very purposefully in an effort to uncover the hidden bombs and save the city from disaster!',
  'Are you bored? Stuck somewhere with nothing to do? We have just the perfect APP for you! Meet ALERT! - The Impossible Game!',
  'Soccer Party is the newest, most addicting, and fun game available! It is perfect for people in search of a simple game that can provide anywhere from two minutes of fun while waiting in line to hours of fun sitting on the couch trying to beat the latest high score!',
  'One Minute Mania! will probably be one of the MOST INSANELY ADDICTIVE game you will ever play!',
  'Do you like to play Puzzle games with Tetrominoes? Then you will love ACTERIS - Super Action Tetromino Puzzle Match!',
  'Quick Status allows you to maintain a list of your favorite and recent status messages that you can post to your Facebook account with a single touch.',
  'Do you get frustrated if cars honk their horns at you and you are powerless to give them a peace of your mind?  Or perhaps you are walking through a crowded area and wish people would get out of your way?',
  'Facebook Celebrity Quotes is the perfect application for following your favorite celebrities, posting their famous and entertaining quotes to your Facebook status, following their own celebrity Facebook fan pages, and learning more about them on Wikipedia, Google, Yahoo and Bing.',
  'Guide the space rocket to avoid asteroids, meteors and collect stars for more gold. Upgrade your shield, buy more bombs, upgrade boosters to achieve warp speeds, and much more!',  
  'Simpler Tips is the easiest and most intuitive tip calculator to use! Simply enter the price of your meal, calculate tip and split the bill in minimum amount of steps.',
  'Quick Tweet allows you to maintain a list of your favorite and recent status messages that you can post to your Twitter account with a single touch.'
];

var appShortDescList = [
  'Air CocoMon is the newest, most addicting, and fun game available!&nbsp;&nbsp;&nbsp;&nbsp;<img src="/img/app_store.png" align="absmiddle" onclick="javascript:goToAppStore(\'340134663\');"/>&nbsp;',
  'The BEST Facebook Events app you will ever find!&nbsp;&nbsp;&nbsp;&nbsp;<img src="/img/app_store.png" align="absmiddle" onclick="javascript:goToAppStore(\'446874045\');"/>&nbsp;',
  'Help save the city from villains and find all the bombs!&nbsp;&nbsp;&nbsp;&nbsp;<img src="/img/app_store.png" align="absmiddle" onclick="javascript:goToAppStore(\'412485913\');"/>&nbsp;',
  'The MOST INSANELY ADDICTING game you will ever play!&nbsp;&nbsp;&nbsp;&nbsp;<img src="/img/app_store.png" align="absmiddle" onclick="javascript:goToAppStore(\'363479896\');"/>&nbsp;',
  'Soccer Party is the newest, most addicting, and fun game available!&nbsp;&nbsp;&nbsp;&nbsp;<img src="/img/app_store.png" align="absmiddle" onclick="javascript:goToAppStore(\'454670766\');"/>&nbsp;',
  'The MOST INSANELY ADDICTING game you will ever play!&nbsp;&nbsp;&nbsp;&nbsp;<img src="/img/app_store.png" align="absmiddle" onclick="javascript:goToAppStore(\'402445925\');"/>&nbsp;',
  'Like Tetrominoes Puzzle Game? You will love ACTERIS!&nbsp;&nbsp;&nbsp;&nbsp;<img src="/img/app_store.png" align="absmiddle" onclick="javascript:goToAppStore(\'408256379\');"/>&nbsp;',
  'Update your Facebook status in one touch!&nbsp;&nbsp;&nbsp;&nbsp;<img src="/img/app_store.png" align="absmiddle" onclick="javascript:goToAppStore(\'326114096\');"/>&nbsp;',
  'iHonk is the perfect tool to strike back!&nbsp;&nbsp;&nbsp;&nbsp;<img src="/img/app_store.png" align="absmiddle" onclick="javascript:goToAppStore(\'351888205\');"/>&nbsp;',
  'Post celebrity quotes and pictures to your Facebook!&nbsp;&nbsp;&nbsp;&nbsp;<img src="/img/app_store.png" align="absmiddle" onclick="javascript:goToAppStore(\'344358861\');"/>&nbsp;',
  'Much more fun than Project 72 and Doodle Jump!&nbsp;&nbsp;&nbsp;&nbsp;<img src="/img/app_store.png" align="absmiddle" onclick="javascript:goToAppStore(\'357426063\');"/>&nbsp;',
  'Calculate tip and split the bill in minimum amount of steps!&nbsp;&nbsp;&nbsp;&nbsp;<img src="/img/app_store.png" align="absmiddle" onclick="javascript:goToAppStore(\'327473606\');"/>&nbsp;',
  'Update your Twitter status in one touch!&nbsp;&nbsp;&nbsp;&nbsp;<img src="/img/app_store.png" align="absmiddle" onclick="javascript:goToAppStore(\'340796638\');"/>&nbsp;'
];

var appIdList = [
  'CocoMon',
  'FBEvents',
  'bombsweeper',
  'Alert',
  'SoccerParty',
  'MinuteMania',
  'Acteris',
  'FacebookQuickStatus',
  'iHonk',
  'FCQ',
  'SpaceMission',
  'SimplerTips',
  'TwitterQuickStatus'
];

var appStatusList = [
  'Now available on the AppStore!&nbsp;<img src="/img/app_store.png" align="absmiddle" onclick="javascript:goToAppStore(\'340134663\');"/>&nbsp;',
  'Now available on the AppStore!&nbsp;<img src="/img/app_store.png" align="absmiddle" onclick="javascript:goToAppStore(\'446874045\');"/>&nbsp;',
  'Now available on the AppStore!&nbsp;<img src="/img/app_store.png" align="absmiddle" onclick="javascript:goToAppStore(\'412485913\');"/>&nbsp;',
  'Now available on the AppStore!&nbsp;<img src="/img/app_store.png" align="absmiddle" onclick="javascript:goToAppStore(\'363479896\');"/>&nbsp;',
  'Now available on the AppStore!&nbsp;<img src="/img/app_store.png" align="absmiddle" onclick="javascript:goToAppStore(\'454670766\');"/>&nbsp;',
  'Now available on the AppStore!&nbsp;<img src="/img/app_store.png" align="absmiddle" onclick="javascript:goToAppStore(\'402445925\');"/>&nbsp;',
  'Now available on the AppStore!&nbsp;<img src="/img/app_store.png" align="absmiddle" onclick="javascript:goToAppStore(\'408256379\');"/>&nbsp;',
  'Now available on the AppStore!&nbsp;<img src="/img/app_store.png" align="absmiddle" onclick="javascript:goToAppStore(\'326114096\');"/>&nbsp;',
  'Now available on the AppStore!&nbsp;<img src="/img/app_store.png" align="absmiddle" onclick="javascript:goToAppStore(\'351888205\');"/>&nbsp;',  
  'Now available on the AppStore!&nbsp;<img src="/img/app_store.png" align="absmiddle" onclick="javascript:goToAppStore(\'344358861\');"/>&nbsp;',
  'Now available on the AppStore!&nbsp;<img src="/img/app_store.png" align="absmiddle" onclick="javascript:goToAppStore(\'357426063\');"/>&nbsp;',
  'Now available on the AppStore!&nbsp;<img src="/img/app_store.png" align="absmiddle" onclick="javascript:goToAppStore(\'327473606\');"/>&nbsp;',
  'Now available on the AppStore!&nbsp;<img src="/img/app_store.png" align="absmiddle" onclick="javascript:goToAppStore(\'340796638\');"/>&nbsp;'
];
  
var imgs = [];

// =======================================
//   preload all images initially needed
// =======================================
var downloadTimer = null;
var downloadInterval = 300;
var imgTimer = null;
var imgInterval = 5000;

function startDownload(idx) {
  if (downloadTimer != null) {
    window.clearTimeout(downloadTimer);
  }
  if (idx < appImgList.length) {
    imgs[idx] = new Image();
    imgs[idx].src = appImgList[idx];
    downloadTimer = window.setTimeout("startDownload("+(idx+1)+")", downloadInterval);
  }
  else {
    if (imgTimer != null) {
      window.clearTimeout(imgTimer);
    }
    // schedule image slideshow immediately
    imgTimer = window.setTimeout("showcaseApps(0)", 10);
  }
}

function showcaseApps(idx) {
  if (imgTimer != null) {
    window.clearTimeout(imgTimer);
  }
  
  var imgObj = document.getElementById("AppImgBox");
  var appTitleObj = changeElem("AppTitle", "<a href=\"javascript:goApp('" + appIdList[idx] + "');\">" + appTitleList[idx] + "</a>");
  var appDescObj = changeElem("AppDesc", appDescList[idx]);  
  var appReadMoreObj = changeElem("AppReadMore", "<a href=\"javascript:goApp('" + appIdList[idx] + "');\">Read more about " + appTitleList[idx] + " >>></a>");
  var appStatusObj = changeElem("AppState", appStatusList[idx]);
  
  if (imgObj && appTitleObj && appDescObj && appReadMoreObj && appStatusObj) {
    imgObj.src = imgs[idx].src;
    if (idx == imgs.length - 1) {
      idx=0;
      imgInterval=8000;
    }
    else {
      idx++;
    }
    imgTimer = window.setTimeout("showcaseApps("+idx+")", imgInterval);
  }
}

function listProducts() {
  var content = "";
  for (var i=0 ; i<appTitleList.length ; i++) {
    content += '<div class="ProductItem' + (i == appTitleList.length - 1 ? 'Last' : '');
    content += '"><table cellpadding="0" cellspacing="0" border="0" width="100%">';
    content += '<tr align="left" valign="middle" width="100%">';
    content += '<td align="center" valign="middle" width="100px" height="62px"><img src="' + appImgIconList[i] + '"/></td>';
    content += '<td align="left" valign="top"><font style="font-size: 14pt; font-weight: bold;">' + appTitleList[i] + '</font><br />';
    content += '<font style="font-size: 12pt; font-weight: normal;">' + appShortDescList[i] + '</font><br /><br />';
    content += "<a href=\"javascript:goApp('" + appIdList[i] + "');\">Read more about " + appTitleList[i] + " >>></a>";
    content += '</td></tr></table></div>';
  }
  changeElem("ProductContentDiv", content);
}

// dynamic HTML utility method
function changeElem(id, innerHTML, top, left, bottom, right, width, height, color, bgColor, bdrTop, bdrLeft, bdrBottom, bdrRight, visibility, zIdx, fontWeight) {
  var obj = document.getElementById(id);
  if (obj) {
    if (innerHTML) obj.innerHTML = innerHTML;

    if (top != null) obj.style.top = top + "px";
    if (left != null) obj.style.left = left + "px";
    if (bottom != null) obj.style.bottom = bottom + "px";
    if (right != null) obj.style.right = right + "px";
    if (width != null) obj.style.width = width + "px";
    if (height != null) obj.style.height = height + "px";
    if (color != null) obj.style.color = color;
    if (bgColor != null) obj.style.backgroundColor = bgColor;
    if (bdrTop != null) obj.style.borderTop = bdrTop;
    if (bdrLeft != null) obj.style.borderLeft = bdrLeft;
    if (bdrBottom != null) obj.style.borderBottom = bdrBottom;
    if (bdrRight != null) obj.style.borderRight = bdrRight;
    if (visibility != null) obj.style.visibility = visibility;
    if (zIdx != null) obj.style.zIndex = zIdx;
    if (fontWeight != null) obj.style.fontWeight = fontWeight;
  }
  return obj;
}

function dbgprint(s) {
  alert(s);
}
