/*
 * Copyright (c) 2008 AKEEBO CORPORATION. All Rights Reserved.
 *
 * This software is the confidential and proprietary information ("Confidential Information") 
 * of AKEEBO CORPORATION ("AKEEBO CORP"). Any disclosure or use of such Confidential Information other 
 * than in accordance with the terms of the license under which it was received is strictly 
 * prohibited.
 *
 * AKEEBO CORP MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF 
 * THE SOFTWARE, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
 * OR NON-INFRINGEMENT. AKEEBO CORP SHALL NOT BE LIABLE FOR ANY DAMAGES
 * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
 * THIS SOFTWARE OR ITS DERIVATIVES.
 */
 
///////////////////////
// VOD CACHING

var genreCache = new Array();
var titleIdCache = new Array();
var fullTitleCache = new Array();
var assetNameCache = new Array();
var actorCache = new Array();

var mediumSummaryCache = new Array();
var yearCache = new Array();
var vodUseGraphicCache = new Array();
var genrePatternCache = new Array();
var ratingPatternCache = new Array();
var subtitlePatternCache = new Array();
var audioTypePatternCache = new Array();
var curVodPosition = 0;
var curColPosition = 0;
var vodServer = "";
var currentClick = 0;

/////////////////////
var vodVisible = false; // for screen saver 

var vodGenreCursor = 0;
var vodTitleCursor = 0;
var vodGenreCurrent = 0;
var vodTitleCurrent = 0;
//
var vodGenreSelected = 0;
var vodTitleSelected = 0;
var curAssetIndex = 0;
var vodCurCursor = 0;
var startIndex = 0;

var vodGenreMax = 9;
var vodTitleMax = 2;
var vodGenreTotal = 0;
var vodTitleTotal = 0;
var titleIndex = 0; // on pressing the right button goes on increasing the asset status.

var selectedTitleCache = new Array();

var selFullTitleCache = new Array();
var selAssetNameCache = new Array();
var selTitleIdCache = new Array();
var selSecurityCache = new Array();
var curVodIndex = new Array();
var selVodUseGraphic = new Array();
var selYearCache = new Array();
var vodClickCounts = 0;

var vodPage = 0;

var trickPlay = false;

var trickPlayHandle = null;
var trickPlayFrameHandle = null;

var vodScreenStatus = false;

/////////////////////

function launchVodPanel() {
	vodPage = 0; // genre page
//	alert(getSystemModel());
	//loadVodCache();
//	printStar();
//	curVodPosition = 1;
	updateGenrePanel();
	if(document.getElementById("vodTag") != null ) {
		document.getElementById("vodTag").innerHTML = records.key443;
	}
	if(document.getElementById("startHeader") != null) {
		document.getElementById("startHeader").innerHTML = records.key445 + ':';
		document.getElementById("dirrectorHeader").innerHTML = records.key446 + ':';
	}
//	document.getElementById("controlPanel1").style.display = "none";
}

function updateGenrePanel() {
	resetGenrePanel();
	var genreHTML = '';
	var i; 
	// aare all boyz hav d same prob..cnt remem d dates
	for(i=0; (genreCache.length > 10 && i < 10) || (genreCache.length <= 10 && i < genreCache.length); ++i) {
		genreHTML += '<tr><td ' + (statusInfo == 1 ? 'style="cursor:pointer;" id="genreId'+ i +'" onmouseover="selGenre(' + i + ');" onmouseout="unSelGenre(' + i + ');" onclick="openGenreAsset(' + i + ');"' : ' ') + ' width="155px" height="30px" valign=center nowrap>&nbsp;&nbsp;&nbsp;' + genreCache[i] + '</td></tr>';
	}
	document.getElementById("vodGenrePanel").innerHTML = ''
			+ '<table width=' + (genreHTML ? "165px" : "190px")+ ' align="left" border="0px" style="margin-top:10px;margin-left:5px;" cellspacing="0" cellpadding="0">' 
			+ (genreHTML ? genreHTML : '<tr><td width=' + (genreHTML ? "155px" : "190px") + ' height="30px" valign="middle" align="center" nowrap>' + records.key372 + '</td></tr>')								
			+ '</table>';
			
	if(document.getElementsByTagName) {  
		var table = document.getElementById("vodGenrePanel");   
		var rows = table.getElementsByTagName("tr");
		rows[0].style.backgroundImage = (genreHTML ? 'url("/view/tv/images/rowGenre.png")' : 'url("/view/tv/images/rowGenreBig.png")');  
		rows[0].style.backgroundRepeat = 'no-repeat'; 
	} 	
	buildTitleCache();
	feedType = "igmp";
}
// make a word power notes
// this should be called when genre is browsed up and down 
function buildTitleCache() {
	selAssetNameCache = new Array();
	selFullTitleCache = new Array();
	selectedTitleCache = new Array();
	selTitleIdCache = new Array();
	curVodIndex = new Array();
	selVodUseGraphic = new Array();
	selYearCache = new Array();
	selSecurityCache = new Array();
	resetTitlePanel();
	var i;
	var cnt = 0;	
//	alert(genreCache);
	for(i=0; i<genrePatternCache.length; ++i) {
		//alert(genrePatternCache[i] + " - matching - |" + genreCache[vodGenreSelected] + "| --> " + genrePatternCache[i].match("|" + genreCache[vodGenreSelected] + "|"));
		if(genrePatternCache[i] != null && genrePatternCache[i].match("#" + genreCache[vodGenreSelected] + "#")) {
			selectedTitleCache[i] = true;
			selAssetNameCache[cnt] = assetNameCache[i];
			selFullTitleCache[cnt] = fullTitleCache[i];
			selTitleIdCache[cnt] = titleIdCache[i];
			selVodUseGraphic[cnt] = vodUseGraphicCache[i];
			selYearCache[cnt] = yearCache[i];
			selSecurityCache[cnt] = vodSecurityCache[i];
			curVodIndex[cnt] = i; 	
			cnt++;
		} else {
			selectedTitleCache[i] = false;
		}	
	}
	vodTitleTotal = (cnt == 0 ? 0 : cnt - 1);	
	updateTitlePanel();
}	

// called when browsing thru genre
function updateTitlePanel() {
	
	var i;
	var titleCount = 0;
	var titleHTML  = '<tr><td colspan="7" width="425px" height="10px">&nbsp;</td></tr><tr><td width="15px" height="80px">&nbsp;</td>';
	var curIndex = curVodIndex[curAssetIndex];
	if(document.getElementById("vodTitlePanel") != null) {
		for(i=0; (selFullTitleCache.length >=9 && i<9) || (selFullTitleCache.length < 9 && i<selFullTitleCache.length); ++i) {
			titleCount++;
			if(i%3 == 0 && i != 0) {
				titleHTML += '</tr><tr><td colspan="7" width="425px" height="10px">&nbsp;</td></tr><tr><td width="15px" height="80px">&nbsp;</td>';
			}
			titleHTML += '<td align="center" valign="middle" nowrap style="width:100px;height:75px;'+ (statusInfo == 1 ? 'cursor:pointer;' : '') +'" '+ (statusInfo == 1 ? 'onmouseover="selVodAsset(' + i + ');" onmouseout="unSelVodAsset(' + i + ');" onclick="openVodAsset(' + i + ');"' : '' ) +' >' + '<img id="titleId'+ i + '" style="width:75px;height:75px;" alt="'+ selFullTitleCache[i]+ '" src='+ (selVodUseGraphic[i] == 1 ? '"/ImageHandler?value=' + selTitleIdCache[i] + '&icon=-1&imageType=3"' : '"./view/tv/images/vod/logo_none.png"' ) + '/>' + '</td><td width="15px" height="80px" >&nbsp;</td>';
		}
		if(titleCount > 0) {
			for(var j=0; j < (9 - titleCount) ; ++j) { 
				if((titleCount+j)%3 == 0) {
					titleHTML += '</tr><tr><td colspan="7" width="425px" height="10px">&nbsp;</td></tr><tr><td width="15px" height="80px">&nbsp;</td>';
				}
				titleHTML += '<td align="center" valign="middle" nowrap style="width:100px;height:80px;">&nbsp;</td><td width="15px" height="80px" >&nbsp;</td>';
			}
		}
		
		titleHTML += '</tr><tr><td colspan="7" width="425px" height="10px">&nbsp;</td></tr>';
		document.getElementById("vodTitlePanel").innerHTML = ''
			+ '<table width="425px"  height="300px" border=0 align="center" valign="middle" cellspacing="0" cellpadding="0" class="item">' 
				+ (selTitleIdCache.length > 0 ? titleHTML : '<tr><td width="425px" height="30" valign="middle" align="center" nowrap>' + records.key373 + ' </td></tr>') // no title available									
			+ '</table>';	
		var result = (selTitleIdCache[0] ? updateTitleNYear(0) : hideVodDetails());
	}
}

function hideVodDetails() {
//	document.getElementById("startHeader").style.visibility = "hidden";
//	document.getElementById("dirrectorHeader").style.visibility = "hidden";
	document.getElementById("titleContent").style.visibility = "hidden";
	document.getElementById("ratingPanel").style.visibility = "hidden";
	document.getElementById("ratingTagPanel").style.visibility = "hidden";
//	document.getElementById("yearPanel").style.visibility = "hidden"; 
	document.getElementById("yearTagPanel").style.visibility = "hidden";
	
//	document.getElementById("startPanel").style.visibility = "hidden";
//	document.getElementById("directorPanel").style.visibility = "hidden";
/*	
	document.getElementById("vodTitleLeft").style.visibility = "hidden";
	document.getElementById("vodTitleRight").style.visibility = "hidden";
*/
}

function updateTitleNYear(currentIndex) {
//	alert(currentIndex);
//	alert("0:  " + mediumSummaryCache[0] + "\n" + "1:  " + mediumSummaryCache[1] + "\n" + "2:  " + mediumSummaryCache[2] + "\n" +"3:  " +  mediumSummaryCache[3] + "\n" + mediumSummaryCache.length);
	var curIndex = curVodIndex[currentIndex];
//	alert("current index : " + curIndex +  ", rating index : " + ratingPatternCache[0] + ", actor index : " + actorCache[curIndex] + ", vod dir cache : " + vodDirCache[curIndex]);
//	alert("titleId: " + currentIndex + " : " + document.getElementById("titleId" + currentIndex));
//	if(document.getElementById("titleId" + currentIndex) != null)
//	document.getElementById("titleId" + currentIndex).style.background = "#ff7700";
	var title = selFullTitleCache[currentIndex];
	if(title.indexOf(".") >= 0) {
		title = title.substring(0, title.indexOf("."));
	}
	document.getElementById("titleContent").innerHTML = (selFullTitleCache[currentIndex] ? title : " ");// + (yearCache[curAssetIndex] ? " (" + yearCache[curAssetIndex] + ")" : " ");
	document.getElementById("ratingPanel").innerHTML =  (ratingPatternCache[curIndex] ? " " + ratingPatternCache[curIndex].replace(/#/, "") + '' : '&nbsp;');
	document.getElementById("ratingTagPanel").innerHTML = (ratingPatternCache[curIndex] ? records.key454 + ": " : "");
	document.getElementById("yearTagPanel").innerHTML = (selYearCache[currentIndex] && selYearCache[currentIndex] != 0 ?  records.key455 + ": " + selYearCache[currentIndex] : "");
}

function emptyAssetContent() {
	document.getElementById("yearTagPanel").innerHTML = "";
	document.getElementById("ratingTagPanel").innerHTML = "";
	document.getElementById("ratingPanel").innerHTML = "";
	document.getElementById("titleContent").innerHTML = "";
}
function updateVodGuide() {
	return;
	////////////////////////////////////
	// vod Guide
	var curIndex = curVodIndex[curAssetIndex];
	if(document.getElementById("vodTitleGuide") != null) {
		document.getElementById("vodTitleGuide").innerHTML = ''
		+ '<table align="left" cellspacing="0" cellpadding="4" style="width:415px;text-align: justify;"><tr>' 
			//+ '<tr><td style="font-weight:bold;font-size:13px;vertical-align:top;>' + fullTitleCache[i] + (yearCache[i] && yearCache[i] != 0 ? '&nbsp;(' + yearCache[i] + ')' : '') + '</td>' 
		+ '<td style="font-weight:bold;font-size:13px;vertical-align:top;text-align: justify;">'
		+ (mediumSummaryCache[curIndex] ? 
					(mediumSummaryCache[curIndex].length > 210 ? mediumSummaryCache[curIndex].substring(0, 210) + '...' : mediumSummaryCache[curIndex]) 
			: '')
		+ '</td>' 				
		+ '</tr>' 					
		+ '</table>';	
	}
	
//	var i;
//	var cnt = 0;
////	alert(fullTitleCache);
//	if(genreCache.length == 0) {
//		document.getElementById("vodTitleGuide").innerHTML = '';
////		document.getElementById("vodTitleImg").innerHTML = '';
//		return;
//	}
//	
//	for(i=0; i<selectedTitleCache.length; ++i) {	
//		if(selectedTitleCache[i] == true) {		
//			if(cnt++ == vodTitleSelected) { // this is it
//				// i is the eye into the original array
////				alert(vodUseGraphicCache);
////				if(vodUseGraphicCache[i] == '1')	{			
////					document.getElementById("vodTitleImg").innerHTML = '<img alt="" width="110px" height="150px" src="/static/images/vod/logo_' + titleIdCache[i] + '.jpg">';
////				} else {
////					document.getElementById("vodTitleImg").innerHTML = '<img alt="" width="110px" height="150px" src="/view/tv/images/logo_none.gif">';
////				}	
//// 			
//				document.getElementById("vodTitleGuide").innerHTML = ''
//					+ '<table align="left" cellspacing="0" cellpadding="4" style="width:415px;text-align: justify;"><tr>' 
//						//+ '<tr><td style="font-weight:bold;font-size:13px;vertical-align:top;>' + fullTitleCache[i] + (yearCache[i] && yearCache[i] != 0 ? '&nbsp;(' + yearCache[i] + ')' : '') + '</td>' 
//						+ '<td style="font-weight:bold;font-size:13px;vertical-align:top;text-align: justify;">'
//							+ (mediumSummaryCache[i] ? 
//										(mediumSummaryCache[i].length > 210 ? mediumSummaryCache[i].substring(0, 210) + '...' : mediumSummaryCache[i]) 
//								: '')
//						+ '</td>' 				
//					+ '</tr>' 					
//					+ '</table>';	
//					
//				
//				break;														
//			}
//		}
//	}			
//	var mediumCache=mediumSummaryCache[i]; 
//	if(cnt == 0) {
////		document.getElementById("vodTitleImg").innerHTML = '';		
//		document.getElementById("vodTitleGuide").innerHTML = ''
//			+ '<table align=left cellspacing="0" cellpadding="4" class="item">' 
//				+ '<tr><td valign=top width="100%" style="font-weight:bold;font-size:15px"></td></tr>' 
//				+ '<tr><td valign=top width="100%">' 
//				+ '</td></tr>' 				
//				+ '<tr><td valign=top width="100%">' 
//				+ '</td></tr>' 					
//				+ '<tr><td valign=top width="100%">' 
//				+ '</td></tr>' 					
//			+ '</table>';			
//	}
//		
} // 

function scrollGenrePage(start, end) {
	var genreHTML = '';
						
	var i; 
	for(i = start; i <= end; ++i) {
		genreHTML += '<tr><td style="cursor:pointer;" id="genreId'+ i +'" onmouseover="selGenre(' + i + ');" onmouseout="unSelGenre(' + i + ');" onclick="openGenreAsset(' + i + ');" width="155px" height="30px" valign="middle" nowrap>&nbsp;&nbsp;&nbsp;' + genreCache[i] + '</td></tr>';
	}
		
	document.getElementById("vodGenrePanel").innerHTML = ''
								+ '<table width=' + (genreHTML ? "165px" : "190px")+ ' align="left" border="0px" style="margin-top:10px;margin-left:5px;" cellspacing="0" cellpadding="0">' 
									+ (genreHTML ? genreHTML : '<tr><td width=' + (genreHTML ? "155px" : "190px")+ ' height="28px" valign="middle" align="center" nowrap>'  + records.key372 +'</td></tr>')	 // no genre availabe							
								+ '</table>';
	highlightGenre();				
}

function scrollTitlePage(start, end) {
	vodPage = 1;
	document.getElementById("vodTitlePanel").innerHTML = '';
	var titleHTML  = '<tr><td colspan="7" width="425px" height="10px">&nbsp;</td></tr><tr><td width="15px" height="80px">&nbsp;</td>';
	var count = 0;
	if(document.getElementById("vodTitlePanel") != null) {
		for(i = start; i <= end; ++i) { 
			if(i%3 == 0 && i != 0 && count != 0) {
				titleHTML += '</tr><tr><td colspan="7" width="425px" height="10px">&nbsp;</td></tr><tr><td width="15px" height="80px">&nbsp;</td>';
			}
			count++;
			titleHTML += '<td align="center" valign="middle" nowrap style="width:100px;height:75px;'+ (statusInfo == 1 ? 'cursor:pointer;' : '' )+'" '+ (statusInfo == 1 ? ' onmouseover="selVodAsset(' + i + ');" onmouseout="unSelVodAsset(' + i + ');" onclick="openVodAsset(' + i + ');" ' : '' ) +'  >' + '<img id="titleId'+ i + '" style="width:75px;height:75px;" alt="'+ selFullTitleCache[i]+ '" src='+ (selVodUseGraphic[i] == 1 ? '"/ImageHandler?value=' + selTitleIdCache[i] + '&icon=-1&imageType=3"' : '"./view/tv/images/vod/logo_none.png"' ) + '/>'+'</td><td width="15px" height="80px" >&nbsp;</td>';
		}
		if(count > 0) {
			for(var j=0; j < (9 - count) ; ++j) { 
				if((count+j)%3 == 0) {
					titleHTML += '</tr><tr><td colspan="7" width="425px" height="10px">&nbsp;</td></tr><tr><td width="15px" height="80px">&nbsp;</td>';
				}
				titleHTML += '<td align="center" valign="middle" nowrap style="width:100px;height:80px;">&nbsp;</td><td width="15px" height="80px" >&nbsp;</td>';
			}
		}
		titleHTML += '</tr><tr><td colspan="7" width="425px" height="10px">&nbsp;</td></tr>';
		document.getElementById("vodTitlePanel").innerHTML = ''
			+ '<table width="425px"  height="310px" border=0 align="center" valign="middle" cellspacing="0" cellpadding="0" class="item">' 
				+ (selTitleIdCache.length > 0 ? titleHTML : '<tr><td width="425px" height="30" valign="middle" align="center" nowrap>' + records.key373 + ' </td></tr>') // no title available									
			+ '</table>';		
		var result = (selTitleIdCache[curVodPosition-1] ? updateTitleNYear(curVodPosition-1) : hideVodDetails());
		if(document.getElementById("titleId" + (curVodPosition-1)) != null)
			document.getElementById("titleId" + (curVodPosition-1)).style.border = "2px solid paleGoldenRod";
	}
}

function resetGenrePanel() {
	vodGenreTotal = (genreCache.length == 0 ? 0 : genreCache.length - 1);
	vodGenreCursor = 0;
	vodGenreCurrent = 0;	
	vodGenreSelected = 0;
	vodGenreClicks = 0;
}

function resetTitlePanel() {	
	var i;
	for(i=0; i<assetNameCache.length; ++i) {
		selectedTitleCache[i] = true;		
	}
	vodTitleTotal = assetNameCache.length - 1;
	vodPage = 0;
	curVodPosition = 0;
	vodCurCursor = 0;
	vodTitleCursor = 0;
	vodTitleCurrent = 0;
	vodTitleSelected = 0;	
	curColPosition = 0;
	startIndex = 0;
		
}

function changeGenreCursor() {
	if(document.getElementsByTagName) {  
		var table = document.getElementById("vodGenrePanel");   
		var rows = table.getElementsByTagName("tr");
	   	var i;
	   	for(i = 0; i < rows.length; i++) {   
	   		if(i == vodGenreCursor) {
	       		rows[i].style.backgroundImage = 'url("/view/tv/images/rowGenre.png")';   
	       		rows[i].style.backgroundRepeat = 'no-repeat';
	    	} else {
	       		rows[i].style.backgroundImage = 'none';  
	    	}
	   }
//	   alert(rows[vodGenreCursor].style.backgroundImage);
	} 
}

function changeTitleCursor() {
	return;
	if(document.getElementsByTagName) {  
		var table = document.getElementById("vodTitlePanel");   
		var rows = table.getElementsByTagName("tr");
	   	var i;
	   	for(i = 0; i < rows.length; i++) {   
	   		if(i == vodTitleCursor) {
	       		rows[i].style.backgroundImage = 'url("/view/tv/images/rowTitle.png")';   
	    	} else {
	       		rows[i].style.backgroundImage = 'none';  
	    	}
	   }
	} 
}


function highlightGenre() {
	if(document.getElementsByTagName) {  
		var genreTable = document.getElementById("vodGenrePanel");   
		var genreRows = genreTable.getElementsByTagName("tr");
		genreRows[vodGenreCursor].style.backgroundImage = 'url("/view/tv/images/rowGenre.png")';  
		genreRows[vodGenreCursor].style.backgroundRepeat = 'no-repeat';  
		
		if( document.getElementById("vodTitlePanel") != null ) {			
			var titleTable = document.getElementById("vodTitlePanel");   
			var titleRows = titleTable.getElementsByTagName("tr");
			titleRows[vodTitleCursor].style.backgroundImage = 'none';   
		}
	} 	
}

function highlightTitle() {
//	document.getElementById("titleId" + vodGenreCursor).style.border = "1px solid white";
	/*
	if(document.getElementsByTagName) {  
		var genreTable = document.getElementById("vodGenrePanel");   
		var genreRows = genreTable.getElementsByTagName("tr");
		genreRows[vodGenreCursor].style.backgroundImage = 'none';   
			
		var titleTable = document.getElementById("vodTitlePanel");   
		var titleRows = titleTable.getElementsByTagName("tr");
		titleRows[vodTitleCursor].style.backgroundImage = 'url("/view/tv/images/rowTitle.png")';   
	} 	
	*/
}

///////////////////////////////
function startVodStream() {
//	alert("vod alert is: " + selSecurityCache[vodTitleSelected] + ", assest name is: " + selAssetNameCache[vodTitleSelected]);
	feedType = "rtsp";
	vodActive = true;
	if(!selAssetNameCache[vodTitleSelected])
		return;

//	var rtspUrl = 'src=rtsp://192.168.1.185:8554/pushkal.ts;servertype=ncube';
	//'src=rtsp://' + vodServer + '/' + selAssetNameCache[vodTitleSelected] + ';servertype=ncube'; 	
	var rtspUrl = 'src=rtsp://' + vodServer + '/' + selAssetNameCache[vodTitleSelected] + ';servertype=ncube';
//	alert(selAssetNameCache[vodTitleSelected]);
				
	if(stbTypeId == 7){
		var hasRequestedVersion = DetectFlashVer(10, 0, 0);
		if(!hasRequestedVersion) {
			showStatusPanel();
			document.getElementById("statusMessagePanel").innerHTML = 'get the flash player now on http://www.adobe.com/go/getflashplayer/';
			return;
		} 
		var fileName = selAssetNameCache[vodTitleSelected];
//		fileName = "rtmp://192.168.1.120/vod/high1.flv";
		var file = fileName.substring(0, fileName.indexOf("."));
		var exten = fileName.substring(fileName.indexOf(".")+1, fileName.length).toUpperCase();
	
		if(exten == "JPEG" || exten == "JPG" || exten == "GIF" || exten == "PNG" || exten == "BMP" || exten == "EXE" || exten == "TIF" || exten == "ICO" || exten == "ZIP" || exten == "TXT" || exten == "DOC" || exten == "DOCX") {
			showStatusPanel();
			document.getElementById("statusMessagePanel").innerHTML = records.key1623;
			return;
		} else {
			if (exten == "MP4" || exten == "MOV" || exten == "F4V" ) {
//				fileName = "rtmp://72.17.154.130:1935/vod/mp4:" + fileName;
				fileName = "mp4:" + fileName;
			} else {
//				fileName = "rtmp://72.17.154.130:1935/vod/"+ file + ".flv";
				fileName = file + ".flv";
			}	
			fileName = file;
			var hostAddr = fmsServerIp + ":" + fmsServerPort;
//			fileName = "jal";
//			if(statusInfo == 1 && document.getElementById("onNowPanelHome") != null)	{
//				document.getElementById("onNowPanelHome").style.visibility = "visible";
//			}
			document.getElementById("epgPlayer").innerHTML = 
//			"<object type='application/x-shockwave-flash' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0' width='623' height='422' id='flvPlayer'>"
//					  												+ "<param name='bgcolor' value='#000000'/>"
//					  												+ "<param name='wmode' value='opaque'>"
//					  												+ "<param name='allowFullScreen' value='true'>"
//					  												+ "<param name='movie' value='http://akeebo.tv/view/online/embed/swfs/player.swf?movie="+ fileName +"&amp;bgcolor=0x000000&fgcolor=0x6f6e6d&autoplay=true&autoload=true&autorewind=on&clickurl=&clicktarget='>"
//					  												+ "<embed src='http://akeebo.tv/view/online/embed/swfs/player.swf?movie="+ fileName +"&amp;bgcolor=0x000000&fgcolor=0x6f6e6d&autoplay=true&autoload=true&autorewind=on&clickurl=&clicktarget=' width='623' height='422' wmode='opaque' bgcolor='#000000' scale='exactfit' allowFullScreen='true' type='application/x-shockwave-flash'>"
//					 												+ "</object>";
					 												'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="624" height="422" id="mediacasterstreammanagerLive" align="middle">'
																	+ '<param name="allowScriptAccess" value="sameDomain" />'
																	+ '<param name="allowFullScreen" value="true" />'
																	+ '<param name="movie" value="/view/tv/flash/vodTvPlayer.swf" />'
																	+ '<param name="quality" value="high" />'
																	+ '<param name="bgcolor" value="#000000" />'
																	+ '<param name="wmode" value="opaque">'
																	+ '<param name="FlashVars" value="streamName='+ fileName +'&ip='+ hostAddr +'&security='+ selSecurityCache[vodTitleSelected] +'" />'
																	+ '<embed src="/view/tv/flash/vodTvPlayer.swf" FlashVars="streamName='+ fileName +'&ip='+ hostAddr +'&security='+ selSecurityCache[vodTitleSelected] +'" wmode="opaque" quality="high" bgcolor="#000000" width="624" height="422" name="mediacasterstreammanagerLive" align="middle" allowScriptAccess="sameDomain" allowFullScreen="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'
																+ '</object>';
			if(document.getElementById("epgPlayer") != null) {
				document.getElementById("epgPlayer").className = "epgPlayer";
			}		
			if(stbTypeId == 7) {
				document.getElementById("homePanelImage").style.visibility = "visible";
			} 
//			if(statusInfo == 1)	{		
//				if(document.getElementById("onNowPanelHome") != null)
//					document.getElementById("onNowPanelHome").style.visibility = "visible";
//			}											
			document.getElementById("waitPanel").style.backgroundImage="none";
		} 
	} else {
		document.getElementById("waitPanel").style.backgroundImage="none";
		playStream(rtspUrl);
	}
}
	
function fastForward() {
	setSpeedStream(6);	
	trickPlayHandle = window.setInterval('getFwdVideoFrames()', 4000);		
}

function getFwdVideoFrames() {
	continueStream();
	trickPlayFrameHandle = window.setTimeout('setSpeedStream(6)', 500);
}

function getRwrVideoFrames() {
	continueStream();
	trickPlayFrameHandle = window.setTimeout('setSpeedStream(-6)', 500);
}

function rewind() {
	setSpeedStream(-6);
	trickPlayHandle = window.setInterval('getRwrVideoFrames()', 4000);	
}

////////////////////////////////////
// GET VOD
function loadVodCache() {
	var postData = "method=getvodcachemenu" + "&serial=" + serial;
    var responseHandler = { success:loadVodCachesSuccessHandler, 
				            failure:loadVodCacheFailureHandler,
				            argument: {}
			             };
    request = YAHOO.util.Connect.asyncRequest('POST', serverUrl, responseHandler, postData);
 	return false;
}

var loadVodCachesSuccessHandler = function(o) {
	var response = o.responseText;
  	 	
	if(response.length > 0) {
		var data = response.split('-$#-');
	    genreCache = data[0].split('-@#-');
	    titleIdCache = data[1].split('-@#-');
	    fullTitleCache = data[2].split('-@#-');
	    assetNameCache = data[3].split('-@#-');
	    actorCache = data[4].split('-@#-');
	    mediumSummaryCache = data[5].split('-@#-');
	    yearCache = data[6].split('-@#-');
	    vodUseGraphicCache = data[7].split('-@#-');
	    genrePatternCache = data[8].split('-@#-');
	    ratingPatternCache = data[9].split('-@#-');
	    subtitlePatternCache = data[10].split('-@#-');
	    audioTypePatternCache = data[11].split('-@#-');
						
		genreCache[0] == '' ? genreCache.shift() : '';
		titleIdCache[0] == '' ? titleIdCache.shift() : '';					
		fullTitleCache[0] == '' ? fullTitleCache.shift() : '';
		assetNameCache[0] == '' ? assetNameCache.shift() : '';
		actorCache[0] == '' ? actorCache.shift() : '';
		mediumSummaryCache[0] == '' ? mediumSummaryCache.shift() : '';
		yearCache[0] == '' ? yearCache.shift() : '';
		vodUseGraphicCache[0] == '' ? vodUseGraphicCache.shift() : '';
		genrePatternCache[0] == '' ? genrePatternCache.shift() : '';
		ratingPatternCache[0] == '' ? ratingPatternCache.shift() : '';
		subtitlePatternCache[0] == '' ? subtitlePatternCache.shift() : '';
		audioTypePatternCache[0] == '' ? audioTypePatternCache.shift() : '';								    
	}	
	updateGenrePanel();				
	//window.setTimeout('showVodPanel();', 2000); 					
}

var loadVodCacheFailureHandler = function(o) {
 	showStatusPanel();
	document.getElementById("statusMessagePanel").innerHTML = ''; 
	document.getElementById("statusMessagePanel").innerHTML = records.key270 +". <br>" + ((companyName != null && companyPhoneNum != null) ? "" + records.key271 + " " + companyName + " " + records.key272 + " " + companyPhoneNum + "." : "");
	window.setTimeout('hideStatusPanel();', 20000);
}

function vodKeyNvg(keyCodeNum) {
	if(selFullTitleCache.length == 0) {
		return;
	}
	if(vodPage == 0) {
		return;
	}
	switch(keyCodeNum) {
		case rcRIGHT:
			if(curVodPosition == selFullTitleCache.length) {
				vodPage = 0;
//				curVodPosition = curVodPosition - vodCurCursor;
//				alert(curVodPosition + " : " + selFullTitleCache.length + " : " + vodCurCursor);
				if(document.getElementById("titleId" + (curVodPosition-1)) != null) {
					document.getElementById("titleId" + (curVodPosition-1)).style.border = "2px solid transparent";
				}
				curVodPosition = curVodPosition - vodCurCursor;	
				vodCurCursor = 0;
				updateTitleNYear(0);
//				curVodPosition = 0;
				return;
			}
			vodCurCursor++;
			if(vodCurCursor > 3 &&  curVodPosition != 0 ) { // [moving right at left moved at pic]
				if(document.getElementById("titleId" + (curVodPosition-1)) != null) {
					document.getElementById("titleId" + (curVodPosition-1)).style.border = "2px solid transparent";
				}
				emptyAssetContent();
				updateTitleNYear(0);
				vodPage = 0;
				curVodPosition = curVodPosition -3;
				vodCurCursor = 0;
				return;
			}
			if(curVodPosition >= 0) {
				if(document.getElementById("titleId" + (curVodPosition - 1)) != null) {
					document.getElementById("titleId" + (curVodPosition - 1)).style.border = "2px solid transparent";
				}
				if(document.getElementById("titleId" + curVodPosition) != null)
					document.getElementById("titleId" + curVodPosition).style.border = "2px solid paleGoldenRod";
//				alert("cur vod position : " + curVodPosition);
				updateTitleNYear(curVodPosition);
				curVodPosition++;
				return;
			}
		break;
		case rcLEFT: // below commented code is there for the further enhancement or changes 
//			if(vodPage == 0) {
//				alert(curVodPosition + " :  " + vodCurCursor);
//				if((curVodPosition + 3) == vodTitleTotal) {
//					curVodPosition += 3; 
//					vodPage = 1;
//					vodCurCursor = 3;
//				} 
////		curVodPosition = (((curVodPosition + 3) == vodTitleTotal) ? curVodPosition )
////				vodPage = 1;
////				if((curVodPosition + 1) == vodTitleTotal) {
////					if(document.getElementById("titleId" + (curVodPosition + vodCurCursor)) != null) {
////						document.getElementById("titleId" + curVodPosition).style.border = "2px solid paleGoldenRod";
////					}
////				}
//				return;
//			}
			vodCurCursor--;
			curVodPosition--;
			if(vodCurCursor == 0) { // [moving right at left moved at pic]
				if(document.getElementById("titleId" + curVodPosition) != null) {
					document.getElementById("titleId" + curVodPosition).style.border = "2px solid transparent";
				}
				emptyAssetContent();	
				updateTitleNYear(0);
				vodPage = 0;
				vodCurCursor = 0;
				return;
			}
			if(curVodPosition >= 0) {
				if(document.getElementById("titleId" + curVodPosition) != null) {
					document.getElementById("titleId" + curVodPosition).style.border = "2px solid transparent";
				}
				if(document.getElementById("titleId" + (curVodPosition - 1)) != null)
					document.getElementById("titleId" + (curVodPosition-1)).style.border = "2px solid paleGoldenRod";
				updateTitleNYear(curVodPosition-1);
				return;
			}
		break;
		case rcUP:
			if(vodPage == 1) {
				vodTitleCurrent--;
				vodTitleCurrent = (vodTitleCurrent < 0 ? ++vodTitleCurrent : vodTitleCurrent);
				if((curVodPosition >= 1 && curVodPosition <= 3)) { // first one
					vodTitleCurrent = 0;
					vodTitleCursor = 0;
					return;
				} // 
				
				if(vodTitleCursor != 0) { // change image, don't scroll though
//					alert("1 : vodCurCursor = " + vodCurCursor + " : vodTitleCurrent = " + vodTitleCurrent + " : vodTitleCursor = " + vodTitleCursor);
					vodTitleCursor--;	
					if(document.getElementById("titleId" + (curVodPosition - 1)) != null)
						document.getElementById("titleId" + (curVodPosition - 1)).style.border = "2px solid transparent";
					curVodPosition -= 3;	
					if(document.getElementById("titleId" + (curVodPosition - 1)) != null)
						document.getElementById("titleId" + (curVodPosition - 1)).style.border = "2px solid paleGoldenRod";
					updateTitleNYear(curVodPosition-1);
				} else {
//					alert("2 : vodCurCursor = " + vodCurCursor + " : vodTitleCurrent = " + vodTitleCurrent + " : vodTitleCursor = " + vodTitleCursor);
					--curColPosition;
					vodTitleCursor = 0;
					var start = 0;
					start = (startIndex < 3 ? 0 : startIndex -3);
					startIndex = start;
					
//					var start = (vodTitleCurrent < 3 ? vodTitleCurrent -1 : vodTitleCurrent);
//					var start = vodTitleCurrent - 1; 
					var end = ((vodTitleTotal - start) > 8 ? (start + 8) : vodTitleTotal);
					curVodPosition -= 3;
//					alert("startIndex : " + startIndex + "start : " + start + ", end : " + end + ", vodTitleCursor : " + vodTitleCursor + ", curVodPosition : " + curVodPosition + ", vodTitleCurrent : " + vodTitleCurrent);
//					vodTitleCurrent = (start == 3 ? 0 : vodTitleCurrent);
					--vodClickCounts;
					scrollTitlePage(start, end);	
				}		
			}
		break;
		case rcDOWN:
			if(vodPage == 1) {
				var countedVod = (vodTitleTotal/3) + 1;
				if((vodTitleCurrent == parseInt(countedVod))) { // last one 
					--vodTitleCurrent;
					return;
				}
				++vodTitleCurrent;
				if(vodTitleCursor < vodTitleMax) { // if the cursor is moving down, no scroll is needed
					if(document.getElementById("titleId" + (curVodPosition - 1)) != null) {
						document.getElementById("titleId" + (curVodPosition - 1)).style.border = "2px solid transparent";
					}
					curVodPosition += 3;
					if(document.getElementById("titleId" + (curVodPosition - 1)) != null) {
						document.getElementById("titleId" + (curVodPosition - 1)).style.border = "2px solid paleGoldenRod";
						updateTitleNYear(curVodPosition-1);
						vodTitleCursor++;
					} else {
						curVodPosition -= 3;
						if(document.getElementById("titleId" + (curVodPosition - 1)) != null)
							document.getElementById("titleId" + (curVodPosition - 1)).style.border = "2px solid paleGoldenRod";
						updateTitleNYear(curVodPosition-1);
						vodTitleCurrent--;
					}
				} else {
					if((parseInt(countedVod)-3) == curColPosition) {
						return;//alert(" curColPosition = " + curColPosition);
					}
					curVodPosition += 3;
					var start = 0;
					if(vodTitleCurrent < 3) {
						start = vodTitleCurrent; //(vodTitleCurrent > 3 ? vodTitleCurrent + 2 : vodTitleCurrent); 
						startIndex = start;
					} else {
						start = startIndex + 3;
						startIndex = start;
					}
					vodTitleCursor = 2;
					var end = ((vodTitleTotal - start) > 8 ? (start + 8) : vodTitleTotal);
					if(curVodPosition > selTitleIdCache.length) {
						curVodPosition -= 3;
						vodTitleCursor -=1;
					} 
					++curColPosition;
					++vodClickCounts;
					scrollTitlePage(start, end);
				}		
			}	
		break;
		case rcOK:
			if(curVodPosition >= 0) {
				vodTitleSelected = curVodPosition - 1;
				curAssetIndex = vodTitleSelected;
//				vodTitleSelected = (curVodPosition >= selTitleIdCache.length ? (curVodPosition-1) : 0);// < 0 ? 0 : curVodPosition-1);
//				alert(curVodPosition);
			}
			
		/*
			if(curVodPosition == 1) {
				++curAssetIndex;
				curAssetIndex = (curAssetIndex == (selFullTitleCache.length) ? 0 : curAssetIndex); 
				document.getElementById("vodTitleLeft").src= wlSelImg.src;
				updateTitlePanel();
			}
			if(curVodPosition == 2) {
				vodTitleSelected = curAssetIndex;
			}
			if(curVodPosition == 3) {
				--curAssetIndex;
				curAssetIndex = (curAssetIndex < 0 ? selFullTitleCache.length-1 : curAssetIndex); 
				document.getElementById("vodTitleRight").src= wrSelImg.src;
				updateTitlePanel();
			}
			if(curVodPosition == 0) {
				vodPage = 0;
			}
			*/
		break;
	}
}

function resetVod() {
	if(vodActive) {
		vodPage = 0;
		curVodPosition = 0;
		launchVodPanel(); 
		hideStatusPanel();
		document.getElementById("statusMessagePanel").innerHTML = '';
		fadeAll();
		document.getElementById("layer8").style.visibility = "visible";	
	}
}

function selVodAsset(index) {
	vodPage = 1;
	vodTitleCurrent = parseInt(index / 3);
	vodTitleCursor = vodTitleCurrent - vodClickCounts;
	vodCurCursor = parseInt(index % 3) + 1;
//	alert(curVodPosition-1);
	if(document.getElementById("titleId" + curVodPosition) != null) {
		document.getElementById("titleId" + curVodPosition).style.border = "2px solid transparent";
	}
	if(document.getElementById("titleId" + index) != null) {
		document.getElementById("titleId" + index).style.border = "2px solid paleGoldenRod";
	}
	curVodPosition = index;
//	alert("cur vod position seeeeeee : " + curVodPosition);
	updateTitleNYear(curVodPosition);
}
 
function unSelVodAsset(index) {
	vodPage = 1;
	return;
	if(document.getElementById("titleId" + index) != null) {
		document.getElementById("titleId" + index).style.border = "2px solid transparent";
	}
}	
	 
function openVodAsset(index) {
	curVodPosition = index +1;
	vodPage = 1;
	keyActionHandler(rcOK);
}	
	
function escapeVodPanel() {
//	document.getElementById("controlPanel1").style.display = "block";
	vodActive = true;
	menuActive = true;
	keyActionHandler(rcMENU);
}
var vodGenreClicks = 0;
function moveVodPageUp() {
	if(vodPage == 0) {
//		if(vodGenreCurrent > 0) {
//			--vodGenreClicks;
//		}
		keyActionHandler(rcUP);
		return;
	}
	
	vodPage = 1;
	keyActionHandler(rcUP);
	return;
//	
//	if(vodTitleTotal > 9) {
//		vodPage = 1;
////		var curIndex = parseInt((vodTitleTotal/3) + 1);
////		curIndex = parseInt(curIndex/2);
//		if(currentClick == 0) {
//			return;
//		}
//		--currentClick;
//		var start = (currentClick*3);
//		var end = ((start+8) > vodTitleTotal ? vodTitleTotal : start+8);
//		vodTitleCursor = 2;
//		curVodPosition -= 3;//start+1;
//		curVodPosition = (curVodPosition < 0 ? (curVodPosition = curVodPosition +3) : curVodPosition);
////		alert(curVodPosition);
////		keyActionHandler(rcUP);
//		scrollTitlePage(start, end);
//	}
}

function moveVodPageDown() {
	if(vodPage == 0) {
//		if(vodGenreCurrent < vodGenreTotal) {
//			++vodGenreClicks;
//		}
		keyActionHandler(rcDOWN);
		return;
	}
	vodPage = 1;
	keyActionHandler(rcDOWN);
	return;
//	if(vodTitleTotal > 9) {
//		vodPage = 1;
//		var curIndex = parseInt((vodTitleTotal/3) + 1);
//		curIndex = parseInt(curIndex/2);
//		if(currentClick == curIndex) {
//			return;
//		}
//		++currentClick;
//		var start = (currentClick*3);
//		var end = ((start+8) > vodTitleTotal ? vodTitleTotal : start+8);
//		vodTitleCursor = 0;
//		curVodPosition += 3; //start+1;
//		curVodPosition = (curVodPosition > vodTitleTotal ? (curVodPosition = curVodPosition -3) : curVodPosition);
////		keyActionHandler(rcDOWN);
////		alert(curVodPosition);
//		scrollTitlePage(start, end);
//	}
}

function showVod(index) {
	document.getElementById("vodMove" + index).style.background = "#fcf3b8";
}

function hideVod(index) {
	document.getElementById("vodMove" + index).style.background = "none";
}

function selGenre(index) {
//	alert(vodGenreCursor);
	vodPage = 0;
//	if(index > 9 ) {
//		vodGenreCursor;
//	} else {
//		vodGenreCursor = index - vodGenreClicks;
//	}
	vodGenreCursor = index - vodGenreClicks;
//	alert(index + " : " + vodGenreClicks);
	vodGenreSelected = vodGenreCurrent = index;
	changeGenreCursor();
	buildTitleCache();
}	

function unSelGenre(index) {
	return;
	document.getElementById("genreId" + index).style.background = "none";
}	

function openGenreAsset(index) {
	keyActionHandler(rcOK);
}		
	
function callFullGuide() {
	if(stbTypeId == 7) {
		document.getElementById("homePanelImage").style.visibility = "visible";
	} 
	keyActionHandler(rcMENU);
}	

function gotoVodPanel() {
	if(stbTypeId == 7) {
		document.getElementById("homePanelImage").style.visibility = "hidden";
	} 
	keyActionHandler(rcMENU);
}

function showHomeImage(index) {
	document.getElementById("homeImage").style.background = (index == 1 ?"#fcf3b8" : "none");
}

///////////////////////	
// END VOD PAGE ////////////////
///////////////////////