/*
 * 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.
 */

var titleRssCache	= new Array();
var descriptionRssCache	= new Array();
var pubDateRssCache	= new Array();

var currentNewsTitle = 0;
var totalNewsTitle = 0;
var currentTitleCursor = 0;
var newsCategory = 0;
var curNewsClicks = 0; // counts the mouse clicks in moving up or down

var newsIndex = 0;
var totalNewsCount = 0;

function createNewPanel(counts) {
	totalNewsCount = counts - 1;
	var widgetId = wrecords.wRecords[currImage].id;
	var useGraphic = wrecords.wRecords[currImage].useGraphic;
	useGraphic = useGraphic.substring(1, useGraphic.length);	
	var widgetTitle = wrecords.wRecords[currImage].title;
	var newsHTML = "<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='70%' id='newsContent'><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='moveNews(1);' src='./view/mobi/images/larrow.png'/></td><td><img onclick='newsKeyHandler(rcMENU);' style='cursor: pointer;' src='/view/mobi/images/home.png' alt=''/></td><td><img style='cursor:pointer;' onclick='moveNews(2);' src='./view/mobi/images/rarrow.png'/></td></tr></table></td></tr></table></td></tr><tr><td id='newsHTML'><table style='height:100%;' >";
	
	for(var i = 0; i < titleRssCache.length && i < 7; i++) {
		newsHTML += "<tr><td width='316px' style='border:1px solid gray;"+(i%2 == 0 ? 'background:DarkSlateGray;' : 'background:DarkSlateGray;')+"' id='newsTitleId"+ i +"' onclick='openNewsContent("+ i +");'>"+ titleRssCache[i]+"</td></tr>";
	}
	newsHTML += "</table></tr></td></table>";
	fadeAll();
	document.getElementById("openChartId").innerHTML = newsHTML;
}

function openNewsContent(index) {
	index = startIndex + parseInt(index);
	var widgetId = wrecords.wRecords[currImage].id;
	getRssWidgetDetails(widgetId, 2, index);
}
function moveNews(index) {
	(index == 1 ? newsKeyHandler(rcLEFT) : newsKeyHandler(rcRIGHT)); 
}

function newsKeyHandler(keyCodeNum) {
	switch(keyCodeNum) {
		case rcLEFT:
			if(totalNewsCount >= 8) {
				startIndex = startIndex - 8;
				startIndex = (startIndex < 0 ? totalNewsCount - totalNewsCount%8  : startIndex);
				endIndex = startIndex + 8;
				endIndex = (endIndex > totalNewsCount ? totalNewsCount : endIndex);
				var widgetId = wrecords.wRecords[currImage].id;
				getRssWidgetDetails(widgetId, 1, -1);
			}
			break;
		case rcRIGHT:
			if(totalNewsCount >= 8) {
				startIndex = startIndex + 8;
				startIndex = (startIndex > totalNewsCount ? 0 : startIndex);
				endIndex = startIndex + 8;
				endIndex = (endIndex > totalNewsCount ? totalNewsCount : endIndex);
				var widgetId = wrecords.wRecords[currImage].id;
				getRssWidgetDetails(widgetId, 1, -1);
			}
			break;
		case rcMENU:
			document.getElementById("openChartId").innerHTML = "";
			newsActive = false;
			showGuidePanel();
			break;
	}
	
}
// selecting the up or down arrows
function showNewsArrow(index) {
	document.getElementById("newsMove" + index).style.background = "#fcf3b8";
}
// hiding the up and down arrows
function hideNewsArrow(index) {
	document.getElementById("newsMove" + index).style.background = "none";
}
// moving news page to down

function moveNewsPageDown() {
	keyActionHandler(rcDOWN);
}
// moving news page to up
function moveNewsPageUp() {
	keyActionHandler(rcUP);
}
// escaping the news panel page
function escapeNewsPanel() {
	document.getElementById("newsCategoryData").style.visibility = "hidden";
	keyActionHandler(rcMENU);
}
// highlighting the home button
function gotoNewsHome(index) {
	if(index == 1) {
		document.getElementById("newsHome").style.background = "#fcf3b8";
	} else if(index == 2) {
		document.getElementById("newsHome").style.background = "none";
	}
}

function updateNewsContent(title, desc) {
	document.getElementById("newsContent").innerHTML = title;
	document.getElementById("newsHTML").innerHTML = '<table style="height:100%;" ><tr><td>'+ desc +'</td></tr></table>';
}


















