// JavaScript Document

$(document).ready(function(){
	
	//__________________________LIGTHBOX_______________________________________//
	try {
		$('.gallery span:eq(0) a').lightBox();
		$('a.ligthBox_plantas').lightBox();
		$('a.ligthBox_galerias').lightBox();
	}catch(e){}
	
	
	//__________________________CONTEUDO EXPANSIVEL - FICHA DE EMPREENDIMENTO_______________________________________//
	$('.boxs h2 a').click(function(){
		var objBox = $(this).parent().parent().next('div');
		var objSeta = $(this).parent().parent().find('img');
		var novoSrcSeta;
		
		if(objBox.css('display') == 'block'){
			 novoSrcSeta = objSeta.attr('src').replace('_on', '_off');
			 objBox.slideToggle('slow');
			 objSeta.attr('src', novoSrcSeta);
		}
		else{
			 novoSrcSeta = objSeta.attr('src').replace('_off', '_on');
			 objBox.slideToggle('slow');
			 objSeta.attr('src', novoSrcSeta);
		}
	});
	
	$('.ExpandAll a').click(function(){
		$('.contentBox').hide();
		var  novoSrc = $('.boxs h2 img').attr('src').replace('_on', '_off');
		$('.boxs h2 img').attr('src' , novoSrc);
	});
	
	
	//__________________________CARROSSEL_______________________________________//
	
	if( $('#carrossel img').length >= 5 )
	{
		$('#carrossel').jcarousel({
			vertical: false,
			scroll: 5,
			animation: 'slow',
			buttonNextHTML: '<a></a>',
			buttonPrevHTML: '<a></a>'
		});	
	}
    
	if( $('#carrosselPlantas img').length >= 5 )
	{
	    
		$('#carrosselPlantas').jcarousel({
			vertical: false,
			scroll: 5,
			animation: 'slow',
			buttonNextHTML: '<a></a>',
			buttonPrevHTML: '<a></a>'
		});	
	}
	
	// Se tiver 5 imagens ou mais, executa o carrossel. Não há necessidade de executar o carrossel com menos de 5 imagens.
	if( $('#carrosselLazer img').length >= 5 )
	{
	    $('#carrosselLazer').jcarousel({
		    vertical: false,
		    scroll: 5,
		    animation: 'slow',
		    buttonnexthtml: '<a></a>',
		    buttonprevhtml: '<a></a>'
	    });
	}
	
	
	if( $('#carrosselEmpreendimentoAba img').length >= 5 )
	{
	    $('#carrosselEmpreendimentoAba').jcarousel({
		    vertical: false,
		    scroll: 5,
		    animation: 'slow',
		    buttonnexthtml: '<a></a>',
		    buttonprevhtml: '<a></a>'
	    });
	}
	
	// Se tiver 5 imagens ou mais, executa o carrossel. Não há necessidade de executar o carrossel com menos de 5 imagens.
	if( $('#carrosselGalerias img').length >= 5 )
	{
		$('#carrosselGalerias').jcarousel({
			vertical: false,
			scroll: 5,
			animation: 'slow',
			buttonNextHTML: '<a></a>',
			buttonPrevHTML: '<a></a>'
		});
	}
	
	if( $('#carrosselGalerias2 strong').length >= 5 )
	{
	    $('#carrosselGalerias2').jcarousel({
		    vertical: false,
		    scroll: 5,
		    animation: 'slow',
		    buttonNextHTML: '<a></a>',
		    buttonPrevHTML: '<a></a>'
	    });
    }
    
	//__________________________TROCAR IMAGENS NO CARROSSEL_______________________________________//
	$('#carrossel li a').click(function(){
		srcImg = $(this).find('img').attr('src').replace('_thumb', '');
		$('.gallery img:eq(0)').attr('src', srcImg);
		var descricaoImg = $(this).attr('rel');
		$('.gallery span a').attr('title' , descricaoImg); 
	});
	
	//__________________________aBAS LOCALIZAÇÃO_______________________________________//
	$('.abasGalerias a').click(function(){
		var divBox = $(this).attr('rel');
		$('.conteudoAbas div.contentGaleria').css('display', 'none');
		$('.conteudoAbas div.contentGaleria:eq(' + divBox + ')').css('display', 'block');
		var qtdImg = $('.abasGalerias a img').length;
		for(var i = 0; i <= (qtdImg - 1); i++){
			novoSrc = $('.abasGalerias a img:eq('+ i +')').attr('src').replace('_on', '');
			$('.abasGalerias a img:eq('+ i +')').attr('src', novoSrc);
		}
		imgOn =$(this).find('img').attr('src').replace('.gif','_on.gif') ;
		$(this).find('img').attr('src', imgOn );
	});
	
	//__________________________FAQ FICHA DE EMPREENDIMENTO_______________________________________//
	$('.tbFinaciamento_part_3 .lisformat a').click(function(){
		if($(this).parent().find('p').css('display') == 'none'){
			$(this).parent().find('p').show();
		}
		else{
			$(this).parent().find('p').hide();
		}
	});
	
	//__________________________TOOLTIP_______________________________________//
	var conteudoBoxToolTip;
	$('.toolTip').hover(function(){
		var boxToolTip = $(this).find('img').attr('alt'); 
		conteudoBoxToolTip = $('#'+ boxToolTip).html();
		$(this).prepend(conteudoBoxToolTip);
	},function(){
		$(this).empty();
		$(this).prepend('<img src="/Util/Img/Conteudo/tooltip_ajuda.gif" alt="contentTooltip" />');
	});
	
	
	
	
});
















