var index = 0;
var newsItems = null;
var intId = null;
var seconds = 10;

function startShow(aSeconds) {
	if (aSeconds) seconds = aSeconds;
	newsItems = $('news-items').immediateDescendants();
	intId = setInterval("advanceShow()", seconds * 1000);
}

function stopShow() {
	clearInterval(intId);
}

function advanceShow() {
	stopShow();
	// hide the current item
	newsItems[index].hide();
	
	// move to the next item to be displayed
	index++;
	if (index == newsItems.size()) {
		index = 0;
	}
	
	newsItems[index].show();
	startShow();
}

function rewindShow() {
	stopShow();
	// hide the current item
	newsItems[index].hide();
	
	// move to the next item to be displayed
	index--;
	if (index < 0) {
		index = newsItems.size() - 1;
	}
	
	newsItems[index].show();
	startShow();
}