// JavaScript Document

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

function rotatePics(currentPhoto) {
var numberOfPhotos = $('.slides img').length; 
currentPhoto = currentPhoto % numberOfPhotos;


$('.slides img').eq(currentPhoto).fadeOut(function() {
  // re-order the z-index
  $('.slides img').each(function(i) {
    $(this).css(
      'zIndex', ((numberOfPhotos - i) + currentPhoto) % numberOfPhotos );
});
  $(this).show();
  setTimeout(function() {rotatePics(++currentPhoto);}, 4000);
});
}
