(function($){
	
	$.fn.newsFaderSection = function(options){
		
		var $active = $(this).find('div.active');

		if ( $active.length == 0 ) $active = $(this).find('div:last');

		var $next =  $active.next().length ? $active.next() : $(this).find('div:first');

		$active.addClass('last-active');

		$next.css({opacity: 0.1})
			.addClass('active')
			.animate({opacity: 1.0}, 1000, function() {
				$active.removeClass('active last-active');
			});
		
		return this;
	};

	$.fn.newsFader = function(options){
		var x = null;
		
		$('#newsRotatorTitle > div > a').click(function(){
			_resetInterval();
			_moveNext();
		});
		
		_resetInterval();
		
		function _resetInterval(){
			if (x) {
				clearInterval(x);
			}
			x = setInterval( "$('#newsRotatorTitle').newsFaderSection();$('#newsRotatorDetail').newsFaderSection();", 5000 );
		};
		
		function _moveNext(){
			$('#newsRotatorTitle').newsFaderSection();
			$('#newsRotatorDetail').newsFaderSection();
		};
	};


	
})(jQuery);

$(document).ready( function() {
	$().newsFader();
});
