/**
 * Launching game panel 
 */
var curGameIndex = new Array();
var gameGenreCache = new Array();
var gameGenreTitle = new Array();
var gameTitleIdCache =  new Array();
var gameTitleDesc = new Array();
var gameFileNameCache = new Array();

var gameCursorIndex = 0;
var gameRowIndex = 0;
var gameColIndex = 0;
var gameGenreIndex = 0;
var gameTitleIndex = 0;
var gameGenreClick = 0;	
var gameGenreCursor = 0;

var gameMenuStatus = false;
var gameMenuActive = false;
var gameActive = false;

function resetGamePanelValue() {
	curGameIndex = new Array();
	gameGenreCache = new Array();
	gameGenreTitle = new Array();
	gameTitleIdCache =  new Array();
	gameTitleDesc = new Array();
	gameFileNameCache = new Array();
	gameActive = false;
	gameMenuActive = false;
	
	gameGenreIndex = 0;
	gameGenreCursor = 0;
	
	gameRowIndex = 0;
	gameColIndex = 0;
	gameCursorIndex = 0;
	gameGenreIndex = 0;
	gameTitleIndex = 0;
	gameGenreClick = 0;	
}
function launchGamePanel() {
	gameActive = true;
	gameMenuActive = true;
	var widgetTitle = wrecords.wRecords[currImage].title;
	var widgetId = wrecords.wRecords[currImage].id;
	var useGraphic = wrecords.wRecords[currImage].useGraphic;
	useGraphic = useGraphic.substring(1, useGraphic.length);		
	document.getElementById("vodGenrePanel").innerHTML = "loading";
	document.getElementById("vodTitlePanel").innerHTML = "<span style='color:white;'>loading...</span>";
	document.getElementById("titleContent").innerHTML = "&nbsp;";
	document.getElementById("yearTagPanel").innerHTML = "&nbsp;";
	document.getElementById("ratingPanel").innerHTML = "&nbsp;";
	document.getElementById("picHolderName").innerHTML = "";
	document.getElementById("picCountPanel").innerHTML = "";
	document.getElementById("vodTag").innerHTML = widgetTitle;
	document.getElementById("htmlHeaderImg").innerHTML = '<img  alt="" height="36px" width="36px" src=' + (useGraphic == 1 ? "/ImageHandlerMobi?value=" + wrecords.wRecords[currImage].id + "&icon=2&imageType=2" : "/view/tv/images/widgets/wImages/widgetNA.png") + ' style="padding:1px;" border="0" align="middle">';
	showVodPanel();
	getGameInfo();
	/*
	var widgetId = wrecords.wRecords[currImage].id;
	var useGraphic = wrecords.wRecords[currImage].useGraphic;
	useGraphic = parseInt(useGraphic.substring(1, useGraphic.length));	
	var widgetTitle = wrecords.wRecords[currImage].title;
	var gamePanelHTML = "<table style='height:100%;text-align:left;font-weight:bold;' width='100%' align='left'><tr><td style='border-bottom:1px solid gray;' width='100%'><table width='100%' ><tr><td width='80%' id='gamePanelContent'><table><tr><td>"+ '<img  alt="" height="36px" width="36px" src=' + (useGraphic == 1 ? "/ImageHandlerMobi?value=" + widgetId + "&icon=2&imageType=2" : "/view/tv/images/widgets/wImages/widgetNA.png") + ' style="padding:1px;" border="0" align="middle"></td><td>' +widgetTitle+"</td></tr></table></td><td width='30%'><table width='50%' align='right' style='text-align:right;'><tr><td><img style='cursor:pointer;' onclick='videoKeyHandler(rcUP);' src='./view/mobi/images/uarrow.png'/></td><td><img onclick='videoKeyHandler(rcMENU);' style='cursor: pointer;' src='/view/mobi/images/home.png' alt=''/></td><td><img style='cursor:pointer;' onclick='videoKeyHandler(rcDOWN);' src='./view/mobi/images/darrow.png'/></td></tr></table></td></tr></table></td></tr><tr><td id='gamePanelHTML'><table style='height:100%;' >";
	gamePanelHTML += "<tr>";
	for(var k = 0; k < 3; k++) {
		curGameIndex[k] = new Array(3); 
		for(var m = 0; m < 3; m++) {
			curGameIndex[k][m] = 0;
		}
	}
	for(var i = 0; i < 9; i++) {
		if(i%3 == 0 && i != 0) {
			gamePanelHTML += "</tr><tr>";
		}
		var rowIndex = parseInt(i/3);
		var colIndex = parseInt(i%3);
		if(i < gameIdCache.length) {
			curGameIndex[rowIndex][colIndex] = 1;
		} else {
			curGameIndex[rowIndex][colIndex] = 0;
		}
		gamePanelHTML += "<td width='100px' height='55px' onmouseover='selVideoPanel("+ i +", "+ i +");' style='border:"+(i < gameIdCache.length ? '1px solid transparent;background:none;' : '1px solid Transparent;background:none;')+"' id='videoTitleId"+ i +"' onclick='openVideoContent("+ i +");'>"+ (i < gameIdCache.length ? '<img width="100px" height="55px" src=\'/ImageHandlerMobi?value=' + gameIdCache[i] + '&icon=1&imageType=8\' >' : '&nbsp;') +"</td>";
	}
	gamePanelHTML += "</tr>";
	gamePanelHTML += "</table></tr><tr><td height='10%' style='border-top:1px solid gray;' id='videoPanelDesc'>&nbsp;</td></tr></td></table>";
	fadeAll();
	document.getElementById("openChartId").innerHTML = gamePanelHTML;
	*/
}
/**
 * 
 */	

function getGameInfo() {
	var widgetId = wrecords.wRecords[currImage].id;
	var params = "method=getGameMenuInfo" + "&widgetId=" + widgetId + "&serial=" + serial;
	createAjaxRequest();
	if(ajaxRequest == null) {
		return;
	}
	ajaxRequest.onreadystatechange = function() { 
		if (ajaxRequest.readyState == 4) {
	    	if(ajaxRequest.status == 200) {
	    		if(ajaxRequest.responseText == "recall") {
	    			getGameInfo();
	    		} else {
	    			var response = ajaxRequest.responseText;
	    			if(response.length > 0) {
	    				var data = response.split("-?#-");
	    				gameGenreCache = (data[0]).split("-*$-");
//	    				var nowData = "Checker" + "-@#-" +"Minesweeper" + "-@#-" + "Tic Tac Toe" + "-@#-" + "Chess" + "-*$-" + data[1];
	    				
	    				var curGenreData = (data[1]).split("-*$-");
	    				gameGenreTitle = new Array(curGenreData.length);
	    				for(var i = 0; i < curGenreData.length; i++) {
	    					gameGenreTitle[i] = (curGenreData[i]).split("-@#-");
	    				}
	    				curGenreData = (data[2]).split("-*$-");
	    				gameTitleIdCache = new Array(curGenreData.length);
	    				for(var i = 0; i < curGenreData.length; i++) {
	    					gameTitleIdCache[i] = (curGenreData[i]).split("-@#-");
	    				}
	    				curGenreData = (data[3]).split("-*$-");
	    				gameTitleDesc = new Array(curGenreData.length);
	    				for(var i = 0; i < curGenreData.length; i++) {
	    					gameTitleDesc[i] = (curGenreData[i]).split("-@#-");
	    				}
	    				curGenreData = (data[4]).split("-*$-");
	    				gameFileNameCache = new Array(curGenreData.length);
	    				for(var i = 0; i < curGenreData.length; i++) {
	    					gameFileNameCache[i] = (curGenreData[i]).split("-@#-");
	    				}
	    			}
	    			gameGenreTotal = gameGenreCache.length == 0 ? 0 : gameGenreCache.length - 1;
					drawGameGenre(0, 3);
//					showGamePanel();
//					hideResetImage();	    		
				}
			} else if(ajaxRequest.status == 500) { 
//				failureInfo();
			}
		} 
	 };
	ajaxRequest.open("POST", '/TvHandler', true);
	ajaxRequest.setRequestHeader("Content-Type" , "application/x-www-form-urlencoded");
	ajaxRequest.send(params);
	return false;	
}
	
function drawGameGenre(start, end) {	
	var genreHTML = "";
	for(var i = 0; i < 4; i++) {
		genreHTML += '<tr><td width="100%" height="16%" valign="middle" style="height:16%;width:100%;vertical-align:middle;" id="gameGenreId' + i + '"  onmouseover="selGamePanel(' + i + ');" >&nbsp;</td></tr>';
	}
	document.getElementById("vodGenrePanel").innerHTML = ''
			+ '<table class="genreMenu" width="100%" height="100%" align="left" border="0px" style="margin-left:0%;margin-top:0px;" cellspacing="0" cellpadding="1.5px">' 
			+ genreHTML				
			+ '</table>';
	genreHTML = "";
	var genreCount = 0;
	for(i = start; i <= end; ++i) {
		document.getElementById("gameGenreId" + genreCount).innerHTML = "&nbsp;"+getGameGenre(gameGenreCache[i]);
		++genreCount;
	}
	selGameGenre();	
}

function selGameGenre() {
	try {
		drawGameTitle();
	} catch(x) {
		alert(x);
	}
	if(document.getElementsByTagName) {  
		var table = document.getElementById("vodGenrePanel"); 
		var rows = table.getElementsByTagName("tr");
		document.getElementById("gameGenreId" + gameGenreCursor).style.background = 'url("/view/mobi/images/rowGenre.png") no-repeat';
//		rows[gameGenreCursor].style.background =  'none';
//		rows[gameGenreCursor].style.background =  'url("/view/mobi/images/rowGenre.png") no-repeat';
//		rows[gameGenreCursor].style.background =  'url("/view/mobi/images/rowGenre.png") no-repeat';
		//rows[gameGenreCursor].style.backgroundRepeat = "no repeat";	
	   	var i;
//	   	alert(rows.length + ", the game genre cursor is: " + gameGenreCursor);
	 	for(i = 0; i < rows.length; i++) { //alert(rows.length);  
	   		if(i != gameGenreCursor) {
	   			document.getElementById("gameGenreId" + i).style.background = "none";
	       		rows[i].style.background = 'none'; 
	       		
	    	}
	   }
	} 
//	try {
//		document.getElementById("gameGenreId" + gameGenreCursor).style.background =  'url("./view/mobi/images/rowGenre.png") no-repeat';	
//	} catch(x) {
//		alert(x);
//	}
}
	
function getGameGenre(index) {
	index = parseInt(index);
	var result = "";
	switch(index) {
		case -1: 
			result = "Latest Games";
			break;
		case 1:
			result = "Arcade";
			break;
		case 2:
			result = "Adventure Games";
			break;
		case 3:
			result = "Fishing Games";
			break;
		case 4:
			result = "Multiplayer";
			break;
		case 5:
			result = "Puzzle Games";
			break;
		case 6:
			result = "Racing Games";
			break;
		case 7:
			result = "Shooting";
			break;
		case 8:
			result = "Others";
			break;
	}
	return result;
}	
	
function updateGameDesc(rowIndex, columnIndex)  {
	try {
		var currentIndex = 3*rowIndex + columnIndex;
		var desc = gameTitleDesc[gameGenreIndex][currentIndex];
		var titleName = gameGenreTitle[gameGenreIndex][currentIndex];
		document.getElementById("picHolderName").innerHTML = "";
		document.getElementById("picCountPanel").innerHTML = "";
		document.getElementById("picHolderName").innerHTML = "<table width='100%' height='100%'><tr><td style='color:white;margin:5px;' align='left'>" +titleName + "</td></tr></table>";
		document.getElementById("picCountPanel").innerHTML = "<table width='100%' height='100%'><tr><td style='color:white;margin:5px;text-align:justify;' align='right'>" + desc + "</td></tr></table>";
//		document.getElementById("vodTitlePanel").style.textAlign = "justify";
	} catch(x) {
		alert(x);
	}
}	

function selGamePanel(index) {
	if(index >= gameGenreCache.length) {
		return;
	}
	gameMenuPanel = 0;
	unSelGamePanel();
	gameGenreCursor = index;
	gameGenreIndex = gameGenreCursor + gameGenreClick;
	selGameGenre();
}	

function unSelGamePanel() {
	try {
		document.getElementById("picHolderName").innerHTML = "";
		document.getElementById("picCountPanel").innerHTML = "";
	} catch (x) {
		
	}
//	try {
//		for(var i = 0; i < 4; i++) {
//			document.getElementById("gameGenreId" + i).style.background =  '';
//		}
//	} catch(x) {
//		alert(x);
//	}
}	
function resetGameTitle() {
	curGameIndex = new Array();
	gameRowIndex = 0;
	gameColIndex = 0;
	gameTitleTotal = 0;
}
function selGameTitlePanel(rowIndex, columnIndex, curIndex) {
	gameMenuPanel = 1;
	unSelGameTitle(gameCursorIndex, gameColIndex);
	gameRowIndex = parseInt(curIndex/3);
	gameColIndex = columnIndex;
	gameCursorIndex = rowIndex;
	selGameTitle(rowIndex, columnIndex);
}	

function selGameTitle(rowIndex, colndex) {
	try {
		updateGameDesc(rowIndex, colndex);
	} catch(x) {
		alert(x);
	}
	try {
		document.getElementById("gameTitle"+ rowIndex + "" +colndex).style.border = "1px solid white";
	} catch(x) {
		
	}
}
function unSelGameTitle(rowIndex, colndex) {
	try {
		document.getElementById("gameTitle"+ rowIndex + "" +colndex).style.border = "1px solid gray";
	} catch(x) {
		
	}
}
function drawGameTitle() {
	resetGameTitle();
 	var gameHTML = "";
	var titleCount = 0;
	var gameHTML  = '';
	for(var k = 0; k < 3; k++) {
		curGameIndex[k] = new Array(3); 
		gameHTML = "<tr>";
		for(var m = 0; m < 3; m++) {
			curGameIndex[k][m] = 0;
			gameHTML += '<td id="gameTitlePanelId'+ rowIndex +''+ columnIndex +'" align="center" valign="middle" nowrap style="width:45px;height:45px;padding:5px;" onmouseover="selGameTitlePanel('+ rowIndex +', '+ columnIndex +', ' + i + ');" onclick="gamePanelKeyHandler('+rcOK+');" >&nbsp;</td>';
		}
		gameHTML = "</tr>";
	}
	titleCache = new Array();
	titleCache = gameGenreTitle[gameGenreIndex];
	for(var i=0; (titleCache.length >=9 && i<9) || (titleCache.length < 9 && i<titleCache.length); ++i) {
		var rowIndex = parseInt(i/3);
		var columnIndex = parseInt(i%3);
		if(i%3 == 0 && i != 0) {
			gameHTML += '</tr><tr>';
		} 
		var currentIndex = 3*rowIndex + columnIndex;
		curGameIndex[rowIndex][columnIndex] = 1;
		var curImage = (gameGenreIndex == 0 ? "./view/tv/images/widgets/gameMenu/gameMenu" + (gameGenreIndex + 1) + "/gameMenu" + (gameGenreIndex + 1)+"" + (i+1) + (gameGenreIndex + 1 == 1 ? ".png" : ".jpg") : '/ImageHandler?value=' + gameTitleIdCache[gameGenreIndex][currentIndex] + '&icon=-1&imageType=11') ;
		gameHTML += '<td id="gameTitlePanelId'+ rowIndex +''+ columnIndex +'" align="center" valign="middle" nowrap style="width:45px;height:45px;padding:5px;" onmouseover="selGameTitlePanel('+ rowIndex +', '+ columnIndex +', ' + i + ');" onclick="gamePanelKeyHandler('+rcOK+');" >' +'<img id="gameTitle'+ rowIndex +'' +columnIndex+'" style="width:40px;height:40px;background:darkolivegreen;border:1px solid gray;cursor:pointer;" src="'+curImage+ '" />'+ '</td>';
		titleCount++;
	}
	if(titleCount > 0) {
		for(var j=0; j < (9 - titleCount) ; ++j) { 
			var rowIndex = parseInt((j+titleCount)/3);
			var columnIndex = parseInt((j+titleCount)%3);
			if((titleCount+j)%3 == 0) {
				gameHTML += '</tr><tr>';
			}
			gameHTML += '<td id="gameTitlePanelId'+ rowIndex +''+ columnIndex +'" align="center" valign="middle" nowrap style="width:45px;height:45px;padding:5px;">&nbsp;</td>';
		}
	}
	
	gameHTML += '</tr>';
	document.getElementById("vodTitlePanel").innerHTML = ''
						+ '<table width="100%" align="left" valign="top" cellspacing="0" cellpadding="0" >' 
							+ (titleCache.length > 0 ? gameHTML : '<tr><td height="28" width="400px" align="center" valign="middle"><span style="width:100%;text-align:center;vertical-align:middle;background-repeat:no-repeat;">No options avaliable</span></td></tr>')
						+ '</table>';
	gameTitleTotal = titleCache.length - 1;						
}	

function openSelectGame(genreIndex, titleIndex) {
	switch(genreIndex) {
		case 0:
			switch(titleIndex) {
				case 0:
					return;
					gameMenuStatus = true;
					gameMenuActive = false;
//					var useGraphic = wrecords.wRecords[currImage].useGraphic;
//						useGraphic = useGraphic.substring(0, (useGraphic.length-1));
//					document.getElementById("gameImagePanel").innerHTML = 
//						'<img  height="36px" width="36px" alt="'+ wrecords.wRecords[currImage].title + '" id="widgetIcon1" src=' + (useGraphic == 1 ? "/ImageHandler?value="+ wrecords.wRecords[currImage].id + "&icon=2&imageType=2" : "/view/tv/images/widgets/logoPanel27.png") + '  />';
//					document.getElementById("gameTitlePanel").innerHTML = wrecords.wRecords[currImage].title;
					gameActive = true;
				  	createCrackerGamePanel();					
//					saveTimeLineData("Widget", "Checkers", 1);
				break;
				case 1:
					return;
					gameMenuStatus = true;
					gameMenuActive = false;
					var useGraphic = wrecords.wRecords[currImage].useGraphic;
						useGraphic = useGraphic.substring(0, (useGraphic.length-1));
					document.getElementById("gameImagePanel").innerHTML = 
						'<img  height="36px" width="36px" alt="'+ wrecords.wRecords[currImage].title + '" id="widgetIcon1" src=' + (useGraphic == 1 ? "/ImageHandler?value="+ wrecords.wRecords[currImage].id + "&icon=2&imageType=2" : "/view/tv/images/widgets/logoPanel27.png") + '  />';
					document.getElementById("gameTitlePanel").innerHTML = wrecords.wRecords[currImage].title;
					gameActive = true;
				  	initMineSweeper();					
//					saveTimeLineData("Widget", "MineSweeper", 1);
				break;
				case 2:
					fadeAll();
					gameMenuStatus = true;
					gameMenuActive = false;
//					var useGraphic = wrecords.wRecords[currImage].useGraphic;
//						useGraphic = useGraphic.substring(0, (useGraphic.length-1));
//					document.getElementById("gameImagePanel").innerHTML = 
//						'<img  height="36px" width="36px" alt="'+ wrecords.wRecords[currImage].title + '" id="widgetIcon1" src=' + (useGraphic == 1 ? "/ImageHandler?value="+ wrecords.wRecords[currImage].id + "&icon=2&imageType=2" : "/view/tv/images/widgets/logoPanel27.png") + '  />';
//					document.getElementById("gameTitlePanel").innerHTML = wrecords.wRecords[currImage].title;
					gameActive = true;
				  	createTicTacToePanel();					
//					saveTimeLineData("Widget", "Tic-Tac-Toe", 1);
				break;
				case 3:
					return;
					gameMenuStatus = true;
					gameMenuActive = false;
					var useGraphic = wrecords.wRecords[currImage].useGraphic;
						useGraphic = useGraphic.substring(0, (useGraphic.length-1));
					document.getElementById("gameImagePanel").innerHTML = 
						'<img  height="36px" width="36px" alt="'+ wrecords.wRecords[currImage].title + '" id="widgetIcon1" src=' + (useGraphic == 1 ? "/ImageHandler?value="+ wrecords.wRecords[currImage].id + "&icon=2&imageType=2" : "/view/tv/images/widgets/logoPanel27.png") + '  />';
					document.getElementById("gameTitlePanel").innerHTML = wrecords.wRecords[currImage].title;
					gameActive = true;	
					loadChessPanel();	
//					saveTimeLineData("Widget", "Chess", 1); 	
				break;
			}
		break;
		case 1:
			switch(titleIndex) {
				case 0:
				case 1:
				case 3:
				case 4:
				case 2:
					gameMenuStatus = true;
					fadeAll();
					document.getElementById("openChartId").innerHTML = '<table style="border:1px solid gray;"><tr><td><img valign="middle" width="15px" height="15px" onclick="homePanelVod(1);" style="cursor: pointer;" src="/view/mobi/images/home.png" alt=""/></td><tr><td><object height="240" width="320" >'
						+'<param name="movie" value="/view/online/embed/games/chess1.swf"/>'
						+'<param value="sameDomain" name="allowScriptAccess"/>'
						+'<param value="true" name="allowFullScreen"/>'
						+'<param value="high" name="quality"/>'
						+'<param value="#000000" name="bgcolor"/>'
						+'<param value="opaque" name="wmode"/>'
						+'<embed  align="middle" height="240" width="320" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="sameDomain" bgcolor="#000000" quality="high" src="/view/online/embed/games/chess1.swf" wmode="transparent"/>'
					+'</object></td></tr></table>';
				break;
			}
		break;
		case 2:
			fadeAll();
			gameMenuStatus = true;
			switch(titleIndex) {
				case 0:
					document.getElementById("openChartId").innerHTML = '<table style="border:1px solid gray;"><tr><td><img valign="middle" width="15px" height="15px" onclick="homePanelVod(1);" style="cursor: pointer;" src="/view/mobi/images/home.png" alt=""/></td><tr><td><embed value="opaque" name="wmode" height="240" width="320" quality="high" name="TakeMonsterHome" id="TakeMonsterHome" src="./view/tv/flash/TakeMonsterHome.swf" type="application/x-shockwave-flash"/></td></tr></table>';
//					document.getElementById("openChartId").innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="625" height="422">' 
//							+'<param name="movie" value="./view/tv/flash/TakeMonsterHome.swf">' 
//							+'<param name="quality" value="high">' 
//							+'<embed src="./view/tv/flash/TakeMonsterHome.swf" width="625" height="422" align="center" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>' 
//							+'</object>';
				break;
				case 1:
					document.getElementById("openChartId").innerHTML = '<table style="border:1px solid gray;"><tr><td><img valign="middle" width="15px" height="15px" onclick="homePanelVod(1);" style="cursor: pointer;" src="/view/mobi/images/home.png" alt=""/></td><tr><td><embed value="opaque" name="wmode" height="240" width="320" quality="high" name="Mathteroids" id="Mathteroids" src="./view/tv/flash/TakeMonsterHome.swf" type="application/x-shockwave-flash"/></td></tr></table>'; 
				break;
				case 2:
//					document.getElementById("openChartId").innerHTML = '<embed height="420" width="600" quality="high" name="Mathteroids" id="Mathteroids" src="http://www.freearcade.com/Mathteroids.flash/Mathteroids.swf" type="application/x-shockwave-flash"/>';
					document.getElementById("openChartId").innerHTML = '<embed value="opaque" name="wmode" height="240" width="320"  quality="high" name="Mathteroids" id="Mathteroids" src="./view/tv/flash/Mathteroids.swf" type="application/x-shockwave-flash"/>';
				break;
				case 3:
					document.getElementById("openChartId").innerHTML = '<embed value="opaque" name="wmode" height="240" width="320"  quality="high" name="PixelBlast" id="PixelBlast" src="./view/tv/flash/PixelBlast.swf" type="application/x-shockwave-flash"/>';
				break;
			}
		break;
		case 3:
			fadeAll();
			gameMenuStatus = true;
			switch(titleIndex) {
				case 0:
				document.getElementById("openChartId").innerHTML = '<table style="border:1px solid gray;"><tr><td><img valign="middle" width="15px" height="15px" onclick="homePanelVod(1);" style="cursor: pointer;" src="/view/mobi/images/home.png" alt=""/></td><tr><td><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" height="240" width="320" >' 
							+'<param name="movie" value="./view/tv/flash/tinycombat2.swf">' 
							+'<param name="quality" value="high">' 
							+'<param value="opaque" name="wmode">'
							+'<embed src="./view/tv/flash/tinycombat2.swf" height="240" width="320"  align="center" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>' 
							+'</object></td></tr></table>';
				break;
				case 1:
					document.getElementById("openChartId").innerHTML = '<table style="border:1px solid gray;"><tr><td><img valign="middle" width="15px" height="15px" onclick="homePanelVod(1);" style="cursor: pointer;" src="/view/mobi/images/home.png" alt=""/></td><tr><td><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" height="240" width="320" >' 
							+'<param name="movie" value="./view/tv/flash/flashstrike.swf">' 
							+'<param name="quality" value="high">' 
							+'<param value="opaque" name="wmode">'
							+'<embed src="./view/tv/flash/flashstrike.swf" height="240" width="320"  align="center" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>' 
							+'</object></td></tr></table>';
				break;
				case 2:
					document.getElementById("openChartId").innerHTML = '<table style="border:1px solid gray;"><tr><td><img valign="middle" width="15px" height="15px" onclick="homePanelVod(1);" style="cursor: pointer;" src="/view/mobi/images/home.png" alt=""/></td><tr><td><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" height="240" width="320" >' 
							+'<param name="movie" value="./view/tv/flash/wingsofglory.swf">' 
							+'<param name="quality" value="high">' 
							+'<param value="opaque" name="wmode">'
							+'<embed src="./view/tv/flash/wingsofglory.swf" height="240" width="320"  align="center" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>' 
							+'</object></td></tr></table>';
				break;
				case 3:
				document.getElementById("openChartId").innerHTML = '<table style="border:1px solid gray;"><tr><td><img valign="middle" width="15px" height="15px" onclick="homePanelVod(1);" style="cursor: pointer;" src="/view/mobi/images/home.png" alt=""/></td><tr><td><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" height="240" width="320" >' 
							+'<param name="movie" value="./view/tv/flash/alienattack_HS.swf">' 
							+'<param name="quality" value="high">'
							+'<param value="opaque" name="wmode">' 
							+'<embed src="./view/tv/flash/alienattack_HS.swf" height="240" width="320"  align="center" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>' 
							+'</object></td></tr></table>';
				break;
			}
		break;
		case 4:
			fadeAll();
			gameMenuStatus = true;
			switch(titleIndex) {
				case 0:
				case 1:
				case 3:
				case 2:
					document.getElementById("openChartId").innerHTML = '<table style="border:1px solid gray;"><tr><td><img valign="middle" width="15px" height="15px" onclick="homePanelVod(1);" style="cursor: pointer;" src="/view/mobi/images/home.png" alt=""/></td><tr><td><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" height="240" width="320" >' 
							+'<param name="movie" value="./view/tv/flash/ninja.swf">' 
							+'<param name="quality" value="high">' 
							+'<param value="opaque" name="wmode">'
							+'<embed src="./view/tv/flash/ninja.swf" height="240" width="320"  align="center" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>' 
							+'</object></td></tr></table>';
				break;
			}
		break;
		case 5:
			fadeAll();
			gameMenuStatus = true;
			switch(titleIndex) {
				case 1:
				case 2:
				case 3:
				case 0:
					document.getElementById("openChartId").innerHTML =  '<table style="border:1px solid gray;"><tr><td><img valign="middle" width="15px" height="15px" onclick="homePanelVod(1);" style="cursor: pointer;" src="/view/mobi/images/home.png" alt=""/></td><tr><td><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" height="240" width="320" >' 
 						 +'<param name="movie" value="./view/tv/flash/attacktime.swf">' 
 						 +'<param name="quality" value="high">' 
 						 +'<param value="opaque" name="wmode">'
 						 +'<embed src="./view/tv/flash/attacktime.swf" height="240" width="320"  align="center" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>' 
					+'</object></td></tr></table>';
				break;
			}
		break;
		case 6:
			fadeAll();
			gameMenuStatus = true;
			switch(titleIndex) {
				case 0:
					document.getElementById("openChartId").innerHTML =  '<table style="border:1px solid gray;"><tr><td><img valign="middle" width="15px" height="15px" onclick="homePanelVod(1);" style="cursor: pointer;" src="/view/mobi/images/home.png" alt=""/></td><tr><td><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" height="240" width="320" >' 
 						 +'<param name="movie" value="./view/tv/flash/bikemania.swf">' 
 						 +'<param name="quality" value="high">' 
 						 +'<param value="opaque" name="wmode">'
 						 +'<embed src="./view/tv/flash/bikemania.swf" height="240" width="320" align="center" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>' 
					+'</object></td></tr></table>';
				break;
				case 1:
					document.getElementById("openChartId").innerHTML =  '<table style="border:1px solid gray;"><tr><td><img valign="middle" width="15px" height="15px" onclick="homePanelVod(1);" style="cursor: pointer;" src="/view/mobi/images/home.png" alt=""/></td><tr><td><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" height="240" width="320" >' 
 						 +'<param name="movie" value="./view/tv/flash/bikemania.swf">' 
 						 +'<param name="quality" value="high">' 
 						 +'<param value="opaque" name="wmode">'
 						 +'<embed src="./view/tv/flash/bikemania.swf" height="240" width="320" align="center" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>' 
					+'</object></td></tr></table>';
				break;
			}
		break;
		case 7:
			fadeAll();
			gameMenuStatus = true;
			switch(titleIndex) {
				case 0:
					document.getElementById("openChartId").innerHTML = '<table style="border:1px solid gray;"><tr><td><img valign="middle" width="15px" height="15px" onclick="homePanelVod(1);" style="cursor: pointer;" src="/view/mobi/images/home.png" alt=""/></td><tr><td><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" height="240" width="320" >' 
  							+'<param name="movie" value="./view/tv/flash/3dlogic.swf">' 
  							+'<param name="quality" value="high">' 
  							+'<param value="opaque" name="wmode">'
  							+'<embed src="./view/tv/flash/3dlogic.swf" height="240" width="320" align="center" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>' 
							+'</object></td></tr></table>';
				break;
				case 1:
				document.getElementById("openChartId").innerHTML = 
					'<table style="border:1px solid gray;"><tr><td><img valign="middle" width="15px" height="15px" onclick="homePanelVod(1);" style="cursor: pointer;" src="/view/mobi/images/home.png" alt=""/></td><tr><td><embed value="opaque" name="wmode" height="240" width="320" quality="high" name="LittleRedRidingHood:PostApocalypse" id="LittleRedRidingHood:PostApocalypse" src="./view/tv/flash/LittleRedRidingHoodPostApocalypse.swf" type="application/x-shockwave-flash"/></td></tr></table>';
				break;
				case 2:
					document.getElementById("openChartId").innerHTML = '<table style="border:1px solid gray;"><tr><td><img valign="middle" width="15px" height="15px" onclick="homePanelVod(1);" style="cursor: pointer;" src="/view/mobi/images/home.png" alt=""/></td><tr><td><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" height="240" width="320" >' 
  							+'<param name="movie" value="./view/tv/flash/alphattack.swf">' 
  							+'<param name="quality" value="high">'
  							+'<param value="opaque" name="wmode">' 
  							+'<embed src="./view/tv/flash/alphattack.swf" height="240" width="320" align="center" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>' 
							+'</object></td></tr></table>';
				break;
				case 3:
//					document.getElementById("openChartId").innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="625" height="422">' 
//  							+'<param name="movie" value="./view/tv/flash/BunchWeb1.swf">' 
//  							+'<param name="quality" value="high">' 
//  							+'<embed src="./view/tv/flash/BunchWeb1.swf" width="625" height="422" align="center" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>' 
//							+'</object>';
//				break;
				case 4:
					document.getElementById("openChartId").innerHTML = '<table style="border:1px solid gray;"><tr><td><img valign="middle" width="15px" height="15px" onclick="homePanelVod(1);" style="cursor: pointer;" src="/view/mobi/images/home.png" alt=""/></td><tr><td><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" height="240" width="320" >' 
  						+'<param name="movie" value="./view/tv/flash/bubbletrouble.swf">'
						+'<param name="quality" value="high">'
						+'<param value="opaque" name="wmode">' 
					  	+'<embed src="./view/tv/flash/bubbletrouble.swf" height="240" width="320"  align="center" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>' 
						+'</object></td></tr></table>';
				break;
			}
		break;
	}
}
var gameMenuPanel = 0;
function gamePanelKeyHandler(keyCodeNum) {
	switch(keyCodeNum) {
		case rcOK:
			var genreTitleIndex = 3*gameRowIndex + gameColIndex; 
			openSelectGame(gameGenreIndex, genreTitleIndex);
			break;
		case rcLEFT:
			if(gameColIndex == 0) {
				gameMenuPanel = 0;
				unSelGameTitle(gameRowIndex, gameColIndex);
 				return;
 			}
 			if(gameMenuPanel == 0) {
 				return;
 			}
 			if(gameColIndex >= 0) {
				unSelGameTitle(gameRowIndex, gameColIndex);
				--gameColIndex;
				selGameTitle(gameRowIndex, gameColIndex);
				return;
			}
 			break;
		break;
		case rcRIGHT:
			if(gameMenuPanel == 0) {
				selGameTitle(gameRowIndex, gameColIndex);
 				gameMenuPanel = 1;
 				return;
 			}
 			var curIndex = gameRowIndex*3 + gameColIndex;
 			if(curIndex == gameTitleTotal || gameColIndex ==2) {
 				return;
 			}
			if(gameColIndex >= 0) {
				unSelGameTitle(gameRowIndex, gameColIndex);
				gameColIndex++;
				selGameTitle(gameRowIndex, gameColIndex);
				return;
			}
		break;
		case rcUP:
 			if(gameMenuPanel == 0) {
 				if(gameGenreIndex == 0) { 								
					return;
				} 
				gameGenreIndex--;
				if(gameGenreCursor != 0) {
					unSelGamePanel();
					gameGenreCursor--;					
					selGameGenre();
				} else { // scroll
					var start = gameGenreIndex; 
					var end = gameGenreIndex + 9;	
					drawGameGenre(start, end);							
				}	
				drawGameTitle();		
 				return;
 			}
 			if(gameRowIndex == 0)
				return;
			unSelGameTitle(gameCursorIndex, gameColIndex);
			gameRowIndex--;
			if(gameCursorIndex != 0) { // if the cursor is moving up, no scroll is needed
				gameCursorIndex--;
				selGameTitle(gameCursorIndex, gameColIndex);
			} else { // scroll	
//				gameCursorIndex = 0;
				var start = 0;
				start = (startGameIndex < 3 ? 0 : startGameIndex -3);
				startGameIndex = start;
				
				var end = ((gameTitleTotal - start) > 8 ? (start + 8) : gameTitleTotal);	
				scrollGameTitle(start, end);
			}	
		break;
		case rcDOWN:
			if(gameMenuPanel == 0) {
 				if(gameGenreIndex == gameGenreTotal) { // last one												
					return;
				} 
				gameGenreIndex++;
				if(gameGenreCursor < 9) { // move cursor
					unSelGamePanel();
					gameGenreCursor++;					
					selGameGenre();
				} else { // scroll
					var start = gameGenreIndex - 9; 
					var end = gameGenreIndex;		
					drawGameGenre(start, end);							
				}			
				drawGameTitle();				
				return;
 			}
			var rowIndex = gameCursorIndex + 1;
			var columnIndex = gameColIndex;
			if(rowIndex < 3) {
				if(curGameIndex[rowIndex][columnIndex] == 0) {
					return;
				}
			}
			var gameCount = (gameTitleTotal/3);
 			if(gameRowIndex == parseInt(gameCount))
				return;
			unSelGameTitle(gameCursorIndex, gameColIndex);
			gameRowIndex++;
					
			if(gameCursorIndex < 2) { 
				gameCursorIndex++;
				selGameTitle(gameCursorIndex, gameColIndex);
			} else { // scroll	
				var start = 0;
				if(gameRowIndex < 3) {
					start = gameRowIndex;  
					startGameIndex = start;
				} else {
					start = startGameIndex + 3;
					startGameIndex = start;
				}
				gameCursorIndex = 2;
				var end = ((gameTitleTotal - start) > 8 ? (start + 8) : gameTitleTotal);
				scrollGameTitle(start, end);
			}	
		break;
		case rcMENU:
			if(gameMenuStatus) {
				gameMenuStatus = false;
				document.getElementById("openChartId").innerHTML = "";
				showVodPanel();
			} else {
				resetGamePanelValue();
				gameMenuStatus = false;
				gameActive = false;
				fadeAll();
				showGuidePanel();
				document.getElementById("openChartId").innerHTML = "";
			}
			break;
	}
}	

function scrollGameTitle(start, end) {	
	for(var i= 0; i < 3; i++) {
		for(var j =0; j < 3; j++) {
			document.getElementById("gameTitlePanelId" +i+ "" + j).innerHTML = "&nbsp;"
		}
	}
	var count = 0;
	for(var i = start; i <= end; i++) {
		var rowIndex = parseInt(count/3);
		var columnIndex = parseInt(count%3);
		var curImage = (gameMenuGenreIndex == 0 ? "./view/tv/images/widgets/gameMenu/gameMenu" + (gameGenreIndex + 1) + "/gameMenu" + (gameGenreIndex + 1)+"" + (i+1) + (gameGenreIndex + 1 == 1 ? ".png" : ".jpg") : '/ImageHandler?value=' + gameTitleIdCache[gameGenreIndex][i] + '&icon=-1&imageType=11') ;
		var gameMenuHTML = '<img id="gameTitle'+ rowIndex +'' +columnIndex+'" style="width:40px;height:40px;background:darkolivegreen;border:1px solid gray;cursor:pointer;" src="'+curImage+ '" />';
		document.getElementById("gameTitlePanelId" +i+ "" + j).innerHTML = gameMenuHTML;
		++count;
	}
}	
	