$(document).ready(function(){
    //LOGO
    $("#logo, a, #menu").mouseover(function(){
       $("#logo #seta img").attr("src", "images/seta_click.png");
    }).mouseout(function(){
       $("#logo #seta img").attr("src", "images/seta_normal.png");
    });
    
    //MENU
    $("#site #menu li ul li span").css("display", "none");
    $("#site #menu li").mouseenter(function(){
       $(this).children("span").stop();
       $(this).children("span").animate({
           width: '300px'
       }, "slow");
       $(this).children("ul").fadeIn();
    }).mouseleave(function(){
        $(this).children("span").animate({
           width: '0px'
       }, "slow");
        $(this).children("ul").fadeOut();
    }).click(function(){
        conteudoDesce();
    });

    //PEGA O MENU E COPIA PARA O CONTEÚDO
    $("#conteudo #topo ul").html($("#site ul").html());

    //MENU DE CONTEÚDO
    $("#conteudo #topo #menu li ul li").mouseenter(function(){
        $(this).fadeTo("slow", 1);
    }).mouseleave(function(){
        $(this).fadeTo("slow", 0.8);
    });

    $("#conteudo #topo #menu li").mouseenter(function(){
       $(this).children("ul").fadeTo("slow", 1);
    }).mouseleave(function(){
       $(this).children("ul").fadeTo("slow", 0);
    }).click(function(){
        $("#conteudo #texto #carrega").fadeTo("slow", 0, function(){
            conteudoCarrega();
            $("#conteudo #texto #carrega").fadeTo("slow", 1);
        });
    });

    $("#conteudo #topo #voltar").click(function(){
        $('html,body').animate({scrollTop: 0}, "slow");
    });

    Cufon.replace('.titulo li a, #conteudo #voltar, h1', {
        hover: {color: '#000'}
    });

    //CARREGA CONTEUDOS
    var link = (document.location.href).split("#");

    if(link.length > 1)
        conteudoDesce();

    function conteudoDesce(){
        var tam = $('#conteudo').css("marginTop");
        tam = parseInt(tam.substring(0, tam.length-2));
        $('html,body').animate({scrollTop: tam}, "slow", function(){
            conteudoCarrega();
        });
    }

    function conteudoCarrega(){
        $("#conteudo #texto #carrega").html("<div id='carregando'><img class='imgleft' src='images/carregando.gif' alt='Carregando...'><h2>Carregando...</h2></div>");
        $("#conteudo #texto #carrega").load("carrega.php?&pag="+pegaurl());
    }

    function pegaurl(){
        var url = window.location.toString().split("#");
        var num = url.length - 1;

        if(num == 1){
            return url[num];
        }else{
            return "";
        }
    }
});
