
	var GLOBALobj = null;
	var GLOBALdrop = false;
	var GLOBALdropper = null;
	
	_$ = function(e){
		
			if (typeof e == 'object'){
				return e;
			}else{
				if (document.getElementById(e)){
					return document.getElementById(e);
				}else{
					return false;
				}
			}
			
	}

	bind = function(o, f){
	    return function() { f.call(o); }
	}

	setStyle = function(o, p){
				for (var i in p){
					o.style[i] = p[i];
				}		
	}

	gOP = function(p){
		var txt = '';
		for (var i in p){
			txt += i + ' = ' + p[i] + '\n';
		}		
		window.alert(txt);
	}

	getOffsetPosition = function(o){
		var curleft = 0;
		var curtop = 0;
		if (o.offsetParent) {
			curleft = o.offsetLeft
			curtop = o.offsetTop
			while (o = o.offsetParent) {
				curleft += o.offsetLeft
				curtop += o.offsetTop
			}
		}
		return [curleft,curtop];			
	}

/*************************************************************************************
	The Drag Class
 *************************************************************************************/
 
	Drag = function(o, p){
		this.o	=	_$(o);
		setStyle(this.o, {position:'relative',left:'0px',top:'0px',MozUserSelect:'none'});
/*
		ABSOLUTE DRAG, experimental
		var aps = getOffsetPosition(this.o);
		this.pLeft = aps[0];
		this.pTop = aps[1];
		setStyle(this.o, {position:'absolute',left:aps[0] + 'px',top:aps[1] + 'px',MozUserSelect:'none'});
		*/
		this.sX = -1;
		this.sY = -1;

		this.storePath = false;
		this.dragX = true;
		this.dragY = true;
		this.emptyDrop = false;
		this.animated = false;
		
		if (p){

			if (p.emptyDrop){
				this.emptyDrop = p.emptyDrop = 'true' ? true : false;
			}
			
			if (p.dragX){
				this.dragX = p.dragX = 'false' ? false : true;
			}

			if(p.dragY){
				this.dragY = p.dragY = 'false' ? false : true;
			}
			if(p.storePath){
				this.storePath = p.storePath = 'true' ? true : false;
				this.path = [];		
				this.cnt  = 0;
			}

			if (p.animated){
				this.animated = p.animated = 'true' ? true : false;
				this.fx		  = new joinkFX2(this.o, {animation:'outCubic',time:'20',style:'top,left',start:'0,0',distance:'0,0'});
				this.fx.onFinish(bind(this, this.finishTrace));
			}

		}
				
		this.o.onmousedown 	=	bind(this, this.startTrace);
	}
	
	Drag.prototype = {
		
		startTrace : function(){
			GLOBALobj = this;
			GLOBALobj.o.className += ' tracin';	
			var e = window.event;
			document.onselectstart = returnFalse;
			setStyle(document.body, {cursor:GLOBALobj.o.style.cursor});
			document.onmousemove = function(e, obj){GLOBALobj.traceMouse(e);};
			document.onmouseup	=  function(obj){GLOBALobj.stopTrace();};			
		},

		stopTrace : function(){
			if ($('dropPlanner')){
				$('dropPlanner').style.display = 'none';
			}
			if (GLOBALobj.emptyDrop === false){
				if (GLOBALdrop === true){
					addToTravelmate(GLOBALobj.o);
				}				
				if (GLOBALobj.animated){
					this.fx.setFunction(bind(this, this.resetFX));
					this.fx.move();
				}else{
					if (GLOBALobj.storePath){
						this.cnt = this.path.length;
						GLOBALobj.animatePath();
					}else{
						setStyle(GLOBALobj.o, {top:'0px',left:'0px'});
					}
				}
				GLOBALobj.sX = -1;
				GLOBALobj.sY = -1;				
			}
			
			if (!this.animated){
				GLOBALobj.o.className = GLOBALobj.o.className.replace(/tracin/,'');
				GLOBALobj = null;
			}
							
			document.onselectstart = '';
			document.onmouseup = null;
			document.onmousemove = null;			
		},
		
		traceMouse : function(e){

			if ($('dropPlanner')){
				if ($('dropPlanner').style.display != 'block'){
					$('dropPlanner').style.display = 'block';
				}
			}			

			if(!e){
				e = window.event;
			}

			var mX = (e.screenX || e.clientX);
			var mY = (e.screenY || e.clientY);
			
			if (this.sX < 0){
				this.sX = mX;
			}
			
			if (this.sY < 0){
				this.sY = mY;
			}
			
			mX -= this.sX;
			mY -= this.sY;
			
			if (this.storePath){
				var pad = new Array(mX, mY);
				this.path.push(pad);
			}
			
			if (this.animated){
				dX = 0 - mX;
				dY = 0 - mY;
				if (this.dragX && this.dragY){
					this.fx.setStart(mY + ',' + mX);
					this.fx.setDistance(dY + ',' + dX);
				}else{
					if (this.dragX){
						this.fx.setStyle('left');
						this.fx.setStart(mX + '');
						this.fx.setDistance(dX + '');
					}else{
						this.fx.setStyle('top');
						this.fx.setStart(mY + '');
						this.fx.setDistance(dY + '');						
					}
				}
			}
			
			if (this.dragX){
				setStyle(this.o, {left:mX + 'px'});
			}
			
			if (this.dragY){
				setStyle(this.o, {top:mY + 'px'});
			}
						
			_$('debug').innerHTML = e + '---' + 'mouse X: ' + mX + ' -- mouse Y: ' + mY + '<br />';
			
		},
		
		animatePath : function(){
			
			if (this.cnt > 0){
				this.cnt--;
				setStyle(this.o, {top:this.path[this.cnt][1] + 'px',left:this.path[this.cnt][0] + 'px'});
				window.setTimeout(bind(this, this.animatePath), 15);
			}else{
				this.cnt = 0;
				this.path = [];
				setStyle(this.o, {top:'0px',left:'0px'});
			}
			
		},
		
		resetFX : function(){
			this.fx.setStart('0');
			this.fx.setDistance('0');
			//window.alert('finish trace');
			if (GLOBALobj){
				GLOBALobj.o.className = GLOBALobj.o.className.replace(/tracin/g,'');
				GLOBALobj = null;
			}				
		}
		
	}
	
	eventTest = function(e){
			window.alert(e);
	}
	
	returnFalse = function(){
		return false;
	}