﻿

var ImageTotal = -1; // number of images in array
var ImageCounter = -1; 

function changerStartup() 
{
    ImageTotal = Images.length;
    ImageCounter = Math.floor(Math.random()*ImageTotal); // start with a random image

    // Show the first image
    // $('#imageChangerJS').attr('src', '/images/homepage/' + Images[ImageCounter]);
    
    // Do we have more than 1 image to loop (no point in looping only 1 image)
    if(ImageTotal > 1)
        setTimeout("imageChanger()", ImageTimeout);
}

// Method to change the image using jQuery
function imageChanger() 
{
    ImageCounter++;

    // Check not out of bounds        
    if(ImageCounter > ImageTotal-1)
        ImageCounter = 0;

    // Try a fancy fade effect
    $("#imageChangerJS").fadeTo(900, 0);
    
    // put in a slight pause so the fade out can finish
    setTimeout(function() {
        var position = Images[ImageCounter].lastIndexOf(".");
        $('#imageChangerJS').attr('src', '/images/homepage/' + Images[ImageCounter])
        $('#imageChangerJS').attr('alt', Images[ImageCounter].substring(0, position))
    }, 850);

    $("#imageChangerJS").fadeTo(900, 1);
    
    setTimeout("imageChanger()", ImageTimeout);
}
