// JScript File

var FadeImages= new Array();
var FadeCount=0;
var FadeTimer=2200;     //Tegether with the 1000 wait time after fade to load the new bottom and start a new fade its 3000
var CurrentAlpha=100;
var AlphaStepSize=2;    //Results in 50 steps
var AlphaStepTime=30;
        // Results in a fade time of 900 ms

var TopImage=null;
var BottomImage=null;

function ImageFade_AddImage(imagesrc) {
    //Lets preload the image here and add it to our know array
    var newPos=FadeImages.length;
    FadeImages[newPos] = new Image();
    FadeImages[newPos].src = imagesrc;
}

function ImageFade_RegisterSpots(imageTop, imageBottom)
{
    TopImage=document.getElementById(imageTop);
    BottomImage=document.getElementById(imageBottom);
    if(!TopImage || !BottomImage) {
        alert("Error: could not found fade image containers!");
    }
}

function ImageFade_Launch() {
    setTimeout("FadeImage()",FadeTimer);
}

function FadeImage()
{
    CurrentAlpha=CurrentAlpha-AlphaStepSize;
    SetAlphaLevel(TopImage,CurrentAlpha);
    if(CurrentAlpha<=0) {
        setTimeout("SwitchImage()",300);
    } else {
        setTimeout("FadeImage()",AlphaStepTime);
    }
}

function ResetTopImage()
{
    SetAlphaLevel(TopImage,100);
}

function SwitchImage()
{
    TopImage.src=BottomImage.src;
    FadeCount++;
    if(FadeCount>=FadeImages.length)
    {
        FadeCount=0;
    }
    //Prepare for next cycle
    CurrentAlpha=100;
    setTimeout("ResetTopImage()", 800);
    setTimeout("LoadNewBottom()",1000);
}

function LoadNewBottom() {
    //SetAlphaLevel(BottomImage,0);
    BottomImage.src=FadeImages[FadeCount].src;
    //SetAlphaLevel(BottomImage,100);
    ImageFade_Launch();
}

/* Cross browser set alpha level function */
function SetAlphaLevel(image,AlphaLevel) {
    if (document.all) {
        image.style.cssText="filter: Alpha(Opacity="+AlphaLevel+");opacity:"+(AlphaLevel/100)+";";
    } else {
        image.setAttribute("style","-moz-opacity:"+(AlphaLevel/100)+";opacity:"+(AlphaLevel/100)+";");
    }
}
