
var doc = document;
var request = false;
var RespuestaXml = false;
var temporadaPrevia = false;
var TemporadaActual = "";

if (window.XMLHttpRequest) {
        request = new XMLHttpRequest();
};

function processReqChange() {

    if (request.readyState == 4) {
        if (request.status == 200) {
            /*<temporadas>
                <temporada>
                    <fecha>30 - ABRIL - 2006</fecha>
                    <ciudad>COLLADO VILLALBA</ciudad>
                    <plaza>EL GORRONAL</plaza>
                    <maestro>Curro Bedoya</maestro>
                    <participante>Julio Benitez</participante>
                    <participante>Angel Teruel</participante>
                    <resultados>2 orejas</resultados>
                </temporada> 
              <temporadas>*/
            RespuestaXml = request.responseXML;

            /*Valores del temporada inicializados.*/
            var resultado   = "";
            var x = RespuestaXml.getElementsByTagName('temporada');
            for (i=0;i<x.length;i++)
            {
                for (j=0;j<x[i].childNodes.length;j++)
                {
            /*
            <div style="background-color: #fff4bd; font-weight:bold;text-indent:12px; padding-top:2px; padding-bottom:2px;">1 Fecha: 30 - ABRIL - 2006</div>            
            <div >
              <p style="text-indent:10px;">Lugar: COLLADO VILLALBA</p>
              <p style="text-indent:54px; margin-top:-12px;">"EL GORRONAL"</p>
              <p></p>
              <p style="text-indent:10px;">Cartel: Curro Bedoya</p>
              <p style="text-indent:58px; margin-top:-12px;">Julio Benitez</p>
              <p style="text-indent:58px; margin-top:-12px;">Angel Teruel</p>
              <p></p>
              <p style="text-indent:10px;">Resultado: 2 orejas</p>

              <hr style="border-style:dashed; width:90%; border-size:2px; border-color: #dddddd">
            </div>
            */
                    if (x[i].childNodes[j].nodeType != 1) continue;
                    if (x[i].childNodes[j].nodeName == 'fecha') {
                        resultado += '<div class="corrida_fecha" style="filter:alpha(opacity=30); opacity:0.30;"> ' +
                                    x[i].childNodes[j].firstChild.nodeValue + 
                                     '</div><div>';
                    };

                    if (x[i].childNodes[j].nodeName == 'ciudad') {
                        resultado += '<p class="corrida_ciudad">Lugar: ' +
                                    x[i].childNodes[j].firstChild.nodeValue + 
                                     '</p>';
                    };

                    if (x[i].childNodes[j].nodeName == 'plaza') {
                        resultado += '<p class="corrida_plaza">' +
                                    x[i].childNodes[j].firstChild.nodeValue + 
                                     '</p><p></p>';
                    };

                    if (x[i].childNodes[j].nodeName == 'maestro') {
                        resultado += '<p class="corrida_maestro">Cartel: ' +
                                    x[i].childNodes[j].firstChild.nodeValue + 
                                     '</p>';
                    };

                    if (x[i].childNodes[j].nodeName == 'participante') {
                        resultado += '<p class="corrida_participante">' +
                                    x[i].childNodes[j].firstChild.nodeValue + 
                                     '</p>';
                    };

                    if (x[i].childNodes[j].nodeName == 'resultados') {
                        resultado += '<p></p><p class="corrida_resultados">Resultado: ' +
                                    x[i].childNodes[j].firstChild.nodeValue + 
                                     '</p><hr></div><br/><br/>';
                    };
                };
            };
            var temp_slider = document.getElementById('temp_slider');
            temp_slider.innerHTML = resultado;
            esconder('loading');

        } else {
            var temp_slider = document.getElementById('temp_slider');
            temp_slider.innerHTML = "";
        };


        /* Ahora hay que indicar que esta nueva temporada es la buena
           y hay que desmarcar la temporada seleccionada anteriormente */
        var temporadaPrevia = document.getElementById('temporadaPrevia');
        if (temporadaPrevia.innerHTML != "") {
            var botonTemporada = document.getElementById(temporadaPrevia.innerHTML);
            botonTemporada.style.border = '0px';
            botonTemporada.style.width = '130px';
        }
        temporadaPrevia.innerHTML = TemporadaActual;
        var botonTemporada = document.getElementById(TemporadaActual);
        botonTemporada.style.border = '4px solid #ffd900';
        botonTemporada.style.width = '122px';
        
        var temporadas_catalog  = document.getElementById("temp_slider");
        temporadas_catalog.scrollTop = 0;
    };
};



function getTemporada(temporada_name) {
    mostrar('loading');
    var temp_slider = document.getElementById('temp_slider');
    temp_slider.innerHTML = "";

    TemporadaActual = temporada_name;
    var actual = document.getElementById('actual');
    if (actual && actual.innerHTML == temporada_name) {
        return;
    };

    if (window.ActiveXObject) {
        try {
            request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch(e) {
            try {
                request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch(e) {
                request = false;
            };
        };
    };

    if (request) {
        request.onreadystatechange = processReqChange;
        request.open("GET", 'temporadas/'+temporada_name+'.xml');
        request.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
        request.send(null);
    };
    setTimeout("esconder('loading')",10000);
};




var AccionTemporadas = ""; 
function SubirTemporadas(cantidad) {
    var temporadas_catalog  = document.getElementById("temp_slider");
    temporadas_catalog.scrollTop = Math.max(temporadas_catalog.scrollTop - cantidad, 0); 
}


function BajarTemporadas(cantidad) {
    var temporadas_catalog  = document.getElementById("temp_slider");
    temporadas_catalog.scrollTop = Math.min(temporadas_catalog.scrollTop + cantidad, 
                                       temporadas_catalog.scrollHeight); 
}


function scrollUp () {
    AccionTemporadas = setInterval("SubirTemporadas(2)",20);
}


function scrollDown () {
    AccionTemporadas = setInterval("BajarTemporadas(2)",20);
}


function scrollStop () {
    clearInterval(AccionTemporadas);
}



function mostrar(nombre) {
    var imagen = document.getElementById(nombre);
    imagen.name = 'SHOWING';
    show(nombre); 
};


function esconder(nombre) {
    var imagen = document.getElementById(nombre);
    imagen.name = 'HIDDING';
    hide(nombre); 
};


function show(nombre) {
    var imagen = document.getElementById(nombre);
    if (imagen.style.filter) {
        var opacidad = imagen.style.filter.replace('alpha(opacity=','');
        opacidad = opacidad.replace(')','');
        if (eval(opacidad) < 80 && imagen.name == 'SHOWING') {
            opacidad = eval(opacidad) + 10;
            imagen.style.filter = "alpha(opacity="+opacidad+")";
            setTimeout("show('"+nombre+"')",50);
        };

    } else if (imagen.style.opacity) {
        if (imagen.style.opacity < 0.8 && imagen.name == 'SHOWING') {
            imagen.style.opacity = eval(imagen.style.opacity) + 0.1;
            setTimeout("show('"+nombre+"')",50);
        };
    };
};



function hide(nombre) {
    var imagen = document.getElementById(nombre);
    if (imagen.style.filter) {
        var opacidad = imagen.style.filter.replace('alpha(opacity=','');
        opacidad = opacidad.replace(')','');
        if (eval(opacidad) > 0 && imagen.name == 'HIDDING') {
            opacidad = eval(opacidad - 10);
            imagen.style.filter = "alpha(opacity="+opacidad+")";
            setTimeout("hide('"+nombre+"')",50);
        };

    } else if (imagen.style.opacity) {
        if (imagen.style.opacity > 0.0 && imagen.name == 'HIDDING') {
            imagen.style.opacity = eval(imagen.style.opacity) - 0.1;
            setTimeout("hide('"+nombre+"')",50);
        };
    };
};
