nccJQuery(function(){
	nccJQuery(".fc_imageHolder img").hide();
	var fcScroll = "";
	var resizeTimer = "";
	var arrayBGColors = new Array("url(images/bullets/largeDot.png) center no-repeat","url(images/bullets/largeDot.png) center no-repeat","url(images/bullets/largeDot.png) center no-repeat","url(images/bullets/largeDot.png) center no-repeat");
	var arrayBGColors2 = new Array("url(images/bullets/smallDot.png) center no-repeat","url(images/bullets/smallDot.png) center no-repeat","url(images/bullets/smallDot.png) center no-repeat","url(images/bullets/smallDot.png) center no-repeat");
	var parentHeight = nccJQuery("#fc_viewport").height();
	
	// defines how long the featured content will be visible for before moving to the next item.
	// in milliseconds, so 1000 = 1 second
	var featuredContentSpeed = 6000;
	
	// defines the speed of the scroll animation for featured content
	var scrollAnimateDuration = 500;
	
	nccJQuery(window).load(function(){
		nccJQuery(".fc_imageHolder img").each(function(){	
			var thisHeight = nccJQuery(this).height();
			var newMargin = (200 - thisHeight)/2;
			nccJQuery(this).css("margin-top",newMargin);
			nccJQuery(this).fadeIn("fast");
		});
	});
	
	nccJQuery(window).resize(function(){
		clearTimeout(resizeTimer);
		resizeTimer = setTimeout(function(){
			var currentIndex = nccJQuery("#fc_links li").index(nccJQuery(".activeLink"));
			setFeaturedAsActive(currentIndex);
		},300);
	});
	
	setFeaturedAsActive(0);

	nccJQuery("#fc_links li a").click(function(){
		var index = nccJQuery("#fc_links li").index(nccJQuery(this).parent());
		setFeaturedAsInactive(index-1);
		setFeaturedAsInactive(index-2);
		setFeaturedAsInactive(index-3);
		setFeaturedAsInactive(index+1);
		setFeaturedAsInactive(index+2);
		setFeaturedAsInactive(index+3);
		setFeaturedAsActive(index);
		return false;
	});
	
	nccJQuery("#fc_viewport").hover(function(){
		clearTimeout(fcScroll);
	},function(){
		fcScroll = setTimeout(function(){
			showNextFeatured();
		},featuredContentSpeed/2);
	});
	
	function showNextFeatured(){
		var currentIndex = nccJQuery("#fc_links li").index(nccJQuery(".activeLink"));
		var newIndex = (currentIndex+1) % 4;
		setFeaturedAsInactive(currentIndex);
		setFeaturedAsActive(newIndex);
	}
	
	function setFeaturedAsActive(i){
		var currentViewportWidth = nccJQuery("#fc_viewport").width();
		var leftOffset = -1 * (i*currentViewportWidth);	
		clearTimeout(fcScroll);
		
		nccJQuery(".activeLink").removeClass("activeLink");
		nccJQuery("#fc_links li").eq(i).addClass("activeLink");
		nccJQuery("#fc_items").animate({left:leftOffset},scrollAnimateDuration,"linear");
		nccJQuery("#fc_links li").eq(i).css("background",arrayBGColors[i]);
		
		fcScroll = setTimeout(function(){
			showNextFeatured();
		},featuredContentSpeed);
	}
	
	function setFeaturedAsInactive(i){
		nccJQuery(".activeLink").removeClass("activeLink");
		nccJQuery("#fc_links li").eq(i).addClass("activeLink");
		nccJQuery("#fc_links li").eq(i).css("background",arrayBGColors2[i]);
	}

});

