/**
 * Article Cycling JavaScript
 *
 * This cycles the news articles on the article front page.
 */
var newsClass = "newsBox"
var newsHighlights;
var currentNewsIndex = -1;
var totalNewsHighlights;
var cycleFn;

// Script initialization
function articleCycleInit() {
	newsHighlights = getNewsHighlights(document.getElementById("articleHighlights"));
	totalNewsHighlights = newsHighlights.length;	
	if (totalNewsHighlights > 0) cycleFn = cycleNewsHighlights();
}

// Retrieve all news highlights
function getNewsHighlights(articleHighlights) {
	var divs = document.getElementById("articleHighlights").getElementsByTagName("div");
	var highlights = new Array();

	for (i=0; i<divs.length; i++) {
		if (divs[i].className == newsClass) highlights.push(divs[i]);
	}

	return highlights;
}

// Cycling function
function cycleNewsHighlights() {

	// Reset last news index 
	if (currentNewsIndex >= 0) newsHighlights[currentNewsIndex].className = newsClass;

	// Increment and set new thing to see
	currentNewsIndex = (currentNewsIndex + 1) % totalNewsHighlights;
	newsHighlights[currentNewsIndex].className = newsClass + " current";

	// Set next time
	cycleFn = setTimeout("cycleNewsHighlights()",10000);
}
