var hfxMoveObj;
var hfxMoveHandle;
var hfxMoveGroup;
var hfxMoveRestrict;

function hfxMoveStart(){
	var path=event.srcElement;
	var att=path.getAttribute('hfxMove',0);
	if(att){
		att=att.split(':');
		hfxMoveGroup=att[0];
		hfxMoveRestrict=(att.length>2)?att[2]:null;
		var origin=nodePath(path,'*.'+att[1]);
		var orj=new obj(origin);
		hfxMoveHandle=origin.cloneNode(true);
		for(st in origin.currentStyle)hfxMoveHandle.style[st]=origin.currentStyle[st];
		with(hfxMoveHandle.style){
			position='absolute';
			width=origin.offsetWidth+'px';
			var xFactor=(hfxMoveRestrict=='h')?10:7;
			var yFactor=(hfxMoveRestrict=='v')?1:-10;
			left=((hfxMoveRestrict!='v')?mouseX(event)+xFactor:orj.x)+'px';
			top=((hfxMoveRestrict!='h')?mouseY(event)+yFactor:orj.y)+'px';
			filter='alpha(opacity=80)';
		}
		with(origin){
			attachEvent('ondrag',hfxMoveDrag);
			attachEvent('ondragend',hfxMoveEnd);
		}
		hfxMoveObj=(att.length>3)?nodePath(origin,att[3]).cloneNode(1):origin;
		d.body.appendChild(hfxMoveHandle);
	}
}

function hfxMoveStart2(){
	var path=event.srcElement;
	var att=path.getAttribute('hfxMove',0);
	if(att){
		att=att.split(':');
		hfxMoveGroup=att[0];
		hfxMoveRestrict=(att.length>2)?att[2]:null;
		var origin=nodePath(path,'*.'+att[1]);
		var orj=new obj(origin);
		hfxMoveHandle=origin.cloneNode(true);
		for(st in origin.currentStyle)hfxMoveHandle.style[st]=origin.currentStyle[st];
		with(hfxMoveHandle.style){
			position='absolute';
			width=origin.offsetWidth+'px';
			var xFactor=(hfxMoveRestrict=='h')?10:7;
			var yFactor=(hfxMoveRestrict=='v')?1:-10;
			left=((hfxMoveRestrict!='v')?mouseX(event)+xFactor:orj.x)+'px';
			top=((hfxMoveRestrict!='h')?mouseY(event)+yFactor:orj.y)+'px';
			filter='alpha(opacity=80)';
		}
		with(origin){
			attachEvent('ondrag',hfxMoveDrag);
			attachEvent('ondragend',hfxMoveEnd);
		}
		hfxMoveObj=(att.length>3)?nodePath(origin,att[3]).children[0].cloneNode(1):origin;
		d.body.appendChild(hfxMoveHandle);
	}
}

function hfxMoveDrag(){
	with(hfxMoveHandle.style){
		var xFactor=(hfxMoveRestrict=='h')?10:7;
		var yFactor=(hfxMoveRestrict=='v')?1:-10;
		if(hfxMoveRestrict!='v')left=(mouseX(event)+xFactor)+'px';
		if(hfxMoveRestrict!='h')top=(mouseY(event)+yFactor)+'px';
	}
}
function hfxMoveEnd(){hfxMoveHandle.removeNode(1)}
function hfxMoveEnter(){
	var path=event.srcElement;
	var att=path.getAttribute('hfxAcceptMove',0);
	if(att){
		att=att.split(':')[0];
		if(att==hfxMoveGroup){
			path.className='dropArea-highlight';
			with(path){
				attachEvent('ondrop',hfxMoveDrop);
				attachEvent('ondragover',hfxMoveOver);
				attachEvent('ondragleave',hfxMoveLeave);
			}
		}
	}
}
function hfxMoveOver(){event.returnValue=false}
function hfxMoveLeave(){
	with(event.srcElement){
		className='dropArea';
		detachEvent('ondrop',hfxMoveDrop);
		detachEvent('ondragover',hfxMoveOver);
		detachEvent('ondragleave',hfxMoveLeave);
	}
}
function hfxMoveDrop(){
	var path=event.srcElement;
	var att=path.getAttribute('hfxAcceptMove',0).split(':')[1];
	path.className='dropArea';
	var cdx=nodePath(path,att);
	cdx.parentNode.insertBefore(hfxMoveObj,cdx);
	with(event.srcElement){
		className='dropArea';
		detachEvent('ondrop',hfxMoveDrop);
		detachEvent('ondragover',hfxMoveOver);
		detachEvent('ondragleave',hfxMoveLeave);
	}
	hfxMoveGroup=null;
}