
jQuery().ready(function() {

    /* Iniciaizar Hover Images
    * ---------------------------*/
    jquery_hover.init();

    /* Iniciaizar Carousel estrutura
    * ---------------------------*/
    if ($(".hrb_estrutura").length > 0)
        {

            $("div.foo").carousel({ autoSlide: true, autoSlideInterval: 5000, delayAutoSlide: 2000 });

            $(".crtlPrevious").click(function() { $('.previous').trigger('click'); })
            $(".crtlNext").click(function() { $('.next').trigger('click'); })
        }

    /* Iniciaizar contentFlow
    * ---------------------------*/
    if ($("#contentFlow").length > 0)
        {
//            var cf = new ContentFlow('contentFlow');
        }

    /* Menu
     * --------------------------*/
    if ($('#menu').length > 0 ) {

        $('#menu ul li').click(function() {
            var el = $(this);
            if (el.children('ul').length > 0) {
                if(!(el.hasClass("active"))) {
                    var acts = $('#menu ul').children('li.active');
                    acts.children('ul').slideUp(1500);
                    acts.removeClass('active');
                    el.children('ul').slideDown(2000);
                }
                el.addClass('active');
            }
        });

        menuMount = function(seg1,seg2) {
            var string,el;
            if (seg1) string = seg1;
            if (seg2) string = string+"/"+seg2;
            if (seg2) {
                el=$('#menu ul li ul li').children("a[href*='"+string+"']");
                if (el.length > 0) {
                    var princ = el.parents('#menu ul li');
                    princ.children("ul").show();
                    princ.addClass('active');
                    el.parents('#menu ul li ul li').addClass('subActive');
                }
            }
            else {
                el=$('#menu ul li').children("a[href*='"+string+"']").parent('li');
                if (el.length > 0) {
                    if(!(el.hasClass("active"))) {
                        el.children('ul').show();
                        el.eq(0).addClass('active');
                    }
                }
            }
        }
    }

    /* Validação Contato
    * ---------------------------*/

    if ( $("#f_fale").length > 0 ) {
        $("#f_fale_submit").click(function() { $(this).parents("#f_fale").submit(); });
        $("#f_fale").validate({
            rules: {
                nome: { required: true },
                telefone: { required: true },
                email: { required: true,email:true },
                mensagem: { required: true }
            },
            messages: {
                nome: { required: "Preecha com o seu nome." },
                telefone: { required: "Preencha com o seu telefone." },
                email: { required: "Preencha com o seu e-mail.", email:"Formato inválido." },
                mensagem: { required: "Preencha com a mensagem."}
            }
        });
    }
    /* Validação Orçamento
    * ---------------------------*/
    if ( $("#f_orc").length > 0 ) {
        $("#f_orc_submit").click(function() { $(this).parents("#f_orc").submit(); });
        $("#f_orc").validate({
            rules: {
//                empresa: { required: true },
                nome: { required: true },
                cidade: { required: true },
                estado: { required: true },
                telefone: { required: true },
                email: { required: true,email:true },
                solicitacao: { required: true }
            },
            messages: {
//                empresa: { required: "Preecha com o nome da organização ou empresa." },
                nome: { required: "Preecha com o seu nome." },
                cidade: { required: "Preecha com a cidade." },
                estado: { required: "Preecha com o estado." },
                telefone: { required: "Preencha com o seu telefone." },
                email: { required: "Preencha com o seu e-mail.", email:"Formato inválido." },
                solicitacao: { required: "Preencha com a mensagem."}
            }
        });
    }

    /* Validação Newsletter
    * ---------------------------*/
    if ( $("#f_news").length > 0 ) {
        $("#f_news_submit").click(function() {
            if($("#f_news").validate().form()) {
                    $.ajax({
                        type: "POST",
                        url: $("base").attr('href')+"index.php/news/add/"+$("#f_news .nome").val()+"/"+$("#f_news .email").val(),

                        beforeSend: function() {
                        },
                        success: function(txt) {
                            $("#f_news .return").html(txt);

                        },
                        error: function(txt) {
                            $("#f_news .return").html("<span class='error'> Tente Novamente. </span>");

                        }
                    });
            }
        });
        $("#f_news").validate({
            rules: {
                nome: { required: true },
                email: { required: true,email:true }
            },
            messages: {
                nome: { required: "Preecha com o seu nome." },
                email: { required: "Preencha com o seu e-mail.", email:"Formato inválido." }
            }
        });
    }

      

        if ($('.boxgrid.caption').length > 0) {
                $('.boxgrid.caption').hover(function(){
					$(".cover", this).stop().animate({top:'0px'},{queue:false,duration:160});
				}, function() {
					$(".cover", this).stop().animate({top:'170px'},{queue:false,duration:160});
				});
        }
        if ($('.boxgrid.static').length > 0) {
                $('.boxgrid.static').hover(function(){
					$(".cover", this).stop().animate({top:'170px'},{queue:false,duration:160});
				}, function() {
					$(".cover", this).stop().animate({top:'170px'},{queue:false,duration:160});
				});
        }

    if ($("#f_log").length > 0 ) {
        $(".f_b_sbmt").click(function() {
            $(this).parents('form').attr('action',$("base").attr('href')+'index.php/login/check');
            var pass = hex_md5($(".f_log_SENHA").val());
            $('.f_log_SENHA').val(pass);
            $(this).parents('form').submit();
        });
        $("#f_log").keypress(function (e) { if (e.which == 13) {$(".f_b_sbmt").trigger('click') } });
    }
    if ($("#f_logi").length > 0 ) {
        $(".f_b_sbmti").click(function() {
            $(this).parents('form').attr('action',$("base").attr('href')+'index.php/login/check');
            var pass = hex_md5($(".f_log_SENHAi").val());
            $('.f_log_SENHAi').val(pass);
            $(this).parents('form').submit();
        });
        $("#f_logi").keypress(function (e) { if (e.which == 13) {$(".f_b_sbmti").trigger('click') } });
    }

    if($("tr.thead").length >0) { alert('aqui');$(".thead").css("border",'1px solid black');}
});
