var currentFact;
var factArray;

function getFactText() {
	return factArray[currentFact];
}

var tickerTimer = 0;
function nextFact() {
	clearTimeout(tickerTimer);
	currentFact == factArray.length - 1 ? currentFact = 0 : currentFact ++ ;
	$('ticker').innerHTML = '' + getFactText(factArray, currentFact) + '';
	$('tickerStatus').innerHTML = (currentFact + 1) + ' '+snippet('of')+' ' + factArray.length;
	tickerTimer = setTimeout('nextFact()', 30*1000); // show the next one every x seconds
}

function previousFact() {
	currentFact == 0 ? currentFact = factArray.length - 1 : currentFact -- ;
	$('ticker').innerHTML = '' + getFactText() + '';
	$('tickerStatus').innerHTML = (currentFact + 1) + ' '+snippet('of')+' ' + factArray.length;
}

function selectFactCat(factCategory) {
	factArray = tickersArray[factCategory]; // change the current array
	currentFact = Math.floor(Math.random() * factArray.length); // select a random fact.
	$('ticker').innerHTML = '' + getFactText() + ''; // update the current fact
	$('tickerStatus').innerHTML = (currentFact + 1) + ' '+snippet('of')+' ' + factArray.length; // update the counter
}

// show the div with the list of tickers
document.observe('dom:loaded', function() {

	if ($('tickers') != null) {
		$('tickers').hide();
		tickerTimer = setTimeout('nextFact()', 30*1000); // show the next one every x seconds
	}
	
	if ($('ticker_container') != null) {
		$('ticker_container').observe('mouseover', function(event){
			$('tickerSelect').removeClassName('off');
			$('tickerSelect').addClassName('on');
			$('tickers').show();
		});
	}
	
	if ($('ticker_container') != null) {
		$('ticker_container').observe('mouseout', function(event){
			$('tickerSelect').removeClassName('on');
			$('tickerSelect').addClassName('off');
			$('tickers').hide();
		});
	}
	
});
