var tips = new Hash();

function loadHelpers(){
  var helpers = $$('.helper');

  for(i=0; i<helpers.length; i++){
    var hid = helpers[i].id;
    // Element.observe(hid, 'mouseover', showTip);
    Element.observe(hid, 'click', showTip);
    // Element.observe(hid, 'mouseout', hideTip);
    tips.set(hid, $(hid).title);
    $(hid).removeAttribute('title');
    }
  Event.observe(document, 'keydown', function(e){
    if((e.keyCode == Event.KEY_ESC) || (e.charCode == 27)){
      hideTip();
      }
    });
  }


function showTip(){
  var help_id = this.id;  
  var loc = $(help_id).positionedOffset();
  var left = loc[0] + 20;
  if(left > 800){
    left = loc[0] - 320;
    }
  var top = loc[1] - 10;
  $('help_box').setStyle({left: left + "px"});
  $('help_box').setStyle({top: top + "px"});
  $('help_box').update("");
  $('help_box').insert(tips.get(help_id));  
  $('help_box').insert('<a href="javascript:void(0);" onclick="hideTip();return false;" class="close_help">[close]</a>');
  $(help_id).writeAttribute("title","");
  $('help_box').show();
  }


function hideTip(){
  $('help_box').hide();
  }


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


