// Modify the following Variables accordingly
var pause_time = 5;
var image_max = 10
var image_min = 0
var image_directory = "PhotoRotator/";
var image_name = "Image";				// Name is the text before the number, example: image1.jpg --> Name = image
var image_extentions = ".jpg";			// Extention is the period and letters after, example: .jpg
var rotate_or_random = "rotate";

// After these settings, you will need to setup the body tag in the file that includes this code so that
// the Onload prepares the images you wish to rotate.
//
// Example: <body onload="PrimeTimer([rotating_image1, rotating_image2]);">

/////////////////////////////////////////////////////////
// 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_name + image_current + image_extentions
	}
    
    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_name + image_current + image_extentions
		}
        InitializeTimer()
    }
    else
    {
        self.status = secs
        secs = secs - 1
        timerRunning = true
        timerID = self.setTimeout("StartTheTimer()", delay)
    }
}
