$(document).ready(function(){
    
    watermark.init();

    /* PLUGIN DE PNG FIX */
    if($.browser.msie && ($.browser.version == "6.0")){
        $(document).pngFix();
    }
    
    if($('#conceitual').size()){
        $('#conceitual').flash({
            src		  : base_url + 'app/assets/swf/conceitual.swf',
            width	  : "990",
            height	  : "325",
            wmode	  : 'transparent',
            flashvars : {
                link  : base_url
            }
        }, {
            update: false
        });
        if(!jQuery.browser.flash)
            $('#showcase').css('background','url('+base_url+'app/assets/swf/conceitual.jpg) no-repeat center center;');
    }
    
    if($('#mycarousel_interior').jcarousel());
    if($('#mycarousel_exterior').jcarousel());
    
    if($('#mycarousel_home').size()){
        jQuery('#mycarousel_home').jcarousel({
            scroll: 1,
            auto: 4,
            wrap: 'circular'
        });
    }
    
    if($('.group').size()){
        $(".group").colorbox({
            rel:'group', 
            transition:"fade"
        });
    }
    
    if($('.group_int').size()){
        $(".group_int").colorbox({
            rel:'group_int', 
            transition:"fade"
        });
    }
    
    if($('.video').size()){
        $(".video").colorbox({
            iframe:true, 
            innerWidth:425, 
            innerHeight:344
        });
    }
    
    /*****************
     * ABAS GALERIA DE FOTOS
     */
    // oculta todas as abas
    $("div.contaba").hide();
    // mostra somente  a primeira aba
    $("div.contaba:first").show();
    // seta a primeira aba como selecionada (na lista de abas)
    $("#abas li a:first").addClass("active");
	 	  
    // quando clicar no link de uma aba
    $("#abas li").click(function(){
        // oculta todas as abas
        $("div.contaba").hide();
        // tira a seleção da aba atual
        $("#abas li").removeClass("active");
	  
        // adiciona a classe selected na selecionada atualmente
        $(this).addClass("active");
        // mostra a aba clicada
        $($(this).attr("rel")).show();
		 
        return false;
    });
	 
    /*****************
     * ABAS MENU RODAPE
     */
    $("div.carabara").hide();
    $("div.carabara:first").show();
    $("#cars li a:first").addClass("active");
	  	  
    $("#cars li").mouseover(function(){
        $("div.carabara").hide();
        $("#cars li").removeClass("active");
	  
        $(this).addClass("active");
        $($(this).attr("rel")).show();
		 
        return false;
    });
    
});


function validaContato(){
    msg = "";

    if($("#nome").val() == "" || $("#nome").val() == "Nome*"){
        msg += "Nome não preenchido.\n";
    }

    if($("#email").val() == "" || $("#email").val() == "E-mail*"){
        msg += "E-mail não preenchido.\n";
    } else if(!valEmail.test($("#email").val())){
        msg += "E-mail inválido.\n";
    }
	
    if($("#telefone").val() == "" || $("#telefone").val() == "Telefone*"){
        msg += "Telefone não preenchido.\n";
    }
		
    if($("#cidade").val() == "" || $("#cidade").val() == "Cidade*"){
        msg += "Cidade não preenchida.\n";
    }
	
    if($("#estado").val() == "" || $("#estado").val() == "Estado*"){
        msg += "Estado não preenchido.\n";
    }
	
    if($("#mensagem").val() == "" || $("#mensagem").val() == "Mensagem*"){
        msg += "Sua mensagem não foi preenchida.\n";
    }

    if(msg != ""){
        msg = "Os seguintes campos são obrigatórios:\n\n" + msg;
        alert(msg);
        return false;
    } else {
        return true;
    }
}

function validaTrabalhe(){
    msg = "";

    if($("#nome").val() == "" || $("#nome").val() == "Nome*"){
        msg += "Nome não preenchido.\n";
    }

    if($("#email").val() == "" || $("#email").val() == "E-mail*"){
        msg += "E-mail não preenchido.\n";
    } else if(!valEmail.test($("#email").val())){
        msg += "E-mail inválido.\n";
    }
	
    if($("#telefone").val() == "" || $("#telefone").val() == "Telefone*"){
        msg += "Telefone não preenchido.\n";
    }
		
    if($("#cidade").val() == "" || $("#cidade").val() == "Cidade*"){
        msg += "Cidade não preenchida.\n";
    }
	
    if($("#estado").val() == "" || $("#estado").val() == "Estado*"){
        msg += "Estado não preenchido.\n";
    }
    
    if($("#arquivo").val() == ""){
        msg += "Obrigatório anexar currículo.\n";
    }
	
    if($("#mensagem").val() == "" || $("#mensagem").val() == "Mensagem*"){
        msg += "Sua mensagem não foi preenchida.\n";
    }

    if(msg != ""){
        msg = "Os seguintes campos são obrigatórios:\n\n" + msg;
        alert(msg);
        return false;
    } else {
        return true;
    }
}

function str_replace(haystack, needle, replacement) {
    var temp = haystack.split(needle);
    return temp.join(replacement);
}

function disabledFormButton(ct) {
    $(ct).attr('disabled','disabled').css('cursor','default').css('filter','alpha(opacity=40)').css('-moz-opacity','0.4').css('opacity','0.4');
}

function enabledFormButton(ct) {
    $(ct).attr('disabled','').css('cursor','pointer').css('filter','alpha(opacity=100)').css('-moz-opacity','1').css('opacity','1');
}

function hideError() {
    $("#retorno_erro").animate({
        left:'+=50',
        height:'toggle'
    },500, function() {
        $("#retorno_erro").html('');
        $("#retorno_erro").css('display','block');
    });
    window.clearTimeout(timeoutID);
}

function topo() {
    window.location = document.URL+'#';
}

function gotoAnchor(value) {
    var elementClicked = '#'+value;
    var destination = $(elementClicked).offset().top;
    $("html:not(:animated),body:not(:animated)").animate({
        scrollTop: destination-20
    }, 500 );
}

var valEmail = /^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;


function abreModelo(url){
    alert(url);
}
