$(document).ready(function(){
  rotatePics(1);
});

function rotatePics(currentPhoto) {
  var numberOfPhotos = $('#photos1 img').length;
  currentPhoto = currentPhoto % numberOfPhotos;
	
  $('#photos1 img').eq(currentPhoto).fadeOut(function() {
		// re-order the z-index
    $('#photos1 img').each(function(i) {
      $(this).css(
        'zIndex', ((numberOfPhotos - i) + currentPhoto) % numberOfPhotos
      );
    });
    $(this).show('slow');
    setTimeout(function() {rotatePics(++currentPhoto);}, 4000);
  });
}


