var curItem;
var imgId;
var secs;
var timerID = null;
var timerRunning = false;
var delay = 600;
var _SECS = 2;

function InitializeTimer()
{
	// Set the length of the timer, in seconds
    secs = _SECS;
    StopTheClock();
    StartTheTimer();
}

function StopTheClock()
{
    if(timerRunning)
        clearTimeout(timerID);

    timerRunning = false;
}

function StartTheTimer()
{
	if(secs==0)
    {
        goForward();
        secs = _SECS;
        timerID = self.setTimeout("StartTheTimer()", delay);
    }
    else
    {
        secs--;
        timerRunning = true;
        timerID = self.setTimeout("StartTheTimer()", delay);
    }
}

function goForward()
{
	if(imgs == null || imgs.length == 0)
		return;
	
	curItem++;
	if(curItem == imgs.length)
		curItem = 0;
	
	updateAnimation();
}

function startAnimation(imgs, id)
{
	curItem = 0;
	imgId = id;
	
	InitializeTimer();
}

function updateAnimation()
{
	if(imgs == null || imgs.length == 0)
		return;
	
	document.getElementById(imgId).src = imgs[curItem];
}

























