jQuery.Tick = {
	setup: function(options){
	
		if(this.length > 1) return;

		this.wrap("<div class='TickContainer'></div>");		
		this.addClass('Ticking');
	
		var 
			DivWidth = 0,
			ULwidth = 0,
			ULleft = 0,
			Lis = $(this).find('li');

		Lis.each(function(){
			ULwidth += $(this).width();
		});
		ULleft = parseInt(this.css('left'));
		
		if(isNaN(ULleft)){
			ULleft = 0;
		}

		DivWidth = this.parent().width();

		options = jQuery.extend({
			speed: 0.1,
			startLeft: ULleft + DivWidth,
			endLeft: ULleft - ULwidth,
			width: DivWidth,
			totalWidth: ULwidth
		}, options || {});

		this.hover(
			function(){
				$(this).stop();
			},
			function(){
				jQuery.Tick.startTick(this, options);
			}
		);
		this.html(this.html() + this.html());
		this.css({
			width: Math.ceil(ULwidth*2),
			left: ULleft + DivWidth
		});
		jQuery.Tick.startTick(this, options);
	},
	
	startTick: function(obj, options){
		var
			obj = $(obj),
			totalDistance = options.startLeft - options.endLeft,
			currentDistance = options.startLeft - parseInt(obj.css('left')),
			position = currentDistance / totalDistance,
			duration = totalDistance / options.speed,
			newDuration = duration - (duration * position);

			obj.animate({left: options.endLeft}, newDuration, "linear", function(){
				obj.css('left', options.endLeft + options.totalWidth);
				jQuery.Tick.startTick(obj, options);
			});
	}
};

jQuery.fn.extend ({
	Tick : jQuery.Tick.setup
});