function Fade(id_fade, tab_images, tempo, vitesse) {
    this.id_fade = id_fade;
    this.tempo = tempo;
    this.tab_images = tab_images;
    this.vitesse = vitesse;
    this.img_courante = 0;
    this.id_principal = 2;
    this.id_secondaire = 1;
    this.Loader = null;
    this.opacite = 0;

    this.fade_next = function() {
        this.id_principal = this.id_secondaire;
        this.id_secondaire = 3-this.id_principal;
        this.Loader = new Image();
        this.Loader.src = this.tab_images[(this.img_courante+1)%this.tab_images.length];
        setTimeout(get_fonction_check_loading_status(this), 200);
    }

    this.check_loading_status = function() {
        if (this.Loader.complete == true) {
            this.id_secondaire = 3-this.id_principal;
            this.div_secondaire = document.getElementById(this.id_fade+'_'+this.id_secondaire);
            document.getElementById('img_'+this.id_fade+'_'+this.id_secondaire).src = this.Loader.src;
            this.change_opacite(0, this.div_secondaire);
            this.opacite = 0;
            this.div_secondaire.style.zIndex += 2;
            this.img_courante = (this.img_courante+1)%this.tab_images.length;
            this.fade();
            
            setTimeout(get_fonction_fade_next(this), this.tempo);
        }
        else  
            setTimeout(get_fonction_check_loading_status(this), 200);
    }

    this.fade = function() {
        this.div_secondaire = document.getElementById(this.id_fade+'_'+this.id_secondaire);
        if (this.opacite < 100) {
            this.opacite += this.vitesse;
            this.change_opacite(this.opacite, this.div_secondaire);
            this.change_opacite(100-this.opacite, document.getElementById(this.id_fade+'_'+this.id_principal));
            setTimeout(get_fonction_fade(this), 1);
        }
    }

    this.change_opacite = function(opacite, id) {
        id.style.opacity = opacite/100;
        id.style.MozOpacity = opacite/100;
        id.style.KhtmlOpacity = opacite/100;
        id.style.filter = "alpha(opacity="+opacite+")";
    }

    html  = "<div id="+this.id_fade+"_1 style='position: absolute; z-index: 100;'><img id=img_"+this.id_fade+"_1 src=\""+this.tab_images[0]+"\"></div>";
    html += "<div id="+this.id_fade+"_2 style='position: absolute; z-index:  99;'><img id=img_"+this.id_fade+"_2 src=\""+this.tab_images[0]+"\"></div>";
    document.getElementById(this.id_fade).innerHTML = html;
    setTimeout(get_fonction_fade_next(this), this.tempo/2);
}

function get_fonction_fade_next(o) {
    return(function(){o.fade_next()});
}

function get_fonction_check_loading_status(o) {
    return(function(){o.check_loading_status()});
}

function get_fonction_fade(o) {
    return(function(){o.fade()});
}


