// Controls the team list on the page.
var LightBox = Class.create({
   initialize: function() {
      if(!$('lightbox')) {
         Element.insert(document.body, '<div id="lightbox"><a href="#" id="lbClose">Close<span></span></a><div id="lbContent"></div></div>');
         Element.insert(document.body, '<div id="lightbox_fade"></div>');
      }
      this.lightbox = $('lightbox');
      this.fade = $('lightbox_fade');
      this.close = $('lbClose');
      this.contents = $('lbContent');
      this.lightbox.hide();
      this.fade.hide();
      this.transition = 0.5;
      Event.observe(this.close, 'click', this.hide.bindAsEventListener(this));
   },
   
   insertContent: function(contents) {
      this.contents.innerHTML = contents;
   },
   
   show: function() {
      new Effect.Appear(this.fade, {
         duration: this.transition,
         from: 0, to: 0.5
      });
      new Effect.Appear(this.lightbox, {
         duration: this.transition,
         delay: this.transition
      });
   },
   
   hide: function(e) {
      e.stop();
      new Effect.Fade(this.fade, {
         duration: this.transition,
         delay: this.transition,
         from: 0.5, to: 0
      });
      new Effect.Fade(this.lightbox, {
         duration: this.transition
      });
   }
});

var SimpleLightBox = Class.create({
   initialize: function(element) {
      this.element = element;      
      // Grab bio information and reset link.
      this.contents = $(this.element.hash.substr(1));
      if(this.contents) {
         this.contents.hide();
      }
      Event.observe(this.element, 'click', this.showContents.bindAsEventListener(this));
      this.lightbox = new LightBox();
   },
   showContents: function(e){
      e.stop();
      $('lbContent').innerHTML = this.contents.innerHTML;
      this.lightbox.show();
   }
});

// Extending all elements to support special interactive functionality.
function setupLightBoxes(e){ 
   $$('.lbOn').each(function(link){
      var lb_on = new SimpleLightBox(link);
   });
}

Event.observe(window, 'load', setupLightBoxes);
