/*
 * 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.
 */
 
///////////////////////
// AOD CACHING


var boxInfo = 1;
var vodRowIndex = 0;
var vodColumnIndex = 0;
var vodStartIndex = 0;
var vodCursorIndex = 0;
var vodTitleTotal = 0;
var vodTitleIndexArr = new Array();
var curVodIndex = new Array();
var curGenreCache = new Array();
var vodPlayStatus = false;
var currVodIndex = -1;
var vodTitleClick = 0;
var flashActive = false;
/////////////////////
var vodVisible = false; // for screen saver 
var curVodPosition = 0;
var vodGenreCursor = 0;
var vodTitleCursor = 0;
var vodGenreCurrent = 0;
var vodTitleCurrent = 0;
var vodServer = "";
var vodGenreSelected = 0;
var vodTitleSelected = 0;

var vodCurCursor = 0;
var curVodPosition = 0;

var vodGenreMax = 3;
var vodTitleMax = 1;
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 keyPanelActive = false;
var playStatus = false;
var vodStartIndex = 0;
var vodCurColPosition = 0;
var vodGenreClicks = 0;
var vodPage = 0;
var vodClickCounts = 0;
var trickPlay = false;

var trickPlayHandle = null;
var trickPlayFrameHandle = null;
var cBtnPosition = 0;
var currentVodClick = 0;

//////////////////////////
// AOD PANEL
/////////////////////

function launchVodPanel() {
	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("picHolderName").innerHTML = "&nbsp;";
	document.getElementById("yearTagPanel").innerHTML = "&nbsp;";
	document.getElementById("ratingPanel").innerHTML = "&nbsp;";
	 
	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">';
	currVodIndex = -1;
	vodPage = 0;
	getVodInfo();
	showVodPanel();
}

function createVodGenre() {
	var count = 0;
	for(i=0; i<genreCache.length; ++i) {
//		if(genrePatternCache[i] != null && genrePatternCache[i].match("#" + genreCache[vodGenreSelected] + "#")) {
			curGenreCache[i] = 	genreCache[i];
			++count;
//		}
	}
	vodGenreTotal = (genreCache.length == 0 ? 0 : genreCache.length -1);
}

function resetVodPanel() {
	vodGenreTotal = (genreCache.length == 0 ? 0 : genreCache.length - 1);
	vodGenreCursor = 0;
	vodGenreCurrent = 0;	
	vodGenreSelected = 0;
}

function updateVodPanel() {
	createVodGenre(); 
	resetVodPanel();
	statusInfo=1;
	var genreCount = 0;
	document.getElementById("vodGenrePanel").innerHTML = "";
	var genreHTML = '';
	var i; 
//	alert(genreCache.length + " :  " + genreCache);
//	return;
	for(i=0; (genreCache.length > 4 && i < 4) || (genreCache.length <= 4 && i < genreCache.length); ++i) {
		genreHTML += '<tr><td width="100%" height="16%" valign="middle" style="cursor:pointer;height:16%;width:100%;vertical-align:middle;background-repeat: no-repeat;" id="genreVodId' + i + '"  onmouseover="selVodGenre(' + i + ');"  onclick="openVodGenre(' + i + ');"  >&nbsp;' + curGenreCache[i] + '</td></tr>';
		genreCount++;
	}
	if(genreCount > 0) {
		for(var j=0; j < (4 - genreCount) ; ++j) { 
			genreHTML += '<tr><td width="100%" height="16%" valign="middle" style="height:17%;width:95%;vertical-align:middle;"></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="0px">' 
			+ (genreHTML.length ? genreHTML : '<tr><td width=' + (genreHTML ? "100%" : "100%")+ ' height="20%" valign="middle" align="center" nowrap>no genre available</td></tr>')								
			+ '</table>';
	if(genreHTML.length) {			
		if(document.getElementsByTagName) {  
			var table = document.getElementById("vodGenrePanel");   
			var rows = table.getElementsByTagName("tr");
			rows[0].style.background =  'url("/view/mobi/images/rowGenre.png") no-repeat';	
			rows[0].style.backgroundRepeat = "no-repeat";
	
		} 	
	}
	try {
		buildTitleCache();
	} catch(x) {
		alert(x);
	}
}

function scrollVodPage(start, end) {
	statusInfo=1;
	document.getElementById("vodGenrePanel").innerHTML = "";
	var genreHTML = '';
	var i; 
	for(i = start; i <= end; ++i) {
		genreHTML += '<tr><td width="100%" height="16%" valign="middle" style="cursor:pointer;height:16%;width:100%;vertical-align:middle;background-repeat: no-repeat;" id="genreVodId' + i + '"  onmouseover="selVodGenre(' + i + ');"  onclick="openVodGenre(' + i + ');"  >&nbsp;' + curGenreCache[i] + '</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 ? genreHTML : '<tr><td width=' + (genreHTML ? "100%" : "100%")+ ' height="20%" valign="middle" align="center" nowrap>no genre available</td></tr>')								
			+ '</table>';
			
			
	if(document.getElementsByTagName) { 
		var table = document.getElementById("vodGenrePanel");   
		var rows = table.getElementsByTagName("tr");
		rows[vodGenreCursor].style.background =  'url("/view/mobi/images/rowGenre.png") no-repeat';	
		rows[vodGenreCursor].style.backgroundRepeat = "no-repeat";

	} 	
}
function changeGenreCursor() {
	if(document.getElementsByTagName) {  
		var table = document.getElementById("vodGenrePanel"); 
		var rows = table.getElementsByTagName("tr");
		rows[vodGenreCursor].style.background =  'url("/view/mobi/images/rowGenre.png") no-repeat';	
		rows[vodGenreCursor].style.backgroundRepeat = "no-repeat";	
	   	var i;
	 	for(i = 0; i < rows.length; i++) { //alert(rows.length);  
	   		if(i != vodGenreCursor) {
	       		rows[i].style.background = 'none'; 
	    	}
	   }
	} 
}


//function highlightVodGenre() {
//	if(document.getElementsByTagName) {  
//		var genreTable = document.getElementById("vodGenrePanel");   
//		var genreRows = genreTable.getElementsByTagName("tr");
//		try { 
//			genreRows[vodGenreCursor].style.background = "url('/view/mobi/images/rowGenre.png') no-repeat"; 
//		} catch(x) {
////			alert(x + " " + genreRows.length + ", aodGenreCursor => " + vodGenreCursor);
//		}     
//	} 	
//}


// this method should be called when genre is browsed up and down 
function resetVodTitlePanel() {
	curVodIndex = new Array();
	vodTitleIndexArr = new Array();
	vodRowIndex = 0;
	vodColumnIndex = 0;
	vodStartIndex = 0;
	vodCursorIndex = 0;
	vodTitleTotal = 0;
//	currVodIndex = -1;
}
function buildTitleCache() {
	resetVodTitlePanel();
	var i;
	var cnt = 0;	
	for(i=0; i<genrePatternCache.length; ++i) {
		if(genrePatternCache[i] != null && genrePatternCache[i].match("#" + genreCache[vodGenreSelected] + "#")) {
			curVodIndex[cnt] = i; 	
			cnt++;
		} 
	}
	vodTitleTotal = curVodIndex.length -1;	
	updateVodTitlePanel();
}	

// called when browsing thru genre
function selVodTitlePanel(rowIndex, columnIndex) {
//	alert("rowIndex=> " + rowIndex + ",columnIndex=> " + columnIndex + ", cursorIndex=> " + vodCursorIndex);
	var titleId = "vodTitleId"+ rowIndex +""+columnIndex;
	var curIndex = 2*rowIndex + columnIndex;
//	showVodKeyPanel(rowIndex, columnIndex);
	try {
		var nowCurIndex = curVodIndex[curIndex];
		var result = (fullTitleCache[curIndex]? updateVodInfo(curIndex) : hideVodDetails());
	} catch(m) {
//		alert(" m=> " + m);
	}
	try {
		document.getElementById(titleId).style.border = "1px solid paleGoldenRod";
	} catch (x) {
		try {
			vodRowIndex -= 1;
			vodRowIndex = (vodRowIndex < 0 ? vodRowIndex+1 : vodRowIndex);
			vodCursorIndex -=1;
			vodCursorIndex = (vodCursorIndex < 0 ? vodCursorIndex+1 : vodCursorIndex);
			selVodTitlePanel(vodRowIndex, vodColumnIndex);
		} catch (y){
			return;
//			alert(" y=> " + y);
		}
	}
}	

function unSelVodTitle(rowIndex, columnIndex) {
	var titleId = "vodTitleId"+ rowIndex +""+columnIndex;
	var curIndex = 2*rowIndex + columnIndex;
 	hideVodKeyPanel(rowIndex, columnIndex);
	try {
		document.getElementById(titleId).style.border = "1px solid gray";
	} catch (x) {
//		alert(" x=> " + x);
	}
}
	
function callLink() {	
	window.location= "http://122.162.61.60:1935/vod/mp4:Extremists_baseline.m4v/playlist.m3u8";
} 
function updateVodTitlePanel() {
	checkPhone();
	var i;
	var titleCount = 0;
	statusInfo =1;
	for(var k = 0; k < 2; k++) {
		vodTitleIndexArr[k] = new Array(2); 
		for(var m = 0; m < 2; m++) {
			vodTitleIndexArr[k][m] = 0;
		}
	}
	var titleHTML  = '<tr><td width="5%" height="50%">&nbsp;</td>';
	if(document.getElementById("vodTitlePanel") != null) {
		for(i=0; (curVodIndex.length >=4 && i<4) || (curVodIndex.length < 4 && i<curVodIndex.length); ++i) {
			var curIndex = curVodIndex[i];
			if(i%2 == 0 && i != 0) {
				titleHTML += '</tr><tr><td width="5%" height="50%">&nbsp;</td>';
			}
			var rowIndex = parseInt(i/2);
			var columnIndex = parseInt(i%2);
			vodTitleIndexArr[rowIndex][columnIndex] = 1;
			titleHTML += '<td align="center" valign="middle"  style="width:42%;height:50%;">'+(boxInfo ==1 ?  
							'<img id="vodTitleId'+ rowIndex + ''+ columnIndex +'" onmouseover="selVodAsset(' + i + ', '+ titleCount+');" onmouseout="unSelVodAsset(' + i + ');" onclick="openVodAsset(' + i + ');"  style="width:70%;height:60%;border:1px solid gray;background:darkslategray;cursor:pointer;"  alt=" " src='+ (vodUseGraphicCache[curIndex] == 1 ? '"/ImageHandlerMobi?value=' + titleIdCache[curIndex] + '&icon=-1&imageType=3"' : '"./view/mobi/images/vod/logo_none.png"' ) + ' />' : '' 
							+ '<img onclick="callLink();" id="vodTitleId'+ rowIndex +''+ columnIndex +'" onmouseover="selVodAsset(' + i + ', '+ titleCount+');" onmouseout="unSelVodAsset(' + i + ');" style="width:70%;height:60%;border:1px solid gray;background:darkslategray;cursor:pointer;" alt=" " src='+ (vodUseGraphicCache[curIndex] == 1 ? '"/ImageHandlerMobi?value='+ titleIdCache[curIndex] + '&icon=-1&imageType=3"' : '"./view/mobi/images/vod/logo_none.png"' )+'  />'
							+ '')
							+ '</td><td width="5%" height="50%" >&nbsp;</td>';
			
			
			titleCount++;
		}
		
		if(titleCount > 0) {
			for(var j=0; j < (4 - titleCount) ; ++j) { 
				if((titleCount+j)%2 == 0) {
					titleHTML += '</tr><tr><td width="5%" height="50%">&nbsp;</td>';
				}
				titleHTML += '<td align="center" valign="top" style="width:42%;height:50%;">&nbsp;</td><td width="5%" height="50%" >&nbsp;</td>';
			}
		}
		
		titleHTML += '</tr>';
		try {
		document.getElementById("vodTitlePanel").innerHTML = ''
			+ '<table width="100%"  height="100%" border=0 align="center" valign="middle" cellspacing="0" cellpadding="0" >' 
				+ (curVodIndex.length > 0 ? titleHTML : '<tr><td width="100%" height="100%" valign="middle" align="center" >no title available </td></tr>') // no title available									
			+ '</table>';	
			
			if(curVodIndex.length) {
				selVodTitlePanel(vodRowIndex, vodColumnIndex);
			}
		} catch (x) {
//			alert("1=> " + x);
		}
	}
}

function scrollVodTitlePage(start, end) {
	checkPhone();
	vodTitleCursor = 1;
	vodPage = 1;
	statusInfo =1;
	for(var k = 0; k < 2; k++) {
		vodTitleIndexArr[k] = new Array(2); 
		for(var m = 0; m < 2; m++) {
			vodTitleIndexArr[k][m] = 0;
		}
	}
	document.getElementById("vodTitlePanel").innerHTML = '';
	var titleHTML  = '<tr><td width="5%" height="50%">&nbsp;</td>';
	var count = 0;
	try {
	if(document.getElementById("vodTitlePanel") != null) {
		for(i = start; i <= end; ++i) { 
			var rowIndex = parseInt(i/2);
			var columnIndex = parseInt(i%2);
			var currIndex = curVodIndex[i];
			if(i%2 == 0 && i != 0 && count != 0) {
				titleHTML += '</tr><tr><td width="5%" height="50%">&nbsp;</td>';
			}
				vodTitleIndexArr[parseInt(count/2)][parseInt(count%2)] = 1; 
				try {
						titleHTML += '<td align="center" valign="middle" style="width:42%;height:50%;">'+(boxInfo ==1 ?  
							'<img id="vodTitleId'+ rowIndex + ''+ columnIndex +'" onmouseover="selVodAsset(' + i + ', '+ count+');" onmouseout="unSelVodAsset(' + i + ');" onclick="openVodAsset(' + i + ');"  style="width:70%;height:60%;border:1px solid gray;background:darkslategray;cursor:pointer;"  alt=" " src='+ (vodUseGraphicCache[currIndex] == 1 ? '"/ImageHandlerMobi?value=' + titleIdCache[currIndex] + '&icon=-1&imageType=3"' : '"./view/mobi/images/vod/logo_none.png"' ) + ' />' : '' 
							+ '<img onclick="callLink();" id="vodTitleId'+ rowIndex +''+ columnIndex +'" onmouseover="selVodAsset(' + i + ', '+ count+');" onmouseout="unSelVodAsset(' + i + ');" style="width:70%;height:60%;border:1px solid gray;background:darkslategray;cursor:pointer;" alt=" " src='+ (vodUseGraphicCache[currIndex] == 1 ? '"/ImageHandlerMobi?value='+ titleIdCache[currIndex] + '&icon=-1&imageType=3"' : '"./view/mobi/images/vod/logo_none.png"' )+'  />'
							+ '')
							+ '</td><td width="5%" height="50%" >&nbsp;</td>';
				} catch(x) {
//					alert(x);
					return;
				}
					
//			titleHTML += '<td align="center" valign="middle" nowrap style="width:42%;height:50%;">'+(boxInfo ==1 ?  
//							'<img id="vodTitleId'+ rowIndex + ''+ columnIndex +'" onmouseover="selVodAsset(' + i + ', '+ titleCount+');" onmouseout="unSelVodAsset(' + i + ');" onclick="openVodAsset(' + i + ');"  style="width:70%;height:60%;border:1px solid gray;cursor:pointer;"  alt="'+ fullTitleCache[curIndex]+ '" src='+ (vodUseGraphicCache[curIndex] == 1 ? '"/ImageHandler?value=' + titleIdCache[curIndex] + '&icon=-1&imageType=3"' : '"./view/tv/images/vod/logo_none.png"' ) + ' />' : '' 
//							+ '<a href="http://122.162.61.60:1935/vod/mp4:Extremists_baseline.m4v/playlist.m3u8">'
//							+ '<img id="vodTitleId'+ rowIndex +''+ columnIndex +'" onmouseover="selVodAsset(' + i + ', '+ titleCount+');" onmouseout="unSelVodAsset(' + i + ');" style="width:70%;height:60%;border:1px solid gray;cursor:pointer;" alt="'+ fullTitleCache[curIndex] +'" src='+ (vodUseGraphicCache[curIndex] == 1 ? '"/ImageHandler?value='+ titleIdCache[curIndex] + '&icon=-1&imageType=3"' : '"./view/tv/images/vod/logo_none.png"' )+'  />'
//							+ '</a>')
//							+ '</td><td width="5%" height="50%" >&nbsp;</td>';
			count++;
		}
		if(count > 0) {
			for(var j=0; j < (4 - count) ; ++j) { 
				if((count+j)%2 == 0) {
					titleHTML += '</tr><tr><td width="5%" height="50%">&nbsp;</td>';
				}
				titleHTML += '<td align="center" valign="top"  style="width:42%;height:50%;">&nbsp;</td><td width="5%" height="50%" >&nbsp;</td>';
			}
		}
		titleHTML += '</tr>';
		document.getElementById("vodTitlePanel").innerHTML = ''
			+ '<table width="100%"  height="100%" border=0 align="center" valign="middle" cellspacing="0" cellpadding="0" >' 
				+ (curVodIndex.length > 0 ? titleHTML : '<tr><td width="100%" height="100%" valign="middle" align="center" > no title available  </td></tr>') // no title available									
			+ '</table>';
//			alert(vodRowIndex + " : " + vodColumnIndex);
		try {
			selVodTitlePanel(vodRowIndex, vodColumnIndex);
		} catch(x) {
			alert("2=> "+ x);
		}
	}
	} catch(x) {
		
	}
}

function hideVodDetails() {
	document.getElementById("vodSHeader").style.visibility = "hidden";
	document.getElementById("vodDHeader").style.visibility = "hidden";
	document.getElementById("vodSPanel").style.visibility = "hidden";
	document.getElementById("vodDPanel").style.visibility = "hidden";
}
var currFileIndex;
function updateVodInfo(currentIndex) {
//	return;
	currFileIndex = currentIndex;
	var curIndex = curVodIndex[currentIndex];
	var nowPlayStream = (currVodIndex != -1 ? assetNameCache[currVodIndex] : assetNameCache[curIndex]);
	var curPlayStream =  assetNameCache[curIndex];
//	nowPlayStream = (nowPlayStream.search(".mp3") ? nowPlayStream.substring(0, nowPlayStream.indexOf(".mp3))) ;
	try {
//		var nowFile = nowPlayStream.substring(0, nowPlayStream.indexOf("."));
//		var currentFile = curPlayStream.substring(0, curPlayStream.indexOf("."));
//		
//		nowFile = (nowFile.length > 15 ? nowFile.substring(0,15) + ".." : nowFile);
//		currentFile = (currentFile.length > 15 ? currentFile.substring(0,15) + ".." : currentFile);
		document.getElementById("picHolderName").innerHTML = (curPlayStream.indexOf(".")>= 0 ? curPlayStream.substring(0, curPlayStream.indexOf(".")) : "&nbsp"+curPlayStream);//records.key447 + ": ";
		document.getElementById("ratingPanel").innerHTML =  ratingPatternCache[curIndex] != "" ? "rating: "+ ratingPatternCache[curIndex] : ""; 
		document.getElementById("yearTagPanel").innerHTML =  yearCache[curIndex] != "" ? "" : "year: " + yearCache[curIndex];;//assetNameCache[curIndex].substring(0, 15) + ".."; //records.key456;//selAssetNameCache[currentIndex];//(selYearCache[currentIndex] ? selYearCache[currentIndex] : " ")
	} catch (x) {
		
	}
}
function checkPhone() {
	if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
		boxInfo = 0;
	} else {
		boxInfo = 1;
	}
}

function startVodStream() {
	flashActive =true;
	feedType = "rtsp";
	var curIndex = curVodIndex[currFileIndex];
	var currIndex = 2*vodRowIndex + vodColumnIndex;
	currIndex = curVodIndex[currIndex];
	var curPlayStream =  assetNameCache[curIndex];
	if(!assetNameCache[currIndex])
		return;
	currVodIndex = 	currIndex;
	vodPlayStatus = true;
//	var hasRequestedVersion = DetectFlashVer(10, 0, 0);
//	if(!hasRequestedVersion) {
//		document.getElementById("statusMessagePanel").innerHTML = 'get the flash player now on http://www.adobe.com/go/getflashplayer/';
//		return;
//	} 
//	var fileName = assetNameCache[currIndex];
	var file = curPlayStream.substring(0, curPlayStream.indexOf("."));
	var exten = curPlayStream.substring(curPlayStream.indexOf(".")+1, curPlayStream.length).toUpperCase();
	if (exten == "MP4" || exten == "MOV" || exten == "F4V" ) {
		return;
	} else {
//	curPlayStream = file + ".flv";
	curPlayStream = file;
	var hostAddr = fmsServerIp + ":" + fmsServerPort;
//		fileName = "rtmp://192.168.1.120/vod/pushkal.flv";
//	}	
//	
		document.getElementById("epgPlayer").innerHTML ='<table height="240px width="320px" bgcolor="#000000" style="position:relative;margin-top:0px;"><tr><td height="15px width="320px" align="left" style="position:relative;margin-top:0px;" >'
															+'<img height="15px" width="15px" id="miniGuideImage" align"right" onclick="homePanelVod(2);"  style="cursor:pointer;" alt="" src="/view/mobi/images/home.png" valign="top" align="left">'
															+'</td></tr><tr><td height="225px width="320px" style="position:relative;margin-top:0px;">' 
															+'<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="320px" height="225px" id="simplevideostreaming" align="top" >'
																+'<param name="allowScriptAccess" value="sameDomain" />'
																+'<param name="allowFullScreen" value="true" />'
																+'<param value="exactfit" name="scale"/>'
																+'<param value="opaque" name="wmode"/>'
																+'<param name="FlashVars" value="mymovie='+curPlayStream+'&ipAddr='+ hostAddr +'">'
																+'<param name="movie" value="./view/mobi/swf/mobileVodPlayer.swf" />' 
																+'<param name="quality" value="high" />' 
																+'<param name="bgcolor" value="#000000" />' 
																+'<embed src="./view/mobi/swf/mobileVodPlayer.swf" FlashVars="mymovie='+curPlayStream+'&ipAddr='+ hostAddr +'" quality="high" bgcolor="#000000" width="320px" height="225px" name="simplevideostreaming" align="top" wmode="opaque" allowScriptAccess="sameDomain" allowFullScreen="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'
															+'</object></td></tr></table>'

		if(document.getElementById("epgPlayer") != null) {
			document.getElementById("epgPlayer").className = "epgPlayer";
		}
	
		fadeAll();		
		//document.getElementById("homePanelImage").style.visibility = "visible";
	}
	
}

function homePanelVod(index){
	if(index == 2){
		flashActive = false;
		document.getElementById("epgPlayer").innerHTML ='';
		document.getElementById("layer8").style.visibility = "visible";			
	}else{					
		homePanel(1);
	}
}
	
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 AOD
function showVodKeyPanel(rowIndex, columnIndex) {
	return;
	var index = 2*rowIndex + columnIndex;
	pauseFlag = 0;
	try {
		document.getElementById("vodKeyPanel" + index).innerHTML = '<img alt="play" src="/view/tv/images/vod/play.png">';
	} catch (x) {
		
	}
}

function hideVodKeyPanel(rowIndex, columnIndex) {
	return;
	var index =2*rowIndex + columnIndex;
	try {
		document.getElementById("vodKeyPanel" + index).innerHTML = "";	
	} catch(x) {
		
	}
	
}


function onVodTitlePanel(index) {
	unSelVodTitle(vodRowIndex, vodColumnIndex);
	var rowIndex = parseInt(index/2);
	var columnIndex = index%2;
	vodRowIndex = rowIndex;
	vodColumnIndex = columnIndex;
	selVodTitlePanel(vodRowIndex, vodColumnIndex);
}
function scrollTitle(index){
	vodPage=1;
	if(index ==1){
		keyActionHandler(rcUP);
	}else{
		keyActionHandler(rcDOWN);
	}
}
function scrollGenre(index){
	vodPage=0;
	if(index ==1){
		keyActionHandler(rcUP);
	}else{
		keyActionHandler(rcDOWN);
	}
}


function vodKeyNvg(keyCodeNum) {
	if(curVodIndex.length == 0) {
		return;
	}
	if(vodPage == 0) {
		return;
	}
	vodKeyHandler(keyCodeNum);
}

function keyPanelNvg(keyCodeNum) {
	switch(keyCodeNum) {
		case rcOK:
			feedType = "rtsp";
			keyVodAction();
		break;
	}
}

function keyVodAction() {
	var currIndex = 2*vodRowIndex + vodColumnIndex;
//	if(feedType == "rtsp") {
		if(pauseFlag == 1) {
			if(playStatus) {
//				document.getElementById("vodKeyPanel" + currIndex).innerHTML = '<img alt="" src="/view/tv/images/vod/play.png">';						
//				pauseStream();
				startVodStream();
				playStatus = false;
			} else {
				playStatus = true;
//				document.getElementById("vodKeyPanel" + currIndex).innerHTML = '<img alt="" src="/view/tv/images/vod/pause.png">';
//				continueStream();
				startVodStream();
			}
		} else {
			stopStream(); // If a stream is playing before pressing enter, we need to stop the stream first
//			currIndex = curVodIndex[currIndex];
//			var rtspUrl = 'src=rtsp://' + vodServer + '/' + assetNameCache[currIndex] + ';servertype=ncube';
			playStatus = true;
			pauseFlag = 1;
//			document.getElementById("vodKeyPanel" + currIndex).innerHTML = '<img alt="" src="/view/tv/images/vod/pause.png">';	
			startVodStream();
//			playStream(rtspUrl);
		}	
//	}			
}

function highLightKeyPanel(currIndex) {
	document.getElementById("vodKeyPanel" + vodTitleSelected).style.background = "#fcf3b8";	
}

function hideKeyPanel(currIndex) {
	document.getElementById("vodKeyPanel" + vodTitleSelected).style.background = "";	
}

function hideVod(index) {
	document.getElementById("vodMove" + index).style.background = "none";
}

function showVod(index) {
	document.getElementById("vodMove" + index).style.background = "#fcf3b8";
}

function escapeVodPanel() {
	keyActionHandler(rcMENU);
}
function highLightVodHome() {
	document.getElementById("vodHome").style.background = "#fcf3b8";
}
function hideVodHome() {
	document.getElementById("vodHome").style.background = "none";
}

function selVodAsset(currentIndex, cursorIndex) {
	vodPage = 1;
	unSelVodTitle(vodRowIndex, vodColumnIndex);
	vodRowIndex = parseInt(currentIndex / 2);;
	vodColumnIndex = parseInt(currentIndex % 2);
	vodCursorIndex = parseInt(cursorIndex/2);
	selVodTitlePanel(vodRowIndex, vodColumnIndex);
}
 
function unSelVodAsset(index) {
//	alert("out");
	return;
	if(document.getElementById("vodTitleId" + index) != null) {
		document.getElementById("vodTitleId" + index).style.border = "0px solid #ff7700";
	}
	hideVodKeyPanel(index);
}	
//  
function openVodAsset(index) {
	vodKeyHandler(rcOK);
}	
	
function moveVodPageUp() {
	keyActionHandler(rcUP);
}
// 
function moveVodPageDown() {
	keyActionHandler(rcDOWN);
}

function selVodGenre(index) {
	vodPage = 0;
	vodGenreCursor = index - vodGenreClicks;
	vodGenreSelected = vodGenreCurrent = index;
	changeGenreCursor();
	buildTitleCache();
}
function openVodGenre(index) {
	vodPage = 0;
	vodGenreCursor = index - vodGenreClicks;
	vodGenreSelected = vodGenreCurrent = index;
	changeGenreCursor();
//	buildTitleCache();
}


function openVodGenreAsset(index) {
	keyActionHandler(rcOK);
}	

function vodKeyHandler(keyCodeNum) {
	switch(keyCodeNum) {
		case rcRIGHT:
			if(vodPage == 0) {
				vodPage = 1;
				return;
			}
			var curIndex = vodRowIndex*2 + vodColumnIndex;
 			if(curIndex == vodTitleTotal || vodColumnIndex ==1) {
 				return;
 			}
			if(vodColumnIndex >= 0) {
				unSelVodTitle(vodRowIndex, vodColumnIndex);
				++vodColumnIndex;
				selVodTitlePanel(vodRowIndex, vodColumnIndex);
				return;
			}
			break;
		case rcLEFT:
			if(vodPage == 0) {
				return;
			}
			if(vodColumnIndex ==0) {
				vodPage = 0;
				hideVodKeyPanel(vodRowIndex, vodColumnIndex);
 				return;
 			}
			if(vodColumnIndex >= 0) {
				unSelVodTitle(vodRowIndex, vodColumnIndex);
				--vodColumnIndex;
				selVodTitlePanel(vodRowIndex, vodColumnIndex);
				return;
			}
			break;
		case rcUP:
			if(vodPage == 0) { // GENRE PAGE	
				if(vodGenreCurrent == 0) { // first one									
					break;
				} 
				vodGenreCurrent--;
				if(vodGenreCursor != 0) { // move cursor
					vodGenreCursor--;					
					changeGenreCursor();
				} else { // scroll
					var start = vodGenreCurrent; 
					var end = vodGenreCurrent + 3;	
					--vodGenreClicks;
					scrollVodPage(start, end);							
				}			
				vodGenreSelected = vodGenreCurrent;
				buildTitleCache();		
				return;			
			} 
			if(vodRowIndex == 0)
				return;
			unSelVodTitle(vodRowIndex, vodColumnIndex);
			vodRowIndex--;
			if(vodCursorIndex != 0) { // if the cursor is moving up, no scroll is needed
				vodCursorIndex--;
				selVodTitlePanel(vodRowIndex, vodColumnIndex);
			} else { // scroll	
				vodCursorIndex = 0;
				var start = 0;
				start = (vodStartIndex < 2 ? 0 : vodStartIndex -2);
				vodStartIndex = start;
				var end = ((vodTitleTotal - start) > 3? (start + 3) : vodTitleTotal);	
				scrollVodTitlePage(start, end);
			}			
			break;
		case rcDOWN:
			if(vodPage == 0) { // GENRE PAGE			
				if(vodGenreCurrent == vodGenreTotal) { // last one												
					break;
				} 
				vodGenreCurrent++;
				if(vodGenreCursor < vodGenreMax) { // move cursor
					vodGenreCursor++;					
					changeGenreCursor();
				} else { // scroll
					var start = vodGenreCurrent - 3; 
					var end = vodGenreCurrent;		
					++vodGenreClicks;	
					scrollVodPage(start, end);							
				}			
				vodGenreSelected = vodGenreCurrent;
				buildTitleCache();		
				return;			
			} 
			var rowIndex = vodCursorIndex + 1;
			var columnIndex = vodColumnIndex;
			if(rowIndex < 2) {
				if(vodTitleIndexArr[rowIndex][columnIndex] == 0) {
					return;
				}
			}
			var vodCount = (vodTitleTotal/2);
 			if(vodRowIndex == parseInt(vodCount)) {
				return;
 			}
			unSelVodTitle(vodRowIndex, vodColumnIndex);
			vodRowIndex++;
					
			if(vodCursorIndex < 1) { 
				vodCursorIndex++;
				selVodTitlePanel(vodRowIndex, vodColumnIndex);
			} else { // scroll	
				var start = 0;
				if(vodRowIndex < 2) {
					start = vodRowIndex;  
					vodStartIndex = start;
				} else {
					start = vodStartIndex + 2;
					vodStartIndex = start;
				}
				vodCursorIndex = 1;
				var end = ((vodTitleTotal - start) > 3 ? (start + 3) : vodTitleTotal);
				scrollVodTitlePage(start, end);
			}	
			break;
		case rcOK:
			if(boxInfo == 1){
			feedType = "rtsp";			
			startVodStream();
			}else{
			 callLink();
			}
			break;
		case rcMENU:
			if(flashActive){
				homePanelVod(2);
			}else{
				vodActive = false;
				homePanelVod(1);	
			}
			break;
	}
}	
// END
///////////////////////