Controller = new Class(Object, {

  init: function () {
    Controller.superClass.init.apply(this, arguments);

    this.handlers = {};
  },

  registerActionHandler: function (action, handler) {
    if (!this.handlers[action])
      this.handlers[action] = [];

    // make sure this is an array
    if (!this.handlers[action].push)
      return;

    this.handlers[action].push(handler);
  },

  // accepts a hash of action => handler pairs
  registerActionHandlers: function (handlers) {
    for (var action in handlers) {
      var handler = handlers[action];

      if (!handler || !action || action == 'hasOwnMethod')
        continue;

      this.registerActionHandler(action, handler);
    }
  },

  removeActionHandler: function (action, handler) {
    if (!this.handlers[action])
      return;

    this.handlers[action].remove(handler);
  },

  dispatchAction: function (action, data) {
    var handlers = this.handlers[action];

    if (!handlers)
      return;

    for (i=0; i<handlers.length; i++) {
      if (handlers[i])
        handlers[i].apply(this, [data]);
    }
  }

});
