var animIndex = 0;
var animArray = new Array();

function Animator(id, p, period) {
	this.play = int_play;
	this.pause = int_pause;
	this.stop = int_stop;
	this.onanimationdone;
	this.elstyle = null;	
	this.path = p;
	this.msec = period;
	this.id = id;
	
	this.index = animIndex;
	animArray[this.index] = this;
	this.thisString = "animArray[" + this.index + "]";
	animIndex++;
	
	function int_play() {
		if (this.elstyle == null) {
			this.elstyle = (document.all != null) ? document.all[this.id].style : document.layers[this.id];
		} 
		if (this.path.step()) {
			this.elstyle.left = this.path.x;
			this.elstyle.top  = this.path.y;
			animArray[this.index].timer = setTimeout(this.thisString + ".play()", this.msec);
		}
		else if (this.onanimationdone != null)
			eval(this.onanimationdone);
	}
	
	function int_pause() {
		clearTimeout(animArray[this.index].timer);
	}
	
	function int_stop() {
		clearTimeout(animArray[this.index].timer);
		this.path.reset();
	}
}