/**
 * Script dragdrop.js
 * Author: Andreas Damm
 * Date: 2009-01-11
 * Description: Drag & Drop any HTML-node with "position:absolute"
 * Usage: DragDrop.init() after document.body has loaded, DragDrop.start([HTML-node]) on HTML-element mousedown
 */
var DragDrop = {
	dragobjekt: null,
	dragx: 0,
	dragy: 0,
	posx: 0,
	posy: 0,
	opac: ['alpha(opacity=100)',1.0,1.0],
	
	init: function() {
		document.onmousemove = function(e){DragDrop.drag(e)};
		document.onmouseup = function(e){DragDrop.stop()};
	},
	start: function(element) {
		this.dragobjekt = element;
		this.dragx = this.posx - this.dragobjekt.offsetLeft;
		this.dragy = this.posy - this.dragobjekt.offsetTop;
		this.opac = [this.dragobjekt.style.filter,this.dragobjekt.style.MozOpacity,this.dragobjekt.style.opacity];
		this.dragobjekt.style.filter = 'alpha(opacity=65)';
		this.dragobjekt.style.MozOpacity = .65;
		this.dragobjekt.style.opacity = .65;
	},
	stop: function() {
		if(this.dragobjekt!=null){
			this.dragobjekt.style.filter = this.opac[0];
			this.dragobjekt.style.MozOpacity = this.opac[1];
			this.dragobjekt.style.opacity = this.opac[2];
		}
		this.dragobjekt=null;
	},
	drag: function(ereignis) {
		this.posx = document.all ? window.event.clientX : ereignis.pageX;
		this.posy = document.all ? window.event.clientY : ereignis.pageY;
		if(this.dragobjekt != null) {
			this.dragobjekt.style.left = Math.max(0, Math.min(this.posx - this.dragx, document.body.offsetWidth - this.dragobjekt.offsetWidth)) + 'px';
			this.dragobjekt.style.top = Math.max(0, Math.min(this.posy - this.dragy, document.body.offsetHeight - this.dragobjekt.offsetHeight)) + 'px';
		}
	}
}

