// JavaScript Document

$(document).ready(function() {
		
///////// SPOTLIGHT	/////////

		var i = 1;
		var n = 1;
		var nn = 1;
		
		function homeSpotlight(n) {
			$("#spotlight-content-" + n).fadeIn(800);
			$("#spotlight-content-" + i).fadeOut(400);		
			$("#spotlight-link-" + i).parent().removeClass('current-spotlight');
			$("#spotlight-link-" + n).parent().addClass('current-spotlight');
			i = n;
		}
		
		function homeSpotlightRotate() {
			
			if(i == 4) {
				nn = 1;
			} else {
				nn = i + 1;
			}
			
			homeSpotlight(nn);
		}
		
		var int = setInterval(homeSpotlightRotate,5000);
		
	
		$("#spotlight-link-1").click(function() {
			window.clearInterval(int);
			homeSpotlight(1);
			int = setInterval(homeSpotlightRotate,5000);
		});
		
		$("#spotlight-link-2").click(function() {
			window.clearInterval(int);
			homeSpotlight(2);
			int = setInterval(homeSpotlightRotate,5000);		
		});
		
		$("#spotlight-link-3").click(function() {
			window.clearInterval(int);
			homeSpotlight(3);
			int = setInterval(homeSpotlightRotate,5000);
		});
		
		$("#spotlight-link-4").click(function() {
			window.clearInterval(int);
			homeSpotlight(4);
			int = setInterval(homeSpotlightRotate,5000);
		});


///////// HOME FEATURE	/////////

		var fi = 1;
		var fn = 1;
		
		function homeFeature(fn) {
			$("#feature-text-" + fn).fadeIn(800);
			$("#feature-text-" + fi).fadeOut(400);			
			$("#feature-link-" + fi).parent().removeClass('current-feature');
			$("#feature-link-" + fn).parent().addClass('current-feature');
			fi = fn;
		}		
	
		$("#feature-link-prev").click(function() {
			var current = $("li.current-feature > a").attr("id");
			current = current.replace('feature-link-', '');
			var prev = parseInt(current) - 1;
			
			if(prev == 0) {
				prev = 3;
			}

			homeFeature(prev);
		});
		
		$("#feature-link-next").click(function() {
			var current = $("li.current-feature > a").attr("id");
			current = current.replace('feature-link-', '');
			var prev = parseInt(current) + 1;
			
			if(prev == 4) {
				prev = 1;
			}

			homeFeature(prev);
		});
	
		$("#feature-link-1").click(function() {
			homeFeature(1);
		});
		
		$("#feature-link-2").click(function() {
			homeFeature(2);
		});
		
		$("#feature-link-3").click(function() {
			homeFeature(3);
		});

})
