$(document).ready(function() {

    //update title
    document.title += $("h1").text();


    if (jQuery.browser.msie)
    {
        $(".left input[type=image]").css("margin-top", 1);
    }
    $(".left input").bind("focus", function() {
        $(this).select()
    });

    $("#login").attr("action", "/np4/si/?login");

    //handle over on menu
    $("#menu li a,#inside li a").hover(
            function() {
                if (!$(this).parents("li").hasClass("sel"))
                    $(this).parents("li").addClass("on")
            },
            function() {
                if (!$(this).parents("li").hasClass("sel"))
                    $(this).parents("li").removeClass("on")
            }
            );


    //handle over and click on news list
    jQuery.each($("#pageBody .anew h2 a,#destaques .anew h2 a,#noticias .anew .date a"), function() {
        var anewClicable = $(this).parents(".anew");
        anewClicable.attr("hloc", $(this).attr('href'));
        anewClicable.hover(
                function() {
                    $(this).addClass("on")
                },
                function() {
                    $(this).removeClass("on")
                }
                );
        anewClicable.click(function() {
            document.location.href = $(this).attr('hloc');
        });
        anewClicable.css("cursor", "pointer");
    });

    //minor twik on menu
    $("#inside li:first").css("border", 0);

    //h2collapse
    $.each($(".h2collapse h2"), function() {
        var proximos = $(this).nextAll();
        var proximoH2 = $(this).nextAll("h2");


        var ateProximo = -1;
        if (proximoH2.length)
            ateProximo = $.inArray(proximoH2[0], proximos);
        if (ateProximo > 0) {
            proximos = proximos.splice(0, ateProximo);
        }
        if (proximos.length) {
            this.proximos = $(proximos);
            this.proximos.hide();
            $(this).click(function() {
                this.proximos.slideToggle();
            });
            $(this).css("cursor", "pointer");
            $(this).append(" (+)");
        }
    });
});

