// Initialize.
function initHeroModuleRotator(listSelector) {

  // Does element exist?
  if (!$(listSelector).length) {

    // If not, exit.
    return;
  }

  // Rotate speed.
  var speed = 2000;

  // Pause setting.
  var pause = false;

  // Rotator function.
  function rotate(element) {

    // Stop, if user has interacted.
    if (pause) {
      return;
    }

    // Either the next /first <li>.
    var $next_li = $(element).next('li').length ? 
                   $(element).next('li') : 
                   $(listSelector+' li:first');

    // Continue.
    function doIt() {
      rotate($next_li);
    }

    // Fade out <li>.
    $(element).fadeOut(speed);

    // Show next <li>.
    $($next_li).fadeIn(speed, function() {

      // Slight delay.
      setTimeout(doIt, speed);
    });
  }

  // Hide all but first <li>.
  $(listSelector+' li:first').siblings('li').hide();

  // Wait for page load.
  $(window).load(function() {

    // Begin rotation.
    rotate($(listSelector+' li:visible:first'));
  });
}

// Start rotating Hero module
$(document).ready(function () {
    initHeroModuleRotator('DIV.WrHeroFlash ul.dfwp-list');
});
