﻿function avanzaUnoFondosI() {
    window.setTimeout(objCarruselFondosI.avanza, objCarruselFondosI.Intervalo);
    return false;
}
function retrocedeUnoFondosI() {
    window.setTimeout(objCarruselFondosI.retrocede, objCarruselFondosI.Intervalo);
    return false;
}
function avanzaFondosI() {
    objCarruselFondosI.intIteracionActual++;

    for (i = 0; i < objCarruselFondosI.intNumeroElementos; i++) {
        objCarruselFondosI.Posiciones[i].moverAdelante();
        objCarruselFondosI.refresca(i);
    }
    
    if (objCarruselFondosI.intIteracionActual == objCarruselFondosI.intNumeroIteraciones) {
        objCarruselFondosI.intPosicionActual++;

        var UltimoItem = objCarruselFondosI.Posiciones[objCarruselFondosI.intNumeroElementos - 1].Item;

        for (i = objCarruselFondosI.intNumeroElementos - 1; i > 0; i--) {
            // MUEVE LOS ITEMS UNA POSICION

            objCarruselFondosI.Posiciones[i].Item = objCarruselFondosI.Posiciones[i - 1].Item;
            objCarruselFondosI.Posiciones[i].restituye()
            objCarruselFondosI.refresca(i);
        }

        if (objCarruselFondosI.tipo != "Interno") {
            objCarruselFondosI.Divs[0].style.zIndex = 1;
            objCarruselFondosI.DivsInvertidas[0].style.zIndex = 1;
            objCarruselFondosI.Divs[1].style.zIndex = 2;
            objCarruselFondosI.DivsInvertidas[1].style.zIndex = 2;
            objCarruselFondosI.Divs[2].style.zIndex = 1;
            objCarruselFondosI.DivsInvertidas[2].style.zIndex = 1;
        }
        else {
            objCarruselFondosI.Divs[0].style.zIndex = 1;
            objCarruselFondosI.DivsInvertidas[0].style.zIndex = 1;
            objCarruselFondosI.Divs[1].style.zIndex = 2;
            objCarruselFondosI.DivsInvertidas[1].style.zIndex = 2;
            objCarruselFondosI.Divs[2].style.zIndex = 3;
            objCarruselFondosI.DivsInvertidas[2].style.zIndex = 3;
            objCarruselFondosI.Divs[3].style.zIndex = 2;
            objCarruselFondosI.DivsInvertidas[3].style.zIndex = 2;
            objCarruselFondosI.Divs[4].style.zIndex = 1;
            objCarruselFondosI.DivsInvertidas[4].style.zIndex = 1;

            // CAMBIA LA IMAGEN DEL FONDO DE PANTALLA


            // DISPARA EVENTO DEL CONTROL QUE QUEDA EN EL MEDIO
            if (objCarruselFondosI.Posiciones[2].Item != null) {
                var strScript = objCarruselFondosI.Posiciones[2].Item.url + ";return false";
                //alert(strScript);
                window.setTimeout(strScript, 0);
            }
        }
    

        objCarruselFondosI.Posiciones[0].Item = UltimoItem;
        objCarruselFondosI.Posiciones[0].restituye();
        objCarruselFondosI.refresca(0);

        objCarruselFondosI.intIteracionActual = 0;
    }
    else
        window.setTimeout(objCarruselFondosI.avanza, objCarruselFondosI.Intervalo);
}
function retrocedeFondosI() {

    objCarruselFondosI.intIteracionActual++;

    for (i = 0; i < objCarruselFondosI.intNumeroElementos; i++) {
        objCarruselFondosI.Posiciones[i].moverAtras();
        objCarruselFondosI.refresca(i);
    }
    if (objCarruselFondosI.intIteracionActual == objCarruselFondosI.intNumeroIteraciones) {
        objCarruselFondosI.intPosicionActual++;

        var PrimerItem = objCarruselFondosI.Posiciones[0].Item;

        for (i = 0; i < objCarruselFondosI.intNumeroElementos - 1; i++) {
            // MUEVE LOS ITEMS UNA POSICION

            objCarruselFondosI.Posiciones[i].Item = objCarruselFondosI.Posiciones[i + 1].Item;
            objCarruselFondosI.Posiciones[i].restituye()
            objCarruselFondosI.refresca(i);
        }

        if (objCarruselFondosI.tipo != "Interno") {
            objCarruselFondosI.Divs[0].style.zIndex = 1;
            objCarruselFondosI.DivsInvertidas[0].style.zIndex = 1;
            objCarruselFondosI.Divs[1].style.zIndex = 2;
            objCarruselFondosI.DivsInvertidas[1].style.zIndex = 2;
            objCarruselFondosI.Divs[2].style.zIndex = 1;
            objCarruselFondosI.DivsInvertidas[2].style.zIndex = 1;
        }
        else {
            objCarruselFondosI.Divs[0].style.zIndex = 1;
            objCarruselFondosI.DivsInvertidas[0].style.zIndex = 1;
            objCarruselFondosI.Divs[1].style.zIndex = 2;
            objCarruselFondosI.DivsInvertidas[1].style.zIndex = 2;
            objCarruselFondosI.Divs[2].style.zIndex = 3;
            objCarruselFondosI.DivsInvertidas[2].style.zIndex = 3;
            objCarruselFondosI.Divs[3].style.zIndex = 2;
            objCarruselFondosI.DivsInvertidas[3].style.zIndex = 2;
            objCarruselFondosI.Divs[4].style.zIndex = 1;
            objCarruselFondosI.DivsInvertidas[4].style.zIndex = 1;

            // DISPARA EVENTO DEL CONTROL QUE QUEDA EN EL MEDIO
            if (objCarruselFondosI.Posiciones[2].Item != null) {
                var strScript = objCarruselFondosI.Posiciones[2].Item.url + ";return false";
                window.setTimeout(strScript, 0);
            }
        }
    
        objCarruselFondosI.Posiciones[objCarruselFondosI.intNumeroElementos - 1].Item = PrimerItem;
        objCarruselFondosI.Posiciones[objCarruselFondosI.intNumeroElementos - 1].restituye();
        objCarruselFondosI.refresca(objCarruselFondosI.intNumeroElementos - 1);

        objCarruselFondosI.intIteracionActual = 0;
    }
    else
        window.setTimeout(objCarruselFondosI.retrocede, objCarruselFondosI.Intervalo);
}