
function OvalonEvent() {
	this.handlers = new Array();
	this.addHandler = function (method, caller, persistent) {
		if(caller != null && ((typeof caller) != 'object')) return false;
		if(typeof method != 'function') return false;
		if(this.containsHandler(method, caller)) return false;
		this.handlers[this.handlers.length] = [method, caller, persistent];
		return true;
	}
	this.removeHandler = function (method, caller) {
		if(caller != null && ((typeof caller) != 'object')) return false;
		if(typeof method != 'function') return false;
		for(var i=0; i<this.handlers.length; i++) {
			var h = this.handlers[i];
			if(h[0] == method && h[1] == caller) {
				this.handlers.removeElementAt(i);
				return true;
			}
		}
		return false;
	}
	this.containsHandler = function (method, caller) {
		if(caller != null && ((typeof caller) != 'object')) return false;
		if(typeof method != 'function') return false;
		for(var i=0; i<this.handlers.length; i++) {
			var h = this.handlers[i];
			if(h[0] == method && h[1] == caller) {
				return true;
			}
		}
		return false;
	}
	this.call = function(sender) {
		for(var i=0; i<this.handlers.length; i++) {
			var h = this.handlers[i];
			if(h[1] != null) {
				h[0](this, sender);
			} else {
				h[0].call(h[1], this, sender);
			}
		}
	}
	this.clearHandlers = function() {
    var i = this.handlers.length;
    while(--i >= 0) {
    	if(this.handlers[i][2] != true)
				this.removeHandler(this.handlers[i][0], this.handlers[i][1]);
    }
	}
	this.getNumHandlers = function() {
    return this.handlers.length;
	}
}
