var AnimationHandler = {

	aAll : [],

	instance : function(iInterval) {
	
		this.aAll = [];
		this.iNewIndex = 0;
		this.iAnimationsCount = 0;
		this.bProcessing = false;
		this.tTimer = null;
		this.iInterval = iInterval;
		this.aFunctions = [];
		this.sId = AnimationHandler.aAll.length;
		
		AnimationHandler.aAll[this.sId] = this;
	
	}
	
}

AnimationHandler.instance.prototype = {		
	
	addAnimation : function(oAnimation) {
	
		this.aAll[++this.iNewIndex] = oAnimation;
		this.iAnimationsCount++;
		
		return this.iNewIndex;		
	
	},
	
	removeAnimation : function(iIndex) {
		
		this.aAll[iIndex] = null;	
		this.iAnimationsCount--;		
		
	},
	
	start : function(oFunction) {
		
		if(!this.bProcessing) {
		
			this.bProcessing = true;		
			this.tTimer = setInterval('AnimationHandler.aAll[' + this.sId + '].process()', this.iInterval);							
			
		}
		
		if(oFunction) {
			this.aFunctions[this.aFunctions.length] = oFunction;
		}		
	
	},
	
	process : function() {
		
		if(this.iAnimationsCount > 0) {
			
			for(var i in this.aAll) {					
			
				if(this.aAll[i] && this.aAll[i].process) {
					this.aAll[i].process();
				}
				
			}
			
		}
		else {
		
			this.bProcessing = false;
		
			clearInterval(this.tTimer);						
			
			if(this.aFunctions.length > 0) {
			
				for(var i in this.aFunctions) {
			
					if(this.aFunctions[i].fFunction) {				
					
						this.aFunctions[i].fFunction(this.aFunctions[i].aParams);			
						delete this.aFunctions[i];
						
					}
					
				}
				
			}
			
		}
	
	}
	
}