// News rotation script
var currentEvent = 1;
var articleCount = 0;

function setCount(count) { articleCount = count; }

function switchEvent(nNum) {

	if (nNum == 'n') {
		if (currentEvent < articleCount) {
			nNum = currentEvent + 1;
		} else {
			nNum = 1;
		}
	} 

	currentEvent = nNum;

	for (i = 1; i <= articleCount; i++) {
		if (i != currentEvent) {
			document.getElementById("event" + i).style.display = "none";
			document.getElementById("eventbutton" + i).style.backgroundPosition = "0px";
		} else {
			document.getElementById("event" + i).style.display = "block";
			document.getElementById("eventbutton" + i).style.backgroundPosition = "-20px";
		}
	}
}

// Auto rotate controls    
var state=1;
var timeDelayRun = 500;
var timeDelayRotate = 11000;
var a;
var b;
var c;

// YOU ARE HERE ---- try to clear every time out via a function
function clearAll () {
	window.clearTimeout(a);
	window.clearTimeout(b);
	window.clearTimeout(c);
} // end function

function startstop() {
	if (state == 0)  {
		state = 1;
		document.getElementById("playpause").style.backgroundPosition = "0px";
		a = window.setTimeout("switchEvent('n');rotater();", timeDelayRun);
	} else {
		state = 0;
		document.getElementById("playpause").style.backgroundPosition = "-20px";
		clearAll();
	}
} // end function

function stop() {
	state = 0;
		document.getElementById("playpause").style.backgroundPosition = "-20px";
	clearAll();
} // end function

function rotater() {
	if (state == 1)  {
		document.getElementById("playpause").style.backgroundPosition = "0px";
		b = window.setTimeout("switchEvent('n');", timeDelayRotate);
		c = window.setTimeout("rotater();", timeDelayRotate);
	} else {
		document.getElementById("playpause").style.backgroundPosition = "-20px";
		clearAll();
	}
} // end function
