var hTimeOut;
var nbDiv = 0;
var divAAfficher = 2;
var divAffiche = 1;
var bPause = false;
var effetFondu = "vide";
var opaciteAfficher;
var opaciteMasquer;

var debutFondu = 100;



function fondu(lNbDiv) {
    if (nbDiv == 0 && !isNaN(lNbDiv)) nbDiv = lNbDiv;
    opaciteMasquer = debutFondu;
    opaciteAfficher = 0;
    if (document.getElementById("img" + divAAfficher)) {
        document.getElementById("img" + divAAfficher).style.zIndex = "1";
        document.getElementById("img" + divAAfficher).style.visibility = "visible";
        setOpacity("img" + divAAfficher, 0);
    }
    //diminuer l'opacité de la div affichée
    if (effetFondu == "vide") {
        effetFondu = window.setInterval("lancerFondu()", 50);
    }
}
function lancerFondu() {
	
    opaciteMasquer = opaciteMasquer - 10;
    opaciteAfficher = opaciteAfficher + 10;

    if (opaciteAfficher == 100) {
        if (document.getElementById("img" + divAffiche)) {
            document.getElementById("img" + divAffiche).style.visibility = "hidden";
            document.getElementById("img" + divAffiche).style.zIndex = "1";
            setOpacity("img" + divAffiche, debutFondu);
            divAffiche = divAAfficher;
            divAAfficher += 1;
            if (divAAfficher > nbDiv) divAAfficher = 1;
            window.clearInterval(effetFondu);
            effetFondu = "vide";
            if (!bPause) hTimeOut = setTimeout("fondu()", 2000);
        }
        return;
    }

    setOpacity("img" + (divAffiche), opaciteMasquer);
    setOpacity("img" + (divAAfficher), opaciteAfficher);

}
function setOpacity(id, value) {
    if (document.getElementById(id)) {
        var object = document.getElementById(id).style;
        object.opacity = (value / 100);
        object.MozOpacity = (value / 100);
        object.KhtmlOpacity = (value / 100);
        object.filter = "alpha(opacity=" + value + ")";
    }
}


function aller(lIndex) {
    clearTimeout(hTimeOut);
    clearTimeout(effetFondu);
    effetFondu = "vide";

    if (document.getElementById("img" + divAffiche)) {
        //on masque le div actuel
        document.getElementById("img" + divAffiche).style.visibility = "hidden";
        document.getElementById("img" + divAffiche).style.zIndex = "1";
        setOpacity("img" + divAffiche, debutFondu);
    }
    divAAfficher = lIndex + 1;
    divAffiche = divAAfficher;

    if (document.getElementById("img" + divAffiche)) {
        document.getElementById("img" + divAAfficher).style.visibility = "visible";
        document.getElementById("img" + divAAfficher).style.zIndex = "1";
        setOpacity("img" + divAAfficher, debutFondu);
    }
}

function reprendre() {
    bPause = false;

    divAffiche = divAAfficher;
    divAAfficher += 1;
    if (divAAfficher > nbDiv) divAAfficher = 1;

    fondu();
}       
