// Created by: Justas | http://www.webtoolkit.info/

var DragHandler = {

// private property.
_oElem : null,

// public method. Attach drag handler to an element.
attach : function(oElem) {
		oElem.onmousedown = DragHandler._dragBegin;
		// callbacks
		oElem.dragBegin = new Function();
		oElem.drag = new Function();
		oElem.dragEnd = new Function();
		return oElem;
},

// private method. Begin drag process.
_dragBegin : function(e) {
		var oElem = DragHandler._oElem = this;
		if (isNaN(parseInt(oElem.style.left))) { oElem.style.left = '0px'; }
		if (isNaN(parseInt(oElem.style.top))) { oElem.style.top = '0px'; }
		var x = parseInt(oElem.style.left);
		var y = parseInt(oElem.style.top);
		e = e ? e : window.event;
		oElem.mouseX = e.clientX;
		oElem.mouseY = e.clientY;
		oElem.dragBegin(oElem, x, y);
		document.onmousemove = DragHandler._drag;
		document.onmouseup = DragHandler._dragEnd;
		return false;
},

// private method. Drag (move) element.
_drag : function(e) {
		var oElem = DragHandler._oElem;
		var x = parseInt(oElem.style.left);
		var y = parseInt(oElem.style.top);
		e = e ? e : window.event;
		oElem.style.left = x + (e.clientX - oElem.mouseX) + 'px';
		oElem.style.top = y + (e.clientY - oElem.mouseY) + 'px';
		oElem.mouseX = e.clientX;
		oElem.mouseY = e.clientY;
		oElem.drag(oElem, x, y);
		return false;
},

// private method. Stop drag process.
_dragEnd : function() {
		var oElem = DragHandler._oElem;
		var x = parseInt(oElem.style.left);
		var y = parseInt(oElem.style.top);
		oElem.dragEnd(oElem, x, y);
		document.onmousemove = null;
		document.onmouseup = null;
		DragHandler._oElem = null;
	}
};

// =============

function beginScript() {
  function begin (element, x, y) {
  		var s = '#' + element.id + ' (begin drag)' + ' x:' + x + ', y:' + y;
  		updateInfo(s);
  }

  function drag (element, x, y) {
  		var s = '#' + element.id + ' (dragging)' + ' x:' + x + ', y:' + y;
  		updateInfo(s);
  }

  function end (element, x, y) {
  		var s = '#' + element.id + ' (end drag)' + ' x:' + x + ', y:' + y;
  		updateInfo(s);
  }

  function updateInfo(s) {
  // Comment out the line below to stop displaying the location
  		//document.getElementById('info').innerHTML = s;
  }

  var dragable1 = DragHandler.attach(document.getElementById('tool'));


  dragable1.dragBegin = begin;
  dragable1.drag = drag;
  dragable1.dragEnd = end;

}

// =============

// Multiple onload function created by: Simon Willison
// http://simon.incutio.com/archive/2004/05/26/addLoadEvent
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(function() {
  beginScript();
});

// end draghandler
function runFlash(movie, width, height, flag) {
		if (flag==0) {
		document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" align="top" width="'+width+'" height="'+height+'">');
		document.write('<param name="movie" value="'+movie+'">');
		document.write('<param name="allowScriptAccess" value="always" />');
		document.write('<param name="quality" value="high">');
		document.write('<param name="wmode" value="transparent">');
		document.write('<embed src="'+movie+'" quality="high"  wmode="transparent" allowScriptAccess="always" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'" align="top"></embed>');
		document.write('</object>');
		document.write('<script language="JavaScript" type="text/javascript">runFlash("http://www.zelfzorg.nl/tool/tool_ext.swf",525,590,1)</script>');
	}
	if (flag==1) {
		document.write('<div id="tool" style="position:absolute; left:0; top:10px; width:525px; height:590px; background:transparent; z-index:2147483646; display:none;">');
		document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" align="top" width="'+width+'" height="'+height+'">');
		document.write('<param name="movie" value="'+movie+'">');
		document.write('<param name="allowScriptAccess" value="always" />');
		document.write('<param name="quality" value="high">');
		document.write('<param name="wmode" value="transparent">');
		document.write('<embed src="'+movie+'" quality="high"  wmode="transparent" allowScriptAccess="always" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'" align="top"></embed>');
		document.write('</object>');
		document.write('</div>');
	}
}
function showtool() {
	winwidth=document.documentElement.offsetWidth;
	p=-262+winwidth/2+"px";
	document.getElementById("tool").style.left=p;
	document.getElementById("tool").style.display="block";
}
function hidetool() {
	document.getElementById("tool").style.display="none";
}
