var tmenu;
var hiding = 0;
var next = 0;

var posx = 0;
var posy = 0;

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function getCursor(e) {
    // return absolute cursor position 
    if (!e) var e = window.event; 
    if (e.clientX || e.clientY)
    {
       var scroll = getScrollXY();
       posx = e.clientX + scroll[0];
       posy = e.clientY + scroll[1];
    }
    else if (e.pageX || e.pageY)
    {
       posx = e.pageX;
       posy = e.pageY;
    }
}
function showMenu (e, id, place) {
    doHide();
    getCursor(e);
    tmenu = document.getElementById(id)
//    tmenu.style.top  = (posy - 15 - place*(tmenu.offsetHeight - 30)) + "px"; 
    tmenu.style.top  = (posy - 15) + "px"; 
    tmenu.style.left = (posx - 25) + "px";
    tmenu.style.visibility = "Visible";
}

function cancelTo() {
   clearTimeout(hiding);
}

function doHide() {
  if (tmenu) {
       tmenu.style.visibility = "Hidden";
       tmenu = null;
  } 
}

function hideMenu(e) {
 if (tmenu) {
   getCursor(e);
   if (tmenu.offsetTop >= posy ||
       tmenu.offsetLeft >= posx ||
       tmenu.offsetTop + tmenu.offsetHeight <= posy ||
       tmenu.offsetLeft + tmenu.offsetWidth <= posx) 
      {
       hiding = setTimeout(doHide, 500);
      } 
     }
   return true;
  }
      
function Iresize(im) {
   var w = im.parentNode.parentNode.offsetWidth;
   var h = im.parentNode.parentNode.offsetHeight;
   im.parentNode.style.width = w+"px";
   im.parentNode.style.height = h+"px";
   im.width = w+20;
   im.height = h+20;
}

function doSelect(ob, yes) {
   if (yes) {ob.style.borderStyle="inset";
	     ob.style.backgroundColor="#f9f9f9";}
   else  {ob.style.borderStyle="outset";
	     ob.style.backgroundColor="white";}
}