// Attiva/disattiva un pulsante dei form di ricerca per l'Archivio Trento.

function toggleButton(obj) {
    var t = $(obj.parents('form').find('select')).length;
    var a = 0;
    $(obj.parents('form').find('select')).each(function() {
        if ($(this).val()<1) ++a;
    });
    if (a==t) obj.parents('form').eq(0).find('input.fancybox').attr('disabled','disabled');
    else obj.parents('form').eq(0).find('input.fancybox').removeAttr('disabled');
}

$(document).ready(function() {

    // Disattiva i pulsanti del form di ricerca per l'Archivio Trento e aggancia Fancybox.
    $('input.fancybox').attr('disabled','disabled').click(function() {
        var d = $(this).parents('form').eq(0).serialize();
        $.ajax({
            url : 'viewer-trento.php',
            data : d,
            type : 'GET',
            dataType : 'html',
            global : false,
            async : false,
            cache : false,
            success : function(data) {
                $.fancybox({
                    type : 'iframe',
                    width : '96%',
                    height : '96%',
                    centerOnScroll : true,
                    scrolling : 'no',
                    titleShow : false,
                    href : 'viewer-trento.php?' + d,
                    content : data
                });
            }
        });
        return false;
    });

    // Attiva un pulsante di ricerca per l'Archivio Trento quando almeno uno dei menu a tendina precedenti nello stesso form ha impostato un valore.

    $('form.search select').each(function() {
        toggleButton($(this));
    }).change(function() {
        toggleButton($(this));
    });

    // Attiva il visualizzatore.

    $('a.fancybox').fancybox({
        type : 'iframe',
        width : '99%',
        height : '99%',
        centerOnScroll : true,
        scrolling : 'auto',
		showCloseButton: true,
		titlePosition: 'inside'
	
    });

    // Attiva lo scorrimento delle immagini in testata.

    $('#portfolio').innerfade({
        animationtype : 'fade',
        speed : 'normal',
        timeout : 4000,
        type : 'sequence',
        containerheight : '264px'
    });

    // Attiva l'effetto lente sulle immagini.

    $('.zoom').jqzoom({
        zoomType : 'reverse',
        lens : true,
        preloadImages : false,
        alwaysOn : false,
        position : 'right',
        xOffset : 10,
        zoomWidth : 300,
        zoomHeight : 300
    });

	// Rende sicuri dagli spambot gli indirizzi e-mail.
	
    $('a.mail').each(function() {
        var m = $(this).attr('href').replace('[AT]','@');
        m = m.replace('[DOT]','.');
        if ($(this).html()==$(this).attr('href').substr(7)) {
            var t = $(this).html().replace('[AT]','@');
            t = t.replace('[DOT]','.');
            $(this).html(t);
        }
        $(this).attr('href',m);
    });

});
