$(document).ready(function() {
  
  /* HOME ANIMATION */
  function contentRotate(feature) {
	if (doAnimate) {  
	  feature.fadeOut("fast", function (feature) {
	    return function () {
		  $(".feature_content div").hide();
			
		  /* HIGHLIGHT RELEVANT CONTROL */
		  if ($(this).attr("id") == "feature_one") {
		    $(".feature_nav .on").removeClass("on");
		    $(".home_one").addClass("on");
		  }
		  else if ($(this).attr("id") == "feature_two") {
		    $(".feature_nav .on").removeClass("on");
		    $(".home_two").addClass("on");
		  }
		  else if ($(this).attr("id") == "feature_three") {
		    $(".feature_nav .on").removeClass("on");
		    $(".home_three").addClass("on");
		  }
		
		  /* FADE IN NEXT ITEM OR GO BACK TO FIRST */
		  feature.fadeIn("fast", function () {
		    if ($(this).attr("id") == "feature_three") {
			  setTimeout(function () {
			    contentRotate($(".feature_content div:first"));
			  }, 10000);
		    }
		    else {
		      setTimeout(function () {
			    contentRotate($(feature.next()));
			  }, 10000);
		    }
		  });
	    };
	  }(feature));
	}
  }


  /* HOME FEATURES */
  $(".feature_nav a").hover(function() {
    var current = $(this).attr("title");
	$(".feature_nav .on").removeClass("on");
	$(this).addClass("on");
  });
  
  $(".feature_nav a").click(function() {
    return false;
  });

  var doAnimate = true;

  contentRotate($(".feature_content div:first"));

  $(".home_one").hover(function() {
	$("#feature_one").fadeIn();
	$("#feature_two").hide();
	$("#feature_three").hide();
	doAnimate = false;
  });
  $(".home_two").hover(function() {
	$("#feature_one").hide();
	$("#feature_two").fadeIn();
	$("#feature_three").hide();
	doAnimate = false;
  });
  $(".home_three").hover(function() {
	$("#feature_one").hide();
	$("#feature_two").hide();
	$("#feature_three").fadeIn();
	doAnimate = false;
  });
  
 
  
});