// Resources page hero
// Slide showing in hero
var currentHeroSlide = 0;
var heroTimeoutId = null;
var heroFadeTime = 1000;
var heroPauseTime = 3000;

/**
 * Animates resources hero
 *
 * @return void
 */
function animateHero()
{
  // Get currently active slide
  var section = $("#homepage-hero");
  var numSlides =  section.find(".item").length;
  var activeSlide = section.find(".item.active:first");
  var nextSlide = activeSlide.next(".item");
  var pos = activeSlide.prevAll(".item").length;

  if (!nextSlide.length)
  {
    pos = 0;
    nextSlide = section.find(".item:first");
  }

  // Fade appropriate slide in and other one out
  var fadeTime = 2000;
  nextSlide.hide().fadeIn(heroFadeTime, function ()
  {
    activeSlide.fadeOut(heroFadeTime).removeClass("active");

    $(this).addClass("active");

    // Reset timeout
    clearTimeout(heroTimeoutId);
    heroTimeoutId = setTimeout("animateHero()", heroPauseTime);

  });

  return false;
}

$(document).ready(function() {

  heroTimeoutId = setTimeout("animateHero()", heroPauseTime);

});

