var photoFiles = new Array();
var posOrder = new Array(2,5,3,1,4);
var nextImageIndex = posOrder.length - 1;
var nextPosIndex = 0;

function startBanner()
{
    setTimeout("doSwap()", 2000);
}

function doSwap()
{
    // Move to next pos on banner
    nextPosIndex++;
    if (nextPosIndex >= posOrder.length)
        nextPosIndex = 0;

    // Move to next photo in array
    nextImageIndex++;
    if (nextImageIndex >= photoFiles.length)
        nextImageIndex = 0;

    // Set the photo against the pos on the back copy
    //alert("setting bannerPhoto" + pos + " to be " + photoFiles[count]);
    document.getElementById('bannerPhotoBack' + posOrder[nextPosIndex]).src = photoFiles[nextImageIndex];

    // Fade out the front picture...
    fadePicture(95);
}

function fadePicture(opacity)
{
    updateOpacity(document.getElementById('bannerPhoto' + posOrder[nextPosIndex]), opacity);

    // Not see-through yet? Then do it again soon
    if (opacity > 0)
    {
        opacity -= 5;
        setTimeout("fadePicture("+opacity+")", 30);
    }

    // Once we get to zero, back image is showing.
    // Set front to be back, show front again, then set timer to do it all again soon!
    else
    {
        // Set front to be back
        document.getElementById('bannerPhoto' + posOrder[nextPosIndex]).src = photoFiles[nextImageIndex];

        // Show front
        updateOpacity(document.getElementById('bannerPhoto' + posOrder[nextPosIndex]), 100);

        // Do it all again in a mo...!
        setTimeout("doSwap()", 2000);
    }
}

function updateOpacity(image, opacity)
{
    if (image.style) {
        if (image.style.MozOpacity!=null) {
            /* Mozilla's pre-CSS3 proprietary rule */
            image.style.MozOpacity = (opacity/100) - .001;
        } else if (image.style.opacity!=null) {
            /* CSS3 compatible */
            image.style.opacity = (opacity/100) - .001;
        } else if (image.style.filter!=null) {
            /* IE's proprietary filter */
            image.style.filter = "alpha(opacity="+opacity+")";
        }
    }
}

