var TabMenu = {

  close_all: function() {
    // hide all popups
    $$('.tab_menu_content').each(function(el) { el.hide() });
    // unmark current
    $$('table.tab_menu td.current').each(function(el) { el.removeClass('current') });
  },

  current: function(tab_el, menu_el) {

    // is this the current element?
    var amCurrent = $(tab_el).hasClass('current');

    // hide all popups
    TabMenu.close_all();

    // if this wasn't current, mark this current and show menu
    if (!amCurrent) {
      $(tab_el).addClass('current');
      $(menu_el).position({relativeTo:tab_el, position:'bottomLeft'});
      $(menu_el).show();
      var position = $(menu_el).getPosition();
      var size = $(menu_el).getSize();
      var window_size = window.getSize();
      if (position.x + size.x > window_size.x) {
        position.x = window_size.x - size.x;
        if (position.x < 0) position.x = 0;
        $(menu_el).setPosition(position);
      }
    } 

  }

};

