﻿
var imgElegida=1;

$(document).ready(function () {

    setInterval("refreshImages()", 4000);

    //Al cargar la página (PostBack) se deben ocultar todas las imágenes excepto la primera
    $('#gw-PaseImagenes').children('img').each(function (i) {
        if (i != 0) {
            $(this).hide();
            
        }
    });

    $('.gw-paginacion li a').click(function () {

        var imgElegida = $(this).text();
        muestraImagen($(this).text() - 1);

        $('.gw-paginacion li a').each(function (i) {

            if ((i + 1) == imgElegida) {
                $(this).attr('class', 'gw-selected');

            } else {
                $(this).removeAttr('class');
            }

        });
    });


});

function refreshImages() {
    
    //Ver la imagen que esta siendo mostrada
    var liTotales = $('.gw-paginacion li').length;
    
    $('.gw-paginacion li a').each(function (i) {

        if ($(this).attr('class') == "gw-selected") {
            imgElegida = $(this).text();
            $(this).removeAttr('class');
        }

    });

    $('.gw-paginacion li a').each(function (i) {
        if ($(this).text() == (imgElegida * 1 + 1)) {
            $(this).attr('class','gw-selected');
        }
    });

    var esUltima = false;
    $('.gw-paginacion li a').each(function (i) {
        if ((imgElegida * 1 + 1) > liTotales) {
            esUltima = true;
        }
    });

    if (esUltima == true) { $('.gw-paginacion li a').parent().first().children('a').addClass('gw-selected');imgElegida = 0; }

    muestraImagen(imgElegida);
    
    
}

function muestraImagen(idItem) {
    $('#gw-PaseImagenes').children('img').each(function (i) {
        if (i != idItem) {
            $(this).hide();
            
        } else {
            $(this).show();
        }
    });    
}




