/*
 *	Usage:
 *	new W.Tween({start: x, change: dx, duration: 10, obj:this, bind: 'methodName', method: 'easeInOutQuad', callback: 'anotherMethodName'});
 */
W.Tween	= function(param)
{
	this.init(param);
};



W.Tween.prototype	= {

	interval	: 30,
	b			: 0,		// beginning value
	c			: 0,		// change in value
	d			: 0,		// duration
	t			: 0,		// current time
	a			: 0,		// amplitude
	p			: 0,		// period
	s			: 0,		// overshoot
	
	o			: null,		// object that initiated the tween
	om			: '',		// object method that is called
	f			: null,		// tween method
	
	timer		: null,		// timer
	
	event		: null,		// event object



	init : function(param)
	{
		var obj	= this;
		
		this.b	= param.start;
		this.c	= param.change;
		this.d	= param.duration;
		this.a	= param.amplitude;
		this.p	= param.period;
		this.s	= param.overshoot;
		
		this.o	= param.obj;
		this.om	= param.bind;
		this.f	= param.method;
		this.cb	= param.callback;
		
		//event	= w.Event.init(this);			// initialize custom event
		
		this.timer = setInterval(function() { obj.tween();}, this.interval);
		
	},
	
	
	
	tween : function()
	{
		++this.t;
		//trace('t: ' + t + ', d:' + d + ', c: ' + c + ', b: ' + b + ', mc: ' + mc + ', pr: ' + mc[pr] + ', f: ' + this[f]());
		if (this.t <= this.d) {		
			this.o[this.om](this[this.f]());
		} else {
			clearInterval(this.timer);
			if (this.cb) { this.o[this.cb](); }
		}
	},
	
	
	
	stop : function()
	{
		clearInterval(this.timer);
	},
	
	
	
	easeInOutQuad : function()
	{
		var t	= this.t;
		var b	= this.b;
		var c	= this.c;
		var d	= this.d;
		
		if ((t/=d/2) < 1) { return Math.floor((c/2*t*t + b)); }
		return Math.floor((-c/2 * ((--t)*(t-2) - 1) + b));
	},
	
	
	
	easeOutQuart : function()
	{
		var t	= this.t;
		var b	= this.b;
		var c	= this.c;
		var d	= this.d;
		
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	},



	easeInOutQuart : function() 
	{
		var t	= this.t;
		var b	= this.b;
		var c	= this.c;
		var d	= this.d;
		
		if ((t/=d/2) < 1) { return Math.floor(c/2*t*t*t*t + b); }
		return Math.floor((-c/2 * ((t-=2)*t*t*t - 2) + b));
	},
	
	
	
	easeInOutSine : function()
	{
		var t	= this.t;
		var b	= this.b;
		var c	= this.c;
		var d	= this.d;
		
		return Math.floor((-c/2 * (Math.cos(Math.PI*t/d) - 1) + b));
	}
};