/**
 * @name		jquery-newsticker
 * @version		1.0
 * @author		Mike Dingjan <mike@dingjan.net>
 * @copyright	2010 - CC2NET.COM
 * 
 * 				feel free to edit 
 * 				but leave this notice in here.
 */

(function($){
	$.fn.newsticker = function( options )
	{
		opts = $.extend( {}, $.fn.newsticker.defaults, options );
		target = $(this);
		
		current = 0;
		old = 0;
		
		$.fn.newsticker.initialize();
	};
	
	$.fn.newsticker.defaults = {
		interval	:	6000,
		speed		:	"slow"
	};
	
	$.fn.newsticker.initialize = function(){
		newscount = target.find("li").size();
		target.find("li:eq("+current+")").css("display", "block");
		
		intval = setInterval( $.fn.newsticker.rotate, opts.interval);
		target.hover( function() { 
			clearInterval(intval);
		}, function(){ 
			intval = setInterval( $.fn.newsticker.rotate, opts.interval ); 
			//$.fn.newsticker.rotate() 
		});
	};
	
	$.fn.newsticker.rotate = function() {
		current = ( old + 1 ) % newscount;
		target.find("li:eq("+old+")").animate( {opacity: 0.1}, opts.speed, function(){ 
			$(this).removeAttr("style");
		});
		target.find("li:eq("+current+")").animate( {}, opts.speed, function(){ 
			$(this).css("display", "block");
		});
		old = current;
	};
	
})(jQuery);

