/* ============================================== */
/*	Javascript to Rotate Content : Andrew Bunker;   Completely Messed Up by: (me!) Russell Banz				*/
/* ============================================== */

/*
if (document.getElementById) 
{
	document.write('<style type="text/css">\n');
	document.write('.slotStyle{display:none;}\n');
	document.write('</style>\n');
}
*/

var slotCurrent = 0;
var slotTotal = 0;
var slotAction = 0;
var slotTimerID = -1;
var slotTimeout = 48;

// ============================================== 
function showSlot()
{
	var slotObj;
	var x = 0;
	
	if(slotAction==1) // forward
		slotCurrent = ( slotCurrent < slotTotal-1 ) ? slotCurrent+1 : 0;
	if(slotAction==2) // backward
		slotCurrent = ( slotCurrent > 0 ) ? slotCurrent-1 : slotTotal-1;

	// get the next image
	slotObj = document.getElementById("slot"+slotCurrent);

	// stop the timer, if it's running
	if(slotTimerID > 0) {
		clearTimeout(slotTimerID);
		slotTimerID = 0;
	}

	// hide all the images
	while(document.getElementById("slot"+x))
		document.getElementById("slot"+x++).style.display = "none";

	// display the correct image
	slotObj.style.display = "block";

	// start the timer	
	if(slotTimerID>=0 && slotTimeout>0) 
		slotTimerID = setTimeout("showSlot()",slotObj.getAttribute("pause"));

	slotTimeout--;
	slotAction = 1;
}
// ============================================== 
function initSlots()
{
	//while (document.getElementById("slot"+slotTotal)!=null) 
	//	slotTotal++
	slotTotal = $("div.slotStyle").size();
	showSlot();
}
// ============================================== 
function nextButton() 
{
	showSlot();
}
// ============================================== 
function stopButton() 
{
	if (slotTimerID > 0)
		clearTimeout(slotTimerID);
	slotTimerID = -1;
}
// ============================================== 

function startButton() 
{
	slotTimeout = 48;
	slotTimerID = 0;
	showSlot();
}
// ============================================== 
function backButton() 
{
	slotAction = 2;
	showSlot();

}

//	if (window.addEventListener) 	window.addEventListener("load",initSlots,false);
//	else if (window.attachEvent) window.attachEvent("onload",initSlots);
$(document).ready(initSlots);


