
// this script allows one menu on a page

var sm = null, timeout = null, to = null; code = null;
function pull_down(submenu,mi,right_offset) {
 off();
 on(submenu,mi,right_offset);
 if(code!=null) {
  eval(code);
 }
}
function pull_up(c) {
 code = c;
 timeout = setTimeout('off();'+code,1200);
}
function on(submenu,mi,right_offset) {
 if(submenu!=null) {
  var mih = mi.clientHeight;
  var miw = mi.clientWidth;
  var c = get_element_coordinates(mi);
  if(right_offset>0) {
   document.getElementById('sm'+submenu).style.left = c.x + miw - right_offset + 'px';
  }
  else {
   document.getElementById('sm'+submenu).style.left = c.x + 'px';
  }
  document.getElementById('sm'+submenu).style.top = c.y + mih + 'px';
  document.getElementById('sm'+submenu).style.display = 'block';
  sm = submenu;
 }
}
function off() {
 if(sm!=null) {
  document.getElementById('sm'+sm).style.display = 'none';
 }
 stop();
}
function stop() {
 if(timeout!=null) {
  clearTimeout(timeout);
 }
}
function swap(i,class_name) {
 document.getElementById(i).className = class_name;
}
function get_element_coordinates(e) {
 var x = 0, y = 0;
 if(e.offsetParent) {
  do {
   x += e.offsetLeft;
   y += e.offsetTop;
  }
  while(e=e.offsetParent);
 }
 else if(e.x && e.y) {
  x = e.x;
  y = e.y;
 }
 else {
  x = y = null;
 }
 return {x:x,y:y};
}
