$(document).ready(function() {    

    $('#abrir_formulario_edicoes').bind('click', function(){
        $('#formulario_edicao').show(800);
        $('#fundo_aux').fadeIn(800);
    });
    
    $('#fechar_formulario_edicoes').bind('click', function(){
        $('#formulario_edicao').hide(800);
        $('#fundo_aux').fadeOut(800);
    });
    
    $('#fundo_aux').bind('click', function(){
        $('#formulario_edicao').hide(800);
        $('#fundo_aux').fadeOut(800);
    });
    
    $('.box').bind('mouseenter', function(){
        $(this).css('backgroundColor','#000000');
        $(this).css('color','#FFFFFF');
        $(this).children('.box_titulo').css('borderTopColor','#FFFFFF');
        $(this).children('.box_titulo').css('borderBottomColor','#FFFFFF');
        $(this).children('.box_descricao, .box_duplo').css('borderBottomColor','#FFFFFF');
        $(this).children('.box_descricao, .box_duplo').css('borderTopColor','#FFFFFF');
        $(this).children('.mais').css('backgroundPosition','-14px 0');  
    });
    
    $('.box').bind('mouseleave', function(){
        $(this).css('backgroundColor','#FFFFFF');
        $(this).css('color','#000000');
        $(this).children('.box_titulo').css('borderTopColor','#000000');
        $(this).children('.box_titulo').css('borderBottomColor','#000000');
        $(this).children('.box_descricao, .box_duplo').css('borderBottomColor','#000000');
        $(this).children('.box_descricao, .box_duplo').css('borderTopColor','#000000');        
        $(this).children('.mais').css('backgroundPosition','0 0');            
    });
    
    $('.box_artista').bind('mouseenter', function(){
        $(this).css('backgroundColor','#000000');
        $(this).css('color','#FFFFFF');
        $(this).children('.box_artista_titulo').css('borderTopColor','#FFFFFF');
        $(this).children('.box_artista_titulo').css('borderBottomColor','#FFFFFF');
        $(this).children('.box_artista_titulo').children('.mais_artista').css('backgroundPosition','-14px 0');
        $(this).children('.box_artista_titulo').children('.mais_artista').css('backgroundColor','#FFFFFF');
    });
    
    $('.box_artista').bind('mouseleave', function(){
        $(this).css('backgroundColor','#FFFFFF');
        $(this).css('color','#000000');
        $(this).children('.box_artista_titulo').css('borderTopColor','#000000');
        $(this).children('.box_artista_titulo').css('borderBottomColor','#000000');
        $(this).children('.box_artista_titulo').children('.mais_artista').css('backgroundPosition','0 0');
        $(this).children('.box_artista_titulo').children('.mais_artista').css('backgroundColor','#000000'); 
    });        


    image_ratio_w = 1280/800;
    image_ratio_h = 800/1280;
    window_ratio_w = $(window).width()/$("#bg").width();
    window_ratio_h = $(window).height()/$("#bg").height();
    
    function resize_window()
    {
        window_ratio_w = $(window).width()/$("#bg").width();
        window_ratio_h = $(window).height()/$("#bg").height();                
        if ($(window).width()>1280 && $(window).height()<=800)
        {
            new_w = $(window).width();
            new_h = $(window).width() / image_ratio_w;
            $("#bg").css('width', new_w);
            $("#bg").css('height', new_h);
        }    
        if ($(window).width()<=1280 && $(window).height()>800)
        {
            new_w = $(window).height() / image_ratio_h;
            new_h = $(window).height();
            $("#bg").css('width', new_w);
            $("#bg").css('height', new_h); 
        }
        if ($(window).width()<1280 && $(window).height()<800)
        {
            $("#bg").css('width', 1280);
            $("#bg").css('height', 800);
        }           
        if ($(window).width()>1280 && $(window).height()>800)
        {
            if(window_ratio_w>window_ratio_h){
                new_w = $("#bg").width() * window_ratio_w;
                new_h = $("#bg").height() * window_ratio_w;
                $("#bg").css('width', new_w);
                $("#bg").css('height', new_h);                
            }
            if(window_ratio_w<window_ratio_h){
                new_w = $("#bg").width() * aspect_ratio_h;
                new_h = $("#bg").height() * aspect_ratio_h;
                $("#bg").css('width', new_w);
                $("#bg").css('height', new_h); 
            }
        }              
          
        if($(window).width()<=1110)
        {
            $('#menu_wrapper').css('left',20);
            $('#menu_wrapper').css('marginLeft',0);
            $('.conteudo_inferior').css('left',20);
            $('.conteudo_inferior').css('marginLeft',0);
            $('.conteudo_inferior_lateral').css('left',20);
            $('.conteudo_inferior_lateral').css('marginLeft',0);
            $('#conteudo_lateral_galeria').css('left',285);
            $('#conteudo_lateral_galeria').css('marginLeft',0);            
            $('#conteudo_lateral_artista').css('left',285);
            $('#conteudo_lateral_artista').css('marginLeft',0);
            $('#conteudo_lateral_exposicao').css('left',285);
            $('#conteudo_lateral_exposicao').css('marginLeft',0);
            $('#conteudo_lateral_edicao').css('left',285);
            $('#conteudo_lateral_edicao').css('marginLeft',0);
            $('#conteudo_lateral_news').css('left',285);
            $('#conteudo_lateral_news').css('marginLeft',0);
            $('#conteudo_lateral_contato').css('left',285);
            $('#conteudo_lateral_contato').css('marginLeft',0);
            $('#rodape_doois').css('right','auto');
            $('#rodape_doois').css('left',1061);
            height = $('.conteudo_inferior_lateral').height();
            if (height!=null) $('#rodape_doois').css('left',1025);
            height = $('#conteudo_lateral_news').height();
            if (height!=null) $('#rodape_doois').css('right',1070);             
        } else
        {
            $('#menu_wrapper').css('left','50%');
            $('#menu_wrapper').css('marginLeft',-535);
            $('.conteudo_inferior').css('left','50%');
            $('.conteudo_inferior').css('marginLeft',-535);
            $('.conteudo_inferior_lateral').css('left','50%');
            $('.conteudo_inferior_lateral').css('marginLeft',-535);
            $('#conteudo_lateral_galeria').css('left','50%');
            $('#conteudo_lateral_galeria').css('marginLeft',-270);            
            $('#conteudo_lateral_artista').css('left','50%');
            $('#conteudo_lateral_artista').css('marginLeft',-270);
            $('#conteudo_lateral_exposicao').css('left','50%');
            $('#conteudo_lateral_exposicao').css('marginLeft',-270);
            $('#conteudo_lateral_edicao').css('left','50%');
            $('#conteudo_lateral_edicao').css('marginLeft',-270);
            $('#conteudo_lateral_news').css('left','50%');
            $('#conteudo_lateral_news').css('marginLeft',-270);
            $('#conteudo_lateral_contato').css('left','50%');
            $('#conteudo_lateral_contato').css('marginLeft',-270);
            $('#rodape_doois').css('left','auto');
            margem_direita=($(window).width()-1080)/2;
            $('#rodape_doois').css('right',margem_direita);
            height = $('.conteudo_inferior_lateral').height();
            if (height!=null) $('#rodape_doois').css('right',margem_direita+40);
            height = $('#conteudo_lateral_news').height();
            if (height!=null) $('#rodape_doois').css('right',margem_direita-8);          
        }
    }        
    $(window).resize(function() {
            resize_window();
    }).trigger("resize");        
});

$(window).load(function() {
    margem_direita=($(window).width()-1080)/2;
    $('#rodape_doois').css('right',margem_direita);    
    height = $('#conteudo_lateral_galeria').height();
    $('#aux_rodape_conteudo_lateral_galeria').css('top',height+79);
    if (height!=null) $('#rodape_doois').css('top',height+60);
    height = $('#conteudo_lateral_artista').height();
    $('#aux_rodape_conteudo_lateral_artista').css('top',height+79);
    if (height!=null) $('#rodape_doois').css('top',height+60);
    height = $('#conteudo_lateral_exposicao').height();
    $('#aux_rodape_conteudo_lateral_exposicao').css('top',height+79);
    if (height!=null) $('#rodape_doois').css('top',height+60);
    height = $('#conteudo_lateral_edicao').height();
    $('#aux_rodape_conteudo_lateral_edicao').css('top',height+79);
    if (height!=null) $('#rodape_doois').css('top',height+60);
    height = $('#conteudo_lateral_news').height();
    $('#aux_rodape_conteudo_lateral_news').css('top',height+49);
    if (height!=null){
        $('#rodape_doois').css('top',height+30);
        $('#rodape_doois').css('right',margem_direita-8);
    }
    height = $('#conteudo_lateral_contato').height();
    $('#aux_rodape_conteudo_lateral_contato').css('top',height+149);
    if (height!=null){
        $('#rodape_doois').css('top',height+118);
        $('#rodape_doois').css('right',margem_direita-3);
    }
    height = $('.conteudo_inferior_lateral').height();
    if (height!=null){
        $('#rodape_doois').css('top',height+182);
        $('#rodape_doois').css('right',margem_direita+40);
    }    
    $('#rodape_doois').show();
    
    $('#mensagem_fundo').bind('click',function(){
	$('#mensagem_fundo').fadeOut("slow");
	$('#mensagem_container').fadeOut("slow");	
    });
    
    $('#mensagem_fechar').bind('click',function(){
	$('#mensagem_fundo').fadeOut("slow");
	$('#mensagem_container').fadeOut("slow");	
    });         
});

$(window).scroll(function(){
    if($(window).width()<=1110)
    {
        var $this = $(this);
        $('#menu_wrapper').css('left', 20 - $this.scrollLeft());
    }
});
