/*
Usage:

<div class="container">
	<ul>...</ul>
</div>

$('.container').slidenstop();

*/
;(function($) {
    
	$.continuScroll = {
		speed: 1,
		rate: 33,
		direction: 'rtl'	
	}

	$.fn.extend({
		
		continuScroll: function(options) {

	        var options = $.extend($.continuScroll, options);		
		
	        return this.each(function() {
				var obj         = $(this);
				var newWidth    = 100;
			
	//Add wrapper to ul before using this code!!! ul.wrap('<div style="position: absolute;"></div>');	

				var objList = obj.find('ul:first');
				var objMover = objList.parent(); //obj.find('div');
			    
			    // Calculate the width based on the width of the contained LI elements
			    obj.find('li').each(function() {
			    	newWidth += $(this).outerWidth(true);
			    	$(this).clone().appendTo(objList);
			    });
			    
			    objMover.css('width', newWidth *2);
			    
				// Move, pause, rinse, repeat
			    setInterval(function() {
					var leftPos = parseInt(objMover.css('marginLeft'));

			    	newPos = leftPos - options.speed;

					objMover.css('marginLeft', newPos +"px");			
						
					if (Math.abs(newPos) > objList.find('li:first').width()) {
						objList.find('li:first').appendTo(objList);
						objMover.css('marginLeft', newPos + objList.find('li:last').outerWidth(true) +'px');
					}	

				}, options.rate);

	        }); // end return
		} // end function
    }); // end extend
})(jQuery);

