$(document).ready(function(){
	rotatePics(1);
});

function rotatePics(currentImage){
	var numberOfImages = $('#slideshow img').length;
	currentImage = currentImage % numberOfImages;
	$('#slideshow img').eq(currentImage).fadeOut(function(){
		//reorder the z-index
		$('#slideshow img').each(function(i){
			$(this).css(
				'zIndex', ((numberOfImages - i) + currentImage) % numberOfImages
			);
		});
		$(this).show();
		setTimeout(function(){rotatePics(++currentImage);}, 4000)
	});
}
