var ourSite = "";
var myServer="http://www.gazette.net";
var myServerFull = location.href;
if (myServerFull.indexOf("/") != -1) {ourSite = myServerFull.substr(7).split("/"); myServer = "http://"+ourSite[0];}
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 {position:absolute;width:284px;height:115px;z-index:1;left: 5px;top: 505px;} #headline2 {position:absolute;width:284px;height:115px;z-index:1;left: 5px;top: 505px;} #headline3 {position:absolute;width:284px;height:115px;z-index:1;left: 5px;top: 505px;} #headline4 {position:absolute;width:284px;height:115px;z-index:1;left: 5px;top: 505px;} #headline5 {position:absolute;width:284px;height:115px;z-index:1;left: 5px;top: 505px;} #photobox1 {position:absolute;width:275px;height:280px;z-index:1;left: 10px;top: 245px;} #photobox2 {position:absolute;width:275px;height:280px;z-index:1;left: 10px;top: 245px;} #photobox3 {position:absolute;width:275px;height:280px;z-index:1;left: 10px;top: 245px;} #photobox4 {position:absolute;width:275px;height:280px;z-index:1;left: 10px;top: 245px;} #photobox5 {position:absolute;width:275px;height:280px;z-index:1;left: 10px;top: 245px;} #photo1, #photo2, #photo3, #photo4, #photo5{position:absolute;clip:rect(0px 275px 250px 0px)} #playbuttons {position:absolute;width:288px;height: auto;z-index:1;left: 10px;top: 493px;}</style>";
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 ==  myServer + "/images/fadepause.jpg") {
		   pausebtn.src = myServer + "/images/pause.jpg";
	 		pauseClick= pausefunc;
	   }
	   // this is to see if it is not paused.
	   else {
		   if (nimrod==1) {
		   pausebtn.src = myServer + "/images/fadepause.jpg" ;
		   pauseClick = null;
		   }
	   }
 }
 }
 

 
 function changePrevious(ringo) {
	 var backbtn = document.getElementById("backLink");
	 var backClick = backbtn.getAttribute("onclick");
	   if (ringo==1) {
		   backbtn.src = myServer + "/images/2008redesign/previous_on.gif";
			backClick = prevfunc;
	   }
	  if (ringo==0 || ringo==19) {
		   backbtn.src = myServer + "/images/2008redesign/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 = myServer + "/images/2008redesign/next_off.gif" && whichHL<headlineName.length-1) {
			 forwardbtn.src = myServer + "/images/2008redesign/next_on.gif";
			 forwardClick = nextfunc ;
		 }
		   else {
			   if (forwardbtn.src != myServer + "/images/2008redesign/next_off.gif") {
			forwardbtn.src = myServer + "/images/2008redesign/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);
}

