//Drag and Drop
//Alex Barnard (c)2007

function _DnD_Update(e){
	if(!__loaded)return true
	if(!e)e=window.event;
	if(e){
		_DnD.mx=(e.pageX)?e.pageX:(e.clientX)?e.clientX:-1
		_DnD.my=(e.pageY)?e.pageY:(e.clientY)?e.clientY:-1
		if(_DnD.o!=0){
			if (window.getSelection)
				window.getSelection().removeAllRanges();
			else if (document.selection)
				document.selection.empty()
			if(_DnD.dx){
				var x=_DnD.ol+_DnD.mx-_DnD.ox
				if(!_DnD.dy){
					if(x>0&&x<_window('Width')-_DnD.mw)
						_DnD.o.style.left = x+"px"
				}else		
					_DnD.o.style.left = x+"px"
			}		
			if(_DnD.dy)
				_DnD.o.style.top = (_DnD.ot+_DnD.my-_DnD.oy)+"px"
			if(_DnD.o.__doMove)_DnD.o.__doMove()
			return false
		}
	}	
	return true
}

function _DnD_Grab(e){
	if(!__loaded||_DnD.o!=0)return true
	me=(e.target)?e.target:(e.srcElement)?e.srcElement:null
	var o

	if(/divider/i.test(me.className)){
		//DIVIDER BAR
		_DnD.dx=1
		_DnD.dy=0
		_DnD.mw = me.offsetWidth
		_DnD.o = me
	}else{ 
		if(/titlebar/i.test(me.parentNode.className))me=me.parentNode
		if(/titlebar/i.test(me.className)){
			if((o=me.parentNode)!=null)
				 if((o=o.parentNode)!=null){
		 			if(/sliderdiv/i.test(o.className)){
					//Sliding DIV
						_DnD.dx=1
						_DnD.dy=0
						_DnD.mw = me.offsetWidth
						_DnD.o = o
					}else if(/popup/i.test(o.className)){
						//POPUP WIN
						_DnD.dx=1
						_DnD.dy=1
						_DnD.o = o
					}
				}
		
		}
	}	
	if(_DnD.o){	
	//alert(_DnD.o.id+" "+_DnD.o.tagName)
		_DnD.me = me
		_DnD.z = _DnD.o.style.zIndex
		_DnD.me.className=_DnD.me.className.replace(/\boff\b/i,"on")
		_DnD.o.style.zIndex = 2000; 
		if(_DnD.o._position==undefined)_DnD.o._position=_getStyle(_DnD.o,"position")
		_DnD.o.style.position = "absolute"
		_DnD.ox = _DnD.mx
		_DnD.oy = _DnD.my
		_DnD.ol = _DnD.o.offsetLeft
		_DnD.ot = _DnD.o.offsetTop
		if(_DnD.o.__doGrab)_DnD.o.__doGrab()
		return false
	}
	return true
}
function _DnD_Drop(){
  if (_DnD.o!=0){
	if(_DnD.o.__doDrop)_DnD.o.__doDrop()
	_DnD.me.className=_DnD.me.className.replace(/\bon\b/i,"off")
    _DnD.o.style.zIndex = _DnD.z;
	_DnD.o.style.position=_DnD.o._position
	_DnD.o = 0;
	
  }
}
_addEvent(document,"_mousemove","return _DnD_Update(e)") 
_addEvent(document,"_mousedown","return _DnD_Grab(e)") 
_addEvent(document,"_mouseup","_DnD_Drop()") 

