function ImageRotator(){

  var delay = 4000;


    $('.image-rotator').each(function(){
      var timer;
      var current = 1;

      if($(this).hasClass('speed-1')) { delay = 1100; }
      if($(this).hasClass('speed-2')) { delay = 2200; }
      if($(this).hasClass('speed-3')) { delay = 3400; }
      if($(this).hasClass('speed-4')) { delay = 4500; }
      if($(this).hasClass('speed-5')) { delay = 5700; }
      if($(this).hasClass('speed-6')) { delay = 6300; }

      $(this).find('li').hide();
      $(this).find('li:first').show();


      var that = this;

      var rotateImages = function(){
        clearInterval(timer);
        $(that).children('li').fadeOut();

        current = (current+1 > $(that).find('li').length) ? 1 : current+1;

        $(that).find("li:nth-child("+current+")'").fadeIn();
        timer = setInterval(rotateImages, delay);
      }

      timer = setInterval(rotateImages, delay);



    });

};


$(document).ready(function() {
  ImageRotator();
});
