// Copyright 1997-1998 insideDHTML.com, LLC.
var elDragged = null  // Track current item.
function doMouseMove() {
    // Check if mouse button is down and if an element is being dragged
    if ((event.button==1) && (elDragged!=null)) {
      // Move the element
      // Where the mouse is in the document
      var intTop =  event.clientY + document.body.scrollTop;
      var intLeft = event.clientX + document.body.scrollLeft;
      // Calculate what element the mouse is really in
      var intLessTop  = 0; var intLessLeft = 0;
      var elCurrent = elDragged.offsetParent;
      while (elCurrent.offsetParent!=null) {
        intLessTop+=elCurrent.offsetTop;
        intLessLeft+=elCurrent.offsetLeft;
        elCurrent = elCurrent.offsetParent;
      }
      // Set new position
      elDragged.style.pixelTop = intTop  - intLessTop - elDragged.y;
      elDragged.style.pixelLeft = intLeft - intLessLeft  - elDragged.x;
      event.returnValue = false;
    }
  }

 function checkDrag(elCheck) {
    // Check if the clicked inside an element that supports dragging
    while (elCheck!=null) {
      if (null!=elCheck.getAttribute("title"))
        return elCheck
      elCheck = elCheck.parentElement
    }
    return null
  }

 function doMouseDown() {
    // Store element on mousedown.  Called from click handler in code below.
    // All elements that have a "title" attribute and are positioned
    // can be dragged.
    var elCurrent = checkDrag(event.srcElement)
    if (null!=elCurrent) {
        elDragged = elCurrent;
        // Determine where the mouse is in the element
        elDragged.x = event.offsetX
        elDragged.y = event.offsetY
        var op = event.srcElement
        // Find real location in respect to element being dragged.
        if ((elDragged!=op.offsetParent) && (elDragged!=event.srcElement)) {
          while (op!=elDragged) {
            elDragged.x+=op.offsetLeft
            elDragged.y+=op.offsetTop
            op=op.offsetParent
          }
        }
    }
  }

  // Process mousemove.
  document.onmousedown = doMouseDown;
  document.onmousemove = doMouseMove;
  // Reset element on mouseup.
  document.onmouseup = new Function("elDragged=null");
