
$(document).ready(function() {		
	
	//Execute the slideShow
	slideShow();

});

function slideShow() {

	//Defina a opacidade de todas as imagens a 0
	$('#jqSSgallery a').css({opacity: 0.0});
	
	//Obter a primeira imagem e exibi-la (defini-lo para opacidade total)
	$('#jqSSgallery a:first').css({opacity: 0.9});
	
	//Definir o plano de fundo legenda para semi-transparente
	$('#jqSSgallery .caption').css({opacity: 0.9});

	//Redimensionar a largura da legenda de acordo com a largura da imagem
	$('#jqSSgallery .caption').css({width: $('#jqSSgallery a').find('img').css('width')});
	
	//Obter a legenda da primeira imagem de atributo rel e exibi-lo
	$('#jqSSgallery .content').html($('#jqSSgallery a:first').find('img').attr('rel'))
	.animate({opacity: 1.0}, 400);
	
	//Chame a função de galeria para executar o slideshow, 6000 = mudança para a próxima imagem depois de 6 segundos
	setInterval('gallery()',10000);
	
}

function gallery() {
	
	//se não tem a classe BMI show, pegar a primeira imagem
	var current = ($('#jqSSgallery a.show')?  $('#jqSSgallery a.show') : $('#jqSSgallery a:first'));

	//Obter próxima imagem, se atingiu o final da apresentação, girá-lo de volta para a primeira imagem
	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#jqSSgallery a:first') :current.next()) : $('#jqSSgallery a:first'));
	
	//Obter legenda da imagem ao lado
	var caption = next.find('img').attr('rel');	
	
	//Defina o efeito de fade in para a próxima imagem, classe show tem maior índice z
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Ocultar a imagem atual
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
	//Defina a opacidade a 0 e altura de 1px
	$('#jqSSgallery .caption').animate({opacity: 0.0}, { queue:false, duration:0 }).animate({height: '1px'}, { queue:true, duration:400 });	
	
	//Animar a legenda, a opacidade de 0,7 e altura de 100px, um slide-se efeito
	$('#jqSSgallery .caption').animate({opacity: 0.9},100 ).animate({height: '73px'},500 );
	
	//Mostrar o conteúdo
	$('#jqSSgallery .content').html(caption);
	
	
}

