// Scripts para as galerias
$(document).ready(function(){
	addGallery("#galeria0");
	addGallery("#galeria1");
	addGallery("#galeria2");
	addGallery("#galeria3");
	addGallery("#galeria4");
	addGallery("#galeria5");
	addGallery("#galeria6");
	addGallery("#galeria7");
	addGallery("#galeria8");
	addGallery("#galeria9");
	
	// hover nos thumbnails
	$(".thumbs img").hover(function(){
		$(this).fadeTo("fast", 0.7);
	},
	function(){
		$(this).fadeTo("fast", 1);
	});
	
});

function addGallery(galeria){
	$("a", galeria).click(function(){
		var url = $(this).attr("href");
		var legenda = $(this).attr("title"); // As legendas capturam o atributo title dos links
		var foto = $(".foto", galeria);
		
		foto.fadeOut(200, function(){
			// Troca a imagem
			foto.attr("src", ""); // Chrome Fix
			foto.attr("src", url);
			
			// Só mostrar a imagem após carregar
			foto.load(function(){
				// Fade in
				foto.fadeIn(400);
				// Troca a leganda
				$(".legenda", galeria).html(legenda);
			})
		});

		return false;
	});
}
