var animIndex = 0;
var animArray = new Array();

var opera = /opera/gi.test(navigator.userAgent);

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 (document.all)	// IE4
				this.elstyle = document.all[this.id].style;
			else if (document.getElementById)	// NGLayout
				this.elstyle = document.getElementById(this.id).style;
			else if (document.layers)	// nn4.x
				this.elstyle = document.layers[this.id]
			else
				return;
		}
		if (this.path.step()) {					// mozilla test hack
			this.elstyle.left = this.path.x + (opera ? 0 : "px");
			this.elstyle.top  = this.path.y + (opera ? 0 : "px");
			animArray[this.index].timer = setTimeout(this.thisString + ".play()", this.msec);
			//alert(this.elstyle.top);
		}
		else if (this.onanimationdone != null) {
			if (typeof(this.onanimationdone) == "string")
				eval(this.onanimationdone);
			else if (typeof(this.onanimationdone) == "function")
				this.onanimationdone();
		}
	}
	
	function int_pause() {
		clearTimeout(animArray[this.index].timer);
	}
	
	function int_stop() {
		clearTimeout(animArray[this.index].timer);
		this.path.reset();
	}
}