/*****

Image Cross Fade Redux
Version 1.0
Last revision: 02.15.2006
steve@slayeroffice.com

Please leave this notice intact.

Rewrite of old code found here: http://slayeroffice.com/code/imageCrossFade/index.html

Modified by Estefania Gonzalez: 15.08.2008
*****/

var d = document;
var imgs = new Array();
var textos = new Array();
var zInterval = null;
var current = 0;
var pause = false;
var css;
var imgCargando;
var inicio = true;

// Navegadores:
var ie7 = false;
var ie = false;
var firefox = false;
var otros = false;

function browser () {
    var userAgent = navigator.userAgent;
    //alert (userAgent);
    var ind = userAgent.toUpperCase().indexOf('MSIE');
    if (ind != -1) {
        ie7 = (userAgent.substr(ind+5,2) == '7.');
        if (!ie7) {
            ie = true;
        }
    }
    ind = userAgent.toUpperCase().indexOf('MOZILLA');
    if (ind != -1) {
        firefox = (userAgent.toUpperCase().indexOf('FIREFOX') != -1);
    }
    if (!ie7 && !ie && !firefox) {
        otros = true;
    }
    //alert ("IE7: " + ie7 + " | IE: " + ie + " | FIREFOX: " + firefox + " | OTROS: " + otros);
}

function ventana (url, ancho_ven, alto_ven) {
    var ancho_pan = screen.width;
    var alto_pan = screen.height;
    if(ancho_ven == 'full'){
        ancho_ven = ancho_pan;
    }
    if(alto_ven == 'full'){
        alto_ven = alto_pan;
    }
    var x = ancho_pan / 2 - ancho_ven / 2;
    var y = alto_pan / 2 - alto_ven / 2;
    window.open (url, '', 'copyhistory=0, directories=0, location=0, menubar=0, scrollbars=yes, status=0, titlebar=0, toolbar=0, resizable=yes, width='+ancho_ven+', height='+alto_ven+', left=' + x + ', top=' + y);
}

/*
function so_init() {

    //alert ("Entra en so_init()...");

    browser();

    if (d.getElementById && d.createElement) {
        // DON'T FORGET TO GRAB THIS FILE AND PLACE IT ON YOUR SERVER IN THE SAME DIRECTORY AS THE JAVASCRIPT!
        // http://slayeroffice.com/code/imageCrossFade/xfade2.css
        css = d.createElement("link");
        css.setAttribute("href","../css/xfade2.css");
        css.setAttribute("rel","stylesheet");
        css.setAttribute("type","text/css");
    }

    d.getElementsByTagName("head")[0].appendChild(css);

    imgCargando = d.getElementById("cargando");
    imgs = d.getElementById("imageContainer").getElementsByTagName("img");
    textos = d.getElementById("imageContainer").getElementsByTagName("div");
    var i;

    //alert ("imgs.length: " + imgs.length);

    for (i=1; imgs!=null && i<imgs.length; i++){
        imgs[i].xOpacity = 0;
    }
    for (i=0; textos!=null && i<textos.length; i++){
        textos[i].xOpacity = 0;
    }

    imgs[0].style.display = "block";
    textos[0].style.display = "block";
    textos[1].style.display = "block";
    textos[2].style.display = "block";

    imgs[0].style.visibility = "visible";
    textos[0].style.visibility = "visible";
    textos[1].style.visibility = "visible";
    textos[2].style.visibility = "visible";

    imgs[0].xOpacity = .99;
    textos[0].xOpacity = .99;
    textos[1].xOpacity = .99;
    textos[2].xOpacity = .99;

    setOpacity(textos[0]);
    setOpacity(textos[1]);
    setOpacity(textos[2]);

    if (imgs[current*2+1].src.indexOf("null") != -1) {
        setTimeout(so_xfadeTextos, 5000);
    } else {
        setTimeout(so_xfadeTextosImagen, 5000);
    }

    if (d.getElementById("cargando") != null) {
        d.getElementById("cargando").style.display = "none";
    }
    if (d.getElementById("imageContainer") != null) {
        d.getElementById("imageContainer").style.display = "";
    }

}
*/

/*
    28/12/2009. Nueva Version:
 */
function so_initNuevo (path) {

    //alert ("Entra en so_init()... path vale: "+path);

    browser();
    //alert ("debajo de browser...");

    if (d.getElementById && d.createElement) {
        // DON'T FORGET TO GRAB THIS FILE AND PLACE IT ON YOUR SERVER IN THE SAME DIRECTORY AS THE JAVASCRIPT!
        // http://slayeroffice.com/code/imageCrossFade/xfade2.css
        css = d.createElement("link");
        css.setAttribute("href",path + "css/xfade2.css");
        css.setAttribute("rel","stylesheet");
        css.setAttribute("type","text/css");
        //alert ("debajo de browser 2...");
    }

    d.getElementsByTagName("head")[0].appendChild(css);
    //alert ("debajo de head...");
    //imgCargando = d.getElementById("imgLoading");

    //alert("el if vale: "+document.getElementById("imageContainer"));

    if (d.getElementById("imageContainer") != null) {
        //alert("dentro de d.get.... imageContainer distinto de null");
        imgs = d.getElementById("imageContainer").getElementsByTagName("img");
        textos = d.getElementById("imageContainer").getElementsByTagName("div");
        //alert("imgs vale: "+imgs);
    }

    //alert (imgs.length + ' / ' + textos.length);

    var i;
    for (i=1; imgs!=null && i<imgs.length; i++){
        //alert("dentro del for imgs");
        imgs[i].style.display = "none";
        imgs[i].style.visibility = "hidden";
        imgs[i].xOpacity = 0;

    }
    for (i=0; textos!=null && i<textos.length; i++){
        //alert("dentro del for textos");
        textos[i].style.display = "none";
        textos[i].style.visibility = "hidden";
        textos[i].xOpacity = 0;
    }

    if (imgs[0] != null)  {
        //alert("dentro del if 1");
        imgs[0].style.display = "block";
        imgs[0].style.visibility = "visible";
        imgs[0].xOpacity = .99;
    }
    if (textos[0] != null)  {
        //alert("dentro del if 2");
        textos[0].style.display = "block";
        textos[0].style.visibility = "visible";
        textos[0].xOpacity = .99;
        setOpacity(textos[0]);
    }
    if (textos[1] != null)  {
        //alert("dentro del if 3");
        textos[1].style.display = "block";
        textos[1].style.visibility = "visible";
        textos[1].xOpacity = .99;
        setOpacity(textos[1]);
    }
    if (textos[2] != null)  {
        //alert("dentro del if 4");
        textos[2].style.display = "block";
        textos[2].style.visibility = "visible";
        textos[2].xOpacity = .99;
        setOpacity(textos[2]);
    }

    if (d.getElementById("imageContainer") != null) {
        //alert ("dentro de d.getElementById(imageContainer) != null");
        d.getElementById("imageContainer").style.display = "block";
    }

    //alert (imgs[current*2+1]);
    if (imgs[current*2+1] != null) {
        setTimeout("so_xfade()", 5000);
    }

}

function so_xfade() {

    var cOpacity = imgs[current].xOpacity;
    //var nuevoCurrent = imgs[(current+1)*2] ? current+1 : 0;
    var nuevoCurrent = (imgs[current+1] != null) ? current+1 : 0;
    var nOpacity = imgs[nuevoCurrent].xOpacity;

    cOpacity-=.05;
	nOpacity+=.05;

    imgs[nuevoCurrent].style.display = "block";
    textos[(nuevoCurrent*3)].style.display = "block";
    textos[(nuevoCurrent*3)+1].style.display = "block";
    textos[(nuevoCurrent*3)+2].style.display = "block";

    imgs[nuevoCurrent].style.visibility = "visible";
    textos[(nuevoCurrent*3)].style.visibility = "visible";
    textos[(nuevoCurrent*3)+1].style.visibility = "visible";
    textos[(nuevoCurrent*3)+2].style.visibility = "visible";

    imgs[current].xOpacity = cOpacity;
    textos[(current*3)].xOpacity = cOpacity;
    textos[(current*3)+1].xOpacity = cOpacity;
    textos[(current*3)+2].xOpacity = cOpacity;

    imgs[nuevoCurrent].xOpacity = nOpacity;
    textos[(nuevoCurrent*3)].xOpacity = nOpacity;
    textos[(nuevoCurrent*3)+1].xOpacity = nOpacity;
    textos[(nuevoCurrent*3)+2].xOpacity = nOpacity;

    setOpacity(imgs[current]);
    setOpacity(textos[(current*3)]);
    setOpacity(textos[(current*3)+1]);
    setOpacity(textos[(current*3)+2]);
    setOpacity(imgs[nuevoCurrent]);
    setOpacity(textos[(nuevoCurrent*3)]);
    setOpacity(textos[(nuevoCurrent*3)+1]);
    setOpacity(textos[(nuevoCurrent*3)+2]);

    if (cOpacity <= 0.0) {
        imgs[current].style.display = "none";
        textos[(current*3)].style.display = "none";
        textos[(current*3)+1].style.display = "none";
        textos[(current*3)+2].style.display = "none";
        imgs[current].style.visibility = "hidden";
        textos[(current*3)].style.visibility = "hidden";
        textos[(current*3)+1].style.visibility = "hidden";
        textos[(current*3)+2].style.visibility = "hidden";
        //alert ('current: ' + current + ' / nuevoCurrent: ' + nuevoCurrent + ' / ' + imgs[current+1]);
        current = nuevoCurrent;
        setTimeout("so_xfade()", 5000);
	} else {
        setTimeout("so_xfade()", 50);
	}
}

function setOpacity(obj) {
		if(obj.xOpacity>.99) {
			obj.xOpacity = .99;
            return;
		}
		obj.style.opacity = obj.xOpacity;
		obj.style.MozOpacity = obj.xOpacity;
		obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
	}
