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

function showFeature(index) {
  $(".chooser li").removeClass('active');
  $("#features .feature").fadeOut("fast");
  $("#feature-" + index).fadeIn("fast");
  $("#chooser-" + index).addClass('active');
  stopHomepageFeaturesTimer();
  startHomepageFeaturesTimer();
}

function startHomepageFeaturesTimer() {
  $(document).everyTime(6000, advanceHomepageFeatures);
}

function stopHomepageFeaturesTimer() {
  $(document).stopTime();
}

function advanceHomepageFeatures() {
  var features = $("#features .feature");
  activeIndex = parseInt($(".chooser li.active").attr('id').replace('chooser-',''));
  if (activeIndex == (features.length - 1)) {
    showFeature(0);
  } else {
    showFeature(activeIndex + 1);
  }
}
