var Site = {

  overlay: null,

  init: function() {

    if (Browser.Engine.trident) { Site.fixTables(); }
    Popup.init();
    Coverage.init();
    About.init();

  },

  fixTables: function() {
    $$('table').set('cellspacing', 0);
  }

};

var Popup = {

  overlay: null,

  pop: null,

  init: function() {
    Popup.overlay = new Element('div', {
      'id': 'overlay',
      'styles': {
        'width': document.body.scrollWidth,
        'height': document.body.scrollHeight,
        'opacity': .5
      }
    });

    $('share_link').addEvent('click', function() {
      Popup.open('sharePopup');
      return false;
    });

  },

  open: function(box) {
    Popup.overlay.inject(document.body);
    $(box).setStyles({
      'display': 'block',
      'left': (document.body.scrollWidth / 2) - (480 / 2)
    });
  }

};

var Coverage = {

  panels: ['print', 'online', 'radio', 'tv'],

  init: function() {

    if (document.getElementById(Coverage.panels[0])) {
      for (var i = 0; i < Coverage.panels.length; i++) {
        $(Coverage.panels[i] + '_btn').addEvent('click', function() {
          Coverage.toggleAll(this.id);
        });
        if (About.panels[i] == window.location.hash.substr(1)) {
          Coverage.toggleAll(Coverage.panels[i] + '_btn');
        } else {
          Coverage.toggleAll(Coverage.panels[0] + '_btn');
        }
      }
    }

  },

  toggleAll: function(id) {
    for (var i = 0; i < Coverage.panels.length; i++) {
      if (id == Coverage.panels[i] + '_btn') {
        $(Coverage.panels[i] + '_btn').addClass('active');
        $(Coverage.panels[i]).removeClass('inactive');
      } else {
        $(Coverage.panels[i] + '_btn').removeClass('active');
        $(Coverage.panels[i]).addClass('inactive');
      }
    }
  }

};

var About = {

  panels: ['video', 'story', 'vision', 'why', 'resources', 'thanks'],

  init: function() {

    if (document.getElementById(About.panels[0])) {
      for (var i = 0; i < About.panels.length; i++) {
        $(About.panels[i] + '_btn').addEvent('click', function() {
          About.toggleAll(this.id);
        });
        if (About.panels[i] == window.location.hash.substr(1)) {
          About.toggleAll(About.panels[i] + '_btn');
        } else {
          About.toggleAll(About.panels[0] + '_btn');
        }
      }
    }

  },

  toggleAll: function(id) {
    for (var i = 0; i < About.panels.length; i++) {
      if (id == About.panels[i] + '_btn') {
        $(About.panels[i] + '_btn').addClass('active');
        $(About.panels[i]).removeClass('inactive');
      } else {
        $(About.panels[i] + '_btn').removeClass('active');
        $(About.panels[i]).addClass('inactive');
      }
    }
  }

};


window.addEvent('domready', function() {
  Site.init();
});
