﻿function cambiaFoto(index) {
    $('#dettaglioImmagineImg').fadeOut(500, function() {
        $('#dettaglioImmagineImg').attr('src', images[index].src);
        $('#dettaglioImmagineImg').attr('alt', images[index].alt);
        $('#dettaglioImmagineImg').fadeIn();
    });
}
$(function() {
    if (images.length > 0) {
        $('#thumbGalleryNoFoto').css('display', 'none');
        $('#dettaglioImmagineImg').attr('src', images[0].src);
        $('#dettaglioImmagineImg').attr('alt', images[0].alt);
        var numeroSpostamenti = Math.ceil(images.length / 3) - 3;
        if (numeroSpostamenti > 0) {
            var contatore = 0;
            var gridHeight = 72;
            var tempo = 500;
            disabilitaPulsanteNoAlt('spostaSU');
            $('#spostaSU').click(function() {
                if (contatore > 0) {
                    contatore--;
                    abilitaPulsanteNoAlt('spostaGIU');
                    disabilitaPulsanteNoAlt('spostaSU');
                    $('#thumbGalleryContent').animate({ top: (parseInt($('#thumbGalleryContent').css('top').replace('px', '')) + gridHeight) + 'px' }, tempo, function() { abilitaPulsanteNoAlt('spostaSU'); if (contatore == 0) disabilitaPulsanteNoAlt('spostaSU'); });
                }
            });
            $('#spostaGIU').click(function() {
                if (numeroSpostamenti > contatore) {
                    contatore++;
                    abilitaPulsanteNoAlt('spostaSU');
                    disabilitaPulsanteNoAlt('spostaGIU');
                    $('#thumbGalleryContent').animate({ top: (parseInt($('#thumbGalleryContent').css('top').replace('px', '')) - gridHeight) + 'px' }, tempo, function() { abilitaPulsanteNoAlt('spostaGIU'); if (numeroSpostamenti == contatore) disabilitaPulsanteNoAlt('spostaGIU'); });
                }
            });
        } else {
            $('.linea').css({ backgroundColor: '#E2E2E2' });
            disabilitaPulsante('spostaSU');
            disabilitaPulsante('spostaGIU');
        }
    }
});
function disabilitaPulsante(elId) {
    $('#' + elId).attr('src', 'images/' + elId + '_disabled.gif');
    $('#' + elId).attr('alt', 'Le foto sono tutte visibili');
    $('#disabilita' + elId).css('display', 'block');
}
function abilitaPulsante(elId, alt) {
    $('#' + elId).attr('src', 'images/' + elId + '.gif');
    $('#' + elId).attr('alt', alt);
    $('#disabilita' + elId).css('display', 'none');
}
function disabilitaPulsanteNoAlt(elId) {
    $('#' + elId).attr('src', 'images/' + elId + '_disabled.gif');
    $('#disabilita' + elId).css('display', 'block');
}
function abilitaPulsanteNoAlt(elId, alt) {
    $('#' + elId).attr('src', 'images/' + elId + '.gif');
    $('#disabilita' + elId).css('display', 'none');
}
