isIE=document.all;
isHot=false;
var offsetx;
var offsety;


function ddInit(e){
  topDog=isIE ? "BODY" : "HTML";
  whichDog=isIE ? document.all.theLayer : document.getElementById("theLayer");  
  hotDog=isIE ? event.srcElement : e.target;  
  while (hotDog && hotDog.id != "titleBar" && hotDog.tagName != topDog){
    hotDog=isIE ? hotDog.parentElement : hotDog.parentNode;
  }  
  offsetx=isIE ? event.clientX : e.pageX;
  offsety=isIE ? event.clientY : e.pageY;
  if (hotDog && hotDog.id=="titleBar"){
    nowX=parseInt(whichDog.style.left);
    nowY=parseInt(whichDog.style.top);
    ddEnabled=true;
    document.onmousemove=dd;
  }
}

function dd(e){
  if (!ddEnabled) return;
  whichDog.style.left=isIE ? nowX+event.clientX-offsetx : nowX+e.clientX-offsetx; 
  whichDog.style.top=isIE ? nowY+event.clientY-offsety : nowY+e.clientY-offsety;
  return false;  
}

function hideMe(){
  whichDog.style.visibility="hidden";
}

function showMe(boxtitle,text){
  var str = "";

  whichDog.style.visibility="visible";
  if (isIE) {
	  document.all.TITLE.innerHTML = boxtitle;
	  document.all.BOX.innerHTML = text;
  } else {
	  document.getElementById("TITLE").innerHTML = boxtitle;
	  document.getElementById("BOX").innerHTML = text;
  }
  if ((offsetx+20+whichDog.offsetWidth) > document.body.offsetWidth) {
     offsetx = document.body.offsetWidth - 20 - whichDog.offsetWidth - (isIE ? 20 : 0);
  }
  str = offsetx + 20;
  whichDog.style.left = str + "px"; 
  if ((offsety+20+whichDog.offsetHeight) > document.body.offsetHeight) {
     offsety = document.body.offsetHeight - 20 - whichDog.offsetHeight;
  }
  str = offsety + 20;
  whichDog.style.top = str + "px"; 
}

function toggle(boxtitle,text) {
	if (whichDog.style.visibility =="visible") {
		hideMe();
	} else {
		showMe(boxtitle,text);
	}
}

document.onmousedown=ddInit;
document.onmouseup=Function("ddEnabled=false");


