$(document).ready(function() {

	var currentFeature = '';

	$('#featureText').cycle({ 
		fx:     'fade', 
		timeout: 10000, 
		delay:  -4000,
		after: onAfter
	});
	
	function onAfter(curr, next, opts) {
		loadFeatureNav($(next).attr("class"));
		currentFeature = $(next).attr("class");
	}
	
	function loadFeatureNav(feature) {
		switch(feature) 
		{
			case 'one':
			{
				$('a.feature-social').css({ backgroundPosition: "0pt -58px" });
				$('a.feature-education').css({ backgroundPosition: "0pt 0pt" });
				$('a.feature-historic').css({ backgroundPosition: "0pt 0pt" });
				$('a.feature-health').css({ backgroundPosition: "0pt 0pt" });
				$('a.feature-commercial').css({ backgroundPosition: "0pt 0pt" });
	
				//$('a.feature-social').bind('mouseenter', featureBtnOver);
				//$('a.feature-social').bind('mouseleave', featureBtnOut);
				//$('a.feature-social').bind('mousedown', featureBtnDown);
				//$('a.feature-social').bind('mousedown', featureBtnClick);
	
				$('a.feature-education').bind('mouseenter', featureBtnOver);
				$('a.feature-education').bind('mouseleave', featureBtnOut);
				$('a.feature-education').bind('mousedown', featureBtnDown);
				$('a.feature-education').bind('mousedown', featureBtnClick);
				
				$('a.feature-historic').bind('mouseenter', featureBtnOver);
				$('a.feature-historic').bind('mouseleave', featureBtnOut);
				$('a.feature-historic').bind('mousedown', featureBtnDown);
				$('a.feature-historic').bind('mousedown', featureBtnClick);
				
				$('a.feature-health').bind('mouseenter', featureBtnOver);
				$('a.feature-health').bind('mouseleave', featureBtnOut);
				$('a.feature-health').bind('mousedown', featureBtnDown);
				$('a.feature-health').bind('mousedown', featureBtnClick);
				
				$('a.feature-commercial').bind('mouseenter', featureBtnOver);
				$('a.feature-commercial').bind('mouseleave', featureBtnOut);
				$('a.feature-commercial').bind('mousedown', featureBtnDown);
				$('a.feature-commercial').bind('mousedown', featureBtnClick);
				
				break;
			}
			case 'two':
			{
				$('a.feature-social').css({ backgroundPosition: "0pt 0pt" });
				$('a.feature-education').css({ backgroundPosition: "0pt -58px" });
				$('a.feature-historic').css({ backgroundPosition: "0pt 0pt" });
				$('a.feature-health').css({ backgroundPosition: "0pt 0pt" });
				$('a.feature-commercial').css({ backgroundPosition: "0pt 0pt" });
	
				$('a.feature-social').bind('mouseenter', featureBtnOver);
				$('a.feature-social').bind('mouseleave', featureBtnOut);
				$('a.feature-social').bind('mousedown', featureBtnDown);
				$('a.feature-social').bind('mousedown', featureBtnClick);
	
				//$('a.feature-education').bind('mouseenter', featureBtnOver);
				//$('a.feature-education').bind('mouseleave', featureBtnOut);
				//$('a.feature-education').bind('mousedown', featureBtnDown);
				//$('a.feature-education').bind('mousedown', featureBtnClick);
				
				$('a.feature-historic').bind('mouseenter', featureBtnOver);
				$('a.feature-historic').bind('mouseleave', featureBtnOut);
				$('a.feature-historic').bind('mousedown', featureBtnDown);
				$('a.feature-historic').bind('mousedown', featureBtnClick);
				
				$('a.feature-health').bind('mouseenter', featureBtnOver);
				$('a.feature-health').bind('mouseleave', featureBtnOut);
				$('a.feature-health').bind('mousedown', featureBtnDown);
				$('a.feature-health').bind('mousedown', featureBtnClick);
				
				$('a.feature-commercial').bind('mouseenter', featureBtnOver);
				$('a.feature-commercial').bind('mouseleave', featureBtnOut);
				$('a.feature-commercial').bind('mousedown', featureBtnDown);
				$('a.feature-commercial').bind('mousedown', featureBtnClick);
				
				break;
			}
			case 'three':
			{
				$('a.feature-social').css({ backgroundPosition: "0pt 0pt" });
				$('a.feature-education').css({ backgroundPosition: "0pt 0pt" });
				$('a.feature-historic').css({ backgroundPosition: "0pt -58px" });
				$('a.feature-health').css({ backgroundPosition: "0pt 0pt" });
				$('a.feature-commercial').css({ backgroundPosition: "0pt 0pt" });
	
				$('a.feature-social').bind('mouseenter', featureBtnOver);
				$('a.feature-social').bind('mouseleave', featureBtnOut);
				$('a.feature-social').bind('mousedown', featureBtnDown);
				$('a.feature-social').bind('mousedown', featureBtnClick);
	
				$('a.feature-education').bind('mouseenter', featureBtnOver);
				$('a.feature-education').bind('mouseleave', featureBtnOut);
				$('a.feature-education').bind('mousedown', featureBtnDown);
				$('a.feature-education').bind('mousedown', featureBtnClick);
				
				//$('a.feature-historic').bind('mouseenter', featureBtnOver);
				//$('a.feature-historic').bind('mouseleave', featureBtnOut);
				//$('a.feature-historic').bind('mousedown', featureBtnDown);
				//$('a.feature-historic').bind('mousedown', featureBtnClick);
				
				$('a.feature-health').bind('mouseenter', featureBtnOver);
				$('a.feature-health').bind('mouseleave', featureBtnOut);
				$('a.feature-health').bind('mousedown', featureBtnDown);
				$('a.feature-health').bind('mousedown', featureBtnClick);
				
				$('a.feature-commercial').bind('mouseenter', featureBtnOver);
				$('a.feature-commercial').bind('mouseleave', featureBtnOut);
				$('a.feature-commercial').bind('mousedown', featureBtnDown);
				$('a.feature-commercial').bind('mousedown', featureBtnClick);
				
				break;
			}
			case 'four':
			{
				$('a.feature-social').css({ backgroundPosition: "0pt 0pt" });
				$('a.feature-education').css({ backgroundPosition: "0pt 0pt" });
				$('a.feature-historic').css({ backgroundPosition: "0pt 0pt" });
				$('a.feature-health').css({ backgroundPosition: "0pt -58px" });
				$('a.feature-commercial').css({ backgroundPosition: "0pt 0pt" });
	
				$('a.feature-social').bind('mouseenter', featureBtnOver);
				$('a.feature-social').bind('mouseleave', featureBtnOut);
				$('a.feature-social').bind('mousedown', featureBtnDown);
				$('a.feature-social').bind('mousedown', featureBtnClick);
	
				$('a.feature-education').bind('mouseenter', featureBtnOver);
				$('a.feature-education').bind('mouseleave', featureBtnOut);
				$('a.feature-education').bind('mousedown', featureBtnDown);
				$('a.feature-education').bind('mousedown', featureBtnClick);
				
				$('a.feature-historic').bind('mouseenter', featureBtnOver);
				$('a.feature-historic').bind('mouseleave', featureBtnOut);
				$('a.feature-historic').bind('mousedown', featureBtnDown);
				$('a.feature-historic').bind('mousedown', featureBtnClick);
				
				//$('a.feature-health').bind('mouseenter', featureBtnOver);
				//$('a.feature-health').bind('mouseleave', featureBtnOut);
				//$('a.feature-health').bind('mousedown', featureBtnDown);
				//$('a.feature-health').bind('mousedown', featureBtnClick);
				
				$('a.feature-commercial').bind('mouseenter', featureBtnOver);
				$('a.feature-commercial').bind('mouseleave', featureBtnOut);
				$('a.feature-commercial').bind('mousedown', featureBtnDown);
				$('a.feature-commercial').bind('mousedown', featureBtnClick);
				
				break;
			}
			case 'five':
			{
				$('a.feature-social').css({ backgroundPosition: "0pt 0pt" });
				$('a.feature-education').css({ backgroundPosition: "0pt 0pt" });
				$('a.feature-historic').css({ backgroundPosition: "0pt 0pt" });
				$('a.feature-health').css({ backgroundPosition: "0pt 0pt" });
				$('a.feature-commercial').css({ backgroundPosition: "0pt -58px" });
	
				$('a.feature-social').bind('mouseenter', featureBtnOver);
				$('a.feature-social').bind('mouseleave', featureBtnOut);
				$('a.feature-social').bind('mousedown', featureBtnDown);
				$('a.feature-social').bind('mousedown', featureBtnClick);
	
				$('a.feature-education').bind('mouseenter', featureBtnOver);
				$('a.feature-education').bind('mouseleave', featureBtnOut);
				$('a.feature-education').bind('mousedown', featureBtnDown);
				$('a.feature-education').bind('mousedown', featureBtnClick);
				
				$('a.feature-historic').bind('mouseenter', featureBtnOver);
				$('a.feature-historic').bind('mouseleave', featureBtnOut);
				$('a.feature-historic').bind('mousedown', featureBtnDown);
				$('a.feature-historic').bind('mousedown', featureBtnClick);
				
				$('a.feature-health').bind('mouseenter', featureBtnOver);
				$('a.feature-health').bind('mouseleave', featureBtnOut);
				$('a.feature-health').bind('mousedown', featureBtnDown);
				$('a.feature-health').bind('mousedown', featureBtnClick);
				
				//$('a.feature-commercial').bind('mouseenter', featureBtnOver);
				//$('a.feature-commercial').bind('mouseleave', featureBtnOut);
				//$('a.feature-commercial').bind('mousedown', featureBtnDown);
				//$('a.feature-commercial').bind('mousedown', featureBtnClick);
				
				break;
			}
		}
		$('a.'+feature).unbind('mouseenter', featureBtnOver);
		$('a.'+feature).unbind('mouseleave', featureBtnOut);
		$('a.'+feature).unbind('mousedown', featureBtnDown);
	};
	
	function featureBtnOver() {
		$(this).css({ backgroundPosition: "0pt -29px" });
	};
	
	function featureBtnOut() {
		$(this).css({ backgroundPosition: "0pt 0pt" });
		loadFeatureNav(currentFeature);
	};
	
	function featureBtnDown() {
		$(this).css({ backgroundPosition: "0pt -58px" });
	};
	
	function featureBtnClick() {
		$('#featureText').cycle(parseInt(this.getAttribute("rel")));
		$('#featureText').cycle('pause');
	};
 
});
