$(document).ready(function() {		
	slideShowNovidades();
});

function slideShowNovidades() {
	$('#galeria_novidades a').css({opacity: 0.0});
	$('#galeria_novidades a:first').css({opacity: 1.0});
	setInterval('mudaNovidades()',5000);
}

function mudaNovidades() {
	
	//if no IMGs have the show class, grab the first image
	var current = ($('#galeria_novidades a.show')?  $('#galeria_novidades a.show') : $('#galeria_novidades a:first'));

	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#galeria_novidades a:first') :current.next()) : $('#galeria_novidades a:first'));	
	
	//Set the fade in effect for the next image, show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 500);

	//Hide the current image
	current.animate({opacity: 0.0}, 500)
	.removeClass('show');
	
}

