$(document).ready(function() {
	var rotateSpeed = 8000;
	var tabsCount = 4;
	
	/* HOME ANIMATION */
	function contentRotate(feature) {
		if (doAnimate) {
			feature.fadeOut("fast", function (feature) {
				return function () {
					$(".feature_content div").hide();
				
					/* HIGHLIGHT RELEVANT CONTROL */
					for (var i = 1; i <= tabsCount; i++) {
						if ($(this).attr("id") == ("feature"+i)) {
							$("#home_top_tabs .active").removeClass("active");
							$("#navTab"+i).addClass("active");
						}
					}
				
					/* FADE IN NEXT ITEM OR GO BACK TO FIRST */
					feature.fadeIn("fast", function () {
						if ($(this).attr("id") == "feature"+tabsCount) {
							setTimeout(function () {
								contentRotate($(".feature_content div:first"));
							}, rotateSpeed);
						} else {
							setTimeout(function () {
								contentRotate($(feature.next()));
							}, rotateSpeed);
						}
					});
				};
			}(feature));
		}
	}

	/* HOME FEATURES */
	$("#home_top_tabs a").hover(function() {
		var current = $(this).attr("title");
		$("#home_top_tabs .active").removeClass("active");
		$(this).addClass("active");
	});

	$("#home_top_tabs a").click(function() {
		return false;
	});

	var doAnimate = true;

	contentRotate($(".feature_content div:first"));
	
	/*for (var i = 1; i <= tabsCount; i++) {
		$("#navTab"+i).hover(function() {
			for (var j = 1; j <= tabsCount; j++) {
				if (j == i) {
					$("#feature"+j).fadeIn();
				} else {
					$("#feature"+j).hide();
				}
			}
			doAnimate = false;
		});
	}*/
});

