(function ($) {
  $(function() {
    $('div.header-rotator').append('<img class="fadein"/>');
    var fadein = $('div.header-rotator img.fadein');

    window.setInterval(function() {
      var active = $('div.header-rotator img.active');
      var next = active.next();
      if (next.hasClass('fadein')) {
        next = active.parent().find('img').first();
      }
      
      fadein.attr('src', next.attr('src'));
      fadein.fadeIn(3000,function() {
        next.addClass('active');
        active.removeClass('active');
        $(this).hide();
      });
    }, 5000);
  });
})(jQuery);

