var count = 1;

function hideLayer(whichLayer) {
	if (document.getElementById) {
		// this is the way the standards work
		document.getElementById(whichLayer).style.visibility = "hidden";
	} else if (document.all) {
		// this is the way old msie versions work
		document.all[whichlayer].style.visibility = "hidden";
	} else if (document.layers) {
		// this is the way nn4 works
		document.layers[whichLayer].visibility = "hidden";
	}
}

function showLayer(whichLayer) {
	if (document.getElementById) {
		// this is the way the standards work
		document.getElementById(whichLayer).style.visibility = "visible";
	} else if (document.all) {
		// this is the way old msie versions work
		document.all[whichlayer].style.visibility = "visible";
	} else if (document.layers) {
		// this is the way nn4 works
		document.layers[whichLayer].visibility = "visible";
	}
}

function handleClick(whichClick) {
	if (whichClick == "news1") {
		showLayer("news1");
		hideLayer("news2");
		hideLayer("news3");
		count = 1;
		InitializeTimer();
	} else if (whichClick == "news2") {
		showLayer("news2");
		hideLayer("news1");
		hideLayer("news3");
		count = 2;
		InitializeTimer();
	} else if (whichClick == "news3") {
		showLayer("news3");
		hideLayer("news1");
		hideLayer("news2");
		count = 3;
		InitializeTimer();
	} else if (whichClick == "prev") {
		if (count == 1){
			count = 3;
		} else {
			count = count - 1;
		}
		
		if (count == 1){
			hideLayer("news2");
			hideLayer("news3");
			showLayer("news1");
			InitializeTimer();
		} else if (count == 2){
			hideLayer("news1");
			hideLayer("news3");
			showLayer("news2");
			InitializeTimer();
		} else if (count == 3){
			hideLayer("news1");
			hideLayer("news2");
			showLayer("news3");
			InitializeTimer();
		}
	} else if (whichClick == "next") {
		if (count == 3){
			count = 1;
		} else {
			count = count + 1;
		}	
		
		if (count == 1){
			hideLayer("news2");
			hideLayer("news3");
			showLayer("news1");
			InitializeTimer();
		} else if (count == 2){
			hideLayer("news1");
			hideLayer("news3");
			showLayer("news2");
			InitializeTimer();
		} else if (count == 3){
			hideLayer("news1");
			hideLayer("news2");
			showLayer("news3");
			InitializeTimer();
		}
	}
}

var secs;
var timerID = null;
var timerRunning = false;
var delay = 1000;

function InitializeTimer(){
	// Set the length of the timer, in seconds
	secs = 20;
	StopTheClock();
	StartTheTimer();
}

function StopTheClock(){
	if(timerRunning)
		clearTimeout(timerID);
	timerRunning = false;
}

function StartTheTimer(){
	if (secs==0){
		StopTheClock();
		if (count == 3){
			count = 1;
		} else {
			count = count + 1;
		}	
		
		if (count == 1){
			hideLayer("news2");
			hideLayer("news3");
			showLayer("news1");
			InitializeTimer();
		} else if (count == 2){
			hideLayer("news1");
			hideLayer("news3");
			showLayer("news2");
			InitializeTimer();
		} else if (count == 3){
			hideLayer("news1");
			hideLayer("news2");
			showLayer("news3");
			InitializeTimer();
		}
	} else {
		self.status = secs;
		secs = secs - 1;
		timerRunning = true;
		timerID = self.setTimeout("StartTheTimer()", delay);
	}
}