var Navigation = Class.create();
Navigation.prototype = {
  initialize: function() {
    this.image  = $('home').down('img');
    this.header = $('header');
    this.toggle = true;
  },

  observe: function() {
    this.image.observe('mouseover', this.show.bind(this));
  },

  enable: function() {
    this.toggle = true;
  },

  disable: function() {
    this.toggle = false;
  },

  static: function() {
    this.header.show();
    this.image.setOpacity(.25);
  },

  show: function() {
    var op = this.image.getStyle('opacity');
    
    if (this.toggle && (op == 1 || op == undefined)) {
      this.disable();
      this.header.setOpacity(0);
      this.header.show();
      this.header.fade({ from:0, to:1, duration:1 });      
      this.image.fade({ from:1, to:.25, duration:1, afterFinish:this.enable.bind(this) });
    }
  },

  hide: function() {
    if (this.toggle) {
      this.disable();
      this.header.fade({ from:1, to:0, duration:1 });
      this.image.fade({ from:.25, to:1, duration:1, afterFinish:this.enable.bind(this) });
    }
  }
}


function set_container_height() {
  var outer = $('content');
  var inner = $('content-inner');

  if (inner && inner.getHeight() < 715) {
    outer.setStyle({height:'715px'});
  }  
}

function set_external_links() {
  $$('a.external').invoke('observe', 'click', function(e) {
    window.open(Event.element(e).href, '_blank');
    Event.stop(e);
  });
}

function set_images() {
  $$('#news .post img', '#news .post object').each(function(el) {
    var div = new Element('div', { 'class': 'image' });
    el.wrap(div);
  });
}


document.observe('dom:loaded', function() {
  setTimeout(set_container_height, 500);
  set_external_links();
  set_images();
});