// This JavaScript file is used to cycle through the homepage features
// It requires the JQuery JavaScript library to provide the fade in functionality

// This is the duration in milliseconds for each feature to appear
var featureDuration = 4000;

// This is the duration in milliseconds of the fade-in
var fadeInTime = 2000;

// Some global variables to hold features, the total number of features and the current feature
var features, totalFeatures, currentFeature = 0;

// Use JQuery to check that the DOM is ready, then find the features and start the animation
$(document).ready(function(){
  features = $('.feature');
  totalFeatures = features.length;
  features[0].style.display = 'block';
  animateFeatures(); 
  });

// Start the timer and call the showFeature() function
function animateFeatures(){
  var timer = setTimeout('showFeature()', featureDuration);  
  }

// Hide the current feature and then fade in the next one
// If we're on the last one, go back to the start
function showFeature(){
  //$('#'+features[currentFeature].id).hide();  
  $('#'+features[currentFeature].id).fadeOut(1000);  
  if(currentFeature < totalFeatures -1)currentFeature += 1;
  else currentFeature = 0;
  $('#'+features[currentFeature].id).fadeIn(fadeInTime);  
  animateFeatures();
  }
