jQuery(document).ready(function(){
	
	var fotoAgora = 1;
	var fotoAtiva = 1;
	var tempo = 500;
	var altura = 1;
	
	$('.foto').each(function(j){
		if(j == 0){
			$(this).children('.ativa').fadeIn(tempo);
		}
	});
	
	$('.foto').each(function(i){
		
		$(this).click(function(){
			
			if(i > 30){
				i = i - 2;				
			}

			fotoAgora = i + 1;
			
			if(fotoAgora != fotoAtiva){
				
				fotoAtiva = fotoAgora;
			
				limpaThumbs();
				
				$(this).children('.ativa').fadeIn();
				
				$('#fotoGrande #load').fadeOut(tempo,function(){
					
					$('#load').css('background-image',"url('imagens/fotos/gd_" + fotoAgora + ".jpg')");
					
					$(this).delay(tempo).fadeIn(tempo,function(){
						
					});
													
				});
				
			}
			
			if(i >= 30){
				i = i + 2;
			}
			
		});
	
	});
	
	function limpaThumbs(){
		
		$('.foto').each(function(){
			
			$(this).children('.ativa').fadeOut(tempo);
			
		});
				
	}
	
	//legenda
	$('.foto').each(function(){
		
		$(this).mouseenter(function(){
			
			var largBox = $(this).width();
			var largText = $(this).children('.legenda').width();
			var mLeft = (largText - largBox)/-2;
						
			$(this).css('z-index',altura);
			altura++;
			$(this).children('.legenda').css('left',mLeft + 'px');
			$(this).children('.legenda').fadeIn(tempo);
			
		});
		
		$(this).mouseleave(function(){
			
			$(this).children('.legenda').fadeOut(tempo,function(){
			});
			
		});
		
	});
	
	
});
