﻿var LongitudArray = ArrayImagenes.length;
var aleatorio = Math.ceil(Math.random()*LongitudArray)-1;
var srcImagen = ArrayImagenes[aleatorio];
var Total = document.getElementById("ctl00_ContentBody_tbNumeroImagenes").value;
var Tiempo = document.getElementById("ctl00_ContentBody_TiempoImagenes").value;



jQuery(function($) {

    jQuery.preload('#images img', {
        onRequest: request,
        onFinish: finish
    });

    function request(data) {

    };

    function finish() {

        jQuery("#ImagenPrincipal").show();
        document.getElementById("ImagenPrincipal").src = srcImagen;
        if (Total > 1) {
            setTimeout("OtraImagen()", Tiempo);
        }
    };

});
    

function ObtenerImagenAleatoria()
{
     aleatorio = Math.ceil(Math.random()*LongitudArray)-1;
     return ArrayImagenes[aleatorio];
}



function OtraImagen()
{
    var igual = true;
    srcImagen = ObtenerImagenAleatoria();
    igual = (srcImagen==jQuery("#ImagenPrincipal").attr("src"));
    while (igual)
    {
        srcImagen = ObtenerImagenAleatoria();
        igual = (srcImagen==jQuery("#ImagenPrincipal").attr("src"));
    }
    
    jQuery("#ImagenPrincipal").fadeOut("slow", function(){
         document.getElementById("ImagenPrincipal").src=srcImagen;
    });
    jQuery("#ImagenPrincipal").fadeIn("slow");
    
    setTimeout("OtraImagen()",Tiempo);
}

