
var slideShowSpeed = 5000;
var CurrentPic;
var Loader;
var SmoothResize;
var DivID;
var PictureID;
var ScaleXFactor;
var ScaleYFactor;
var MaxPreviews = 6;


function StartSlideShow(DIV_ID, IMG_ID, Mode)
{
    CurrentPic   = 0;
    DivID        = DIV_ID;
    PictureID    = IMG_ID;
    SmoothResize = Mode;
    document.getElementById(PictureID).style.display = "none";
    changeOpac(0, PictureID);
    Loader = new Image();
    Loader.src = '/accueil/adrenaline-passion-'+CurrentPic+'.jpg';
    setTimeout("CheckLoadingStatus(0)", 200);
}

function CheckLoadingStatus(Mode)
{
    if (Loader.complete == true)
    {
        if (Mode == 0)
        {
            document.getElementById(PictureID).src = '/accueil/adrenaline-passion-'+CurrentPic+'.jpg';
            document.getElementById(PictureID).style.display = "inLine";
            document.getElementById(PictureID).width    = Loader.width;
            document.getElementById(PictureID).height   = Loader.height;
            currentOpac(PictureID, 100, 300);
        }
        else
            currentOpac(PictureID, 0, 300);
    }
    else
        setTimeout("CheckLoadingStatus("+Mode+")", 200);
}

function NextPic()
{
    CurrentPic = CurrentPic + 1;
    if (CurrentPic >= MaxPreviews)
        CurrentPic = 0;
    Loader = new Image();
    Loader.src = '/accueil/adrenaline-passion-'+CurrentPic+'.jpg';
    setTimeout("CheckLoadingStatus(1)", 200);
}

function ShowNext()
{
    if (document.getElementById(PictureID).width != Loader.width && SmoothResize == 1)
    {
        StretchImage();
        return(0);
    }
    else if (document.getElementById(PictureID).width != Loader.width && SmoothResize == 0)
    {
        document.getElementById(PictureID).width    = Loader.width;
        document.getElementById(PictureID).height   = Loader.height;
    }
    document.getElementById(PictureID).src = '/accueil/adrenaline-passion-'+CurrentPic+'.jpg';
    currentOpac(PictureID, 100, 300);
}

function StretchImage()
{
    ScaleXFactor = (document.getElementById(PictureID).width - Loader.width) / 10;
    ScaleYFactor = (document.getElementById(PictureID).height - Loader.height) / 10;

    setTimeout("ResizeFactor()",20);
}

function ResizeFactor()
{
    if (document.getElementById(PictureID).width == Loader.width)
    {
        ShowNext();
        return(0);
    }
    Width  = document.getElementById(PictureID).width - ScaleXFactor;
    Height = document.getElementById(PictureID).height - ScaleYFactor;

    document.getElementById(PictureID).width    = Width;
    document.getElementById(PictureID).height   = Height;
    setTimeout("ResizeFactor()",20);
}

function opacity(id, opacStart, opacEnd, millisec)
{
    var speed = Math.round(millisec / 100);
    var timer = 0;

    if(opacStart > opacEnd)
    {
        for(i = opacStart; i >= opacEnd; i--)
        {
            setTimeout("changeOpac("+i+",'"+id+"')",(timer * speed));
            timer++;
        }
        setTimeout("ShowNext()",(timer * speed));
    }
    else if(opacStart < opacEnd)
    {
        for(i = opacStart; i <= opacEnd; i++)
        {
            setTimeout("changeOpac("+i+",'"+id+"')",(timer*speed));
            timer++;
        }
        setTimeout("NextPic()",slideShowSpeed);
    }
}

function changeOpac(opacity, id)
{
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity="+opacity+")";
}

function currentOpac(id, opacEnd, millisec)
{
    var currentOpac = 100;
    if (document.getElementById(id).style.opacity < 100)
        currentOpac = document.getElementById(id).style.opacity * 100;
    opacity(id, currentOpac, opacEnd, millisec)
}
