/**
 * Created by Benny on 12.10.2014.
 */

"use strict";

var TB = TB || {};

TB.EventDispatcher = function() {
    var _prefix = 'on_',
        _listeners = {};
    this.register = function(evt_name, bind, callback) {
        var _evt_name = _prefix + evt_name;
        if(typeof _listeners[_evt_name] == 'undefined') {
            _listeners[_evt_name] = [];
        }
        _listeners[_evt_name].push([bind === null ? this : bind, callback]);
    };

    this.emit = function(evt_name, params) {
        var _evt_name = _prefix + evt_name;
        if(typeof _listeners[_evt_name] != 'undefined') {
            for(var i = 0, l = _listeners[_evt_name].length; i < l; i++) {
                _listeners[_evt_name][i][1].call(_listeners[_evt_name][i][0], params, evt_name );
            }
        }
    };
};