﻿Array.prototype.idGallery = function(_id) { return _id }  
var galleries = new Array();
var gridHeight = 75;
function cambiaFoto(id, indexGallery, index) {
    $('#dettaglioImmagineImg_' + id).fadeOut(500, function() {
        $('#dettaglioImmagineImg_' + id).attr('src', galleries[indexGallery][index].src);
        $('#dettaglioImmagineImg_' + id).attr('alt', galleries[indexGallery][index].alt);
        $('#zoomLink_' + id).attr('href', galleries[indexGallery][index].src);
        $('#zoomLink_' + id).attr('title', galleries[indexGallery][index].alt);
        $('#IMGzoomLink_' + id).attr('href', galleries[indexGallery][index].src);
        $('#IMGzoomLink_' + id).attr('title', galleries[indexGallery][index].alt);
        var w = 400;
        var h = (w * galleries[indexGallery][index].height) / galleries[indexGallery][index].width;
        $('#div_fotoBig_' + id).animate({ height: h + 'px' }, 400, function() { $('#dettaglioImmagineImg_' + id).fadeIn(); });
        
    });
}
$(function() {
    var numeroSpostamenti = new Array();
    var contatore = new Array();
    for (var yg = 0; yg < galleries.length; yg++) {
        if (galleries[yg].length > 0) {
            $('#thumbGalleryNoFoto_' + galleries[yg].idGallery).css('display', 'none');
            $('#zoomLink_' + galleries[yg].idGallery).css('display', 'block');
            $('#IMGzoomLink_' + galleries[yg].idGallery).css('display', 'block');
            var w = 400;
            var h = (w * galleries[yg][0].height) / galleries[yg][0].width;
            $('#div_fotoBig_' + galleries[yg].idGallery).animate({ height: h + 'px' }, 400, function() {});
            $('#dettaglioImmagineImg_' + galleries[yg].idGallery).attr('src', galleries[yg][0].src);
            $('#dettaglioImmagineImg_' + galleries[yg].idGallery).attr('alt', galleries[yg][0].alt);
            $('#zoomLink_' + galleries[yg].idGallery).attr('href', galleries[yg][0].src);
            $('#zoomLink_' + galleries[yg].idGallery).attr('title', galleries[yg][0].alt);
            $('#IMGzoomLink_' + galleries[yg].idGallery).attr('href', galleries[yg][0].src);
            $('#IMGzoomLink_' + galleries[yg].idGallery).attr('title', galleries[yg][0].alt);
            numeroSpostamenti[galleries[yg].idGallery] = Math.ceil(galleries[yg].length / 2) - 4;
            if (numeroSpostamenti[galleries[yg].idGallery] > 0) {
                contatore[galleries[yg].idGallery] = 0;
                var tempo = 500;
                disabilitaPulsanteNoAlt('spostaSU_' + galleries[yg].idGallery, 'spostaSU');
                $('#spostaSU_' + galleries[yg].idGallery).click(function() {
                    var id = $(this).attr('id').replace('spostaSU_', '');
                    if (contatore[id] > 0) {
                        contatore[id]--;
                        abilitaPulsanteNoAlt('spostaGIU_' + id, 'spostaGIU');
                        disabilitaPulsanteNoAlt('spostaSU_' + id, 'spostaSU');
                        $('#thumbGalleryContent_' + id).animate({ top: (parseInt($('#thumbGalleryContent_' + id).css('top').replace('px', '')) + gridHeight) + 'px' }, tempo, function() { abilitaPulsanteNoAlt('spostaSU_' + id, 'spostaSU'); if (contatore[id] == 0) disabilitaPulsanteNoAlt('spostaSU_' + id, 'spostaSU'); });
                    }
                });
                $('#spostaGIU_' + galleries[yg].idGallery).click(function() {
                    var id = $(this).attr('id').replace('spostaGIU_', '');
                    if (numeroSpostamenti[id] > contatore[id]) {
                        contatore[id]++;
                        abilitaPulsanteNoAlt('spostaSU_' + id, 'spostaSU');
                        disabilitaPulsanteNoAlt('spostaGIU_' + id, 'spostaGIU');
                        $('#thumbGalleryContent_' + id).animate({ top: (parseInt($('#thumbGalleryContent_' + id).css('top').replace('px', '')) - gridHeight) + 'px' }, tempo, function() { abilitaPulsanteNoAlt('spostaGIU_' + id, 'spostaGIU'); if (numeroSpostamenti[id] == contatore[id]) disabilitaPulsanteNoAlt('spostaGIU_' + id, 'spostaGIU'); });
                    }
                });
            } else {
                $('.linea_' + galleries[yg].idGallery).css({ backgroundColor: '#F0F0F0' });
                disabilitaPulsante('spostaSU_' + galleries[yg].idGallery, 'spostaSU');
                disabilitaPulsante('spostaGIU_' + galleries[yg].idGallery, 'spostaGIU');
            }
        }
    }
});
function disabilitaPulsante(elId, elIdImg) {
    $('#' + elId).attr('src', '/images/' + elIdImg + '_disabled.gif');
    $('#' + elId).attr('alt', 'Le foto sono tutte visibili');
    $('#disabilita' + elId).css('display', 'block');
}
function abilitaPulsante(elId, alt, elIdImg) {
    $('#' + elId).attr('src', '/images/' + elIdImg + '.gif');
    $('#' + elId).attr('alt', alt);
    $('#disabilita' + elId).css('display', 'none');
}
function disabilitaPulsanteNoAlt(elId, elIdImg) {
    $('#' + elId).attr('src', '/images/' + elIdImg + '_disabled.gif');
    $('#disabilita' + elId).css('display', 'block');
}
function abilitaPulsanteNoAlt(elId, elIdImg) {
    $('#' + elId).attr('src', '/images/' + elIdImg + '.gif');
    $('#disabilita' + elId).css('display', 'none');
}
function zoomFotogallery(idgallery, idFoto) {
    $('lightbox_' + idgallery + '_' + idFoto).click();
}
