// Modify the following Variables accordingly
var pause_time = 3;
var image_max = 793
var image_min = 0
var image_directory = "rotating_images/";
var image_extemtions = ".jpg";
var rotate_or_random = "random";

// DO NOT MODIFY ANYTHING UNDER THIS POINT!!!!!!!!!!!!

var secs
var timerID = null
var timerRunning = false
var delay = 1000
var image_current = Math.floor(Math.random() * (image_max - image_min) + 1 ) + image_min;
var rotating_image_element = [];

function PrimeTimer(rotating_image_ele)
{
	var ptr = 0;
	for (var ptr=0; ptr<rotating_image_ele.length; ptr++) 
	{
		// prime the image with a random image
		image_current = Math.floor(Math.random() * (image_max - image_min) + 1 ) + image_min;
		rotating_image_element[ptr] = rotating_image_ele[ptr];
    	rotating_image_element[ptr].src = image_directory + image_current + image_extemtions
	}
    
    InitializeTimer()
}

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

function StopTheClock()
{
    if(timerRunning)
        clearTimeout(timerID)
    timerRunning = false
}

function StartTheTimer()
{
    if (secs==0)
    {
        StopTheClock();
        for (var ptr=0; ptr<rotating_image_element.length; ptr++) 
		{
	        if(rotate_or_random == "random")
    	    	image_current = Math.floor(Math.random() * (image_max - image_min) + 1 ) + image_min;
        	else
        		image_current++;
	        if(image_current > image_max)
    	    	image_current = image_min;
        	rotating_image_element[ptr].src = image_directory + image_current + image_extemtions
		}
        InitializeTimer()
    }
    else
    {
        self.status = secs
        secs = secs - 1
        timerRunning = true
        timerID = self.setTimeout("StartTheTimer()", delay)
    }
}