(function($) { 
	$.fn.scrolling = function (o)
	{
		o = $.extend(
		{
			speed:50
		}, o);
		var actualspeed = 100 - o.speed;
		if(actualspeed <= 0)
			actualspeed = 1;
		$(this).each(function(){
			var i = $(this);
			i.unbind();
			i.parent().css('position','relative');
			var widthpx = i.parent().css('width');
			width = widthpx.replace(/px/,'');
			var scrollwidth = i.width();
			i.css({'position':'absolute','left':+width,'top':'0'});
			i.bind('mouseenter',function(){
				i.stop(true);
			});
			i.bind('mouseleave',function(){
				var currentpos = i.position().left;
				var leftover = currentpos + scrollwidth;
				var currentspeed = (actualspeed*1000*leftover)/(+width + scrollwidth);
				i.clearQueue();
				i.animate({left:'-'+scrollwidth},currentspeed,'linear',function(){i.scrolling(actualspeed);});
			});
			i.animate({left:'-'+(scrollwidth)},actualspeed*1000,'linear',function(){i.scrolling(actualspeed);});
		});
		
	}
})(jQuery);
