/*	
 *	nxTicker v.1.0 by G.Cochez
 *	Copyright (c) 2009 netXtra Ltd.
 */
 
 // closure
;(function($)
{
	// declaration
	$.fn.nxTicker = function(o) 
	{
		// defaults
		var d = 
		{
			prefix: 'nxTicker', // css id prefix
			speed: 0.04, // scrolling speed
			tag: 'li' // item list tag
		};
		
		// merge default with options
		o = $.extend({}, d, o);
		
		// iterate list holder
		return this.each(function()
		{
			var 
				s = $(this).addClass(o.prefix),
				sw = 0,
				ww = s.wrap('<div class="'+o.prefix+'Mask"></div>').parent().wrap('<div class="'+o.prefix+'Wrap"></div>').parent().parent().width();
				
			// iterate list item
			s.find(o.tag).each(function(i)
			{
				sw += $(this, i).width();
			});
			
			s.width(sw);
			
			var 
				d = sw+ww,
				t = d/o.speed;			
			
			move(d, t);				
			
			// onmouseover stop / start onmouseout
			s.hover(function()
			{
				$(this).stop();
			},
			function()
			{
				var offset = $(this).offset(),
					rd = offset.left + sw,
					rt = rd/o.speed;
					
				move(rd, rt);
			});
			
			// start animation
			function move(d, t)
			{
				s.animate({left: '-='+ d}, t, "linear", function(){s.css("left", ww); move(d, t);});
			};
		});	
	};
})(jQuery);
