var svt = {
  initialize: function() {
    this.boxes = $$('.box').map(function(box) {
      this.registerBox(box);
      return box;
    }.bind(this));
    this.sheets = $$('.sheet').map(function(sheet) {
      this.registerSheet(sheet);
      return sheet;
    }.bind(this));
    this.posts = $$('.post').map(function(post) {
      this.registerPost(post);
      return post;
    }.bind(this));
  },

  registerBox: function(box) {
    box.down('marquee').setAttribute('scrollamount', 1, 0);
    box.observe('mouseenter', function() {
      box.down('marquee').setAttribute('scrollamount', 6, 0);
      box.morph('background:#ec008c;', { duration: 1 });
    });
    box.observe('mouseleave', function() {
      box.down('marquee').setAttribute('scrollamount', 1, 0);
      box.morph('background:#000;', { duration: .4 });
    });
    box.observe('click', function(event) {
      if (event.element().tagName == 'EMBED' || event.element().tagName == 'OBJECT' || event.element().id == 'events')
        return;
      window.location = 'index.html#'+box.getAttribute('name');
    });
  },

  registerSheet: function(sheet) {
    var headline = sheet.down('h3');
    headline.observe('click', function(event) {
      event.stop();
      headline.toggleClassName('active');
      sheet.down('.sheet-content').toggle();
    });
  },

  registerPost: function(post) {
    post.observe('mouseenter', function() {
      post.down('h2').morph('color:#ec008c;', { duration: .4 });
    });
    post.observe('mouseleave', function() {
      post.down('h2').morph('color:#000;', { duration: .4 });
    });
  }
};

document.observe('dom:loaded', svt.initialize.bind(svt));