function DragDrop() {
	var ie  = document.all
	var ns6 = document.getElementById&&!document.all
	this.dragapproved = false
	this.func_args    = new Array();
	this.more_left    = 0;
	this.more_top     = 0;
	this.main_DIV = null;
	this.mirror   = null;
	this.temp_div = null;
	this.submeter = null;
	this.idPasta  = null;
	this.idItem   = null;
	//this.toolMan  = ToolMan;
	
	var z,x,y,temp1,temp2, firedobj, parentobj
	
	this.getPosition = function (e){
		var left = e.offsetLeft;
		var top  = e.offsetTop;
	
		return {x:left, y:top};
	
	}
	
	this.mouseCoords = function (ev){
		ev = ev || window.event;
		if(ev.pageX || ev.pageY){
			return {x:ev.pageX, y:ev.pageY};
		}
		return {
			x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
			y:ev.clientY + document.body.scrollTop  - document.body.clientTop
		};
	}
	
	this.getMouseOffset = function (target, ev){
		ev = ev || window.event;
	
		if (target.id == "DragButton")
			target = target.parentNode;
	
		var docPos    = this.getPosition(target);
		var mousePos  = this.mouseCoords(ev);
		return {x:mousePos.x - docPos.x, y:mousePos.y - docPos.y};
	}
	
	this.move = function (e){
		if (this.dragapproved){
			var coordinates  = this.mouseCoords(e);
			z.style.top  = coordinates.y + this.more_top  + 'px';
			z.style.left = coordinates.x + this.more_left + 'px';
			
			return true
		}
	}
	this.drags = function (e){
		if (!ie&&!ns6) return false;
		var coordinates; // = this.toolMan._coordinatesFactory.mouseOffset(e);
		firedobj  = ns6 ? e.target : event.srcElement
		parentobj = ns6? firedobj.parentNode : firedobj.parentElement
		
		if (firedobj.getAttribute('drag')) {
			this.main_DIV     = this.findObj(firedobj.getAttribute('main'));
			this.dragapproved = true;

			if (this.getItem() != 'Null')
				this.idItem  = firedobj.getAttribute( this.getItem() );
			
			if ((div_clone   = firedobj.getAttribute('clone')) != undefined) {;
				this.mirror  = this.findObj(div_clone);
				
				this.temp_div = document.createElement('DIV');
				this.temp_div.setAttribute('id','div_temp');
				this.temp_div.setAttribute('className', this.main_DIV.className );
				this.temp_div.innerHTML    = this.main_DIV.innerHTML;
				this.temp_div.style.cursor = 'move';
				this.mirror.appendChild(this.temp_div);
								
				z = this.temp_div
			} else {
				z = this.main_DIV
			}
			
			z.style.position = 'absolute';
			z.style.zIndex   = 1;
			
			document.body.style.MozUserSelect = "none";
			document.onselectstart            = new Function("return false");
			
			//coordinates.y  += this.more_top;
			//coordinates.x  += this.more_left;

			coordinates  = this.mouseCoords(e);
			z.style.top  = coordinates.y + this.more_top  + 'px';
			z.style.left = coordinates.x + this.more_left + 'px';

			//coordinates.reposition(z);	
			
			return true;
		}
	}
	
	this.MouseUp = function (e) {
		objfired = ns6 ? e.target : event.srcElement;
		
		if (this.dragapproved) {
			if (this.mirror) 
				this.mirror.removeChild(this.temp_div);

			document.body.style.MozUserSelect = "";
			document.onselectstart            = new Function("return true");

			this.dragapproved = false;
			this.submeter     = true;
			
			if (this.submeter) {
				if (objfired.getAttribute( this.getPasta() ) && objfired.getAttribute('notget')==null)  {
					this.idPasta = objfired.getAttribute( this.getPasta() );
					
					if (this.RunFuncAfter() == "S") {
						this.func_args[ this.getHidden(0,true) ] = this.idPasta;
						this.func_args[ this.getHidden(1,true) ] = this.idItem;
						this.func_args[ this.getHidden(2,true) ] = junkdrawer.inspectListOrder( this.getDivDrags(), true );
						
						eval( this.RunFunc() )
					} else {
						this.getHidden(0).value = this.idPasta;
						this.getHidden(1).value = this.idItem;
						this.getHidden(2).value = junkdrawer.inspectListOrder( this.getDivDrags(), true );
						this.getForm().submit();
					}
				}
				
				this.submeter = false;
			}
		}
	}
	
	this.MouseMove = function (e) {
		class_Drags.move(e || window.event);
	}
	
	this.Start = function () {
		var divs    = document.getElementsByTagName('DIV');
		var objDrag = this;
		for (var i = 0; i < divs.length; i++) {
			if (divs[i].getAttribute('drag')) {
				classObjetos.register(divs[i], 'click', function () {
																		objDrag.idPasta  = null;
																		objDrag.idItem   = null;
																		
																		if (objDrag.RunFuncAfter() != 'Null') {
																			if (objDrag.RunFuncAfter() == "S") {
																				objDrag.func_args[ objDrag.getHidden(0,true) ] = 0;
																				objDrag.func_args[ objDrag.getHidden(1,true) ] = 0;
																				objDrag.func_args[ objDrag.getHidden(2,true) ] = 0;
																			} else {
																				objDrag.getHidden(0).value = 0;
																				objDrag.getHidden(1).value = 0;
																				objDrag.getHidden(2).value = 0;
																			}
																		}
																	} );
			}
		}
		
		classObjetos.register(document, 'mousedown', function (e) { class_Drags.drags(e || window.event) } );
		classObjetos.register(document, 'mouseup', function (e) { class_Drags.MouseUp(e) } );
		classObjetos.register(document, 'mousemove', function (e) { class_Drags.MouseMove(e) } );
	}
	
	this.findObj = function (n, d) {
		var p,i,x;
	
		if (!d) d = document;
	
		if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
			d = parent.frames[n.substring(p+1)].document;
			n = n.substring(0,p);
		}
	
		if (!(x = d[n]) && d.all) x = d.all[n];
	
		for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
	
		for (i = 0; !x && d.layers && i < d.layers.length; i++) x = findObj(n,d.layers[i].document);
	
		if (!x && d.getElementById) x = d.getElementById(n);
	
		return x;
	}
	
	this.getForm = function () { return this.findObj(this.str_form); }
	this.setForm = function (valor) { this.str_form = valor; }
	
	this.getHidden = function (indice, arr) {
		if (indice!=null) {
			if (arr!=null) {
				return eval( 'this.str_hidden['+indice+']' );
			} else {
				return this.findObj( eval( 'this.str_hidden['+indice+']' ) );
			}
		} else {
			return this.str_hidden.length;
		}
	}
	this.setHidden = function (valor) { this.str_hidden = valor; }
	
	this.getPasta = function () { return this.str_pasta; }
	this.setPasta = function (valor) { this.str_pasta = valor; }
	
	this.getDivDrags = function () { return this.str_dvdrags; }
	this.setDivDrags = function (valor) { this.str_dvdrags = valor; }
	
	this.getItem = function () { return this.str_item; }
	this.setItem = function (valor) { this.str_item = valor; }
	
	this.RunFunc = function () { return this.str_func_after_drag; }
	this.setRunFunc = function (valor) { this.setRunFuncAfter('S'); this.str_func_after_drag = valor; }
	
	this.RunFuncAfter = function () { return this.str_func_after_drag_after; }
	this.setRunFuncAfter = function (valor) { this.str_func_after_drag_after = valor; }
	
	this.RunFuncArgs = function (indice) {
		if (indice != null) {
			return this.func_args[indice];
		}
		
		return this.func_args.length;
	}
	
	this.getRunFuncArgs = function () { return this.func_args; }
	
	this.setRunFuncArgs = function (value, indice) {
		this.func_args  = (this.func_args) ? this.func_args : new Array();
		len = (indice!=null) ? indice : this.RunFuncArgs();
		this.func_args[len] = value;
	}
}

var class_Drags = new DragDrop();
