/// class PD.EventBusManager

PD.EventBusManager = Class.extend({

    //===================================
    // FIELDS
    //===================================

    _global: null,
    _locals: null,
    _currentLocal: null,

    //===================================
    // CONSTRUCTOR
    //===================================

    init: function () {
        this._global = new PD.EventBus();
        this._locals = new PD.EventBusCollection();
    },

    //===================================
    // PROPERTIES
    //===================================

    get_currentLocalId: function () {
        return this._currentLocal;
    },

    //===================================
    // PUBLIC METHODS
    //===================================

    setLocal: function (id) {
        this._currentLocal = id;
        this._locals.add(id);
    },

    local: function (id) {
        var result = null;
        if (id != null) {
            result = this._locals.getById(id);
        }
        else {
            result = this._locals.getById(this._currentLocal);
        }
        return result;
    },

    global: function () {
        return this._global;
    },

    destroy: function (id) {
        this._locals.remove(id);
        if (this._currentLocal === id) {
            this._currentLocal = null;
        }
    }

});