function N2EventManager()
{
    this.aEvents = {};
    
    // 1) Register a widget to be notified when any event in the
    // given list is published.
    // ARGS: oWidget a ref to a widget
    //       aMessages a ref to an array of events to subscribe to
    this.subscribe = function(oWidget, aEvents)
    {
        var i;
        for (i = 0; i< aEvents.length; i++)
        {
            var sEvent = aEvents[i];
            var aWidgets = this.aEvents[sEvent];
            if (!aWidgets)
            {
                aWidgets = this.aEvents[sEvent] = [];
            }
            // Push widget onto array
            aWidgets.push(oWidget);
        }
    };

	this.unsubscribe = function(oWidget)
    {
        for (var i in this.aEvents)
        {
            var aWidgets = this.aEvents[i];
            // Push widget onto array
			for (a = 0; a< aWidgets.length; a++){
				if (aWidgets[a] === oWidget){
					aWidgets.splice(a,1);
				}
			}
        }
    };
    
    // 2) When an event comes in notify all the widgets that have 
    // subscribed to the event
    this.publish = function(oSrcWidget, sEvent, oData)
    {   
        var aWidgets = this.aEvents[sEvent];
        if (aWidgets)
        {
            var i;
            for (i = 0; i < aWidgets.length; i++)
            {
                var oWidget = aWidgets[i];
				//debgdiv("e: " + sEvent + " : "+oWidget.oname);
                oWidget.onEvent(oSrcWidget, sEvent, oData);
            }
        }    
    };
}
