/**
 * @class This class represents an application event, provides mechanisms to
 * subscribe/unsubscribe listeners.
 * @constructor
 *
 * @param {String} name The event name.
 * @return A new event.
 */
HD.util.Event = function(name) {
	/**
	* @private
	*/
	this.name = name;
	
	/**
	* @private
	*/	
	this.listeners = [];
};

/**
 * Function for subscribing a listener.
 *
 * @param {Function} listener The function to add to the list of listeners.
 */
HD.util.Event.prototype.subscribe = function(listener) {
	this.listeners.push(listener);
};

/**
 * Function for unsubscribing a listener.
 *
 * @param {Function} listener The function to remove from the list of listeners.
 */
HD.util.Event.prototype.unsubscribe = function(listener) {
	var tempListeners = [];
	for(var a = 0, len = this.listeners.length; a < len; a++) {
		var l = this.listeners[a];
		if(l != listener) {
			tempListeners.push(l);
		}
	}
	this.listeners = tempListeners;
};


/**
 * Function for unsubscribing all event listener functions.
 *
 */
HD.util.Event.prototype.unsubscribeAll = function() {
	this.listeners = [];
};

/**
 * Function for notifying event listeners that the event has taken place.
 *
 */
HD.util.Event.prototype.fire = function(object1, object2) {
	for(var a = 0, len = this.listeners.length; a < len; a++) {
		this.listeners[a](object1, object2);
	}
};

HD.register("hd_event", HD.util.Event, {version: "1.0", build: "1"});