<!-- document.getElementById('myDiv').innerHTML = myXMLReqObj.responseText; -->
<!--
/* global variables*/
var cnnRootUrlForContent = "/video/portable/";
var cnnRootUrlForImages = "http://i.a.cnn.net/cnn/video/portable/";
var cnnLiveStream1Dir = "video/live/stream1";
var cnnLiveStream2Dir = "video/live/stream2";
var cnnLiveStream3Dir = "video/live/stream3";
var cnnLiveStream4Dir = "video/live/stream4"; 
var cnnVideoVolume = 6;
var cnnMuteStateOn = false;
var cnnTickerItems = new Array();
var cnnTickerCount = 0;
var cnnCurMode = "";
var cnnCurVOD = "";
var cnnPipe1OvernightRelatedsUrl = "";
var cnnCurDayNightMode = "";
var cnnCurJustInScheduleTabDefault = "";
var pollingIntervalMS = 10000;
//var cnnOmnitureId = "cnnglobal";
var cnnOmnitureId = "";
var cnnDPFlag = false;


var cnnSearchJSP = (location.hostname.indexOf('turner.com')>0)?'http://srch8ref1.turner.com/cnnvideo/pages/portableSearch.jsp':' http://search.cnn.com/cnnvideo/pages/portableSearch.jsp';

var msie = false;
var msie7 = false;
var safari = false;
var firefox = false;
var windows = false;
var videoActiveX = false;
var cnnFlip4Mac = false;

var cnnCurrentTopStory = 1;
var cnnNextTopStory = 2;
var cnnPreviousTopStory = 3;

var cnnTopStoriesSecs = 10;
var cnnTopStoriesCounter = 0;
var cnnTopStoriestTimerID = null;
var cnnTopStoriesTimerRunning = false;
var cnnTopStoriesDelay = 1000;
var cnnTopStoriesMouseOverPaused = false;

var cnnFadeTopStoriesOpac= 99;
var cnnFadeTopStoriesCurrent= false;

var cnnCurrentOnDemandFrame="cnnOnDemandFrame";
var cnnOnDemandTotalPages=0;
var cnnOnDemandSlidePos=0;
var cnnOnDemandSlideCounterN=0;
var cnnOnDemandSlideCounterP=790;

var liveFeedPlaying = null;
var cnnCurLiveStream = 1;
var lastNowPlayingImageSrc = null;

var cnnBrowseSection = "ALL";
var cnnBrowseButton = "";
var cnnBrowseOrderAsc = false;
var cnnBrowsePage = 0;
var cnnBrowseTotal = 0;
var cnnBrowseSectionTitle = "";

var cnnSearchQuery = "";
var cnnSearchFilter = "ALL";
var cnnSearchButton = "time";
var cnnSearchOrderAsc = false;
var cnnSearchPage = 1;
var cnnSearchTotal = 1;

var cnnYourVoiceOn = false;

var cnnCurrentVideoDirectory= "content/video/standby";
var cnnRefreshTimers = new Array();


function setPollingIntervalMS(pollInt) {
    //alert("Inside scripts.js setPollingIntervalMS [" + pollInt + "]");
    pollingIntervalMS = pollInt;
//    pollingIntervalMS = 30000;
}

function CNN_targetOpener(url) {
 if (parent.window.opener && !parent.window.opener.closed && url.charAt(0) == '/') {
  parent.window.opener.location.href = url;
  parent.window.opener.focus();
  this.focus();
 } else {
  var satelliteWindow = window.open(url, 'new');
  cnnCurrentOpenerTargetWin = satelliteWindow;
  satelliteWindow.focus();
  this.focus();
 }
}

function CNN_targetOpener3(url) {
 if (parent.window.opener && !parent.window.opener.closed && url.charAt(0) == '/') {
  parent.window.opener.location.href = url;
  parent.window.opener.focus();
 } else {
  var satelliteWindow = window.open(url, 'new');
  cnnCurrentOpenerTargetWin = satelliteWindow;
  satelliteWindow.focus();
 }
}

function CNN_targetOpener2(url) {
 if (parent.window.opener && !parent.window.opener.closed && url.charAt(0) == '/') {
  parent.window.opener.location.href = url;
  parent.window.opener.focus();
 } else {
  var satelliteWindow = window.open(url, 'new', 'top=0,left=0,height=768,width=1024,scrollbars=yes,resizable=yes');
  cnnCurrentOpenerTargetWin = satelliteWindow;
  satelliteWindow.focus();
 }
}

function cnnUpdateSearchResults() {
        var results = document.getElementById("cnnSearchResults");
        results.innerHTML = "VIDEO SEARCH RESULTS for \""+cnnSearchQuery+ "\" - Results " + cnnVideoCount;
}
 
function CNN_openPopup( url, name, widgets )
{
 window.top.name = "CNNVideoPlayer";
 window.open( url, name, widgets );
}
 
function cnnVideo( mode, arg) {
 switch (mode) {
  case 'play':
   cnnLoadVideo(arg);
   break;
  case 'browse':
   cnnShowBrowse();
   cnnSelectSection(arg, arg);
   break;
  default:
 }
}
 
function LaunchVideo( videoPath ) {
	cnnPlayVideo('/video'+videoPath.substring(0,(videoPath.length -1)));
}

/* Load Player */
function cnnLoadPlayer() {
	setBrowser();
	cnnLoadInterface();

    if (windows) {
        if (parent.isSubscriber() && document.getElementById('cnnDownloadButton')) {
            cnnDisplayDownloadButton(true);
        }
    }

	cnnRefreshRelated();	
	cnnRefreshJustIn();	
	cnnRefreshSchedule();	
	cnnRefreshNowInTheNews();
	cnnRefreshTopStories();	
	cnnRefreshLiveFeeds();
	cnnRefreshLiveFeedImages();
	cnnPlayTopStories();
	cnnRefreshOnDemand();
        cnnLoadBrowse('time');
	cnnRefreshWhatsOn();
	pollForContentUpdates();
	cnnLoadMode();
}

function cnnLoadInterface() {
	if(videoActiveX) {
		document.getElementById('cnnInterface').className = "PC";
		document.getElementById('cnnVideoWindow').className = "cnnVideoWindowPC";
		document.getElementById('cnnVideoScreen').className = "cnnVideoScreenPC";
		document.getElementById('cnnWhatsOn').className = "cnnWhatsOnOn";
	} else {
                if (cnnFlip4Mac) {
                    document.getElementById('cnnInterface').className = "cnnFlip4Mac";
                    document.getElementById('cnnVideoWindow').className = "cnnVideoWindowFlip4Mac";
                    document.getElementById('cnnVideoScreen').className = "cnnVideoScreenFlip4Mac";
                } else {
                    document.getElementById('cnnInterface').className = "MAC";
                    document.getElementById('cnnVideoWindow').className = "cnnVideoWindowMAC";
                    document.getElementById('cnnVideoScreen').className = "cnnVideoScreenMAC";
                }
	}
}

function cnnLoadMode() {
        //alert(document.location.search.substring(1));
        var queryString = document.location.search.substring(1);
	//var queryString = window.top.location.search.substring(1);
	var mode = getParameter(queryString,'mode');
	if(mode=='live') {
		var stream = getParameter(queryString,'stream');
		cnnLoadLiveStream(parseInt(stream));
	} else if(mode=='vod') {
		var video = getParameter(queryString,'video');
		cnnShowOnDemand();
		cnnLoadVideo(video);	
	} else if(mode=='browse') {
		var name = getParameter(queryString,'sectionName');
		var dir = getParameter(queryString,'sectionDir');
		if (name == "null" && dir != "null")
		{
			switch(dir)
			{
				case "/ALL": case "/all":
					dir = 'ALL';
					name = 'All';
					break;
				case "/topvideos":
					name = 'Top Videos';
					break;
				case "/producer.picks":
					name = 'Producer Picks';
					break;
				case "/world":
					name = 'World';
					break;
				case "/us":
					name = 'U.S.';
					break;
				case "/business":
					name = 'Business';
					break;
				case "/sports":
					name = 'Sports';
					break;
				case "/politics":
					name = 'Politics';
					break;
				case "/tech":
					name = 'Sci-Tech';
					break;
				case "/law":
					name = 'Law';
					break;
				case "/health":
					name = 'Health';
					break;
				case "/showbiz":
					name = 'Entertainment';
					break;
				case "/education":
					name = 'Education';
					break;
				case "/bestoftv":
					name = 'Best of TV';
					break;
				case "/moos":
					name = 'Jeanne Moos';
					break;
				case "/offbeat":
					name = 'Offbeat';
					break;
				case "/specials":
					name = 'Special Reports';
					break;
				default:
					break;
			}  
		}

        // new requirement: on startup for browse mode, also play pipe #1
		cnnLoadLiveStream(1);
 
		cnnShowBrowse();

		if(name && dir)
  		{
			cnnSelectSection(name,dir);
		}

        } else if (mode=='search') {
                var query = getParameter(queryString,'searchQuery');
                var searchField = document.getElementById("cnnSearchField");
                searchField.value = query;
                cnnSearch();

	} else {
		cnnLoadLiveStream(1);
	}
}

/* global utility functions */

function getParameter ( queryString, parameterName ) {
    var parameterName = parameterName + "=";
    if ( queryString.length > 0 ) {
        begin = queryString.indexOf ( parameterName );
        if ( begin != -1 ) {
            begin += parameterName.length;
            end = queryString.indexOf ( "&" , begin );
            if ( end == -1 ) {
                end = queryString.length
            }
            return unescape ( queryString.substring ( begin, end ) );
        }
        return "null";
    } else {
        return "null";
    }
} 

function popWindow(url,name,width,height) {
	window.open(url,name,'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=' + width + ',height=' + height);
}

function setBrowser() {
	var agent = navigator.userAgent.toLowerCase();
	if(agent.indexOf('safari')>-1) safari = true;
	if(agent.indexOf('firefox')>-1) firefox = true;
	if(agent.indexOf('msie')>-1) msie = true;
	if(agent.indexOf('msie 7')>-1) msie7 = true;
	if(agent.indexOf('windows')>-1) windows = true;
	if(agent.indexOf('msie')>-1) videoActiveX = true;

        if (!windows) {
            var wmvPlugins = Plugin.getPluginsForMimeType("video/x-ms-wmv");
            if (wmvPlugins) {
                if (wmvPlugins.length >= 0) {
                    cnnFlip4Mac = wmvPlugins[0].indexOf("Flip4Mac") != -1;
                    //alert("flip4mac [" + cnnFlip4Mac + "]");
                }
            }
        }

}

function cnnGetContentFromURL(frameName,divId,url, cacheTime) {
    if (cnnDPFlag) return;

    if (divId == null || divId == "cnnPollerLoader") {
        //alert("scripts.js:cnnGetContentFromURL...");
        //alert("divId[" + divId + "], url[" + url + "]");

    }
	window.frames[frameName].location = url;
	cnnLoadContentFromURL(frameName,divId,5, cacheTime);
}

function cnnLoadContentFromURL(frameName,divId,wait) {
    if (cnnDPFlag) return;

    if (divId == null || divId == "cnnPollerLoader") {
        //alert("scripts.js:cnnGetContentFromURL.#2 with divId[" + divId + "], wait[" + wait + "..");
    }

	if(wait==0) {
		return;
	} else if(wait==5) {
		wait--;
		self.setTimeout("cnnLoadContentFromURL('" + frameName + "','" + divId + "'," + wait + ")",1000);
		return;
	} else {
		wait--;
	}
	var content = null;
	var myDoc = window.frames[frameName].document;
	try {		
		content = myDoc.body.innerHTML;
		if(content==null || content=='') {
                    if (divId == null || divId == "cnnPollerLoader") {
                        //alert("scripts.js:cnnGetContentFromURL.#2 divId[" + divId + "] content not avail, wait 20,000ms...");
                    }

			self.setTimeout("cnnLoadContentFromURL('" + frameName + "','" + divId + "'," + wait + ")",2000);
		} else {
                    if (divId == null || divId == "cnnPollerLoader") {
                        //alert("scripts.js:cnnGetContentFromURL.#2 divId[" + divId + "] content now available!...");
                    }
			document.getElementById(divId).innerHTML = content;	
			cnnInitiateFrame(divId);
		}
	} catch(e) {
                    if (divId == null || divId == "cnnPollerLoader") {
                        //alert("scripts.js:cnnGetContentFromURL.#2 divId[" + divId + "] exception...content not available.. wait 20,000ms...");
                    }

		self.setTimeout("cnnLoadContentFromURL('" + frameName + "','" + divId + "'," + wait + ")",2000);

	}
}

function cnnSearchForTag(nodeList, tagName)
{
	var retArray = new Array();
	for(var i=0;i<nodeList.length;i++)
	{
		if(nodeList.item(i)&&nodeList.item(i).nodeName&&nodeList.item(i).nodeName==tagName &&nodeList.item(i).firstChild&&nodeList.item(i).firstChild.nodeValue)
		{
			retArray.push(nodeList.item(i).firstChild&&nodeList.item(i).firstChild.nodeValue);
		}
		else if(nodeList.item(i)&&nodeList.item(i).childNodes)
		{
			retArray.concat( cnnSearchForTag(nodeList.item(i).childNodes, tagName ) );
		}
	}
	return retArray;
}

function cnnExecuteInlineScripts(html)
{
	html = html.split(/\n|\r/).join('');
	
	var scriptText = '';
	var openScripts = html.split(/<script[^>]*?>/i)

	for(var i=1;i<openScripts.length;i++)
	{
		scriptText+=openScripts[i].split(/<\/script>/i)[0];
	}

	if(scriptText)
	{
		eval(scriptText);
	}
}


function cnnExecuteResponseScripts( response ) 
{
    if (response && response.readyState == 4) 
	{
        if (response.status == 200) 
		{
        	var scriptTags = null;
            var goodParse = true;
            var xmlDoc = '';
            if(safari || firefox) 
			{
            	scriptTags = response.responseXML.getElementsByTagName("script");
			}
			else 
			{
//				alert('would have created activeX object here!');
            }
			if((scriptTags!=null)  && goodParse)
            {
            	for(x=0;x<scriptTags.length;x++) 
				{
					var localScriptTags = scriptTags;
					if(localScriptTags[x].firstChild && localScriptTags[x].firstChild.nodeValue)
					{
						//alert(scriptTags[x].firstChild.nodeValue);
						eval(localScriptTags[x].firstChild.nodeValue);
					}
					localScriptTags = null;
				}
			}
			scriptTags = null;
			xmlDoc = null;
        } else 
		{
        }
    }
	else 
	{
    }
}

function cnnDrawResponse( response, divId ) {
    if (response && response.readyState == 4) {
        if (response.status == 200) {
        	document.getElementById(divId).innerHTML = response.responseText;
        	cnnInitiateFrame(divId);
			if(usingActiveX)
			{
				cnnExecuteInlineScripts(response.responseText);
			}
			else
			{
	        	cnnExecuteResponseScripts( response );
			}
        }
    }
}

var usingActiveX = false;
//var lastUrlRequest = new Array();

function cnnLoadContent(reqVar,loaderId,divId,url, cacheTime) {

 if (cnnDPFlag) return;
    // If msie or safari, then use XMLHttpRequest. Firefox has problems
    // due to the manipulation of document.domain. To be safe, we
    // are only going to use XMLHttpRequest for msie.

    if (msie || safari) {
        if (reqVar==null) {
            if (window.XMLHttpRequest) {
                reqVar = new XMLHttpRequest();
				if(reqVar.overrideMimeType)
				{
	                reqVar.overrideMimeType("text/xml");
				}
				else if(msie7)
				{
					url = addCacheBusting(url, cacheTime);
					usingActiveX=true;
				}
            } else if (window.ActiveXObject) {
                try {
                    reqVar = new ActiveXObject("Msxml2.XMLHTTP");
					usingActiveX = true;
                } catch(e) {
                    try {
                        reqVar = new ActiveXObject("Microsoft.XMLHTTP");
						usingActiveX = true;
                    } catch(e) {
                        // do nothing
                    }
                }
            }
        }
    }

    // use IFRAME 
    if ((!msie && !safari) || (reqVar == null)) {
        if (divId == null || divId == "cnnPollerLoader") {
            //alert("scripts.js:cnnLoadContent:cnnPollerLoader; divId[" + divId + "] not msie/safari... call cnnGetContentFromURL..."); 
        }

        cnnGetContentFromURL(loaderId,divId,url, cacheTime);
        return;  
    }

    // continue with XMLHttpRequest stuff
    if (divId != null && typeof divId != 'undefined') {
        reqVar.onreadystatechange = function( ) {
       	    cnnDrawResponse(reqVar,divId);
    	}
    } else {
			if(usingActiveX)
			{
				cnnDrawResponse(reqVar, 'cnnWriteContents');
			}
			else
			{
		        reqVar.onreadystatechange = function( ) {
	            cnnExecuteResponseScripts(reqVar);
			}
        }
    }
    try {
        reqVar.open("GET", url);
        reqVar.send("");
	} catch (e) {
    }
}


function cnnInitiateFrame(divId) {
	if(divId=='cnnJustInFrame') {
		if(document.getElementById("cnnJustIn").className == "cnnJustInOn") {
			parent.initJustInScrollLayer();
		}
	} else if(divId=='cnnScheduleFrame') {
		if(document.getElementById("cnnSchedule").className == "cnnScheduleOn") {
			parent.initScheduleScrollLayer();
		}
	}  else if(divId=='cnnRelated') {
		parent.initRelatedScrollLayer();
	}  else if(divId=='cnnBrowseFrame') {
		if(document.getElementById("cnnBrowseFrame").style.visibility == "visible") {
			parent.initBrowseScrollLayer();
		}
	}  else if(divId=='cnnSearchFrame') {
		parent.initSearchScrollLayer();
	} else if(divId=='cnnLiveFeeds') {
		if(liveFeedPlaying!=null) {
			selectNowPlaying(liveFeedPlaying);
		}
	}
}

function changeOpacity(opacity, id) { 
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100); 
	object.MozOpacity = (opacity / 100); 
	object.KhtmlOpacity = (opacity / 100); 
	object.filter = "alpha(opacity=" + opacity + ")"; 
}

function changeOpacity2(opacity, styleObject) {
        styleObject.opacity = (opacity / 100);
        styleObject.MozOpacity = (opacity / 100);
        styleObject.KhtmlOpacity = (opacity / 100);
        styleObject.filter = "alpha(opacity=" + opacity + ")";
}


function cnnLoadVideo(directory) {
    if (cnnDPFlag) return;

	cnnCurVOD = directory;
	clearNowPlaying();
	cnnCurrentVideoDirectory = directory;
	var video = document.getElementById('cnnVideoScreen');

        // See which video file to pick up. The promoscripts.js file is the only file that
        // defines the "previewPlayer" variable.

        if (typeof(previewPlayer) == "undefined") {
            //alert("video file [" + cnnRootUrlForContent + cnnCurrentVideoDirectory + "/video.html]");
	    video.src = addCacheBusting(cnnRootUrlForContent + cnnCurrentVideoDirectory + '/video.html');
        } else {
            //alert("video file [" + cnnRootUrlForContent + cnnCurrentVideoDirectory + "/video.preview.html]");
            video.src = addCacheBusting(cnnRootUrlForContent + cnnCurrentVideoDirectory + '/video.preview.html');
        }
//alert(video.src);
        cnnRefreshRelated();
}

function cnnLoadLiveStream(streamNum) {
    //alert("Inside cnnLoadLiveStream ... cnnDPFlag is " + cnnDPFlag);
    if (cnnDPFlag) return;

        cnnCurLiveStream = streamNum;
	switch(streamNum) {
		case 1:			
			cnnLoadVideo(cnnLiveStream1Dir);
			liveFeedPlaying = 'liveStream1';
			break;
		case 2: 
			cnnLoadVideo(cnnLiveStream2Dir);
			liveFeedPlaying = 'liveStream2';
			break;
		case 3:
			cnnLoadVideo(cnnLiveStream3Dir);
			liveFeedPlaying = 'liveStream3';
			break;
		case 4:
			cnnLoadVideo(cnnLiveStream4Dir);
			liveFeedPlaying = 'liveStream4';
			break;
	}
        cnnCurMode = "live";
	selectNowPlaying(liveFeedPlaying);
}

/* content loading / refreshing */

var cnnRelatedReq = null;
function cnnRefreshRelated(cacheTime) {
    // see if we are in overnight mode, and the user is currently watching
    // live feed pipe 1
    if ((cnnCurDayNightMode == "overnight") && 
        (liveFeedPlaying) &&
        (cnnCurLiveStream == 1)) {
        
        // load the CMS-generated related file for pipe #1
        cnnLoadContent(cnnRelatedReq,'cnnRelatedLoader','cnnRelated', cnnPipe1OvernightRelatedsUrl, cacheTime);
    } else {
        cnnLoadContent(cnnRelatedReq,'cnnRelatedLoader','cnnRelated',cnnRootUrlForContent + cnnCurrentVideoDirectory + '/related.html', cacheTime);
    }
}

var cnnJustInReq = null;
function cnnRefreshJustIn(cacheTime) {
//alert("Got a request to refresh Just In...");
	cnnLoadContent(cnnJustInReq,'cnnJustInLoader','cnnJustInFrame',cnnRootUrlForContent + 'content/justin/latest.html',cacheTime);
}

var cnnScheduleReq = null;
function cnnRefreshSchedule(cacheTime) {
	cnnLoadContent(cnnScheduleReq,'cnnScheduleLoader','cnnScheduleFrame',cnnRootUrlForContent + 'content/schedule/latest.html',cacheTime);
}

var cnnNITNReq = null;
function cnnRefreshNowInTheNews(cacheTime) {
	cnnLoadContent(cnnNITNReq,'cnnNowInTheNewsLoader','cnnNowInTheNews',cnnRootUrlForContent + 'content/now_in_the_news/latest.html', cacheTime);
}

var cnnTP1Req = null;
var cnnTP2Req = null;
var cnnTP3Req = null;
function cnnRefreshTopStories(cacheTime) {
	cnnLoadContent(cnnTP1Req,'cnnTopStory1Loader','cnnTopStories1',cnnRootUrlForContent + 'content/top_stories/1.html', cacheTime);
	cnnLoadContent(cnnTP2Req,'cnnTopStory2Loader','cnnTopStories2',cnnRootUrlForContent + 'content/top_stories/2.html', cacheTime);
	cnnLoadContent(cnnTP3Req,'cnnTopStory3Loader','cnnTopStories3',cnnRootUrlForContent + 'content/top_stories/3.html', cacheTime);
}

var cnnLiveFeedsReq = null;
function cnnRefreshLiveFeeds(cacheTime) {
	cnnLoadContent(cnnLiveFeedsReq,'cnnLiveFeedsLoader','cnnLiveFeeds',cnnRootUrlForContent + 'content/live_feeds/latest.html', cacheTime);
}

function addCacheBusting(src, cacheTime) {
   var cur = new Date()
   var cnnCB = (cur.getTime() % 3000);
   if(cacheTime) { cnnCB = cacheTime;}

    // only works for files that do not have a query string...fine for now
    if (src.indexOf("?") == -1) {
        // no query string
        src = src + "?cur=" + cnnCB;
    } else {
        // query string found
        src = src.substring(0, src.indexOf("?")) + "?cur=" + cnnCB;
    }
    
    return src;
}

function cnnRefreshLiveFeedImages(cacheTime) {
    if (cnnDPFlag) return;

    if(document.images['liveStream1']) document.images['liveStream1'].src = addCacheBusting(document.images['liveStream1'].src, cacheTime);
    if(document.images['liveStream2']) document.images['liveStream2'].src = addCacheBusting(document.images['liveStream2'].src, cacheTime);
    if(document.images['liveStream3']) document.images['liveStream3'].src = addCacheBusting(document.images['liveStream3'].src, cacheTime);
    if(document.images['liveStream4']) document.images['liveStream4'].src = addCacheBusting(document.images['liveStream4'].src, cacheTime);

    self.setTimeout("cnnRefreshLiveFeedImages()", pollingIntervalMS);
}

var cnnOnDemandReq = null;
function cnnRefreshOnDemand(cacheTime) {
	cnnLoadContent(cnnOnDemandReq,'cnnOnDemandLoader','cnnOnDemandFrame',cnnRootUrlForContent + 'content/on_demand/latest.html', cacheTime);
}

var cnnOnDemandCheckReq = null;
function cnnRefreshOnDemandCheck(cacheTime) {
	cnnLoadContent(cnnOnDemandCheckReq,'cnnOnDemandCheckLoader','cnnOnDemandCheckFrame',cnnRootUrlForContent + 'content/check_this_out/latest.html', cacheTime);
}

var cnnBrowseReq = null;
function cnnRefreshBrowse(url, cacheTime) {
	cnnLoadContent(cnnBrowseReq,'cnnBrowseLoader','cnnBrowseFrame',cnnRootUrlForContent + url, cacheTime);
}

var cnnSearchReq = null;
function cnnRefreshSearch(cnnQueryString, cacheTime) {
	cnnGetContentFromURL('cnnSearchLoader','cnnSearchFrame',cnnSearchJSP + cnnQueryString, cacheTime);
        //cnnLoadContentFromURL(cnnSearchReq,'cnnSearchLoader','cnnSearchFrame', cnnSearchJSP + cnnQueryString);
}

function cnnSetVideoTitle(title) {
	document.getElementById('cnnVideoTitle').innerHTML = title;
}

var cnnWhatsOnReq = null;
function cnnRefreshWhatsOn(cacheTime) {
	if(videoActiveX) {
		cnnLoadContent(cnnWhatsOnReq,'cnnWhatsOnLoader','whatsOnTempStpace',cnnRootUrlForContent + 'content/whats_on/latest.html', cacheTime);
	}
}

function cnnRunTickers() {
	var text = "";
	if(cnnTickerItems.length>0) {
		if(cnnTickerCount<cnnTickerItems.length) {
			text = cnnTickerItems[cnnTickerCount];	
		} else {
			cnnTickerCount = 0;
			text = cnnTickerItems[cnnTickerCount];
		}
		if(text.length>0) {
			document.getElementById("cnnWhatsOn").innerHTML = text;
			cnnTickerCount++;
			self.setTimeout("cnnRunTickers()",pollingIntervalMS);
		} else {
			cnnTickerCount++;
			cnnRunTickers();
			return;
		}
	} else {
		self.setTimeout("cnnRunTickers()",pollingIntervalMS);
	}
	
}

/* Poller */

var pollLastUpdateArr = new Array();
var pollLastCheckArr = new Array();
var pollLastPolledTime = -1;
var hasPolled = false;

var cnnPollerReq = null;
function pollForContentUpdates() {
    if (cnnDPFlag) return;

    var pollerFile = "/video/portable/poller/index.exclude.ppl";

    cnnLoadContent(cnnPollerReq,'cnnPollerLoader','PollerStpace', pollerFile);
    self.setTimeout("pollForContentUpdates('" + cnnPollerLoader + "',null, '" + pollerFile + "')",pollingIntervalMS);

}

function pollLastUpdatecontent(id, time) {
	pollLastUpdateArr[ id ] = time;
}


function cnnGrabHeadline() {
	var cnnLiveFeedHeadline= "";
	if (document.getElementById('cnnRelated')) {
		cnnLiveFeedHeadline = document.getElementById('cnnRelated').getElementsByTagName('div')[1].innerHTML;
		return cnnLiveFeedHeadline;
	}
	return false;
}

function pollHandleUpdates() {

	for(var areaId in pollLastUpdateArr) {
		if(areaId && pollLastUpdateArr[ areaId ]) {
			var time = pollLastUpdateArr[ areaId ];
			if(!pollLastCheckArr[ areaId ] ||pollLastCheckArr[ areaId ]==null) {
				pollLastCheckArr[ areaId ] = time;
				//alert(areaId + ":" + time);
				continue;
			}

			var lastTimeCheck = pollLastCheckArr[ areaId ];
//alert("lastTimeCheck for " + areaId + " is " + lastTimeCheck);
			if((!lastTimeCheck) || (lastTimeCheck<time)) {
				pollLastCheckArr[ areaId ] = time;
				//alert(areaId + ":" + time);
				switch( areaId ) {
					case 'liveStream1':
						if(liveFeedPlaying=='liveStream1') {
							cnnRefreshRelated(time);
							window.setTimeout("cnnSetVideoTitle(cnnGrabHeadline())",1000);
						}
						break;
					case 'liveStream2':
						if(liveFeedPlaying=='liveStream2') {
							cnnRefreshRelated(time);
							window.setTimeout("cnnSetVideoTitle(cnnGrabHeadline())",1000);
						}
						break;
					case 'liveStream3':
						if(liveFeedPlaying=='liveStream3') {
							cnnRefreshRelated(time);
							window.setTimeout("cnnSetVideoTitle(cnnGrabHeadline())",1000);
						}
						break;
					case 'liveStream4':
						if(liveFeedPlaying=='liveStream4') {
							cnnRefreshRelated(time);
							window.setTimeout("cnnSetVideoTitle(cnnGrabHeadline())",1000);
						}
						break;
					case 'liveFeeds':
						cnnRefreshLiveFeeds(time);	
						break;
					case 'justIn':
						cnnRefreshJustIn(time); 
						break;
					case 'topStories':
						cnnRefreshTopStories(time);
						break;
					case 'nowInTheNews':
						cnnRefreshNowInTheNews(time);
						break;
					case 'schedule':
						cnnRefreshSchedule(time); 
						break;
					case 'onDemand':
						cnnRefreshOnDemand(time);
						break;
					case 'onDemandCheck':
						cnnRefreshOnDemandCheck(time);
						break;
					case 'whatsOn':
						cnnRefreshWhatsOn(time);
						break; 
				}
			}
		}
	}
}


/* header area */
function cnnDisplayDownloadButton(show) {
	if(show) {
		document.getElementById('cnnDownloadButton').style.visibility='visible';
	} else {
		document.getElementById('cnnDownloadButton').style.visibility='hidden';
	}
}

/* top left select section */

function cnnActivateSelectSection() {
	document.getElementById('cnnSelectSectionOptions').style.visibility='visible';
	document.getElementById('cnnSelectSectionOptionsHide').style.visibility='visible';
}

function cnnDeactivateSelectSection() {
	document.getElementById('cnnSelectSectionOptions').style.visibility='hidden';
	document.getElementById('cnnSelectSectionOptionsHide').style.visibility='hidden';
}

function cnnSelectSection(title,section) {
        cnnBrowseSectionTitle = title;
	cnnBrowseSection = section;
	cnnLoadBrowse('default');
	var select1= document.getElementById("cnnSelectSectionText");
	select1.innerHTML = title;
	var select2= document.getElementById("cnnBrowseSelectSectionText");
	select2.innerHTML = title;
	cnnDeactivateSelectSection();
	cnnDeactivateBrowseSelectSection();
	cnnShowBrowse();
}

/* top stories */

function cnnStopTopStories() {
        document.getElementById("cnnTopStoriesPlayButton").src = cnnRootUrlForImages + "images/topstories_play.gif";
        changeOpacity(99, "cnnTopStories1");
        changeOpacity(99, "cnnTopStories2");
        changeOpacity(99, "cnnTopStories3");
        cnnFadeTopStoriesOpac = 99;
        cnnFadeTopStoriesCurrent = false;
        //if(cnnTopStoriesTimerRunning) {
                clearTimeout(cnnTopStoriestTimerID);
        //}
        cnnTopStoriesTimerRunning = false;
        cnnTopStoriesCounter = 0;
}

function cnnStartTopStories() {
        cnnTopStoriesTimerRunning = true;
        if (cnnTopStoriesSecs==0) {
                if(cnnTopStoriesCounter==6) {
                        cnnStopTopStories();
                } else {
                        cnnLoadNextTopStory();
                        cnnFadeTopStories();
                        cnnTopStoriesSecs=10;
                        cnnTopStoriesCounter++;
                        cnnTopStoriestTimerID = self.setTimeout("cnnStartTopStories()", cnnTopStoriesDelay);
                }
        } else {
                cnnTopStoriesSecs = cnnTopStoriesSecs - 1;
                cnnTopStoriestTimerID = self.setTimeout("cnnStartTopStories()", cnnTopStoriesDelay);
        }
}

function cnnPlayTopStories() {
        document.getElementById("cnnTopStoriesPlayButton").src = cnnRootUrlForImages + "images/topstories_pause.gif";
        cnnStartTopStories();
}

function cnnActivateTopStories() {
        if(cnnTopStoriesTimerRunning) {
                if(cnnFadingOut) {                                                           
                        cnnLoadPreviousTopStory();                                           
                }
                cnnStopTopStories();
        } else {
                cnnTopStoriesSecs = 0;
                cnnPlayTopStories();
        }
}

function cnnSwapTopStories() {
        document.getElementById("cnnTopStories" + cnnPreviousTopStory).className = "cnnTopStoriesOff";
        document.getElementById("cnnTopStories" + cnnCurrentTopStory).className = "cnnTopStoriesOn";
        document.getElementById("cnnTopStories" + cnnNextTopStory).className = "cnnTopStoriesOff";
}

var cnnFadingOut = false;
function cnnFadeTopStories() {
        if(!cnnTopStoriesTimerRunning) return;
        if(!cnnFadeTopStoriesCurrent) {
                cnnFadingOut = true;
                if(cnnFadeTopStoriesOpac>0) {
                        cnnFadeTopStoriesOpac = cnnFadeTopStoriesOpac-3;
                        changeOpacity(cnnFadeTopStoriesOpac, "cnnTopStories" + cnnPreviousTopStory);
                        setTimeout("cnnFadeTopStories()",50);
                        return;
                } else {
                        document.getElementById("cnnTopStories" + cnnPreviousTopStory).className = "cnnTopStoriesOff";
                        changeOpacity(99, "cnnTopStories" + cnnPreviousTopStory);
                        cnnFadeTopStoriesCurrent = true;
                        changeOpacity(1,"cnnTopStories" + cnnCurrentTopStory);
                        document.getElementById("cnnTopStories" + cnnCurrentTopStory).className = "cnnTopStoriesOn";
                        setTimeout("cnnFadeTopStories()",50);
                        cnnFadingOut = false;
                        return;
                }
        } else {
                if(cnnFadeTopStoriesOpac<99) {
                        cnnFadeTopStoriesOpac = cnnFadeTopStoriesOpac+3;
                        changeOpacity(cnnFadeTopStoriesOpac, "cnnTopStories" + cnnCurrentTopStory);
                        setTimeout("cnnFadeTopStories()",50);
                        return;
                } else {
                        cnnFadeTopStoriesCurrent = false;
                }
        }
}

function cnnLoadNextTopStory() {
        if(cnnCurrentTopStory==3) {
                cnnCurrentTopStory = 1;
                cnnNextTopStory = 2;
                cnnPreviousTopStory = 3;
        } else if(cnnCurrentTopStory==2) {
                cnnCurrentTopStory = 3;
                cnnNextTopStory = 1;
                cnnPreviousTopStory = 2;
        } else if(cnnCurrentTopStory==1) {
                cnnCurrentTopStory = 2;
                cnnNextTopStory = 3;
                cnnPreviousTopStory = 1;
        }
}

function cnnSelectNextTopStory() {
        cnnStopTopStories();
        cnnLoadNextTopStory();
        cnnSwapTopStories();
}

function cnnLoadPreviousTopStory() {
        if(cnnCurrentTopStory==3) {
                cnnCurrentTopStory = 2;
                cnnNextTopStory = 3;
                cnnPreviousTopStory = 1;
        } else if(cnnCurrentTopStory==2) {
                cnnCurrentTopStory = 1;
                cnnNextTopStory = 2;
                cnnPreviousTopStory = 3;
        } else if(cnnCurrentTopStory==1) {
                cnnCurrentTopStory = 3;
                cnnNextTopStory = 1;
                cnnPreviousTopStory = 2;
        }
}

function cnnSelectPreviousTopStory() {
        cnnStopTopStories();
        cnnLoadPreviousTopStory();
        cnnSwapTopStories();
}

function cnnMouseOverTopStories(link){
        link.className = "cnnStoryOn";
//        if(msie) {
                link.childNodes[0].style.visibility = "visible";
//        } else {
//                link.childNodes[1].style.visibility = "visible";
//        }
        if(cnnTopStoriesTimerRunning) {
                if(cnnFadingOut) {
                        cnnLoadPreviousTopStory();
                }
                cnnStopTopStories();
                cnnTopStoriesMouseOverPaused = true;
        }
}

function cnnMouseOutTopStories(link){
        link.className = "cnnStoryOff";
//        if(msie) {
                link.childNodes[0].style.visibility = "hidden";
//        } else {
//                link.childNodes[1].style.visibility = "hidden";
//        }
        if(cnnTopStoriesMouseOverPaused) {
                cnnPlayTopStories();
                cnnTopStoriesMouseOverPaused = false;
        }
}

/* just in */

function cnnShowJustIn() {
	document.getElementById("cnnJustIn").className = "cnnJustInOn";
	document.getElementById("cnnSchedule").className = "cnnScheduleOff";
	parent.initJustInScrollLayer();
}

/* schedule */

function cnnShowSchedule() {
	document.getElementById("cnnJustIn").className = "cnnJustInOff";
	document.getElementById("cnnSchedule").className = "cnnScheduleOn";
	parent.initScheduleScrollLayer();
}

/* your voice */

function cnnClearYourVoiceFields() {
	//document.getElementById('cnnYourVoiceName').value='';
	//document.getElementById('cnnYourVoiceEmail').value='';
	document.getElementById('cnnYourVoiceFeedback').value='';
}

function cnnLaunchYourVoice(name,email,feedback) {
	document.getElementById('cnnYourVoiceName').value=name;
	document.getElementById('cnnYourVoiceEmail').value=email;
	document.getElementById('cnnYourVoiceFeedback').value=feedback;
	cnnOpenYourVoice();
}

function cnnOpenYourVoice() {
	if(!cnnYourVoiceOn) {
		document.getElementById('cnnYourVoice').style.visibility='visible';
		document.getElementById('cnnYourVoice').style.display='';
		cnnYourVoiceOn = true;
		} else {
		cnnCloseYourVoice();
		}
}

function cnnCloseYourVoice() {
	cnnCloseYourVoiceThankyou();
	cnnClearYourVoiceFields();
	document.getElementById('cnnYourVoice').style.visibility='hidden';
	document.getElementById('cnnYourVoice').style.display='none';
	cnnYourVoiceOn = false;
}

function cnnCloseYourVoiceThankyou() {
	document.getElementById('cnnYourVoiceThankyou').style.visibility='hidden';
	document.getElementById('cnnYourVoiceThankyou').style.display='none';
}

function cnnSendYourVoice() {
	var feedback = document.getElementById('cnnYourVoiceFeedback').value;
	if (feedback == "") {
		alert("Please enter your feedback.");
		return;
        }
	if (document.getElementById('cnnYourVoiceForm').permissionCheck.checked) {
		document.getElementById('cnnYourVoiceForm').permission.value = "on";
        } else {
                document.getElementById('cnnYourVoiceForm').permission.value = "off";
	}

	document.getElementById('cnnYourVoiceForm').submit();
	document.getElementById('cnnYourVoiceThankyou').style.visibility='visible';
	document.getElementById('cnnYourVoiceThankyou').style.display='';
	cnnClearYourVoiceFields();
}

/* bottom area  */

function cnnHideAllBottomAreas() {
	document.getElementById("cnnLiveFeedsButton").src = cnnRootUrlForImages + "images/live_feeds_off.gif";
	document.getElementById("cnnLiveFeeds").className = "cnnLiveFeedsOff";	
	document.getElementById("cnnOnDemandButton").src = cnnRootUrlForImages + "images/on_demand_off.gif";
	document.getElementById("cnnOnDemand").className = "cnnOnDemandOff";
	document.getElementById("cnnBrowseButton").src = cnnRootUrlForImages + "images/browse_off.gif";
	if(msie) {
		document.getElementById("cnnBrowse").className = "cnnBrowseOffNoDisplay";
		} else {
		document.getElementById("cnnBrowse").className = "cnnBrowseOff";
		}
	document.getElementById("cnnSearch").className = "cnnSearchOff";
	document.getElementById("cnnOnDemandFrame").style.visibility='hidden';
	document.getElementById("cnnOnDemandCheckFrame").style.visibility='hidden';
	if(firefox || msie) {
		document.getElementById("cnnLiveFeeds").style.display = 'none';
		document.getElementById("cnnOnDemand").style.display = 'none';
		document.getElementById("cnnSearch").style.display='none';
		document.getElementById("cnnBrowse").style.display='none';
		}
}

function cnnShowLiveFeeds() {
	cnnCurMode = "live";
	cnnHideAllBottomAreas();
	document.getElementById("cnnLiveFeedsButton").src = cnnRootUrlForImages + "images/live_feeds_on.gif";
	document.getElementById("cnnLiveFeeds").className = "cnnLiveFeedsOn";
	if(firefox || msie) {
		document.getElementById("cnnLiveFeeds").style.display = '';
		}
}

function cnnShowOnDemand() {
	cnnCurMode = "vod";
	cnnHideAllBottomAreas();
	document.getElementById("cnnOnDemandButton").src = cnnRootUrlForImages + "images/on_demand_on.gif";
	document.getElementById("cnnOnDemand").className = "cnnOnDemandOn";
	if(firefox || msie) {
		document.getElementById("cnnOnDemand").style.display = '';
		}
	cnnResetOnDemandFrames();
}

function cnnShowBrowse() {
	cnnCurMode = "browse";
	cnnHideAllBottomAreas();
	document.getElementById("cnnBrowseButton").src = cnnRootUrlForImages + "images/browse_on.gif";
	document.getElementById("cnnBrowse").className = "cnnBrowseOn";
	if(firefox || msie) {
		document.getElementById("cnnBrowse").style.display='';
		}
	parent.initBrowseScrollLayer();
}

function cnnShowSearch() {
	cnnCurMode = "search";
	cnnHideAllBottomAreas();
	document.getElementById("cnnSearch").className = "cnnSearchOn";
	if(firefox || msie) {
		document.getElementById("cnnSearch").style.display='';
		}
}

/* on demand */

function cnnMouseOverLiveOnDemand(link){
	link.parentNode.className = "cnnOnDemandMouseOver";
//	if(msie) {
		link.childNodes[0].style.visibility = "visible";
//	} else {
//		link.childNodes[1].style.visibility = "visible";
//	}
}

function cnnMouseOutLiveOnDemand(link){
	link.parentNode.className = null;
//	if(msie) {
		link.childNodes[0].style.visibility = "hidden";
//	} else {
//		link.childNodes[1].style.visibility = "hidden";
//	}
}

function cnnSetOnDemandTotalPages(num) {
	cnnOnDemandTotalPages = num;
	cnnOnDemandSlidePos=0;
	cnnRefreshOnDemandHeader("PRODUCER PICKS: " + (cnnOnDemandSlidePos+1) + " of " +  cnnOnDemandTotalPages);
}

function cnnRefreshOnDemandHeader(text) {
	document.getElementById("cnnOnDemandHeader").innerHTML = text;
}

function cnnResetOnDemandFrames() {
	document.getElementById("cnnOnDemandFrame").style.visibility='hidden';
	document.getElementById("cnnOnDemandCheckFrame").style.visibility='hidden';
	document.getElementById(cnnCurrentOnDemandFrame).style.visibility='visible';
}

function cnnLoadProducerPicks() {
	cnnCurrentOnDemandFrame="cnnOnDemandFrame";
	cnnResetOnDemandFrames();
	if(firefox && windows) {
		document.getElementById("cnnOnDemand").style.display = 'none';
		document.getElementById("cnnOnDemand").style.display = '';
		}
	cnnRefreshOnDemandHeader("PRODUCER PICKS: " + (cnnOnDemandSlidePos+1) + " of " +  cnnOnDemandTotalPages);
	document.getElementById("cnnOnDemandProducerButton").className = "cnnOnDemandProducerButtonOn";
	cnnSetPreviousNextOnDemandButtonState();
	document.getElementById("cnnOnDemandCheckButton").className = "cnnOnDemandCheckButtonOff";
	}

/*
function cnnLoadCheckThisOut() {
	cnnCurrentOnDemandFrame="cnnOnDemandCheckFrame";
	cnnResetOnDemandFrames();
	if(firefox && windows) {
		document.getElementById("cnnOnDemandFrame").style.display = 'none';
		document.getElementById("cnnOnDemandFrame").style.display = '';
		}
	cnnRefreshOnDemandHeader('CHECK THIS OUT');
	document.getElementById("cnnOnDemandProducerButton").className = "cnnOnDemandProducerButtonOff";
	document.getElementById("cnnOnDemandNextButton").className = "cnnOnDemandNextOff";
	document.getElementById("cnnOnDemandPreviousButton").className = "cnnOnDemandPreviousOff";
	document.getElementById("cnnOnDemandCheckButton").className = "cnnOnDemandCheckButtonOn";
}
*/

function cnnOnDemandSlideNext() {
	cnnCurrentOnDemandFrame="cnnOnDemandFrame";
	cnnResetOnDemandFrames();
	if(firefox && windows) {
		document.getElementById("cnnOnDemand").style.display = 'none';
		document.getElementById("cnnOnDemand").style.display = '';
		}
	cnnOnDemandSlideNextMove();
}

function cnnSetPreviousNextOnDemandButtonState() {
	if(cnnOnDemandSlidePos==(cnnOnDemandTotalPages-1)){
		document.getElementById("cnnOnDemandNextButton").src = cnnRootUrlForImages + "images/on_demand_next_on.gif";
	} else {
		document.getElementById("cnnOnDemandNextButton").src = cnnRootUrlForImages + "images/on_demand_next_off.gif";
	}
	if(cnnOnDemandSlidePos==0){
		document.getElementById("cnnOnDemandPreviousButton").src = cnnRootUrlForImages + "images/on_demand_previous_on.gif";
	} else {
		document.getElementById("cnnOnDemandPreviousButton").src =cnnRootUrlForImages + "images/on_demand_previous_off.gif";
	}
}

function cnnOnDemandSlideNextMove() {
	var move = 10;
	var timer = 10;
	if(firefox) {
		move = 10;
		timer = 10;
	}
	if(cnnOnDemandSlidePos<(cnnOnDemandTotalPages-1)) {
		if(cnnOnDemandSlideCounterN<785) {
			cnnOnDemandSlideCounterN = cnnOnDemandSlideCounterN + move;	
			document.getElementById('cnnOnDemandFrame').style.left = "-" + (cnnOnDemandSlideCounterN + (cnnOnDemandSlidePos*785)) + "px";			
			setTimeout("cnnOnDemandSlideNextMove()",timer);
			
		} else {
			cnnOnDemandSlideCounterN=0;
			cnnOnDemandSlidePos++;
			cnnRefreshOnDemandHeader("PRODUCER PICKS: " + (cnnOnDemandSlidePos+1) + " of " +  cnnOnDemandTotalPages);
			cnnSetPreviousNextOnDemandButtonState();
		}
	}
}

function cnnOnDemandSlidePrevious() {
	cnnCurrentOnDemandFrame="cnnOnDemandFrame";
	cnnResetOnDemandFrames();
	if(firefox && windows) {
		document.getElementById("cnnOnDemand").style.display = 'none';
		document.getElementById("cnnOnDemand").style.display = '';
		}
	cnnOnDemandSlidePreviousMove();
}

function cnnOnDemandSlidePreviousMove() {
	var move = 10;
	var timer = 10;
	if(firefox) {
		move = 10;
		timer = 10;
	}
	if(cnnOnDemandSlidePos>0) {
		if(cnnOnDemandSlideCounterP>0) {
			cnnOnDemandSlideCounterP = cnnOnDemandSlideCounterP - move;	
			document.getElementById('cnnOnDemandFrame').style.left = "-" + (cnnOnDemandSlideCounterP + ((cnnOnDemandSlidePos-1)*785)) + "px";
			setTimeout("cnnOnDemandSlidePreviousMove()",timer);
		} else {
			cnnOnDemandSlideCounterP=790;
			cnnOnDemandSlidePos--;
			cnnRefreshOnDemandHeader("PRODUCER PICKS: " + (cnnOnDemandSlidePos+1) + " of " +  cnnOnDemandTotalPages);
			cnnSetPreviousNextOnDemandButtonState();
		}
	}
}


/* browse */

function cnnActivateBrowseSelectSection() {
	document.getElementById('cnnBrowseSelectSectionOptions').style.visibility='visible';
	document.getElementById('cnnBrowseSelectSectionOptionsHide').style.visibility='visible';
}

function cnnDeactivateBrowseSelectSection() {
	document.getElementById('cnnBrowseSelectSectionOptions').style.visibility='hidden';
	document.getElementById('cnnBrowseSelectSectionOptionsHide').style.visibility='hidden';
}

function cnnLoadBrowse(header) {
	cnnBrowsePage = 1;
	if(header=="default") {
		cnnBrowseButton = "time";
		cnnBrowseOrderAsc = false;
		header = cnnBrowseButton;
    } else {
            if(cnnBrowseButton==header) {
                cnnBrowseOrderAsc = !cnnBrowseOrderAsc;
            } else {
                cnnBrowseButton=header;
                if ((header == "time") || (header == "most_watched")) {
                    cnnBrowseOrderAsc = false;
                } else {
                    cnnBrowseOrderAsc = true;
                }
            }
        }


	cnnBrowseButtonsOff();
	var buttonName;
	if(header=="headline") {
		buttonName = "Headline";
		} else if(header=="time") {
		buttonName = "Time";
		} else if(header=="section") {
		buttonName = "Section";
		} else if(header=="most_watched") {
		buttonName = "MostWatched";
		}		
	var button = document.getElementById("cnnBrowse" + buttonName + "Button");
	//var frame = document.getElementById("cnnBrowseFrame");
	if(cnnBrowseOrderAsc) {
		button.src = cnnRootUrlForImages + "images/browse/" + cnnBrowseButton + "A.jpg";
		cnnRefreshBrowse("content/browse/" + cnnBrowseSection + "/" + cnnBrowseButton + "/asc/" + cnnBrowsePage + ".html");
	} else {
		button.src = cnnRootUrlForImages + "images/browse/" + cnnBrowseButton + "D.jpg";
		cnnRefreshBrowse("content/browse/" + cnnBrowseSection + "/" + cnnBrowseButton + "/desc/" + cnnBrowsePage + ".html");
	}
}

function cnnBrowseButtonsOff() {
	if(cnnBrowseButton!="headline") {
		var button = document.getElementById("cnnBrowseHeadlineButton");
		button.src = cnnRootUrlForImages + "images/browse/headline.jpg";
	}
	if(cnnBrowseButton!="time") {
		var button = document.getElementById("cnnBrowseTimeButton");
		button.src = cnnRootUrlForImages + "images/browse/time.jpg";
	}
	if(cnnBrowseButton!="section") {
		var button = document.getElementById("cnnBrowseSectionButton");
		button.src = cnnRootUrlForImages + "images/browse/section.jpg";
	}
	if(cnnBrowseButton!="most_watched") {
		var button = document.getElementById("cnnBrowseMostWatchedButton");
		button.src = cnnRootUrlForImages + "images/browse/most_watched.jpg";
	}
}

function cnnSetBrowsePagination(num,total) {
	cnnBrowsePage = num;
	cnnBrowseTotal = total;
	var area = document.getElementById("cnnBrowsePages");
	area.innerHTML = "";
	var start = 1;
	var url;
	if(num>2 && total>5) {
		start = num-2;
		if(num>(total-2)) {
			start = start - ( (num-total)+2);
		}
	}
	
	area.innerHTML += '&nbsp;&nbsp;';
	for(var i=start;i<(start+5) && i<=total;i++) {
		if(cnnBrowseOrderAsc) {
			url = "content/browse/" + cnnBrowseSection + "/" + cnnBrowseButton + "/asc/" + i + ".html";
		} else {
			url = "content/browse/" + cnnBrowseSection + "/" + cnnBrowseButton + "/desc/" + i + ".html";
		}
		if(i==num) {
			area.innerHTML += '<a href="#" class="on" onClick="cnnRefreshBrowse(\''+ url +'\')">' + i + '</a>';
			} else {
			area.innerHTML += '<a href="#" onClick="cnnRefreshBrowse(\''+ url +'\')">' + i + '</a>';
			}
	area.innerHTML += '&nbsp;&nbsp;';
	}
	var next = document.getElementById("cnnBrowseNextButton");
	if(cnnBrowsePage<cnnBrowseTotal) {
		next.src = cnnRootUrlForImages + "images/on_demand_next_off.gif";
	} else {
		next.src = cnnRootUrlForImages + "images/on_demand_next_on.gif";
	}
	var previous = document.getElementById("cnnBrowsePreviousButton");
	if(cnnBrowsePage>1) {
		previous.src = cnnRootUrlForImages + "images/on_demand_previous_off.gif";
	} else {
		previous.src = cnnRootUrlForImages + "images/on_demand_previous_on.gif";
	}
}

function cnnBrowseNext() {
	if(cnnBrowsePage<cnnBrowseTotal) {
		cnnBrowsePage++;
		var frame = document.getElementById("cnnBrowseFrame");
		cnnRefreshBrowse("content/browse/" + cnnBrowseSection + "/" + cnnBrowseButton + "/asc/" + cnnBrowsePage + ".html");		
	}
}

function cnnBrowsePrevious() {
	if(cnnBrowsePage>1) {
		cnnBrowsePage--;
		var frame = document.getElementById("cnnBrowseFrame");
		cnnRefreshBrowse("content/browse/" + cnnBrowseSection + "/" + cnnBrowseButton + "/asc/" + cnnBrowsePage + ".html");		
	}
}

/* search */

function cnnActivateSearchFilter() {
	document.getElementById('cnnSearchFilterOptions').style.visibility='visible';
	document.getElementById('cnnSearchFilterOptionsHide').style.visibility='visible';
}

function cnnDeactivateSearchFilter() {
	document.getElementById('cnnSearchFilterOptions').style.visibility='hidden';
	document.getElementById('cnnSearchFilterOptionsHide').style.visibility='hidden';
}

function cnnSearch() {
	var search = document.getElementById("cnnSearchField");
	cnnSearchQuery = document.getElementById("cnnSearchField").value;
	cnnSearchFilter = "All";
	cnnSearchButton = "time";
	cnnSearchOrderAsc = true;
        cnnSearchPage = 1;
	cnnLoadSearch();
	var results = document.getElementById("cnnSearchResults");
	results.innerHTML = "VIDEO SEARCH RESULTS for \""+cnnSearchQuery+ "\" - Results " + cnnSearchTotal;
	cnnShowSearch();
	return false;
}

function cnnLoadSearch() {
	var text= document.getElementById("cnnSearchFilterText");
	text.innerHTML = cnnSearchFilter;
	cnnSearchButtonsOff();
	var buttonName;
	if(cnnSearchButton=="headline") {
		buttonName = "Headline";
		} else if(cnnSearchButton=="time") {
		buttonName = "Time";
		} else if(cnnSearchButton=="section") {
		buttonName = "Section";
		} else if(cnnSearchButton=="most_watched") {
		buttonName = "MostWatched";
		}		
	var button = document.getElementById("cnnSearch" + buttonName + "Button");
	if(cnnSearchOrderAsc) {
		button.src = cnnRootUrlForImages + "images/search/" + cnnSearchButton + "A.jpg";
	} else {
		button.src = cnnRootUrlForImages + "images/search/" + cnnSearchButton + "D.jpg";
	}	
	//var url = "content/search/search.html?query=" + cnnSearchQuery + "&sortBy=" + cnnSearchButton + "&sortByAsc=" + cnnSearchOrderAsc + "&filterBy=" + cnnSearchFilter + "&currentPage=" + cnnSearchPage;
        var cnnQueryString = "?query=" + cnnSearchQuery + "&sortBy=" + cnnSearchButton + "&sortByAsc=" + cnnSearchOrderAsc + "&filterBy=" + cnnSearchFilter + "&currentPage=" + cnnSearchPage;

	cnnRefreshSearch(cnnQueryString);
}

function cnnSearchByHeader(header) {
	 if(cnnSearchButton==header) {
		cnnSearchOrderAsc = !cnnSearchOrderAsc;
	} else {
		cnnSearchButton=header;
                if (header == "most_watched") {
                    cnnSearchOrderAsc = false;
                } else {
                    cnnSearchOrderAsc = true;
                }

	}
	cnnSearchPage = 1;
	cnnLoadSearch();
}

function cnnSearchByPage(num) {
	cnnSearchPage = num;
	cnnLoadSearch();
}

function cnnSearchByFilter(filter) {
	cnnSearchPage = 1;
	cnnSearchFilter = filter;
	cnnSearchButton = "headline";
	cnnDeactivateSearchFilter();
	cnnLoadSearch();
}

function cnnSetSearchFilterOptions(options) {
	var filter = document.getElementById("cnnSearchFilterOptions");
	filter.innerHTML = "";
	for(var x=0; x<options.length;x++) {
		filter.innerHTML += "<a href=\"#\" onClick=\"cnnSearchByFilter('" + options[x] + "');\">" + options[x] + "</a>\n";	
	}
	var hide = document.getElementById("cnnSearchFilterOptionsHide");
	hide.style.height = (options.length*30) + "px";
}

function cnnSearchButtonsOff() {
	if(cnnSearchButton!="headline") {
		var button = document.getElementById("cnnSearchHeadlineButton");
		button.src = cnnRootUrlForImages + "images/search/headline.jpg";
	}
	if(cnnSearchButton!="time") {
		var button = document.getElementById("cnnSearchTimeButton");
		button.src = cnnRootUrlForImages +  "images/search/time.jpg";
	}
	if(cnnSearchButton!="section") {
		var button = document.getElementById("cnnSearchSectionButton");
		button.src = cnnRootUrlForImages + "images/search/section.jpg";
	}
	if(cnnSearchButton!="most_watched") {
		var button = document.getElementById("cnnSearchMostWatchedButton");
		button.src = cnnRootUrlForImages + "images/search/most_watched.jpg";
	}
}

function cnnSetSearchPagination(num, total, totalResults) {
	cnnVideoCount = totalResults;
	cnnSearchPage = num;
	cnnSearchTotal = total;
	var area = document.getElementById("cnnSearchPages");
	area.innerHTML = "";
	var start = 1;
	var url;
	if(num>2 && total>5) {
		start = num-2;
		if(num>(total-2)) {
			start = start - ( (num-total)+2);
		}
	}
	for(var i=start;i<(start+5) && i<=total;i++) {
		if(i==num) {
                        area.innerHTML += '<a href="#" onclick="cnnSearchByPage(' + i + ');" class="on">' + i + '</a>';
			} else {
                        area.innerHTML += '<a href="#" onclick="cnnSearchByPage(' + i + ');">' + i + '</a>';
			}
		if(i<total) {
			area.innerHTML += '&nbsp;&nbsp;';
		}
	}
	var next = document.getElementById("cnnSearchNextButton");
	if(cnnSearchPage<cnnSearchTotal) {
		next.src = cnnRootUrlForImages + "images/on_demand_next_off.gif";
	} else {
		next.src = cnnRootUrlForImages + "images/on_demand_next_on.gif";
	}
	var previous = document.getElementById("cnnSearchPreviousButton");
	if(cnnSearchPage>1) {
		previous.src = cnnRootUrlForImages + "images/on_demand_previous_off.gif";
	} else {
		previous.src = cnnRootUrlForImages + "images/on_demand_previous_on.gif";
	}
}

function cnnSearchNext() {
	if(cnnSearchPage<cnnSearchTotal) {
		cnnSearchPage++;
		cnnLoadSearch();		
	}
}

function cnnSearchPrevious() {
	if(cnnSearchPage>1) {
		cnnSearchPage--;
		cnnLoadSearch();		
	}
}

/* click to now playing */
function clearNowPlaying() {
	var image = null;
	if(liveFeedPlaying!=null) {
		try {
			image = document.getElementById(liveFeedPlaying);
			} catch(e) {}
	if(image!=null && lastNowPlayingImageSrc!=null) {	
		image.src = lastNowPlayingImageSrc;
		}
	liveFeedPlaying = null;
	lastNowPlayingImageSrc = null;	
	}
}

function selectNowPlaying(streamName) {
	clearNowPlaying();
	liveFeedPlaying = streamName;
	image = document.getElementById(streamName);
	if(image && image.src!="images/now_playing.jpg") {
		lastNowPlayingImageSrc = image.src;
		}
	if(image)
	{
		image.src = cnnRootUrlForImages + "images/now_playing.jpg";
	}
        cnnRefreshRelated();

}

function cnnReloadRegWall() {
    var file = "/video/portable/player.html";
    var queryStr = "?";

    if (cnnCurMode=='live') {
        queryStr += "mode=live&stream=" + cnnCurLiveStream;
    } else if (cnnCurMode=='vod') {
        queryStr += "mode=vod&video=" + cnnCurVOD;
    } else if (cnnCurMode=='browse') {
        queryStr += "mode=browse";
        queryStr += "&sectionName=" + cnnBrowseSectionTitle;
        queryStr += "&sectionDir=" + cnnBrowseSection;
    } else if (cnnCurMode=='search') {
        queryStr += "mode=search";
        queryStr += "&searchQuery=" + cnnSearchQuery;
    } else {
        //alert("invalid mode [" + cnnCurMode + "]");
    }

    top.location.href = file + queryStr;
}

function cnnHandleStreamStop(streamNum) {

    // see if the user is currently watching this particular feed
    if ((cnnCurMode == "live") && (cnnCurLiveStream == streamNum)) {
        cnnSetVideoTitle("");
        cnnCurrentVideoDirectory = "content/video/standby";
        cnnRefreshRelated();
    }
}

function setDayNightMode(mode) {
    // see if the player has just started 
    if (cnnCurDayNightMode == "") {
       // just set the mode and return
       cnnCurDayNightMode = mode;
       return;
    }

    // see if the mode has been switched
    if (cnnCurDayNightMode != mode) {
        if (mode == "daytime") {
            // switch from overnight mode to day mode
            cnnCurDayNightMode = mode;

            // Switch the tab to be Live Feeds
            cnnShowLiveFeeds();            

            // Show Pipe 1
            cnnLoadLiveStream(1);
        } else if (mode == "overnight") {
            // switch from day mode to overnight mode
            cnnCurDayNightMode = mode;

            // Switch the tab to be On Demand
            cnnShowOnDemand();

            // Load the "standby" video.
            cnnLoadVideo("content/video/standby");
            cnnSetVideoTitle("");
        } else {
            // alert("unknown day/night mode [" + mode + "]");
        }
    }
}

function setOvernightModeRelatedsUrl(url) {
    cnnPipe1OvernightRelatedsUrl = url;
    cnnRefreshRelated();
}

function setJustInScheduleTabDefault(tabDefault) {
    if (cnnCurJustInScheduleTabDefault != tabDefault) {

        // switch the tab
        if (tabDefault == "justin") {
            cnnCurJustInScheduleTabDefault = tabDefault;
            cnnShowJustIn();
        } else if (tabDefault == "schedule") {
            cnnCurJustInScheduleTabDefault = tabDefault;
            cnnShowSchedule();
        } else {
            // alert("Unknown just in/schedule default [" + tabDefault + "]");
        }
    }
}

function cnnreloadThisImg(name)
{
	var imgObj = document.getElementById(name);	
	if(imgObj && imgObj.src)
	{
		imgObj.src = imgObj.src;
	}
}

function cnnPrepareReloadImages()
{
	var reloadImgs = new Array('liveStream1','liveStream2','liveStream3','liveStream4');
	for(imgC=0;imgC<reloadImgs.length;imgC++)
	{
		var switchImgFrom = imgC;
		var switchImgTo   = imgC;
		var switchImgFrom = Math.floor(Math.random()*reloadImgs.length);
		var switchImgTo = Math.floor(Math.random()*reloadImgs.length);
		var tmpStore = reloadImgs[ switchImgTo ];
		reloadImgs[ switchImgTo ] = reloadImgs[ switchImgFrom ];
		reloadImgs[ switchImgFrom ] = tmpStore;
	}
	for(var imgC=0;imgC<reloadImgs.length;imgC++)
	{
		window.setTimeout('cnnreloadThisImg("'+reloadImgs[ imgC ] +'");',(imgC+1)*15000);
	}
	window.setTimeout("cnnPrepareReloadImages();",60000);
}
cnnPrepareReloadImages();

// -->

