
(function($) {

	$.fn.mycarusel = function(o){
			s = $.extend({
					speed: 8000
				}, o||{});

			return this.each(function(i){
				if( $('li', this).length == 0  ) return;

				var self = $(this);
				var self_width = self.innerWidth();
				var ul = $('ul', self);
				var ul_width = 0;
				var li_width = $('li', ul).eq(0).outerWidth(true);
					ul_width = li_width * $('li', ul).length;
				if( self_width >= ul_width ) return;

				var ul_padding = 0;
					ul.css({ width: ul_width, padding: ul_padding, position: 'absolute' });

				// При остановке должна учитываться позиция
				var delta_start = 0;

				var go = function( ds ){
					var to_left = li_width - ds;
					var speed = ( s.speed / li_width  ) * to_left;
					delta_start = 0;
					$(ul).animate({'left': '-='+to_left }, speed, 'linear', function(){
							ul_padding = ul_padding + li_width
							$(this).css({ paddingLeft: ul_padding });
							$('li', ul).eq(0).appendTo(ul);
						go(0);
					});
				};

				var stop = function(){
					delta_start = -( $(ul).position().left + ul_padding );
					$(ul).stop(true);
					}

				$('li', ul).each(function(i){
					$(this).hover( stop, function(){ go(delta_start); });
				})

				go(0);

			});
		};

})(jQuery);

/**

(function($) {

	$.fn.mycarusel = function(o){
			s = $.extend({
					speed: 8000
				}, o||{});

			return this.each(function(i){
				if( $('li', this).length == 0  ) return;

				var c = $(this),
					cw = c.width(),
					lw = $('li', c).eq(0).width(),
					clcnt = Math.ceil( cw / lw ),
					lcnt = $('li', c).length;

				if (clcnt >= lcnt) return;

				var go = function(){
					$('li', c).animate({'left': '-=1'}, s.speed/100, 'linear', function(){
						var left = $(this).position().left;
						if( left <= - lw ){
							$(this).css({left: (lcnt*lw - lw ) });
						}
						go();
					});
				};

				var stop = function(){ $('li', c).stop(true); }

				$('li', c).each(function(i){
					$(this).css({position: 'absolute', top: 0, left: (i*lw) }).hover( stop, go);
				})

				go();

			});
		};

})(jQuery);

**/
