var MoverSlide = function(elementName) {
	this.initialize(elementName);
};
MoverSlide.prototype = {
	flame      : 12,
	startPoint : 0,
	endPoint   : 0,
	nowPoint   : 0,
	showWidth  : 208,
	moveWidth  : 0,
	second     : 4,
	count      : 1,
	animation  : '',

	initialize: function(elementName){
		this.element = $('#' + elementName);
		this.setup();
	},

	info: function(){
		alert(this.nowPoint);
	},

	setup :function(){
		// endPointは、0で変動しない
		// startPointは、マイナスになる
		// moveWidth
		this.startPoint = this.showWidth - this.element.width();
		// 距離
		this.distance   = this.startPoint - this.endPoint;
		// 速度
		this.speed      = -(this.distance) / (this.second * this.flame);
		// debug
		// setInterval(this.counting.bind(this), (1000/this.flame));

	},

	start : function(){
		this.update();
	},

	back : function(){
		this.rollback();
	},

	update: function(){
		this.nowPoint = this.element.css('margin-left').replace('px', '');
		var speed = Math.floor(this.second * this.nowPoint/this.distance * 1000);
		this.element.animate({marginLeft: this.endPoint}, speed, 'linear');
	},

	rollback: function(){
		this.nowPoint = this.element.css('margin-left').replace('px', '');
		var speed = Math.floor(this.second * (this.distance - this.nowPoint)/this.distance * 1000);
		this.element.animate({marginLeft: this.startPoint}, speed, 'linear');
	},


	thisPoint: function(point){
		this.nowPoint = -point;
		this.element.css('margin-left', this.nowPoint + 'px');
	},

	// cancel時に場所を調整
	startCancel: function(){ //不要
		if(this.nowPoint != this.endPoint){
			this.element.css('margin-left', this.endPoint + 'px');
			this.cancel();
		}else{
			this.cancel();
		}
	},

	// cancel時に場所を調整
	rollbackCancel: function(){ //不要
		if(this.nowPoint != this.startPoint){
			this.element.css('margin-left', this.startPoint + 'px');
			this.cancel();
		}else{
			this.cancel();
		}
	},

	cancel : function(){
		this.element.stop();
	},

	counting : function(){
		if($('#count')){
			$('#count').html(this.nowPoint);
		}
	}
};

