var ie5=(document.getElementById && document.all);
var ns6=(document.getElementById && !document.all);

var speed = 50; //the speed
var stop = 3000; // temps de pause

var nPlus = 2;   //the % of fading for each step
var nOpac = 100; // You don't have to edit below this line

var img_id_1 = "img1";
var img_id_2 = "img2";

var num_img_max = 14; // Indice maximum des bannières dans le dossier images/banners/
var num_1; // indice de l'image bannière à afficher en premier (banner_7.png)

function Transition_Fade_Image(){
    if(document.getElementById){
        imgs_1 = document.getElementById(img_id_1);
        imgs_2 = document.getElementById(img_id_2);

        opacity = nOpac+nPlus;
	nOpac = opacity;

        if(opacity>=100 || opacity<=0) {
            v_speed = stop;
        }
        else v_speed = speed;

        setTimeout("Transition_Fade_Image()" , v_speed);

        if ( opacity < 0 || opacity > 100 ) {nPlus=-nPlus;}

        if(ie5){ // Internet Explorer
            //alert("IE");
            imgs_1.style.filter="alpha(opacity=0)";
            imgs_1.filters.alpha.opacity = opacity;
            imgs_2.style.filter="alpha(opacity=100)";
            imgs_2.filters.alpha.opacity = eval(100-opacity);
        }
        if(ns6){ // Netscape
            //alert("NS");
            imgs_1.style.opacity = Math.min( Math.max( eval(opacity/100) ,0 ),1 );
            imgs_2.style.opacity = 1 - (Math.min( Math.max( eval(opacity/100) ,0 ),1 ));
            imgs_1.style.MozOpacity = 0 + '%';
            imgs_1.style.MozOpacity = opacity + '%';
            imgs_2.style.MozOpacity = 100 + '%';
            imgs_2.style.MozOpacity = eval(100 - opacity) + '%';
        }

        if(opacity>=100 || opacity<=0) {
            num_1 = Num_Gen(num_img_max,num_1);
            if(opacity>=100) imgs_2.src = "images/banners/banner_"+num_1+".png";
            num_1 = Num_Gen(num_img_max,num_1)
            if(opacity<=0) imgs_1.src = "images/banners/banner_"+num_1+".png";
        }


     }
}

function Num_Gen(max,different){
    do{
        var randomnumber=Math.floor(Math.random()*eval(max+1));
    } while (randomnumber==different)
    return randomnumber;
}

onload=setTimeout("Transition_Fade_Image()" , stop);

