// Scripts for image rotation used on the storehouse website
var index1 = 0;
var index2 = 0;
var index3 = 0;
var Pics1 = new Array();
var Pics2 = new Array();
var Pics3 = new Array();

// function to initialise images
function InitImg(pagetype, numImages)
{
    var i = 1;
    // build array of image sources, and preload to hidden image
    for (i = 1; i < (numImages+1); i++) 
    {
        Pics1[i-1] = "images/titles/rotation/" + pagetype + "/1/" + i + ".gif";
        var pic1 = new Image(256,150);
        pic1.src = Pics1[i-1];
    }
    
    var i = 1;
    // build array of image sources, and preload to hidden image
    for (i = 1; i < (numImages+1); i++) 
    {
        Pics2[i-1] = "images/titles/rotation/" + pagetype + "/2/" + i + ".gif";
        var pic2 = new Image(256,150);
        pic2.src = Pics2[i-1];
    }
    
    var i = 1;
    // build array of image sources, and preload to hidden image
    for (i = 1; i < (numImages+1); i++) 
    {
        Pics3[i-1] = "images/titles/rotation/" + pagetype + "/3/" + i + ".gif";
        var pic3 = new Image(256,150);
        pic3.src = Pics3[i-1];
    }
    
    // call function to play next image
    setTimeout("nextImg1()", 5000);
    setTimeout("nextImg2()", 7000);
    setTimeout("nextImg3()", 11000);
}

// function to display next 1st image
function nextImg1() 
{
    if (index1 >= Pics1.length)
    {
        index1 = 0;
    }
    crossfade(document.getElementById('imgTitle1'), Pics1[index1], '2', 'Accessible Website Menu [white]');
    index1++;
    var iInterval = Math.floor(Math.random()*7) + 5;
    iInterval = iInterval*1000;
    setTimeout("nextImg1()", iInterval);
}

// function to display next 2nd image
function nextImg2() 
{
    if (index2 >= Pics2.length)
    {
        index2 = 0;
    }
    crossfade(document.getElementById('imgTitle2'), Pics2[index2], '2', 'Accessible Website Menu [white]');
    index2++;
    var iInterval = Math.floor(Math.random()*7) + 5;
    iInterval = iInterval*1000;
    setTimeout("nextImg2()", iInterval);
}

// function to display next 3rd image
function nextImg3() 
{
    if (index3 >= Pics3.length)
    {
        index3 = 0;
    }
    crossfade(document.getElementById('imgTitle3'), Pics3[index3], '2', 'Accessible Website Menu [white]');
    index3++;
    var iInterval = Math.floor(Math.random()*7) + 5;
    iInterval = iInterval*1000;
    setTimeout("nextImg3()", iInterval);
}

