/**
 * Generic Event Object
 */
Generic_Event = function() {
	this.observers = [];
	
};
Generic_Event.prototype = {
	/**
	 * Adds an observer for this event
	 * @param {Function} fn
	 * @param {Object} scope to call fn()
	 */
	addObserver: function(fn, scope) {
		//alert('AddObserver: '+fn);
		if (scope) {
			this.observers.push(function() {
				//alert('arguments: '+arguments.toString())
				fn.apply(scope, arguments);
			});
		} else {
			this.observers.push(fn);
		}
	},
	/**
	 * Removes the Observer equivalent to "fn"
	 * @param {Function} fn
	 */
	removeObserver: function(fn) {
		for(var i = 0; i < this.observers.length; i++) {
			if (this.observers[i] == fn) {
				this.observers[i] = function() { /* removed */ };
				return true;
			}
		}
		return false;
	},
	/**
	 * Trigger all the Observers Attached to this Event
	 * @param {Array} Arguments
	 * @param {Object} Scope to call observer methods from
	 */
	triggerEvent: function(args, scope) {
		//alert('Observers: '+this.observers);
		for(var i = 0; i < this.observers.length; i++) {
			if (this.observers[i].apply(scope || this, args) === false) {
				return false;
			}
		}
		return true;
	}
};

