// JavaScript Document

var numSlides = 5;
var currentSlide = numSlides; 
var numsecs = 8;
var secs = numsecs;
var timerID = null;
var timerRunning = false;
var delay = 1000;

function startBoxTimer()
{
    // Set the length of the timer, in seconds
    secs = numsecs;
    StopTheClock();
	switchSlide(1);
    StartTheTimer();
}

function StopTheClock()
{
    if(timerRunning)
        clearTimeout(timerID);
    timerRunning = false;
}

function StartTheTimer()
{
	if (secs==0)
	{
		StopTheClock();
		switchSlide(1);
		secs = numsecs;
		timerID = setTimeout("StartTheTimer()", delay);
	}
	else
	{
		secs = secs - 1;
		timerRunning = true;
		timerID = setTimeout("StartTheTimer()", delay);
	}
}

function switchSlide(sDir) 
{
    newSlide = currentSlide + sDir;
    if (!newSlide) newSlide=numSlides;
        if (newSlide > numSlides) 
		    newSlide=1;
	document.getElementById('image'+newSlide).style.display="block";
	document.getElementById('image'+currentSlide).style.display="none";
  currentSlide = newSlide;
}

