﻿var time1 = 4;                                                  //Length of time (in seconds) to display each image
//var time2 = 7;                                                //Length of time (in seconds) to display the last image

var div = document.getElementById('home-images');               //Grab the div holding the images
var imgs = div.getElementsByTagName('img');                     //Grab the images
var idx = -1;                                                   //Counter to determine which image is currently displayed, set to -1 to indicate none

var curOpc = 100;

setTimeout(checkImagesLoaded, 100);                             //Initial call to check if all images are loaded

function checkImagesLoaded() {
    var c = 0;                                                  //Holds the number of images loaded
    for (var i = 0; i < imgs.length; i++) {                     //Loop through each image
        if (imgs[i].complete) { c++; }                          //If their "complete" property is true increment the counter
    }
    if (c == imgs.length) {                                     //If all images are loaded
        showNext();                                             //Begin the slideshow
    } else {                                                    //Otherwise
        setTimeout(checkImagesLoaded, 100);                     //Pause and repeat the image check routine
    }
}
function setOpc(img, opc) {
    img.style.MozOpacity = opc / 100;
    img.style.opacity = opc / 100;
    img.style.filter = 'alpha(opacity=' + opc + ')';
}
function showNext() {
    if (idx >= 0) {                                             //If we've loaded at least one image this will be true
        imgs[idx].style.display = 'none';                       //Hide the displayed image
    }
    idx++;                                                      //Increment our current image counter
    if (idx > imgs.length - 1) {                                //If our counter is more than the total image count
        idx = 0;                                                //Reset it back to the first image
    }
    imgs[idx].style.display = 'block';                          //Show the current image
    //setTimeout('showNext()', (idx == (imgs.length - 1) ? time2 : time1) * 1000);//Set the timeout to show the next image, show the last image for a little bit longer
    setTimeout(showNext, time1 * 1000);                         //Set the timeout to show the next image
}