
isIE = document.all;
topTagName = isIE ? "BODY" : "HTML";
layerPopup = "";
isMoving = false;

function layerPopupInit(e, id, titleId) {
  layerPopup = document.getElementById(id);
  if(!layerPopup) return;

  movingBar  = isIE ? event.srcElement : e.target;
  while (movingBar.id!=titleId && movingBar.tagName!=topTagName) {
    movingBar = isIE ? movingBar.parentElement : movingBar.parentNode;
  }
  if (movingBar.id == titleId) {
    offsetx   = isIE ? event.clientX : e.clientX;
    offsety   = isIE ? event.clientY : e.clientY;
    nowX      = parseInt(layerPopup.style.left);
    nowY      = parseInt(layerPopup.style.top);
    isMoving = true;
    document.onmousemove = layerPopupMove;
  }
}

function layerPopupMove(e) {
  if (!isMoving) return;
  layerPopup.style.left = isIE ? nowX+event.clientX-offsetx : nowX+e.clientX-offsetx;
  layerPopup.style.top  = isIE ? nowY+event.clientY-offsety : nowY+e.clientY-offsety;
  return false;
}

function hideLayerPopup(id) {
  var obj = document.getElementById(id);
  obj.style.visibility  = "hidden";
}

function showLayerPopup(id) {
  var obj = document.getElementById(id);
  obj.style.visibility  = "visible";
}
