(function($) {

$.fn.newsScroller = function(options) {
	
	return this.each(function() {	
	
		var
			$this = $(this), 
		  
			defaults = {
		  		speed: 400, 
		  		delay: 3000, 
		  		list_item_height: $this.children('div').outerHeight() 
	     	},
	     
			settings = $.extend({}, defaults, options); 
			
			$this
	  	 	  .children('div:first')
  		 	  .css('zIndex', 3)
  		 	  .addClass('activebox');
			  
			$this
			  .children('div:first')
			  .next('div')
			  .css('zIndex', 2);
			  
			var id = $this.children('div:first').attr('id');
		  	    			
		  	$('#tab'+id).addClass('active');
		 	
			setInterval(function() {
				
				if ($('.switch').size() == 0) {
				
					if ($this.children().size() > 1) {
		  	    		$this.children('div:first')
		  	    			.fadeOut(settings.speed, function() {
		  	    			
		  	    				var id = $this.children('div:first').attr('id');
		  	    				
		  	    				$('#tab'+id).removeClass('active');
		  	    				$('#'+id).removeClass('activebox');
		  	   	 		
	  	 						$this
	  	 						  .children('div:first')
	  	 						  .appendTo($this)
	  	 						  .css('zIndex', 1)
	  	 						  .fadeIn(300); 
	  	 						  
	  	 						$this
	  	 							.children('div:first')
  		 							.css('zIndex', 3);
  		 						
		  	    				var id = $this.children('div:first').attr('id');
		  	    				
		  	    				$('#tab'+id).addClass('active');
		  	    				$('#'+id).addClass('activebox');
  		 						
  		 						$this
  		 							.children('div:first')
  		 							.next('div')
  		 							.css('zIndex', 2);
  		 							  		 						
  		 					}
 	 					); // end animate
 	 				
 	 				}
 	 			}
 	 			
			}, settings.delay); // end setInterval
	});
	
}

})(jQuery);

$(function() {
	
	$('#featureinfo').newsScroller({
		speed: 500,
		delay: 6000
	});
	
});

function switchFeature(id) {
	
	$('#'+id).addClass('switch');
	$('.feature').css('zIndex', 1);
	$('#'+id).css('zIndex', 3);
	$('.activebox').css('zIndex', 4);
	$('.activebox').fadeOut(500, function() {
		
		var fixId = $('.activebox').attr('id');
		
		$('.activebox').css('zIndex', 1);
		$('.activebox').removeClass('activebox');
		$('.active').removeClass('active');
		
		$('#'+id).css('zIndex', 4);
		$('#'+id).addClass('activebox');
		$('#tab'+id).addClass('active');
		
		$('#'+fixId).fadeIn(500);
		
		
	});
	
}
