/*

Class: Controllers

This is a namespace for all the classes that control interactive behavior on the
page. It also manages event messaging so that controllers can communicate with
each other.

*/
var Controllers = new Class({

  Implements: Events,
  
  initialize: function(cssPrefix) {
    this.controllers = [];
    window.addEvent('domready', this.initializeControllers.bind(this, cssPrefix));
  },
  
  initializeControllers: function(cssPrefix) {
    
    // After the page loads, search for elements with particular CSS classes
    // that correspond to JavaScript behavior controllers.
    
    for (property in this) {
      if ($type(this[property]) != 'class') {
        continue;
      }
      dbug.log(property);
      $$('.' + cssPrefix + property).each(function(el) {
        try {
          var Controller = this[property];
          this.controllers.push(new Controller(el, this));
        } catch(e) {
          dbug.log(e.message);
        }
      }.bind(this));
    }
    this.fireEvent('onInitialize');
    
  }
  
});

dbug.enable();
var Page = new Controllers('JS_');

// In another file, calendar.js
Page.Calendar = new Class({
  initialize: function(el, page) {
    // ...
  }
});