$(document).ready(function () {

    $(".pulsantiera").buttonset();


    $(function () {
        $(".buttons").button();

        $(".buttonsPrint").button({
            icons: {
                primary: "ui-icon-print"
            }
        });


    });
    //maschero i link non da navigare

    //menu
    function addMega() {
        var mc = $(this).attr("class");
        //alert($(this).attr("href"));
        //$(this).find('a:first').attr("href","javascript:void(0);");
        $(this).removeClass(mc).addClass(mc + "_hover");

        var es = $(this).find('div:first li').length;
        if (es == 0) $(this).find('.bottWr').addClass('nodisp');

        var l = $(this).find('div:first li').length;
        if (l == 0) return;
        //$(this).find('h2:first').addClass("hover");  //non serve??
        var offset = $(this).offset();
        var wh = $(this).width();
        $(this).find('.bottWr').width(wh);
        $(this).find('.bottMd').width(wh - 30);

        //alert(wh);
        $(this).find('div:first').css({ 'left': offset.left, 'width': wh }).animate({
            opacity: 1,
            right: '0',
            height: 'toggle'
        }, 300, function () { }
		);

    }

    function removeMega() {

        var mc = $(this).attr("class");
        $(this).removeClass(mc).addClass(mc.replace("_hover", ""));
        $(this).find('.bottWr').removeClass('nodisp');
        $(this).find('h2:first').removeClass("hover");
        $(this).find('div:first').animate({
            opacity: 0.9,
            right: '0',
            height: 'toggle'
        }, 300, function () { });

    }

    var megaConfig = {
        interval: 10,
        sensitivity: 4,
        over: addMega,
        timeout: 100,
        out: removeMega
    };


    $('ul#menu li').hoverIntent(megaConfig);

    if ($.browser.msie) {
        if (parseInt($.browser.version) < 7) {
            //$('ul#menu li div li').hover( function(ev){ alert('k'); $(this).addClass('_hover'); }, function(ev){ $(this).removeClass('_hover'); } );
        }
    }


    //$('.hidden ul').corner("bl 15px").corner("br 15px");
    $('.hidden').each(function () {
        // $(this).find('li:last').addClass("liLast").append('<div class="bottWr"><div class="bottRt"></div><div class="bottMd"></div><div class="bottLt"></div></div>');
    });

    $('div.annuncio').each(function () {
        $w = $(this).height();
        //alert($('.content').height());
        if ($w > 0) {
            $('.content').height($('.content').height() - $w - 10);
            $('.mainContent').css({ 'height': 'auto' });
        }
        //alert($('.content').height());
    });

    $('.content').jScrollPane({ scrollbarWidth: 7, scrollbarMargin: 20, wheelSpeed: 50, dragMinHeight: 10, dragMaxHeight: 40 });
    //nascondo l'

    $('div#breadcrumb').find('a').eq(1).attr("href", "javascript:void(0);");
    //$('li.mega').find('a').eq(0).attr("href","javascript:void(0);");


    //COMPORTAMENTO RICERCA AVANZATA
    $('span.chpu input:[type=checkbox]').each(function () {
        $divf = $(this).parent().next().next().not('.chp');
        $divf.hide();  //nascondo i figli
        var $chsf = $divf.find('input:[type=checkbox]'); //.attr("checked", "checked")  //seleziono i figli
        $chsf.each(function () {
            $(this).hide();
        });
        $(this).change(function (ev) {
            //alert('a');
            if ($(this).attr("checked")) {
                $(this).parent().next().next().show();
            } else {
                $(this).parent().next().next().hide();
            }
        });
        $(this).parent().find('label').click(function (event) {  //aprochiudo con label
            event.preventDefault();
            $(this).parent().next().next().not('.chp').each(function () {
                $(this).toggle();
            });

        });
    });

    $('span.chp input:[type=checkbox]').each(function () {
        //alert($(this).attr("name"));
        var $ch = $(this).attr("checked", "");  //li seleziono tutti
        $divf = $(this).parent().next().next().not('.chp');
        $divf.hide();  //nascondo i figli
        var $chsf = $divf.find('input:[type=checkbox]'); //.attr("checked", "checked")  //seleziono i figli
        $chsf.change(function () {
            if ($chsf.length == $(this).parents('div.list').find(':checked').length) {
                $ch.attr("checked", true);
            } else {
                $ch.attr("checked", false);
            }
        });
        $(this).change(function () {
            if ($(this).attr("checked")) {
                //seleziono tutti i figli
                $chsf.attr("checked", true);
            }

        }).click(function (ev) {
            //alert('a');
            $(this).parent().next().next().show();
        });
        $(this).parent().find('label').click(function (event) {  //aprochiudo con label
            event.preventDefault();
            $(this).parent().next().next().not('.chp').each(function () {
                $(this).toggle();
            });

        });

    });


    //CORREZIONE TABELLA ORGANI ASSOCIATIVI

    $("div.organi").each(function () {
       // $('td.tdfirst,td.tdsecond,td.tdthird', this).css({ 'vertical-align': 'top' });
         $('span.carica', this).each(function () {
            $(this).css({ 'padding-top': '0','white-space': 'nowrap' });
            $p = $(this).parent().parent();
            $('td', $p).each(function () {
                $(this).css({ 'padding-top': '20px' });
            });

        });
    });


    //CORREZIONE FORM ASP.NET
    //alert(location.href);
    //$('form#aspnetForm').attr("action",location.href);

    //regioni per ricerca
    /*$('area').click(function(){
    var reg =$(this).attr("id");
    idreg = reg.replace("reg_","");
    $('.f_reg').val(idreg).trigger('change');
    //alert($(this).attr("id"));
    return false;
    });*/
    //$('.contMod').corner("5px");
    $('.contModIn').corner("round 5px").parent().css('padding', '1px').corner("round 7px");
    $('.feacoIn').corner("round 5px").parent().css('padding', '1px').corner("round 7px");
    //$('.buttons').wrap().corner("round 5px");
    $(document).pngFix();




});



function myprint() {
    alert('i');
    $('#TB_window').css({ 'marginLeft': '0', 'marginTop': '0', 'left': '0', 'top': '0' });
    return false;
}
//window.print = function(o) { alert("hi"); };

    
