$( document ).ready( function(){
	
    var IS_IE_6 = $.browser.msie && $.browser.version < 7;
	
    $('.botao a').hover(
        function(){
            $(this).find('span')
            .css({
                'display' : 'block',
                'opacity':0,
                'left': '-10px'
            })
            .animate({
                'left':0,
                'opacity': 1
            }, 250)
        },
        function(){
            $(this).find('span').fadeOut('fast');
        }
        );


    $('.botao a').ready(
        function(){
            $(this).find('span')
            .css({
                'display' : 'block',
                'opacity':0,
                'left': '-10px'
            })
            .animate({
                'left':0,
                'opacity': 1
            }, 250)
            setTimeout(escondeBotoes,9500);
        },
        function(){
            $(this).find('span').fadeOut('fast');
        }
        );

    $('.botao a').click(function(){
        var to = $(this).attr('href');
		
        $.scrollTo(to, 1200);
		
        return false;
    });
    $("#botaoEnviar").click(function(){
        erro = 0;
        $("#aviso").fadeIn();
        $("#aviso").html("Validando os campos...");
        validaMensagem();
    });

    $(".detalhes").click(function(){
        $(".trabalhos-realizados").hide();
        $("#d"+$(this).attr("id")).fadeIn();
    });

    jQuery.each(jQuery.browser, function(i) {
        if($.browser.msie){
        }else{
            $(".campo").corner("5px");
        }
    });
    $("#aviso").corner("5px");
	
    /** Animation **/
    for( var i in items) {
        $(items[i]).hide();
    }
    //_animate(0, 700);
	
    $('.botoes').fadeIn( 'slow', function(){
        $('.menu').fadeIn( function(){
            $('.sobre-nos-link, .portifolio-link, .fale-conosco-link').fadeIn();
            if (IS_IE_6) {
                $('.astronauta').show();
            } else {
                $('.astronauta')
                .css({
                    'display' : 'block',
                    'opacity':0,
                    'left': '800px'
                })
                .animate({
                    'left':540,
                    'opacity': 1
                }, 800, function(){
                    $('.astronauta').show();
                });
            }
        });
    });
    $(".portifolio").click(function(){
        $(".trabalho-detalhes").hide();
        $(".trabalhos-realizados").fadeIn();
  
    });

});


function validaMensagem() {
    $("#frmMensagem input").each(function(){
        if ($(this).val() == "") {
            erro++;
            $(this).attr("class","campo-erro");
        } else {
            $(this).attr("class","campo");
        }
    })
    if (erro > 0 ) {
        $("#aviso").html("Preencha os campos destacados");
    } else {
        $('#aviso').html('Enviando...');
        var dados =$("#frmMensagem").serialize();
        $.post('exe_cad_mensagem.php',dados,function(response) {
            if($.trim(response) == "000") {
                $('#aviso').html('A sua mensagem foi enviada.<br/> Em breve responderemos.');
            } else {
                $('#aviso').html('N&atilde;o foi poss&iacute;vel enviar a mensagem. Tente um e-mail.');
            }
        })
    }
}

function escondeBotoes(){
    $('.botao a').find('span').fadeOut('slow');
}

var items = ['.botoes', '.menu', '.astronauta', '.sobre-nos-link', '.portifolio-link', '.fale-conosco-link'];