﻿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("NRC_130.gif","Quad_Knopf_100.gif","USAC_125.gif","NCNCA_100.gif", "Yokohl_130.gif");
var link = new initArray("http://www.usacycling.org/nrc/","http://www.quadknopf.com/", "http://www.usacycling.org/", "http://www.ncnca.org/", "http://www.yokohlranch.com/");
var alt = new initArray("National Race Calendar", "Quad Knopf Engineering", "USA Cycling", "Northern-California Nevada Cycling Association", "Yokohl Ranch");

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/logos/" + image[currentIndex];
	document.getElementById("imgSponsLogo").alt = alt[currentIndex];
	document.getElementById("imgSponsLogo").title = alt[currentIndex];
	timerID = setTimeout("showPic()",timerDelay);
	timerRunning = true;
	
}

function pause()
{	
	window.status = link[currentIndex];
	stopRotate();
	return true;
}

function resume()
{
	if (currentIndex == 0)
	{
		currentIndex = arrayLen - 1;
	}
	else
	{
		currentIndex = Math.abs((currentIndex - 1)) % arrayLen;
	}
	showPic(3000);
	window.status = '';
	return true;
}

function doClick(hLink)
{
	document.getElementById("aSponsLink").href = link[currentIndex];		
}
