/* 
Quick port of Adobe Flash Tween class
Requires common.js and easing_equations.js

Author: Sergey Chikuyonok (gonarch@design.ru)
17.09.2006
*/ 

function Tween(elemTarget, sStyleProperty, oEaseType, iStartValue, iEndValue, iDuration){
	this.target=elemTarget;
	this.time=0;
	this.duration=iDuration;
	this.position=iStartValue;
	this.finish=parseInt(iEndValue);
	
	/* private properties */
	this._style=elemTarget.style;
	this._prop=sStyleProperty;
	this._ease=oEaseType;
	this._start=parseInt(iStartValue);
	this._change=this.finish - this._start;
	this._animate=true;
	
	this.constructor._add(this);
}

Tween.aStack=[];
Tween._poll=function(){
	for(var i=0; i<this.aStack.length; i++){
		this.aStack[i]._onMotion();
	}
}

Tween._add=function(obj){
	this.aStack.push(obj);
}

Tween._remove=function(obj){
	this.aStack.remove(obj);
}

Tween.prototype._onMotion=function(){
	if(this._animate){
		if(this.time < this.duration){
			this.time++;
			this.position=this._ease(this.time, this._start, this._change, this.duration, 50, 1.1);
			this._style[this._prop]=this.position + "px";
//			alert(this._style[this._prop]);
			this.onMotionChanged();
			if(this.time == this.duration){
				this.onMotionFinished();
				this.constructor._remove(this);
			}
		}
		else{
			this.onMotionFinished();
			this.constructor._remove(this);
		}
	}
}

Tween.prototype.onMotionChanged=function(){
	return;
}

Tween.prototype.onMotionFinished=function(){
	return;
}

setInterval('Tween._poll()', 20);