/* Script written by Michael Libman */
   
/* Editable Global Variables */
var imageAmount = 14;            //Enter the number of images you have
var imageType   = ".png"         //ALL your images MUST be in this format
var imagePrefix = "slideShow_"   //Images must be named slideShow_x
var nameOfID    = "slideShowImg" //Name of <img id="">


/* ********** DO NOT EDIT ANYTHING BELOW THIS LINE! ********** */
var imageArray   = new Array(); //Create image array
var currentImage = 0;           //Initialize current image

   //Adds an image to the array
for( i = 0; i < imageAmount; i++ ) {
    imageArray[i] = new Image();
    imageArray[i].src = "./images/slideshow/" + imagePrefix + (i + 1) + imageType;
}

/* ##########
## playSlideShow - Plays the slide show
########## */
function playSlideShow() {
       //Makes sure the item is an image
    if( document.images ) {        
        var nextImage = currentImage + 1; //Sets the next image location

           //If nextImage is our of the array size
           //Set nextImage to 0
        if( nextImage >= imageAmount )
            nextImage = 0;
            
           //If the items is an image and is complete
        if( imageArray[nextImage] && imageArray[nextImage].complete ) {
            var target = 0; //Target image is null
            
               //If the ID is the actual ID
               //Target becomes the image
            if( /*document.all &&*/ document.getElementById( nameOfID ) )
                target = document.getElementById( nameOfID );
                
               //If target is valid
               //Set the new image and update the current image
            if( target ) {
                target.src   = imageArray[nextImage].src;
                currentImage = nextImage;
            }
            
            setTimeout( "playSlideShow()", 5000 ); //Timer (5 seconds)
        }
        else {
            currentImage = 0;
            setTimeout( "playSlideShow()", 5000 ); //Timer (5 seconds)
        }
    }
}

//window.onload = playSlideShow(); //Start the looping  // Gives ERROR in IE8

window.document.onload = playSlideShow(); //Start the looping


