function Umbrella() {
  
  this.contents = false;
  this.link_selector = '#umbrella li a';
  this.leave_selector = "#header_container #header";
  this.leave_delay = 500;
  this.leave_timer = null;

  var umbrella = this;
  
  this.bind = function() {
    this.contents = [];
    jQuery(this.link_selector).each(function(){
      var content = umbrella.content(this);
      if (!content) return;
      umbrella.contents.push(content);
      jQuery(this).click(umbrella.show);
    });
    jQuery(this.leave_selector)
      .hover(this.enter, this.leave);
  }

  this.enter = function() {
    if (umbrella.leave_timer) {
      clearTimeout(umbrella.leave_timer);
      umbrella.leave_timer = null;
    }
  }

  this.leave = function() {
    umbrella.enter();
    umbrella.leave_timer = setTimeout(umbrella.show, umbrella.leave_delay);
  }

  this.content = function(link) {
    var href = jQuery(link).attr('href');
    if (href) {
      var id = href.match(/#.+$/);
      if (id.length) {
        var content = jQuery(id[0]);
        if (content.length) {
          return content[0];
        }
      }
    }
    return false;
  }

  this.show = function() {
    jQuery(umbrella.contents).hide();
    if (this != undefined && this != umbrella) {
      jQuery(umbrella.content(this)).show();
    }
    return false;
  }
}

var umbrella = new Umbrella();

jQuery(function() {
  umbrella.bind();
  jQuery(".fc-rollover").each(function(){
    var cl = this.className.replace('fc-rollover', 'fc-rolledover');
    var src = this.src.replace(/(\.[a-zA-Z0-9]+)$/, "_ov$1");
    $('<img class="'+cl+'" src="'+src+'" alt="'+this.alt+'" />').appendTo($(this).parent());
  });
});

