$(function() {
	$('ul.lista_fotos_hide li a').hover(function(){
		alturaTop = 160 - $(this).find('span').outerHeight();		
		
		$(this).find('span').animate({
			top: alturaTop
		}, 150, 'easeOutCirc');
	},function(){
		$(this).find('span').animate({
			top: 165
		}, 150, 'easeInCirc');
	});
    
    
    ($(".lista_fotos_thumbs_wrap_bts").length > 0) && $(".lista_fotos_thumbs_wrap_bts").jCarouselLite({
        btnNext: ".lista_fotos_wrap_bts .next",
        btnPrev: ".lista_fotos_wrap_bts .prev",
        visible: 1,
		speed: 500,		
		easing: "easeOutCirc",
		circular: false
    });
    
    ($(".lista_fotos_plantas_wrap_bts").length > 0) && $(".lista_fotos_plantas_wrap_bts").jCarouselLite({
        btnNext: ".lista_fotos_wrap_bts .next",
        btnPrev: ".lista_fotos_wrap_bts .prev",
        visible: 4,
		speed: 500,		
		easing: "easeOutCirc",
		circular: false
    });
    
    ($(".empreendimento_imagens_areas").length > 0) && $(".empreendimento_imagens_areas").jCarouselLite({
        btnNext: ".empreendimento_imagens_areas .next",
        btnPrev: ".empreendimento_imagens_areas .prev",
        visible: 3,
        speed: 500,		
        easing: "easeOutCirc",
        circular: false
    });
    
    ($(".empreendimento_imagens_apartamentos").length > 0) && $(".empreendimento_imagens_apartamentos").jCarouselLite({
        btnNext: ".empreendimento_imagens_apartamentos .next",
        btnPrev: ".empreendimento_imagens_apartamentos .prev",
        visible: 3,
        speed: 500,		
        easing: "easeOutCirc",
        circular: false
    });
    
    ($(".empreendimento_imagens_entregues").length > 0) && $(".empreendimento_imagens_entregues").jCarouselLite({
        btnNext: ".empreendimento_imagens_entregues .next",
        btnPrev: ".empreendimento_imagens_entregues .prev",
        visible: 6,
        speed: 500,		
        easing: "easeOutCirc",
        circular: false
    });
    
    // Efeito que mostra e esconde (sobe e desce) a legenda dos thumbs das fotos
	$('ul.lista_fotos_hide li a').hover(function(){
            alturaTop = 160 - $(this).find('span').outerHeight();		
            
            $(this).find('span').animate({
                top: alturaTop
            }, 150, 'easeOutCirc');
        },function(){
            $(this).find('span').animate({
                top: 165
            }, 150, 'easeInCirc');
	});
    
    // Mostra o zoom da planta quando clica no thumb
    $('ul.lista_fotos_plantas li a').click(function(){
        $('ul.lista_fotos_plantas li a').removeClass('current');
        $(this).addClass('current');
        $('#subContent').show();
        $('.mainContent_bottom').removeClass('mainContent_bottom').addClass('subContent_bottom');
    });
    
    // Slide da imagem de apresenta��o de um empreendimento
    $('#img_empreendimento div.content').nivoSlider({
        effect:'fold',
        slices:15,
        animSpeed:500,
        pauseTime:5000,
        directionNav:true, //Next & Prev
        directionNavHide:true, //Only show on hover
        controlNav:true, //1,2,3...
        pauseOnHover:true //Stop animation while hovering
    });
    
    // Flutuante overlay bot�o indique este im�vel
    $('ul.buttons li.indique a').click(function(){
        $('.windowOverlay_indique').lightbox_me({
            centered: true,
            closeSelector: '.close'
        });
    });
    
    // Flutuante overlay bot�o indique este im�vel
    $('.folder_email a').click(function(){
        $('.success').hide();
        $('.error').hide();
        $('.windowOverlay_folder').lightbox_me({
            centered: true,
            closeSelector: '.close'
        });
    });
    
    // Flutuante overlay bot�o folder email
    $('.folder_email a').click(function(){
        $('.success').hide();
        $('.error').hide();
        $('.windowOverlay_folder_wrap').prependTo('body').fadeIn(200);
    });
    
    /*
    // Funcionamento Flutuante
    $('#windowOverlay .head .close').click(function(){
        $(this).closest('#windowOverlay').fadeOut(200);
    });
    
    $('#windowOverlay_wrap').mouseup(function(e){
        var $target = $(e.target);
        // se o target � filho da div que envolve o form MAS n�o � a input submit ent�o ignora este evento
        if ($target.parents('#windowOverlay_middle').length == 1) return false;
        $(this).closest('#windowOverlay').fadeOut(200);
    }); 
    */
    
    $('#formFolder').click( function(){
        $('.success').hide();
        $('.error').hide();
		$('.loading').show();
        $.post( 
            "../../action/email_folder.php", 
            $(this).serialize(), 
            function( data ){
                if ( data.sucess == '1' ) {
            		$('.success').html(data.msg).show();
            		$('.error').hide();
                } else { 
                	$('.error').html(data.msg).show();
            		$('.success').hide();
                }
				$('.loading').hide();
            },
            'json'
        );
        return false;
        
	});
    
    $('#formIndica').submit( function(){

        $('.success').hide();
        $('.error').hide();
		$('.loading').show();
        $.post( 
            "../../action/email_indicacao.php", 
            $(this).serialize(), 
            function( data ){
                if ( data.sucess == '1' ) {
            		$('.success').html(data.msg).show();
            		$('.error').hide();
                } else { 
                	$('.error').html(data.msg).show();
            		$('.success').hide();
                }
				$('.loading').hide();
            },
            'json'
        );
        return false;
        
	});

    // Box classificados
    // Pega a altura de todas as li's
    var allHeights = [];
    $('.box_classificados ul li').each(function() {
        allHeights.push($(this).height());
    });
    // Pega a li mais alta de todas
    var maxHeight = Math.max.apply(Math, allHeights);
    // Seta a altura minima da ul
    $('.box_classificados ul').css('minHeight', maxHeight + 20);
    // Anima��o do box com os classificados     
    $('.box_classificados .bt_previous').click(function(){
        $('.box_classificados ul li:first').fadeOut(250);
        setTimeout(function(){
            $('.box_classificados ul li:last').detach().prependTo('.box_classificados ul').fadeIn(250);
        }, 300);
    });    
    $('.box_classificados .bt_next').click(function(){
        $('.box_classificados ul li:first').fadeOut(250).next().delay(300).fadeIn(250);
        setTimeout(function(){
            $('.box_classificados ul li:first').detach().appendTo('.box_classificados ul');
        }, 550);
    });
});

