$(document).ready(function() {
  
  /* HOME ANIMATION */
  function contentRotate(feature) {
	if (doAnimate) {  
	  feature.fadeOut(1000, function (feature) {
	    return function () {
		  $("#slideshow div").hide();
			
		  /* HIGHLIGHT RELEVANT CONTROL */
		  if ($(this).attr("id") == "coach") {
		    $(".navSecondary .on").removeClass("on");
		    $("#navCoach").addClass("on");
		  }
		  else if ($(this).attr("id") == "treatments") {
		    $(".navSecondary .on").removeClass("on");
		    $("#navTreatments").addClass("on");
		  }
		  else if ($(this).attr("id") == "doctor") {
		    $(".navSecondary .on").removeClass("on");
		    $("#navDoctor").addClass("on");
		  }
		
		  /* FADE IN NEXT ITEM OR GO BACK TO FIRST */
		  feature.fadeIn(1000, function () {
		    if ($(this).attr("id") == "doctor") {
			  setTimeout(function () {
			    contentRotate($("#slideshow div:first"));
			  }, 10000);
		    }
		    else {
		      setTimeout(function () {
			    contentRotate($(feature.next()));
			  }, 10000);
		    }
		  });
	    };
	  }(feature));
	}
  }


  /* HOME FEATURES */
  $(".navSecondary a").hover(function() {
    var current = $(this).attr("title");
	$(".navSecondary .on").removeClass("on");
	$(this).addClass("on");
  });
  
  var doAnimate = true;

  contentRotate($("#slideshow div:first"));

  $("#navCoach").hover(function() {
	$("#coach").fadeIn();
	$("#treatments").hide();
	$("#doctor").hide();
	doAnimate = false;
  });
  $("#navTreatments").hover(function() {
	$("#coach").hide();
	$("#treatments").fadeIn();
	$("#doctor").hide();
	doAnimate = false;
  });
  $("#navDoctor").hover(function() {
	$("#coach").hide();
	$("#treatments").hide();
	$("#doctor").fadeIn();
	doAnimate = false;
  });
  
  
});
