var timeoutlength		=	3000;
var translength			=	600;




$(document).ready( function() {

	// Give first image in slideshow a decent z-index so all the others
	// can  have a highish z-index too
	$('#slideshow > img:first').addClass('crnt').css('zIndex', 100);
	
	
	// Make all images' z-indices one lower than the first one in the
	// DOM so they don't pop up accidentally
	$('#slideshow > img:not(:first)').each(function(i) {
		var prevZ = $(this).prev().css('zIndex');
		$(this).css('zIndex', parseFloat(prevZ)-1);
	});
	
	// Run the next slide function
	setTimeout(nextSlide, timeoutlength);	
	
	
});





function nextSlide() {
	$('#slideshow .crnt').fadeOut(translength, function() {

		$(this).removeClass('crnt');
		
		if ( $(this).next().length ) {
			$(this).next().addClass('crnt');
			setTimeout(nextSlide, timeoutlength);
		}
		else {
			// show all the images since they were hidden,
			// z-index will handle the layering
			$('#slideshow > img').show();
			$('#slideshow > img:first').addClass('crnt');
			setTimeout(nextSlide, timeoutlength);
		}	
			
	});
}