//http://www.quaese.de/HTML-Design/texte/js/scripts/drag_and_drop/drag_and_drop.html
//edited by hitzi

  var objDrag = null;

  var mouseX   = 0;       
  var mouseY   = 0;       

  var offX = 0;           
  var offY = 0;           

  IE = document.all&&!window.opera;
  DOM = document.getElementById&&!IE;

  function init_drag(){
    document.onmousemove = doDrag;  
    document.onmouseup = stopDrag;  
  }

  function startDrag(objElemID, otherElemID) {
    objDrag = getObjectWithID(objElemID);
    offX = mouseX - objDrag.offsetLeft;
    offY = mouseY - objDrag.offsetTop;
	swapZIndex(objDrag, getObjectWithID(otherElemID));
  }

  function doDrag(ereignis) {
    mouseX = (IE) ? window.event.clientX : ereignis.pageX;
    mouseY = (IE) ? window.event.clientY : ereignis.pageY;

    if (objDrag != null) {
      objDrag.style.left = (mouseX - offX) + "px";
      objDrag.style.top = (mouseY - offY) + "px";
    }
  }

  function stopDrag(ereignis) {
    objDrag = null;
  }
  
  function getObjectWithID(strID)
  {
  	return (IE)?document.all[strID]:document.getElementById(strID);
  }
  
  function showElement(strID){
  	var myObj = getObjectWithID(strID);
 	myObj.style.display = 'block';
  }
  
  function hideElement(strID){
  	var myObj = getObjectWithID(strID);
 	myObj.style.display = 'none';
  }
  
  function setPositionToMouse(strID){
  	var myObj = getObjectWithID(strID);
	myObj.style.left = (mouseX + 10) + "px";
    myObj.style.top = (mouseY + 10) + "px";	
  }
  
  function swapZIndex(objElem, otherElem)
  {
  	objElem.style.zIndex = 5;
	otherElem.style.zIndex = 1;
  }
 

