//script to make div draggable

var divisvisible=0; //global variable to flag whether the pano div is showing


// Script Source: CodeLifter.com
// Copyright 2003
// Do not remove this header

isIE=document.all;
isNN=!document.all&&document.getElementById;
isN4=document.layers;
isHot=false;

var initialx=5;
var initialy=5;

function ddInit(e){

  topDog=isIE ? "BODY" : "HTML";
  whichDog=isIE ? document.all.theLayer : document.getElementById("theLayer");  
//alert (whichDog.id); //this is the main outer draggable layer, which dowsn't change, provided it's there!
  hotDog=isIE ? event.srcElement : e.target; 
 // alert (hotDog.tagName) //this is the target of the mousedown which varies as the user clicks around the page
  
 if (isIE&&!hotDog.parentElement) return; //break out of the function if the user clicks the scroll bar, as it is at the highest level and therefore has no parentElement
  while (hotDog.id!="titleBar"&&hotDog.tagName!=topDog){
    hotDog=isIE ? hotDog.parentElement : hotDog.parentNode;
  }  
  if (hotDog.id=="titleBar"){
    offsetx=isIE ? event.clientX : e.clientX;
    offsety=isIE ? event.clientY : e.clientY;
    nowX=parseInt(whichDog.offsetLeft);
    nowY=parseInt(whichDog.offsetTop);
    ddEnabled=true;
    document.onmousemove=dd;
  }
}

function dd(e){
  if (!ddEnabled) return; 

  var leftpos=isIE ? nowX+event.clientX-offsetx : nowX+e.clientX-offsetx; 
  var toppos=isIE ? nowY+event.clientY-offsety : nowY+e.clientY-offsety;
  
  //leftpos+="px";
  //toppos+="px";
  
  if (leftpos>0) whichDog.style.left=leftpos+"px";
  if (toppos>0)whichDog.style.top=toppos+"px";
  
  return false; 

}

function ddN4(whatDog){
  if (!isN4) return;
  N4=eval(whatDog);
  N4.captureEvents(Event.MOUSEDOWN|Event.MOUSEUP);
  N4.onmousedown=function(e){
    N4.captureEvents(Event.MOUSEMOVE);
    N4x=e.x;
    N4y=e.y;
  }
  N4.onmousemove=function(e){
    if (isHot){
      N4.moveBy(e.x-N4x,e.y-N4y);
      return false;
    }
  }
  N4.onmouseup=function(){
    N4.releaseEvents(Event.MOUSEMOVE);
  }
}

function hideMe(){
  if (isIE||isNN) whichDog.style.visibility="hidden";
  else if (isN4) document.theLayer.visibility="hide";
  whichDog.style.left=initialx;
  whichDog.style.top=initialy;
  divisvisible=0;
}

function showMe(){
  if (isIE||isNN) whichDog.style.visibility="visible";
  else if (isN4) document.theLayer.visibility="show";
  divisvisible=1;
}

function openPano(pano) {
if (divisvisible==0) {showMe()}
writecode(pano);
}

document.onmousedown=ddInit;
document.onmouseup=Function("ddEnabled=false");
