﻿var currentFactId = 0;
var factList = $empty;
var currentFactBlock = $empty;

window.addEvent('domready', function() {
	factList = $$('div.myth_fact_item');
	currentFactBlock = $('current_myth_fact');
	
	setFact(0);
	
	$('control_prev').addEvent('click', function(e) {
		new Event(e).stop();
		setFact(currentFactId - 1);
		sendAnalyticsEvent('myth_vs_fact/previous');
	});
	
	$('control_next').addEvent('click', function(e) {
		new Event(e).stop();
		setFact(currentFactId + 1);
		sendAnalyticsEvent('myth_vs_fact/next');
	});
	
	$('tip_count').set('html', factList.length);
});

function setFact(factId)
{
	if (factId > factList.length - 1) factId = 0;
	if (factId <= -1) factId = factList.length - 1;
	currentFactId = factId;
	$('tip_number').set('html', currentFactId + 1);
	currentFactBlock.set('html', factList[factId].get('html'));
}

function sendAnalyticsEvent(params)
{
	// This function is called by both the flash and DHTML methods on this
	// page.
	
	// params: a string value containing the specific tracking information
	//		   in a slash seperated list.
	
	// TODO: Insert proper tracking call.
}
