this is slider code......please tell me whats happening in this script?

this is slider code......please tell me whats happening in this script?

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

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




here currentPhoto is incrementing but in the script its cutting down into 0,1 or 2 by modulus with numberOfPhotos....then how the scirpt is executing??