//Global variables

var timer_is_on=0; //Timer control variable 0=off, 1=on
var t; //setTimeout number. IDs the setTimeout process currently running
var c=0; //Slideshow counter
var manual=0; //Manual mode control 0=auto, 1=manual
var slideCnt=5 //Total number of slides in the show
var speed=10000 //Slide show speed
var ssDir="SlideShow/" //Path to slideshow images

//End of Global variables

//Load slideshow
var im = new Array();

for (i=0;i<slideCnt;i++)
{
    im[i]=ssDir+"IMG_"+(i+1)+".jpg"
}


//im[0] = "IMG_0001.jpg";
//im[1] = "IMG_0002.jpg";
//im[2] = "IMG_0003.jpg";
//im[3] = "IMG_0004.jpg";
//im[4] = "IMG_0005.jpg";
//End of load slideshow


function newImage(ss_im) { //Loads a new image in the defined id
    document.getElementById('slideshow').src=ss_im[c];
    if (c < (ss_im.length-1)){
        c++;
    }
    else {
        c=0;
    }
    
    //If the mode is set to auto, recursively load a new image
    
    if (manual == 0){
        t=setTimeout("newImage(im)",speed);
    }
}

function doTimer(){ //Start the slideshow
    manual = 0;
    if (!timer_is_on){
        timer_is_on=1; //Turn the timer control variable on
        newImage(im);
    }
}
function stopCount(){ //stop the slideshow
    clearTimeout(t); //Stop the setTimeout function as defined by t
    timer_is_on=0; //Turn the timer control variable off
}
function manualAdvance() {
    if (timer_is_on){ //if the slideshow is running, stop it
        stopCount();
    }
    manual = 1; //set to manual mode
    newImage(im); //call for a new image
}
loadDoc();
