var myServerFull = location.href;

var o = 0;

var thisHeadline = 0;

var headlineName = new Array("headline1", "headline2", "headline3", "headline4", "headline5");

var photoBoxName = new Array("photobox1", "photobox2", "photobox3", "photobox4", "photobox5");

var photoName = new Array("photo1", "photo2", "photo3", "photo4", "photo5");

var pausefunc = "";

var nextfunc = "";

var prevfunc ="";

var nimrod=0;

var myInterval = "";

var pbn="";

var nb="";

var prb="";

var editpicks=0;

var editpicks2=0;

var existheads = new Array;

var existphotos = new Array;

var existphotoboxes = new Array;


var tsstyles="<style type='text/css'>#headline1, #headline2, #headline3, #headline4, #headline5 {left: 5px; top: 505px;} #photobox1, #photobox2, #photobox3, #photobox4, #photobox5 {left: 10px; top: 245px;} #playbuttons {position:absolute;width:288px;height: auto;z-index:1;left: 10px;top: 493px;}</style>";

	



function initBtn() {

	document.getElementById("backLink").onclick = processFirst();

	document.getElementById("forwardLink").onclick = processSecond();

}





function rotate_headlines() {

	//alert(o);

document.getElementById(headlineName[o]).style.visibility = "hidden";

document.getElementById(photoBoxName[o]).style.visibility = "hidden";

o++;

if (o==headlineName.length){

	o=0;

	} 

changeNext(o);

changePrevious(o);

//document.getElementById(photoName[o]).style.width = "275px";

document.getElementById(photoName[o]).style.position="absolute";

//document.getElementById(photoName[o]).style.clip="rect(0px 275px 250px 0px)";

document.getElementById(headlineName[o]).style.visibility = "visible";

document.getElementById(photoBoxName[o]).style.visibility = "visible";

}







function timeline(w,headline_Number) {

	if (w==1 && myInterval!=""){clearInterval(myInterval);}

	else {

		o = headline_Number; 

	myInterval = window.setInterval("rotate_headlines()", 7000);}

}







 function pausefunction() {

	 nimrod++

	 timeline(1,o);

	 changePause();

 }

 

 

 

 function changePause() {

	 var pausebtn = document.getElementById("pauseLink");

	 var pauseClick = pausebtn.getAttribute("onclick");

	 //this statement is to check to see if the pause button is paused.

	 if (nimrod<=1){

	   if (pausebtn.src ==  theroot + "/images/fadepause.jpg") {

		   pausebtn.src = theroot + "/images/pause.jpg";

	 		pauseClick= pausefunc;

	   }

	   // this is to see if it is not paused.

	   else {

		   if (nimrod==1) {

		   pausebtn.src = theroot + "/images/fadepause.jpg" ;

		   pauseClick = null;

		   }

	   }

 }

 }

 



 

 function changePrevious(ringo) {

	 var backbtn = document.getElementById("backLink");

	 var backClick = backbtn.getAttribute("onclick");

	   if (ringo==1) {

		   backbtn.src = theroot + "/images/previous_on.gif";

			backClick = prevfunc;

	   }

	  if (ringo==0 || ringo==19) {

		   backbtn.src = theroot + "/images/previous_off.gif" ;

		   backClick=null;

 }

 if (ringo==19) {

	 for (punchy=0;punchy<headlineName.length;punchy++) {

		 if (document.getElementById(headlineName[punchy])) {

			existheads.push(headlineName[punchy]);

			existphotos.push(photoName[punchy]);

			existphotoboxes.push(photoBoxName[punchy]);

		 editpicks++; 

		 }

	 }

	

		 if (editpicks<headlineName.length && editpicks>0) {

			 var losethese = headlineName.length-editpicks;

			 var startwhere = headlineName.length-losethese;

		 headlineName.splice(startwhere,losethese);

		  photoBoxName.splice(startwhere,losethese);

		   photoName.splice(startwhere,losethese);

		 for (outoforder=0;outoforder<editpicks.length;outoforder++) {

		 headlineName[outoforder]=existheads[outoforder];

		 photoBoxName[outoforder]=existphotoboxes[outoforder];

		 photoName[outoforder]=existphotos[outoforder];

		 }

 }

 }

 }

 

 

 

 

 function changeNext(whichHL) {

	  var forwardbtn = document.getElementById("forwardLink");

	 var forwardClick = forwardbtn.getAttribute("onclick");

		 if (forwardbtn.src = theroot + "/images/next_off.gif" && whichHL<headlineName.length-1) {

			 forwardbtn.src = theroot + "/images/next_on.gif";

			 forwardClick = nextfunc ;

		 }

		   else {

			   if (forwardbtn.src != theroot + "/images/next_off.gif") {

			forwardbtn.src = theroot + "/images/next_off.gif";

		forwardClick = null;

			   }

 }

 }

 



 function processFirst() {

	nimrod=0;

	changePause(); 

timeline(1,0);

	if (o>0) {

		var headlinenumber = o-1;

			document.getElementById(headlineName[o]).style.visibility = "hidden";

			document.getElementById(photoBoxName[o]).style.visibility = "hidden";

		document.getElementById(headlineName[headlinenumber]).style.visibility = "visible";

		document.getElementById(photoBoxName[headlinenumber]).style.visibility = "visible";

		

        }

		else {

			headlinenumber = o;

		}

			if (headlinenumber == 0) {

			changeNext(headlinenumber);

		}

			

		changeNext(headlinenumber);

changePrevious(headlinenumber);

		timeline(0,headlinenumber);

}

 





	

function processSecond() {

nimrod=0;

changePause();

timeline(1,0);

		if (o<headlineName.length-1) {

			var headlinenumber = o+1;

		document.getElementById(headlineName[o]).style.visibility = "hidden";

		document.getElementById(headlineName[headlinenumber]).style.visibility = "visible";

		document.getElementById(photoBoxName[o]).style.visibility = "hidden";

		document.getElementById(photoBoxName[headlinenumber]).style.visibility = "visible";

		}

		else {

			headlinenumber = o;

		}

		if (headlinenumber == headlineName.length-1) {

			changeNext(headlinenumber);

		}

		changeNext(headlinenumber);

changePrevious(headlinenumber);

		timeline(0,headlinenumber);

}



