﻿var indice_testata=1;
var tmpImg;
var stepMoz=-0.1
var step = -10
var timer_immagine = 3000;
var timer_fade = 70;
var browser="explorer"
function start_change_testata() {
    //theobject = document.getElementById("wrapper-img")
    theobject = document.getElementById("ctl00_Testata1_img_fade")
    theobject.style.MozOpacity = 1;
    if (navigator.userAgent.toString().toLowerCase().indexOf("firefox") > 0) {
        browser = "firefox"
        theobject.style.MozOpacity = 1;
    }
    else if (navigator.userAgent.toString().toLowerCase().indexOf("msie") > 0) {
        browser = "explorer"
    }
    else {
        browser = "safari"
        theobject.style.opacity = 1;
    }
    highlighting = setInterval("highlightit(theobject)", timer_fade)
}

/*function clow(which2) {
    clearInterval(highlighting)
    if (which2.style.MozOpacity)
        which2.style.MozOpacity = 0.3
    else if (which2.filters)
        which2.filters.alpha.opacity = 30
}*/
function highlightit(cur2) {
    if (browser=="firefox") {
        // Modzilla
        cur2.style.MozOpacity = parseFloat(cur2.style.MozOpacity) + stepMoz
        if (cur2.style.MozOpacity < 1) {
            if (cur2.style.MozOpacity <= 0) {
                //Cambio immagine e inverto fade
                cambio_immagine();
                stepMoz = -stepMoz
            }
        }
        else {
            // attendo prima di lanciare di nuovo il cambio immagine
            stepMoz = -stepMoz
            clearInterval(highlighting)
            setTimeout("call_cambio()", timer_immagine);
        }
    }
    else if (browser == "safari") {
    // Safari/Chrome
        cur2.style.opacity = parseFloat(cur2.style.opacity) + stepMoz
        if (cur2.style.opacity < 1) {
            if (cur2.style.opacity <= 0) {
                //Cambio immagine e inverto fade
                cambio_immagine();
                stepMoz = -stepMoz
            }
        }
        else {
            // attendo prima di lanciare di nuovo il cambio immagine
            stepMoz = -stepMoz
            clearInterval(highlighting)
            setTimeout("call_cambio()", timer_immagine);
        }
    }
    else {
        // Explorer
        cur2.filters.alpha.opacity += step
        if (cur2.filters.alpha.opacity < 100) {
            if (cur2.filters.alpha.opacity <= 0) {
                //Cambio immagine e inverto fade
                cambio_immagine();
                step = -step
            }
        }
        else {
            // attendo prima di lanciare di nuovo il cambio immagine
            step = -step
            clearInterval(highlighting)
            setTimeout("call_cambio()", timer_immagine);
        }
    }
}
function call_cambio() {
    highlighting = setInterval("highlightit(theobject)", timer_fade)
}
function cambio_immagine(){
    //theobject.src = path_testata[indice_testata]
    //theobject.style.backgroundImage = "url(" + path_testata[indice_testata] + ")"
    theobject.src = path_testata[indice_testata] 
    indice_testata++
    if (indice_testata == path_testata.length)
        indice_testata = 0;
    tmpImg = new Image();
    tmpImg.src = path_testata[indice_testata];
}