
//function fixpng() {
//    if($.browser.msie && ($.browser.version == "6.0")){
//        DD_belatedPNG.fix('.png_bg');
//    }
//
//}

menu = {
    elem: '#menu li',
    load: function(){
        $(this.elem).each(function(){
            var el = $(this).find('ul:eq(0)');
            //el.parent("li").addClass("subm");
            $(this).hover(function() {
                //$(this).addClass("hover").children("a:eq(0)").addClass("hover");
                $(this).addClass("hover").children("a:eq(0)").addClass("hover");
                el.parent(this).addClass("hoverseta");
                el.fadeIn(0);
            },
            function(){
                $(this).removeClass("hover").children("a:eq(0)").removeClass("hover");
                el.parent(this).removeClass("hoverseta");
                el.fadeOut('fast');
            });
        });
    }
}



jQuery(document).ready(function() {
     
    var swfVer = GetSwfVer();
    var msgSwfVer = "";
    if (swfVer == -1) {
        msgSwfVer = "Para uma melhor visualização, instale o Adobe Flash Player. <a href='http://www.adobe.com/go/getflashplayer' target='_blank'> Clique aqui </a>";
        msgSwfVer =  "<div id='noflashdetected'>"+msgSwfVer+"</div>";

    }
    else {
        var swfVerSplit = swfVer.split(".");
        if (swfVerSplit[0] < 10) {
            msgSwfVer = "Para uma melhor visualização, atualize o Adobe Flash Player. <a href='http://www.adobe.com/go/getflashplayer' target='_blank'> Clique aqui </a>";
            msgSwfVer =  "<div id='noflashdetected'>"+msgSwfVer+"</div>";
        }
    }
    if (msgSwfVer != "")  $("body").before(msgSwfVer);
    if ($("#menu").length > 0 ) {
         menu.load();
    }


    generateImgs = function() {

        $('.ins_img_left').each(function() {
                    $(this).wrap('<span class="insimg"></span>');
                    if ($(this).attr('src')  == $(this).parents('div.txt').find('img:eq(0)').attr('src')) {nclass=' marginTop4';} else {nclass='';}
                    pai = $(this).parent().wrap('<span class="insimg_left gnot'+nclass+'"></span>');
                    leg = $(pai).find('img').attr('alt');
                    $(pai).append('<strong class="insimg_leg">'+leg+'</strong>');
//                $(this).wrap( "<a href='"+$('base').attr('href')+$(this).attr('rel')+"' title='"+$(this).attr('alt')+"' class='thickbox' rel='gallery'>" );
        });
        $('.ins_img_center').each(function() {
                    $(this).wrap('<span class="insimg"></span>');
                    if ($(this).attr('src')  == $(this).parents('div.txt').find('img:eq(0)').attr('src')) {nclass=' marginTop4';} else {nclass='';}
                    pai = $(this).parent().wrap('<span class="insimg_center gnot'+nclass+'"></span>');
                    leg = $(pai).find('img').attr('alt');
                    $(pai).append('<strong class="insimg_leg">'+leg+'</strong>');
//                $(this).wrap( "<a href='"+$('base').attr('href')+$(this).attr('rel')+"' title='"+$(this).attr('alt')+"' class='thickbox' rel='gallery'>" );
        });
        $('.ins_img_right').each(function() {
                $(this).wrap('<span class="insimg"></span>');
                if ($(this).attr('src')  == $(this).parents('div.txt').find('img:eq(0)').attr('src')) {nclass=' marginTop4';} else {nclass='';}
                pai = $(this).parent().wrap('<span class="insimg_right gnot'+nclass+'"></span>');
                leg = $(pai).find('img').attr('alt');
                $(pai).append('<strong class="insimg_leg">'+leg+'</strong>');
//                $(this).wrap( "<a href='"+$('base').attr('href')+$(this).attr('rel')+"' title='"+$(this).attr('alt')+"' class='thickbox' rel='gallery'>" );
        });


        $('.insimg').each(function() {
            var img = $(this).children("img");
            var title= $(img).attr('alt').replace('"','');
            var href= $("base").attr('href')+$(img).attr('src').replace('_269.','.').replace('_510.','.').replace('./','');
            $(img).wrap('<a rel="gnf" href="'+href+'" title="'+title+'" ></a>');
        });
        $("a[rel='gnf']").colorbox();
    }

    if (  $("#c_not").length >=1 ) {generateImgs(); }

    popup = function(end) {
    }

    ajustaColunaCentro = function(exc,item) {
        if ($("#coluna_centro_externo").height() < 1202) $("#coluna_centro").height(1158);
        if (exc && $("#coluna_centro").height() < 1158) $("#coluna_centro").height($(item).height()+item);
    }
    if($("#coluna_centro_externo").length > 0) { ajustaColunaCentro(); }


    $(".bl3galfot_i").click( function () {
        var urlid = $(this).attr("id");
        urlid = $("base").attr("href")+"galerias/carregar/"+urlid.replace("igalid_","");
        $.modal('<iframe src="'+urlid+'" height="565" width="930"  scrolling="NO" BORDER="0" FRAMEBORDER="No"style="overflow-x:hidden;overflow-y:hidden; border:0px;">', {
            containerCss:{
                backgroundColor:"#F7F7F7",
                borderColor:"gray",
                height:575,
                padding:0,
                width:960
            },
            overlayClose:true
        });
    });
    $(".c_fotos_img").click( function () {
        var urlid = $(this).attr("id");
        urlid = $("base").attr("href")+"galerias/carregar/"+urlid.replace("c_fotos_img_","");
        $.modal('<iframe src="'+urlid+'" height="565" width="930"  scroll="NO" BORDER="0" FRAMEBORDER="No" style="overflow-x:hidden;overflow-y:hidden;border:0px;">', {
            containerCss:{
                backgroundColor:"#F7F7F7",
                borderColor:"gray",
                height:575,
                padding:0,
                width:960
            },
            overlayClose:true
        });
    });
    $(".f_enq_more").click( function () {
        var urlid = $(this).attr("id");
        urlid = $("base").attr("href")+"enquetes/verResultados";
        $.modal('<iframe src="'+urlid+'" height="457" width="582"  scrolling="No" style="border:0">', {
            containerCss:{
                backgroundColor:"#F7F7F7",
                borderColor:"gray",
                height:460,
                padding:0,
                width:585
            },
            overlayClose:true
        });
    });

/*
 *   Area Restrita
 */
    if ( $("#f_ares").length > 0 ) {
       // $("#f_ares").jqTransform();
        $(".fares_senha").keypress(function (e) { if (e.which == 13) { $(".fares_entrar").trigger('click'); } });
        $(".fares_entrar").click(function() {
           $('.fares_senha').val($(".fares_senha").val());
           $(this).parents("form").submit(); });
    }

/*
 * Enquetes
 */

    if ( $("#f_enq").length > 0 ) {
        $('#f_enq input[type=radio]').prettyCheckboxes();
    }

    $(".enquete_button").click(function() {
        if ( $("input[name=e_enq_resp]:checked").val() ) {

            $(this).parents("#f_enq").submit();
        }
    });


/*
 *  Campanhas
 */
    pagerFactory = function(idx, slide) {
        var s = idx > 2 ? ' style="display:none"' : '';

        return '<li'+s+'><a href="#">'+(idx+1)+'</a></li>';
    };
    if ( $("#slide_campanhas").length > 0 ) {
        $('#slide_campanhas').cycle({
            fx:      'scrollHorz',
            timeout:  0,
            pager:   '#camp_nav',
            pagerAnchorBuilder: pagerFactory
        });
    }
/*
 *  Notícia principal
 */

    if ( $(".bl1np_cycle").length > 0 ) {
        $('.bl1np_cycle').cycle({
            fx:      'scrollUp',
            timeout:  10000
        });

    }
/*
 *  Links
 */
    if ( $("#blcont4_lnks").length > 0 ) {
        $(".bl4lnks_dest").children(".bl4lnksdest_lnk").children('div').fadeTo(0,'0.5');
        $(".bl4lnks_dest").children(".bl4lnksdest_lnk").mouseover(function() {
            $(this).children('div').fadeTo(0,'1');
        }).mouseout(function() {
            $(this).children('div').fadeTo(0,'0.5');
        });
    }
/*
 *  Galeria de imagens
 */
    if ( $("#blcont3_galfot").length > 0 ) {
        $(".bl3galfot_dest .bl3galfotdest_thumbs").mouseover(function() {
            $(this).children('img').css('border','4px solid #037447');
            $(this).parents("#blcont3_galfot").children(".bl3galfot_legend").show().text($(this).children('img').attr('alt'));

        }).mouseout(function() {
            $(this).children('img').css('border','4px solid #F4F4F4');
            $(this).parents("#blcont3_galfot").children(".bl3galfot_legend").hide();
        });
    }
    $(".d_box_icon").mouseover(function() {
        $(this).next().children("div").children("a").css({
            'text-decoration': 'underline'
        });
        $(this).css({ 'cursor': 'pointer'});
    }).mouseout( function() {
        $(this).next().children("div").children("a").css({
            'text-decoration': ''
        }).css({ 'cursor': 'pointer'});
    }).click(function() {
        $(location).attr('href', $(this).next().children("div").children("a").attr('href'));
    });


    $("#twitter").mouseover(function() {
        $(this).children("h3").addClass('underline');

    }).mouseout(function() {
         $(this).children("h3").removeClass('underline');
    });

    $("#rss").mouseover(function() {
        $(this).children("h3").addClass('underline');

    }).mouseout(function() {
         $(this).children("h3").removeClass('underline');
    });
    $("#newsletter").mouseover(function() {
        $(this).children("h3").addClass('underline');

    }).mouseout(function() {
         $(this).children("h3").removeClass('underline');
    });

/*
 * Formulário: Comentar
 */


    if ( $("#f_cmt").length > 0 ) {
        $('#f_cmt input[type=checkbox]').prettyCheckboxes();
        $("#f_cmt_submit").click(function() { $(this).parents("form").submit(); });
        $("#f_cmt").validate({
            rules: {
                f_cmt_NOME: { required: true, maxlength: 250 },
                f_cmt_CIDADE: { required: true, maxlength: 250 },
                f_cmt_COMENTARIO: { required: true }
            },
            messages: {
                f_cmt_NOME: { required: "Preecha com o seu nome.", maxlength: "Quantidade de caracteres excedido." },
                f_cmt_CIDADE: { required: "Preencha com a cidade.", maxlength: "Quantidade de caracteres excedido." },
                f_cmt_COMENTARIO: { required: "Preencha com o comentário."}
            }
        });

        $('#f_cmt_anonimo').click(function () {
            if(this.checked){
                $("#f_cmt_nome").attr("disabled", true).rules("remove");
                $("#f_cmt_nome.error").removeClass('error');

            }
            else {
                $("#f_cmt_nome").removeAttr("disabled");
                $("#f_cmt_nome").rules("add", { required: true });
            }
        });
    }

/*
 * Slides de itens das listagens.
 */
        if ($(".c_exp").length != 0 ) {
            $(".c_setaControl").toggle(
                function() {
                    $(this).parents(".c_expBloco").children("p").slideDown('slow');
                    $(this).addClass("setaUp");
                },
                function() {
                    $(this).parents(".c_expBloco").children("p").slideUp('slow');
                    $(this).removeClass("setaUp");
                }
            );
        }
        if ($(".c_sec").length != 0 ) {
           
            $(".c_setaControl").toggle(
                function() {
                    $(this).parents(".c_sec .c_secBloco").children("p").slideDown('slow');
                    $(this).addClass("setaUp");
                },
                function() {
                    $(this).parents(".c_sec .c_secBloco").children("p").slideUp('slow');
                    $(this).removeClass("setaUp");
                }
            );
        }

        $(".c_setaMaximize").toggle(
            function() {
                var altura=$(this).parents(".fixheight div").innerHeight();
                $(this).parents(".c_exp").children(".c_expBloco").animate({"height": altura+"px"}, "slow");
                $(this).addClass("setaUp");
            },

            function() {
                $(this).parents(".c_exp").children(".c_expBloco").animate({"height": "30px"}, "slow");
                $(this).removeClass("setaUp");
            }
        );



/*
 * Formulário: Seus Direitos
 */
    if ( $("#perg_seus_direitos").length > 0 ) {
        $("#perg_seus_direitos").click(function() {
            $("#pergunta_sd").slideToggle('slow');
        });
    }

    if ( $("#f_sd").length > 0 ) {
            $("#f_sd_submit").click(function() { $(this).parents("form").submit(); });

            $("#f_sd").validate({
                rules: {
                    f_sd_NOME: { required: true, maxlength: 250 },
                    f_sd_EMAIL: { required: true, email: true, maxlength: 250 },
                    f_sd_PERGUNTA: { required: true }
                },
                messages: {
                    f_sd_NOME: { required: "Preecha com o seu nome.", maxlength: "Quantidade de caracteres excedido." },
                    f_sd_EMAIL: { required: "Preencha com o seu e-mail.", email: "Formato de e-mail inválido", maxlength: "Quantidade de caracteres excedido."},
                    f_sd_PERGUNTA: { required: "Preencha com a pergunta."}
                }

            });
    }


/*
 * Formulário: Fale Conosco
 */
    if ( $("#f_fc").length > 0 ) {
            $("#f_fc_submit").click(function() { $(this).parents("form").submit(); });

            $("#f_fc").validate({
                rules: {
                    f_fc_NOME: { required: true, maxlength: 250 },
                    f_fc_EMAIL: { required: true, email: true, maxlength: 250 },
                    f_fc_ASSUNTO: { required: true, maxlength: 250 },
                    f_fc_MENSAGEM: { required: true }
                },
                messages: {
                    f_fc_NOME: { required: "Preecha com o seu nome.", maxlength: "Quantidade de caracteres excedido." },
                    f_fc_EMAIL: { required: "Preencha com o seu e-mail.", email: "Formato de e-mail inválido", maxlength: "Quantidade de caracteres excedido."},
                    f_fc_ASSUNTO: { required: "Preecha com o assunto.", maxlength: "Quantidade de caracteres excedido." },
                    f_fc_MENSAGEM: { required: "Preencha com a pergunta."}
                }

            });
    }
/* ----------------------------
 *  Newsletter
 * /
 */
    $("#newsletter").click( function () {
        urlid = "<iframe height='301' width='582' scrolling='No' style='border:0' src='http://www2.isend.com.br/iSend/external/open_insert_data.do?fecosul=true&b_key=iSend1&bean.cliente_id=2135'></iframe>";
        $.modal(urlid, {
            containerCss:{
                backgroundColor:"#F7F7F7",
                borderColor:"gray",
                width:590,
                padding:0,
                height:309
            },
            overlayClose:true
        });
    });
    if ( $("#f_nws").length > 0 ) {
            $("#f_nws_submit").click(function() { $(this).parents("form").submit(); });

            $("#f_nws").validate({
                rules: {
                    f_nws_NOME: { required: true, maxlength: 250 },
                    f_nws_EMAIL: { required: true, email: true, maxlength: 250 }
                },
                messages: {
                    f_nws_NOME: { required: "Preecha com o seu nome.", maxlength: "Quantidade de caracteres excedido." },
                    f_nws_EMAIL: { required: "Preencha com o seu e-mail.", email: "Formato de e-mail inválido", maxlength: "Quantidade de caracteres excedido."}
                }
            });
    }

    if ( $(".i_b_mapadosite").length > 0 ) {
        $(".mapa_do_site").hide();
        $(".i_b_mapadosite").click(function() { $(".mapa_do_site").slideToggle(3000,function() { $('window').scrollTop();
                } ); }  );
    }
    if ($("#footer").length > 0) {
        $(".logo_ilume,.logo_jl").mouseover(
            function () { $(this).css({'background-position':'0 44px'}); }
        ).mouseout(function() {
                $(this).css({'background-position':'0 0'});
        });
    }
    if ($(".h_search").length > 0) {
        $(".hs_input").focus(function() { if ($(this).val() == "BUSCA") $(this).val('')});
        $(".hs_input").keypress(function (e) { if (e.which == 13) {$(".hs_button").trigger('click') } });
        $(".hs_button").click(function () {
            if ( ($(".hs_input").val() != "BUSCA") && ( $(".hs_input").val() != "") ) {
                $(location).attr('href', $("base").attr("href")+'pesquisa/'+$(".hs_input").val().replace(" ","_"));
            }
        });
    }
    if ($(".h_searchint").length > 0) {
        $(".hs_inputint").focus(function() { if ($(this).val() == "BUSCA") $(this).val('')});
        $(".hs_inputint").keypress(function (e) { if (e.which == 13) {$(".hs_buttonint").trigger('click') } });
        $(".hs_buttonint").click(function () {
            if ( ($(".hs_inputint").val() != "BUSCA") && ( $(".hs_inputint").val() != "") ) {
                $(location).attr('href', $("base").attr("href")+'sindpesquisa/'+$(".hs_inputint").val().replace(" ","_") );
            }
        });
    }
    if ($("#blcont1").length > 0) {

        $("#coluna_centro").find("a").children().mouseover(function () { $(this).css('text-decoration','underline'); }).mouseout(function () { $(this).css('text-decoration','none'); });
    }

    $('.imprimir').click(function() {
        window.open($(this).attr('href'),'win2','status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=640,height=480,directories=no,location=no');
        return false;
    });
     $(".enviaremail").click( function () {
        urlid = $(this).attr('href');
        $.modal('<iframe src="'+urlid+'" height="315" width="350"  scrolling="No" style="border:0">', {
            containerCss:{
                backgroundColor:"#F7F7F7",
                borderColor:"gray",
                height:320,
                padding:0,
                width:385
            },
            overlayClose:true
        });
        return false;
    });
});
