var Navigation = Class.create({
  initialize: function() {
    this._triggers = $$('span.trigger');
    this._init();
  },
  _init: function() {
    if (this._triggers.size() > 0) {
      this._triggers.each(function(trig) {
        trig.observe('click', this._expandCollapse.curry(trig).bind(this));
        if (Prototype.Browser.IE) {
          this._setupIEHover(trig);
        }
      }, this);
    }
  },
  _expandCollapse: function(span) {
    var clicked = span.readAttribute('id');
    var openSub = $(clicked + "-subnav");
    Effect.SlideDown(openSub, { queue: 'front' });
    this._triggers.each(function(trig) {
      var thisSub = $(trig.readAttribute('id') + '-subnav');
      if (thisSub != openSub && thisSub.readAttribute('display') != 'none') {
        thisSub.hide();
      }
    });
  },
  _setupIEHover: function(span) {
    span.observe('mouseover', function() {
      this.setStyle({
        cursor: 'pointer',
        color: '#099'
      });
    }, span);
    span.observe('mouseout', function() {
      this.setStyle({
        color: '#620000'
      });
    }, span);
  }
});
document.observe('dom:loaded', function() {
  new Navigation();
});