(function ($) {
	var feature = mm.extend({
		//初回時スクロール開始までのライムラグ
		initScrollTimeout: 500,
		//スクロールする移動スピード(ミリ秒)
		scrollSpead: 250,
		//スクロールする時間間隔(ミリ秒)
		scrollInterval: 5000,
		
//=========================================================================================//
		
		lock:  false,
		intTimer: null,
		timeoutTimer: null,
		
		init: function () {
			var ul      = $('div#frm-feature-scroll ul');
			var prev_li = ul.find('li:first');
			var next_li = ul.find('li:last');
			var move    = 233;
			
			setTimeout(this.bind(function () {
				ul.animate({left: 0}, 500, this.bind(function () {
					this.ctrl();
					this.initSetTimeout();
				}));
			}), this.initScrollTimeout);
		},
		
		initSetTimeout: function () {
			if (!this.featureTimer) {
				this.timeoutTimer = setTimeout(this.bind(function () {
					this.ctrlNext();
						this.initSetTimer();
				}), this.scrollInterval);
			}
		},
		
		initSetTimer: function () {
			this.intTimer = setInterval(this.bind(function () {
				this.ctrlNext();
			}), this.scrollInterval);
		},
		
		ctrl: function () {
			var ul   = $('div#frm-feature-scroll ul');
			var prev = $('div#frm-feature-ctrl-left a');
			var next = $('div#frm-feature-ctrl-right a');
			var move = 233;
			this.lock = false;
			
			prev.click(this.bind(function () {
				if (this.lock)
			    return false;
			  this.lock = true;
				
				clearTimeout(this.timeoutTimer);
				clearInterval(this.intTimer);
				this.ctrlPrev();
				this.initSetTimer();
			  return false;
			}));
			
			next.click(this.bind(function () {
			  if (this.lock)
			    return false;
			  this.lock = true;
				
				clearTimeout(this.timeoutTimer);
				clearInterval(this.intTimer);
				this.ctrlNext();
				this.initSetTimer();
				return false;
			}));
		},
		
		ctrlPrev: function () {
			var ul   = $('div#frm-feature-scroll ul');
			var prev = $('div#frm-feature-ctrl-left a');
			var next = $('div#frm-feature-ctrl-right a');
			var move = 233;
		  
			var next_li = ul.find('li:last');
	    ul.prepend(next_li.clone());
	   	ul.css({left: -233 });
		  ul.animate({left: '+=' + move}, this.scrollSpead, this.bind(function () {
		    now = parseInt($(ul).css('left'));
		    ul.find('li:last').remove();
		    this.lock = false;
		  }));
		},
		
		ctrlNext: function () {
			var ul   = $('div#frm-feature-scroll ul');
			var prev = $('div#frm-feature-ctrl-left a');
			var next = $('div#frm-feature-ctrl-right a');
			var move = 233;
		  
			var prev_li = ul.find('li:first');
	    ul.append(prev_li.clone());
		  ul.animate({left: '-=' + move}, this.scrollSpead, this.bind(function () {
		    now = parseInt($(ul).css('left'));
		    ul.find('li:first').remove();
		    ul.css({left: 0});
		    this.lock = false;
		  }));
		}
	});
	
	$(feature.bind(feature.init));
})(jQuery);
