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

function rotatePics(currentPhoto) {

    var numberOfPhotos = $('#slideshow img').length;
    currentPhoto = currentPhoto % numberOfPhotos;

    $('#slideshow img').eq(currentPhoto).fadeOut(function () {
          $('#slideshow img').each(function(i) {
               $(this).css (
                    'zIndex', ((numberOfPhotos - i) + currentPhoto) % numberOfPhotos);
          });
          $(this).show();
          setTimeout(function() {rotatePics(++currentPhoto);}, 4000);
   });
}

