(function(){
	if(typeof window.$JN == 'undefined'){
		window.$JN = {};
	}

	$JN.methods = {
		line : function(x){
			return	(x*x-0.005).toFixed(3);
		},
		normal : function(x){
			return x;
		},
		easeIn : function(x){
			return x*(2-x);
		},
		easeOut : function(x){
			return x*x;
		},
		backIn : function(x){
			return 1.5*x*x-0.5*x;
		},
		easeInBack: function(pos){
                    var s = 1.70158;
                    return (pos)*pos*((s+1)*pos - s);
                }
	};
	$JN.tween = function(elem, config){
		config = config || {};
		this.elem = elem;
		this.from = config.from || 0;	//	起始位置
		this.to = config.to || 0;	//	结束位置
		this.dire = config.dire || 'left';	//	滚动的方向
		this.durTime = config.durTime || 1000;	//	滚动所需的时间
		this.frame = config.frame || 50;	 //	滚动的帧数
		this.beginFun = config.beginFun || function(){};	//	滚动前执行的函数
		this.endFun = config.endFun || function(){};	//	滚动后执行的函数
		this.scrollEnd = config.scrollEnd || function(){};	//	滚动是否结束，回调函数
		this.method = $JN.methods[config.method] || $JN.methods.normal;	//	滚动函数
		this.startTime = null;
		this.endTime = null;
		this.beginTween();
	};
	$JN.tween.prototype = {
		beginTween : function(){
			this.startTime = new Date().getTime();
			this.beginFun();
			this.mTween();
		},
		mTween : function(){
			var	_this = this;
			(function(){
				_this.endTime = new Date().getTime();
				var offset = _this.method((_this.endTime - _this.startTime) / _this.durTime);
				if(offset < 1){
					_this.from = _this.from + (_this.to - _this.from) * offset;
					_this.elem.style[_this.dire] = _this.from + 'px';
					setTimeout(arguments.callee, _this.durTime/_this.frame);
				}else{
					_this.elem.style[_this.dire] = _this.to+'px';
					_this.endFun();
					_this.scrollEnd();
				}
			})();
		}
	}
})();