/***************************************************************************
	Animation - Animation object.
	
	Contains an array of objects of type 'Animate' or inherit from it.
	
	Version:
		v0.1, Monday, July 08, 2002
	
	Requires:
		
	Author:
		Alexander Whillas

	Copyright (C) 2002 Taylor Square Designs
***************************************************************************/
function Animation (p_msec) {
	// Flag to indicate wether we are animating or not.
	this.greenLight = true;
	// Number of millie second between time outs.
	this.timeout = p_msec;
	// Array that will hold all the objects of type 'Animate'.
	this.sprites = new Array();
	
	// The setTimeout() function needs an absolute eference to this object to make one up.
	this.obj = "Object" + Math.round(Math.random() * 1000);
	eval(this.obj + " = this;");
	
	return this;
}

// Acceps a variable number of sprite objets and adds them to its internal array of sprite to animate.
Animation.prototype.addSprites = function (p_sprites) {
	if (Animation.prototype.addSprites.arguments)
		for (var i = 0; i < Animation.prototype.addSprites.arguments.length; i++)
			this.sprites[this.sprites.length] = Animation.prototype.addSprites.arguments[i];

	return true;
}

Animation.prototype.addSpritesArray = function (p_sprite_array) {
	this.sprites = this.sprites.concat(p_sprite_array);

	return true;
}

// IE Arrays done seem to suport teh push() method?
Animation.prototype.addSprite = function (p_sprite) {
	return this.sprites.push(p_sprite);
}

Animation.prototype.start = function () {
	this.greenLight = true;
	this.animate();
	return true;
}

Animation.prototype.stop = function () {
	this.greenLight = false;
	return true;
}

Animation.prototype.animate = function () {
	if (this.greenLight)
		for (var i = 0; i < this.sprites.length; i++)
			this.sprites[i].move();
			
	window.setTimeout(this.obj+".animate()", this.timeout);
}

Animation.prototype.toString = function () { 
	return "Animation Object: " +  this.obj;
}