// Event handler
//--------------------------------------------------------
function EventHandler() {
    this.fns = [];
}

EventHandler.prototype = {
    subscribe : function(fn) 
    {   
//        fn.fn = fn;
//        this.fns.push(fn);
        var bExists = false;
        var i = 0;
        while (i < this.fns.length) {
            if (this.fns[i] == fn) {
                bExists = true;
                break;
            } else {
                i++;
            }
        }
        
        if(bExists == false) {
            this.fns.push(fn);
        }
    },
    unsubscribe : function(fn) 
    {
        var i = 0;
        while (i < this.fns.length) {
            if (this.fns[i] == fn) {
                this.fns.splice(i, 1);
            } else {
                i++;
            }
        }
    },
    fire : function(o, thisObj) 
    {
        var scope = thisObj || window;
        for (var i = 0; i < this.fns.length; i++) //obj in this.fns)
        {
            try 
            {
                if(typeof(this.fns[i])=='function')
                    this.fns[i](o);
            } 
            catch ( e)
            {
               alert("catch: " + typeof(e));
               // log("catch: " + typeof(e));
            }
            
        }
    }
};
//--------------------------------------------------------