/**
* AnimationEngine
*
* Organization behind an animation.  The AnimationEngine contains an array of AnimationSteppers which it iterates through each time step
* is called on the Engine.  
**/
function AnimationEngine() { 

	this.stepper_array = new Array();

}

new AnimationEngine();

/**
* AnimationEngine.addAnimationStepper
*
* Add an animation stepper to the stepper_array
*
* @param s The AnimationStepper to add
**/
AnimationEngine.prototype.addAnimationStepper = function( s ) { 

	this.stepper_array.push( s );

}

/**
* AnimationEngine.step
*
* Iterate through all contained AnimationSteppers, calling step on each of them.  As step is called on each AnimationStepper, the return 
* value of step is checked.  If that value is false, that indicates that the AnimationStepper is done animating and should be removed from 
* the engine.
**/
AnimationEngine.prototype.step = function() { 

	for ( var i=0; i<this.stepper_array.length; i++ ) { 
		if ( ! this.stepper_array[i].step() ) 
			this.stepper_array.splice(i,1);
	}

}

/**
* AnimationEngine.getEngineClosure
*
* @returns A closure containing the AnimationEngine and a call to the step function of said engine
**/
AnimationEngine.prototype.getEngineClosure = function() { 

	var animation_engine = this;
	
	return function() { animation_engine.step(); } ;

}

/**
* AnimationEngine.startEngine
*
* Create a closure function and attach it to the increment runner using the given increment amount
*
* @param interval_amount in ms
**/
AnimationEngine.prototype.startEngine = function( interval_amount ) { 

	setInterval( this.getEngineClosure(), interval_amount );

}

