﻿var timerID = null;
var timerRunning = false;
var timerDelay = 3000;
var currentIndex = -1;
var arrayLen = 0;

function initArray()
{
	this.length = initArray.arguments.length;
	for (var i = 0; i < this.length; i++)
	{
		this[i] = initArray.arguments[i];
	}
}

var image = new initArray("2006_CVC_Spons_StewartTitle.gif","2006_CVC_Spons_fizik.gif","2008_CVC_Spons_ESPN.gif","2008_CVC_Spons_Hammer.gif","2006_CVC_Spons_Nask.gif","2006_CVC_Spons_RudyProject.gif","2006_CVC_Spons_Shimano.gif", "2006_CVC_Spons_SpinalHealth.gif");
var link = new initArray("http://www.producersdairy.com/","http://www.fizik.it/","","http://www.nask.pl/","http://www.priceassociates.com/","http://www.rudyprojectusa.com/","http://www.shimano.com/","http://www.spinalhealthcenter.net/");

arrayLen = image.length;

function stopRotate ()
{
	if(timerRunning)
	{
		clearTimeout(timerID);
	}
	timerRunning = false;
}

function startRotate(delay)
{
	if (document.getElementById("imgSponsLogo") != null)
	{
		timerDelay = delay;
		stopRotate();
		showPic();
	}
}

function showPic ()
{	
	currentIndex = (currentIndex + 1) % arrayLen;	
	document.getElementById("imgSponsLogo").src = "/images/sponsors/" + image[currentIndex];
	timerID = setTimeout("showPic()",timerDelay);
	timerRunning = true;
	
}

function pause()
{
	stopRotate();
}

function resume()
{
	if (currentIndex == 0)
	{
		currentIndex = arrayLen - 1;
	}
	else
	{
		currentIndex = Math.abs((currentIndex - 1)) % arrayLen;
	}
	showPic(3000);
}

function doClick(hLink)
{
	document.getElementById("aSponsLink").href = link[currentIndex];		
}
