function Interpolator(v1, v2) {
	this.v1 = v1;
	this.v2 = v2;
}
Interpolator.prototype.getIntValue = function(factor) {
	return Math.ceil(this.v1 + (this.v2 - this.v1) * factor);
}

var _iplmgr = {};
var _iplmgrCounter = 0;
function InterpolatorManager() {
	this.factor = 0;
	this.exclude = {
		exclude		 : 1,
		init		 : 1,
		run			 : 1,
		onStep		 : 1,
		factor		 : 1,
		_interpolate : 1,
		_step		 : 1,
		_nextStep	 : 1,
		_key		 : 1
	} 
}
InterpolatorManager.prototype.init = function(duration, steps) {
	// debugger;
	var ipols = {};
	for (var key in this) {
		if (!this.exclude[key]) {
			ipols[key] = this[key];
			delete this[key];
		}
	}
	this.ipols = ipols;	

	this.duration = duration;
	this.steps = steps;

	this.curDur = 0;
	this.stepDur = Math.floor(duration / steps);
	this.curStep = 0;
	
	this._key = 'i'+(_iplmgrCounter++);
	_iplmgr[this._key] = this;
 
	var time = 0;

	// initial
	this._interpolate();
	this.onStep();
}
InterpolatorManager.prototype.run = function(){
	this._nextStep();
}

InterpolatorManager.prototype._interpolate = function(){
	// debugger;
	if (this.curStep == this.steps) 
		this.factor = 1;
	else 
		this.factor = this.curDur / this.duration;
	
	for (var key in this.ipols) {
		var ipol = this.ipols[key];
		this[key] = ipol.getIntValue(this.factor);
	}
}

InterpolatorManager.prototype._step = function() {
	this.curStep++;
	this.curDur += this.stepDur;

	this._interpolate();
	this.onStep();

	if (this.factor == 1) 
		delete _iplmgr[this._key];
	else 
		this._nextStep();
}

InterpolatorManager.prototype._nextStep = function() {
	setTimeout('_iplmgr.'+this._key+'._step()', this.stepDur);
}

/* override this */
InterpolatorManager.prototype.onStep = function(){
}

