(function($){
	$.fn.TextSlider = function(){
		var _option = { 
						time    : 10, 
						sp      : 1, // 移動距離 px
						dispArea: 783, // マスクの表示領域
						fps     : 30, // フレームレート
						slideSel: $(this)
		}
		
		var _width;
		
		function init(){
			_width = 0;
			_option.slideSel.hover(hoverOnEvent, hoverOffEvent);
//			buid();
			slideStart()
		}
		
		
		function buid(){
			var appendCount = 1;
			while(_width < _option.dispArea){
				_option.slideSel.find('li').each(function(){
					var _clone = $(this).clone();
					_option.slideSel.append(_clone);
					_width += $(this).width();
				});
				appendCount++;
			}
			_option.slideSel.width(_width * appendCount);
		}
		
		
		function slideStart(){
			slide(_option);
		}
		
		
		function slide(opt){
			var _first = opt.slideSel.find('li').filter(':first');
			var d = ~~Math.abs(opt.time / opt.sp * _first.width() * 
				(_first.offset().left - opt.slideSel.offset().left < 0 ? 
					(_first.width() + _first.offset().left - opt.slideSel.offset().left) / _first.width() : 1 ));
					
			_first.animate({marginLeft: -1 * _first.width()},
						   {
							duration: d,
						    easing: "linear",
							complete: function(){
								_first.appendTo(opt.slideSel).css("marginLeft", 0);
								slide(opt);
							}});
			
		}
		
		
		function hoverOnEvent(){
			$(this).find('li').stop();
		}
		
		
		function hoverOffEvent(){
			slideStart();
		}
		
		
		init();
	}
	
})(jQuery);


