AnimatorEffects = {
	linear: function (x) { return x; },
	up: function (x) { return Math.pow (x, 4); },
	down: function (x) { return -1 * Math.pow (x - 1, 4) + 1; }
}

Animator = Class.create ();
Animator.prototype = {
	minStep: 10,
	duration: 1000,
	effect: AnimatorEffects.linear,

	initialize: function (options) {
		if (options.minStep != undefined) this.minStep = options.minStep;
		if (options.duration != undefined) this.duration = options.duration;
		if (options.effect != undefined) this.effect = options.effect;
		if (options.onComplete != undefined) this.onComplete = options.onComplete;
		this.action = options.action;
		this.timeStart = new Date ().getTime ();
		this.timeEnd = this.timeStart + this.duration;
		this.doAnimate ();
	},

	doAnimate: function () {
		var time = new Date ().getTime ();
		var y = this.effect ((time - this.timeStart) / this.duration);
		this.action (y);
		if (time < this.timeEnd) {
			window.setTimeout (this.doAnimate.bind (this), this.minStep);
		} else {
			this.action (1);
			if (this.onComplete != undefined) this.onComplete ();
		}
	}
}

