/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
var coef = 0.02 ; // avancement de l'opacit�
var temps = 70 ; // temps entre chaque changement d'opacit�
var temps_pause = 1500 ; // temps d'attente entre 2 changements d'images
var isIE = navigator.userAgent.toLowerCase().indexOf('msie')!=-1 ;

var g_nb    =   4;
var g_rnk1  =   1;
var g_rnk2  =   2;
var g_bg    =   document.getElementById("defil_bg");
var img1    =   document.getElementById("defil_img");
var g_root  =   "/imgs/bands/";
var g_ext   =   ".jpg";
var tabImg;

function init()
{
    //preload_imgs();
    window.setTimeout("update_fade()", temps_pause);
}

function preload_imgs(){
    tabImg = new Array(g_nb);
    for (i=0; i<g_nb; i++){
        tabImg[i]=new Image();
        tabImg[i].src = g_root+(i+1)+g_ext;
    }
}

function update_fade()
{
    if (isIE) // for IE
    {
        opacity_from        =   GetMSIEOpacity(img1.style.filter);
        opacity_to          =   (opacity_from + coef * 100);
        if (opacity_to == 100)
        {
            g_rnk1  =   g_rnk1 % g_nb + 1;
            g_rnk2  =   g_rnk2 % g_nb + 1;
            update_imgs();
            opacity_to  =   0;
            window.setTimeout("update_fade()",temps_pause) ; // attente
        }
        else
        {
            window.setTimeout("update_fade()",temps) ;
        }
        img1.style.filter   =   SetMSIEOpacity(opacity_to);
    }
    else
    {
        opacity_from = parseFloat(img1.style.opacity);
        opacity_to   = opacity_from + coef;
        if (opacity_to >= 1)
        {
            g_rnk1  =   g_rnk1 % g_nb + 1;
            g_rnk2  =   g_rnk2 % g_nb + 1;
            update_imgs();
            opacity_to  =   0;
            window.setTimeout("update_fade()",temps_pause) ; // attente
        }
        else
        {
            window.setTimeout("update_fade()",temps) ;
        }
        img1.style.opacity = opacity_to;
    }
}

function update_imgs()
{
    g_bg.style.backgroundImage  =   "url(" + g_root + g_rnk1 + g_ext + ")";
    img1.src                    =   g_root + g_rnk2 + g_ext;
}

function GetMSIEOpacity(i_strValue)
{
    return parseFloat(i_strValue.replace(/alpha\(opacity=(.+)\)/, '$1'));
}

function SetMSIEOpacity(i_intValue)
{
    return "alpha(opacity=" + i_intValue +")";
}
    
init();

