(function() {
	$.fn.featureFade = function(){
		return this.each(function(){
			var $panels = $('#feature .article').css({'position':'absolute','top':'0px','left':'0px','zIndex':'0'}),
				$navLink = $('#main-nav a'),
			
				items = $panels.length,
				clickCount = 0,
				currentPanel = 0;
			
			// Paging function
			function gotoPanel(panel){
				if (panel >= items){
					panel = 0
				}
				
				$panels.stop(false,true).eq(currentPanel).css({'zIndex':'0'}).end().eq(panel).css({'zIndex':'1'}).fadeIn(1000, function(){
					$panels.not(this).hide();
				});
				
				currentPanel = panel
				
				$navLink.removeClass('current').eq(panel, this).addClass('current');
			}
			
			// Direct Links
			$navLink.hover(
				function(){
					var index = $navLink.index(this);
					timeoutId = setTimeout(function(){
						gotoPanel(index);

						clearInterval(rotator);
					},400);
				}, function(){
					clearTimeout(timeoutId);
				}
			);
			
			gotoPanel(0);
			
			// Next panel for automatic fading
			$(this).bind('next',function(){
				gotoPanel(currentPanel + 1)
			});
		});
	};
})(jQuery);
