$(document).ready(function() {		
	
	//Executa o slideShow, configurando para o tempo de execução
	slideShow(4500);

});

function slideShow(speed) {


	//Liga um LI ao UL lita para mostar a legenda da imagem
	$('ul.slideshow').append('<li id="slideshow-caption" class="caption"><div class="slideshow-caption-container"><h3></h3><p></p></div></li>');

	//Configura a opacidade de todas as imagens para 0
	$('ul.slideshow li').css({opacity: 0.0});
	
	//Pega a primeira imagem e apresenta
	$('ul.slideshow li:first').css({opacity: 1.0});
	
	//Pega a legenda da primeira imagem da atributo REL e mostra
	$('#slideshow-caption h3').html($('ul.slideshow a:first').find('img').attr('title'));
	$('#slideshow-caption p').html($('ul.slideshow a:first').find('img').attr('alt'));
		
	//Mostra a legenda
	$('#slideshow-caption').css({opacity: 0.7, bottom:0});
	
	//Chama a galeria de funções e executa o slideshow	
	var timer = setInterval('gallery()',speed);
	
	//pausa o slideshow no mouse over
	$('ul.slideshow').hover(
		function () {
			clearInterval(timer);	
		}, 	
		function () {
			timer = setInterval('gallery()',speed);			
		}
	);
	
}

function gallery() {
        if(qtSlides ==  1){
          return;
        }

	//se não houver outras imagems, pega a primeira
	var current = ($('ul.slideshow li.show')?  $('ul.slideshow li.show') : $('#ul.slideshow li:first'));

	//Pega a próxima imagem, se chegar ao fim do slideshow, retorna para a primeira imagem
	var next = ((current.next().length) ? ((current.next().attr('id') == 'slideshow-caption')? $('ul.slideshow li:first') :current.next()) : $('ul.slideshow li:first'));
		
	//Get next image caption
	var title = next.find('img').attr('title');	
	var desc = next.find('img').attr('alt');	

	//Configura a transição fade in para a imagem seguinte, show class has higher z-index
	next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);
	
	//Esconde a primeira legenda, de então apresenta novamente
	$('#slideshow-caption').animate({bottom:-70}, 300, function () {
			//Display the content
			$('#slideshow-caption h3').html(title);
			$('#slideshow-caption p').html(desc);				
			$('#slideshow-caption').animate({bottom:0}, 500);	
	});		

	//Esconde a imagem corrente
	current.animate({opacity: 0.0}, 1000).removeClass('show');

}
