/**
 * @class HD.util.Queue
 * @description A reusable class that other classes can extend with to provide an function queue
 * @constructor
 */
HD.util.Queue = function() {
	this.items = [];
};

HD.util.Queue.prototype = {
	/**
	 * Adds an item to the queue
	 * @param {function} item The function to add to the queue
	 */
	add : function(item) {
		this.items.push(item);				
	},
	
	/**
	 * Removes an item from the queue
	 * @param {function} item The function to remove to the queue
	 */
	remove : function(item) {
		var tempItems = [];
		var items = this.items;
		for(var i = 0, len = items.length; i < len; i++) {
			var tempItem = items[i];
			if(tempItem != item) {
				tempItems.push(tempItem);
			}
		}
		
		this.items = tempItems;
	},
	
	/**
	 * Executes all items within the queue and then clears it
	 */
	execute : function() {
		var items = this.items;
		for(var i = items.length - 1; i > -1; i--) {
			items[i]();
		}
		this.clear();
	},
	
	/**
	 * Clears the queue
	 */
	clear : function() {
		this.items = [];
	},
	
	/**
	 * Checks for the existence of an item within the queue
	 * @param {function} item The function to search for
	 * @returns {boolean}
	 */
	contains : function(item) {
		var items = this.items;		
		for(var i = 0, len = items.length; i < len; i++) {
			var tempItem = items[i];
			if(tempItem == item) {
				return true;
			}
		}		
		return false;
	}
};

HD.register("hd_queue", HD.util.Queue, {version: "1.0", build: "1"});
