$(function(){
	var tempo = 10000;
	var index = 0;
	var slide = 0;
	var slideWidth = 562; // Largura de cada imagem (slide)
	var lengthSlide = $('#slideshow ul#imagem li').length; // Total de slides no slideshow
	var ulWidth = lengthSlide * slideWidth;

	var proximoSlide = function(){
		index = (index >= (lengthSlide -1)) ? 0 : index + 1;
		$('#thumb ul li:eq('+ index +') a').trigger('click');

		timeout = setTimeout(proximoSlide, tempo);
	}

	var timeout = setTimeout(proximoSlide, tempo);

	// Define a largura total do slideshow
	$('#slideshow ul#imagem').css('width', ulWidth + 'px');
	$('#slideshow #descricao ul li:eq(0)').addClass('selecionado');

	$('#thumb .link-thumb').click(function(){
		index = (index >= (lengthSlide -1)) ? 0 : index + 1;
		index = $(this).parent().index();
		slide = -1 * (index * slideWidth);

		$('#slideshow #descricao ul li').removeClass('selecionado');
		$('#thumb ul li a').removeClass('ativo-thumb');

		$("#slideshow ul#imagem").animate({ left: slide + 'px' }, 'slow', function(){
			$('#slideshow #descricao ul li:eq(' + index + ')').addClass('selecionado');
			$('#thumb ul li:eq('+ index +') a').addClass('ativo-thumb');
		});

		return false;
	});
;
});
