var cnnSlateDoc, cnnSlideArrowIntID, cnnSlateCountIntID, cnnSlateSliderID, cnnSlateSliderImgID, cnnSlateTeaseID, cnnNextVideo;
var cnnSlateXPos = -450;
var cnnSlateXPosSlideBy = 10;
var cnnSlateCountDownNum = 5;
var cnnSlateNextUp = 0;
var cnnPlayListProgression = 0;
var cnnSectionPlayListSection, cnnSectionPlayListBrowseSection, cnnRowDiv, cnnAccordionIntID, cnnActiveID, cnnResetNode;	
var rowCounter = 0;
var cnnPlayListDoc = "";
var cnnPlayedListArry = new Array();
var cnnExpandableDivHead = new Array();
var cnnExpandableDiv = new Array();
var cnnVisitedDiv = new Array();
var cnnMaxRowHeight = 140;
var cnnMinRowHeight = 0;
var cnnCollapseRowHeight = 140;
var cnnExpandedNode;
var cnnClickBtn=new Image();
var cnnClickBtnOver=new Image();
 cnnClickBtn.src="http://i.a.cnn.net/cnn/.element/img/1.3/video/broadband/btn/2.0/email.this_up.gif";
 cnnClickBtnOver.src="http://i.a.cnn.net/cnn/.element/img/1.3/video/broadband/btn/2.0/email.this_over.gif";
var cnnOutOfBoundsHeadline = false;
var cnnRelatedPaneLoaded = false;

var cnnPOCCounter = 0;

var cnnPOCNodes = new Array('rowOne','rowTwo','rowThree','rowFour','rowFive','rowSix')

function cnnUpdateRelatedHeadline(headline) {
	top.playerframe.document.getElementById('cnnPlayListLinkValue1').innerHTML = headline;
}

function cnnSlateAutomateSlider() {
	if (cnnSlateSliderID && (cnnSlateXPos < 0)) {
		cnnSlateXPos = cnnSlateXPos + cnnSlateXPosSlideBy;
		cnnSlateSliderID.style.left = cnnSlateXPos+"px";
	} else {
		cnnSlateStopSlider();
	}
}

function cnnSlateStopSlider() {
	window.clearInterval(cnnSlideArrowIntID);
	cnnSlateDisplayTease();
}

function cnnSlateDisplayTease() {
	if (cnnSlateTeaseID) {
		cnnSlateTeaseID.style.display = "block";
		if(cnnSlateTimerID) {
			cnnSlateTimerID.style.display = "block";
			cnnSlateCountIntID = window.setInterval("cnnSlateCountDown()",1000);
		}
	}
}

function cnnSlateCountDown() {
	if (cnnSlateCountDownNum > 0) {
		cnnSlateTimerID.innerHTML = "0"+(cnnSlateCountDownNum -1);
		cnnSlateCountDownNum--;
	} else {
		window.clearInterval(cnnSlateCountIntID);
		cnnSlateShift();
	}
}

function cnnSlateShift(){
	cnnNextVideo = cnnPlayedListArry[cnnPlayListProgression][0];
	if (cnnPOCNodes[cnnPlayListProgression] != cnnExpandedNode) {
		//cnnResizeDiv(cnnPOCNodes[cnnPlayListProgression]);	
	}
	if (cnnPlayedListArry[0]) {
		cnnSlateReset();
	}
	cnnPlayNextVideo( cnnNextVideo, cnnPlayListProgression );

}

function cnnPlayNextVideo(url, progression) {
	cnnPlayListVideo( url, progression );
}

function cnnSlateReset(){
	cnnSlateTeaseID.style.display = "none";
	cnnSlateTimerID.style.display = "none";	
	cnnSlateCountDownNum = 5	
	cnnSlateXPos = -450;
	cnnSlateSliderID.style.left = cnnSlateXPos+"px";
}

function cnnSlateUnload() {
	window.clearInterval(cnnSlideArrowIntID);
	window.clearInterval(cnnSlateCountIntID);	
}

function cnnSlateInit() {
	cnnSlateDoc = window.frames['contentframe'];
	cnnSlateSliderID = cnnSlateDoc.document.getElementById('cnnSlateSlider') || null;
	cnnSlateTeaseID = cnnSlateDoc.document.getElementById('cnnSlateTease') || null;
	cnnSlateTeaseHeadID = cnnSlateDoc.document.getElementById('cnnSlateTeaseHead') || null;	
	cnnSlateTimerID = cnnSlateDoc.document.getElementById('cnnSlateTimer') || null;
	cnnSlateSetDisplay();
	cnnSlideArrowIntID = window.setInterval("cnnSlateAutomateSlider()",10);
}

function cnnSlateSetDisplay() {
	if (cnnSlateTimerID) {
		cnnSlateTimerID.innerHTML = "0"+cnnSlateCountDownNum;
	}
	
	if (cnnSlateTeaseHeadID) {
		cnnSlateTeaseHeadID.innerHTML = cnnPlayedListArry[cnnPlayListProgression][1];
	}	
}

function cnnShowSlate(num) {
	//top.document.getElementById('contentframe').src = '/video/slate/content.exclude.html';
	window.contentframe.location.replace('/video/slate/content.exclude.html');

}

function cnnShowEndedSlate(num) {
	//top.document.getElementById('contentframe').src = '/video/slate/end/content.exclude.html';
	window.contentframe.location.replace('/video/slate/end/content.exclude.html');
}

function cnnEndSlateInit() {
	cnnResizeDiv(cnnPOCNodes[(cnnPlayListProgression - 1)]);
}

function windowLoadedInit() {
	cnnExpandedNode = cnnActiveID || cnnPOCNodes[0];
	cnnActiveID = "";
	rowCounter = 0;
	cnnExpandableDiv = [];
	cnnExpandableDivHead = [];	
	cnnPlayListDoc = window.frames['playerframe'];
	cnnRowDiv = cnnPlayListDoc.document.getElementsByTagName("div");

	cnnPlayListDoc.document.getElementById('cnnPlayListTitle').innerHTML = cnnSectionPlayListSection.toUpperCase();

		for(var i=0; i < cnnRowDiv.length; i++) {
			var div = cnnRowDiv[i];
			var clas = div.className;	
			var id = div.id;
				if (id && (clas == "cnnPlayListRowContainer")) {
					cnnExpandableDiv[rowCounter] = id;
					rowCounter++;
				}
		}

	rowCounter = 0;

		for(var i=0; i < cnnRowDiv.length; i++) {
			var div = cnnRowDiv[i];
			var clas = div.className;
			var id = div.id;	
	 			if (clas == "cnnPlayListBar") {
					cnnExpandableDivHead[rowCounter] = id;
					rowCounter++;
	 			}
		}
			for (var i = 0; i < cnnPlayedListArry.length; i++) {
				cnnPlayListDoc.document.getElementById('cnnPlayListBar'+(i+1)).innerHTML = '<div class="cnnPlayListBarArrow" onclick="cnnResizeDiv(\''+top.cnnPOCNodes[i]+'\')"><div class="cnnPlayListPlusBtn"><img src="http://i.a.cnn.net/cnn/.element/img/1.3/video/broadband/player/2.0/slate/plus.gif" border="0" alt=""></div><div class="cnnPlayListMinusBtn"><img src="http://i.a.cnn.net/cnn/.element/img/1.3/video/broadband/player/2.0/slate/minus.gif" border="0" alt=""></div><\/div><div onclick="cnnPlayListVideo(\''+cnnPlayedListArry[i][0]+'\',\''+i+'\')"><a href="javascript:cnnPlayListVideo(\''+cnnPlayedListArry[i][0]+'\',\''+i+'\')" id="cnnPlayListLinkValue'+(i+1)+'">'+cnnPlayedListArry[i][1]+'<\/a></div>';
			}
			cnnPlayListDoc.document.getElementById('cnnPlayListBrowseLink').innerHTML = '<a href="javascript:cnnVideo(\'browse\',\''+cnnSectionPlayListBrowseSection+'\');">Browse '+cnnSectionPlayListSection.toUpperCase()+' Video<\/a>';
			cnnResizeDiv(cnnExpandedNode);
		
}


function cnnResizeDiv(node) {

	if((cnnActiveID != node) && typeof(cnnAccordionIntID) == "undefined" || (cnnAccordionIntID == 0) && (window.frames['playerframe'].location.href.indexOf('relateds.exclude.html') > -1)) {
		for (var y = 0; y < cnnExpandableDiv.length; y++) {
			if (node == cnnExpandableDiv[y]) {
				cnnAccordionIntID = window.setInterval("cnnAccordionExpand('"+cnnExpandableDiv[y]+"','"+cnnActiveID+"')",40);

				if(cnnActiveID && (node == cnnActiveID)) {
					cnnResetNode = cnnExpandableDivHead[y];					
				} else {
					try {
						cnnPlayListDoc.document.getElementById(cnnExpandableDivHead[y]).className = "cnnPlayListBar expanded";
					} catch(e) {}
				}
				cnnVisitedDiv.push(cnnExpandableDivHead[y])
			} else {
				for (var n = 0; n < cnnVisitedDiv.length; n++) {
					if ((n+1) > y) {
						try {
					//cnnPlayListDoc.document.getElementById(cnnExpandableDivHead[y]).className = "cnnPlayListBar visited";
					cnnPlayListDoc.document.getElementById(cnnExpandableDivHead[y]).className = "cnnPlayListBar";					
						} catch(e) {}
					} else {
						try {
					cnnPlayListDoc.document.getElementById(cnnExpandableDivHead[y]).className = "cnnPlayListBar";
						} catch(e) {}
					}
				}
			}
		}
	}
}

function cnnAccordionExpand(which,collapse) { 
try {
	if (cnnMaxRowHeight > cnnMinRowHeight && (cnnPlayListDoc.document.getElementById(which) && (cnnPlayListDoc.document.getElementById(which).style.height != "140px"))) {
		cnnMinRowHeight = cnnMinRowHeight + 10;
		cnnCollapseRowHeight = cnnCollapseRowHeight - 10;
		cnnPlayListDoc.document.getElementById(which).style.height = cnnMinRowHeight+"px";
			if(cnnActiveID) {
				cnnPlayListDoc.document.getElementById(collapse).style.height = cnnCollapseRowHeight+"px";
			}	
	} else if(cnnMaxRowHeight > cnnMinRowHeight && cnnPlayListDoc.document.getElementById(which) && (which == cnnActiveID) && (cnnPlayListDoc.document.getElementById(which).style.height != "0px")) {
		cnnMinRowHeight = cnnMinRowHeight + 10;	
		cnnCollapseRowHeight = cnnCollapseRowHeight - 10;
		cnnPlayListDoc.document.getElementById(which).style.height = cnnCollapseRowHeight+"px";

	} else if(cnnPlayListDoc.document.getElementById(which).style.height == "0px") {
		cnnAccordionReset();
		try {
			//cnnPlayListDoc.document.getElementById(cnnResetNode).className = "cnnPlayListBar visited";
			cnnPlayListDoc.document.getElementById(cnnResetNode).className = "cnnPlayListBar";
		} catch(e) {}						

	} else {
		cnnAccordionReset(which);	
	}
} catch(e) {};	
}

function cnnAccordionReset(node) {
	window.clearInterval(cnnAccordionIntID);
	cnnAccordionIntID = 0;
	cnnMinRowHeight = 0;
	cnnCollapseRowHeight = 140;

	if (node) {
		cnnActiveID = node;
		cnnExpandedNode = node;
	} else {
		cnnActiveID = "";
		cnnExpandedNode = "";
	}
}

var alreadyPlayedListArry = new Array();


//For IE 5, since it doesn't play nice with the more advanced Array functions
// Array Extensions  v1.0.6
// documentation: http://www.dithered.com/javascript/array/index.html
// license: http://creativecommons.org/licenses/by/1.0/
// code by Chris Nott (chris[at]dithered[dot]com)


var undefined;
function isUndefined(property) {
  return (typeof property == 'undefined');
}


// Array.concat() - Join two arrays
if (isUndefined(Array.prototype.concat) == true) {
  Array.prototype.concat = function (secondArray) {
     var firstArray = this.copy();
     for (var i = 0; i < secondArray.length; i++) {
        firstArray[firstArray.length] = secondArray[i];
     }
     return firstArray;
  };
}

// Array.copy() - Copy an array
if (isUndefined(Array.prototype.copy) == true) {
  Array.prototype.copy = function() {
     var copy = new Array();
     for (var i = 0; i < this.length; i++) {
        copy[i] = this[i];
     }
     return copy;
  };
}

// Array.pop() - Remove the last element of an array and return it
if (isUndefined(Array.prototype.pop) == true) {
  Array.prototype.pop = function() {
     var lastItem = undefined;
    if ( this.length > 0 ) {
        lastItem = this[this.length - 1];
        this.length--;
    }
    return lastItem;
  };
}

// Array.push() - Add an element to the end of an array
if (isUndefined(Array.prototype.push) == true) {
  Array.prototype.push = function() {
     var currentLength = this.length;
     for (var i = 0; i < arguments.length; i++) {
        this[currentLength + i] = arguments[i];
     }
     return this.length;
  };
}

// Array.shift() - Remove the first element of an array and return it
if (isUndefined(Array.prototype.shift) == true) {
  Array.prototype.shift = function() {
     var firstItem = this[0];
     for (var i = 0; i < this.length - 1; i++) {
        this[i] = this[i + 1];
     }
     this.length--;
     return firstItem;
  };
}

// Array.slice() - Copy several elements of an array and return them
if (isUndefined(Array.prototype.slice) == true) {
  Array.prototype.slice = function(start, end) {
     var temp;
     
     if (end == null || end == '') end = this.length;
     
     // negative arguments measure from the end of the array
     else if (end < 0) end = this.length + end;
     if (start < 0) start = this.length + start;
     
     // swap limits if they are backwards
     if (end < start) {
        temp  = end;
        end   = start;
        start = temp;
     }
     
     // copy elements from array to a new array and return the new array
     var newArray = new Array();
     for (var i = 0; i < end - start; i++) {
        newArray[i] = this[start + i];
     }
     return newArray;
  };
}

// Array.splice() - Splice out and / or replace several elements of an array and return any deleted elements
if (isUndefined(Array.prototype.splice) == true) {
  Array.prototype.splice = function(start, deleteCount) {
     if (deleteCount == null || deleteCount == '') deleteCount = this.length - start;
     
     // create a temporary copy of the array
     var tempArray = this.copy();
     
     // Copy new elements into array (over-writing old entries)
     for (var i = start; i < start + arguments.length - 2; i++) {
        this[i] = arguments[i - start + 2];
     }
     
     // Copy old entries after the end of the splice back into array and return
     for (var i = start + arguments.length - 2; i < this.length - deleteCount + arguments.length - 2; i++) {
        this[i] = tempArray[i + deleteCount - arguments.length + 2];
     }
     this.length = this.length - deleteCount + (arguments.length - 2);
     return tempArray.slice(start, start + deleteCount);
  };
}

// Array.unshift - Add an element to the beginning of an array
if (isUndefined(Array.prototype.unshift) == true) {
  Array.prototype.unshift = function(the_item) {
     for (loop = this.length-1 ; loop >= 0; loop--) {
        this[loop+1] = this[loop];
     }
     this[0] = the_item;
     return this.length;
  };
}
