function Event()
{
    this._binds = new Array();
}

Event.prototype.Bind = function(method, object)
{
    if (method == null) return;
    
    if (object == null) object = window;
    this._binds.push({ Method: method, Param: object });
}

Event.prototype.Unbind = function(method, userParam)
{
    for(var i in this._binds){
        var bind = this._binds[i];
        if (bind.Method == method && bind.Param == userParam){
            this._binds = this._binds.splice(i, 1);
            return;
        }
    }
}

Event.prototype.Trigger = function(params)
{
    if (params == null) params = new Array();
    
    var RemoveBinds = new Array;
    
    // trigger all binds
    for (var i = 0; i < this._binds.length; i++)
    {
        var bind = this._binds[i];
        
        try {
            bind.Method.apply(bind.Param, params);
        } catch (e)
        {
            RemoveBinds.push(bind);
        }
    }        
    
    // remove any binds that give an error
    for(var i in RemoveBinds){
        this.Unbind(RemoveBinds[i]);
    }
}
