var oDrag;
var cZIndex;

var n		= (document.layers) ? 1 : 0;
var ie		= (document.all) ? 1 : 0;
var layer	= (n) ? 'layer' : 'div';

function dragObj(obj, nest){
	nest		= (!nest) ? '' : 'document.' + nest + '.';
	this.css	= (n) ? eval(nest + 'document.' + obj) : eval('document.all.' + obj + '.style');
	this.evnt	= (n) ? eval(nest + 'document.' + obj) : eval(obj);
	this.getLeft	= b_getLeft;
	this.getTop	= b_getTop;
	this.moveIt	= b_moveIt;
	this.name	= obj;
	
	return this;
}

function b_moveIt(x,y){
	this.css.left	= x;
	this.css.top	= y;
}

function b_getLeft(){
	x = (n) ? this.css.left : this.css.pixelLeft;
	
	return x;
}

function b_getTop(){
	y = (n)? this.css.top : this.css.pixelTop;
	
	return y;
}

function dragInit(){
	if (n) document.captureEvents(Event.MOUSEMOVE | Event.MOUSEDOWN | Event.MOUSEUP);
	
	document.onmousedown	= mdown;
	document.onmouseup	= mup;
	document.onmousemove	= mmove;
}

function mmshowIt(num, show){
	if (PageLoaded) oDrag[num].css.visibility = (show) ? 'visible' : 'hidden';
}

function mmover(num){
	if (PageLoaded) oDrag[num].isOver = true;
}

function mmout(num){
	if (PageLoaded) oDrag[num].isOver = false;
}

function mup(){
	for(var i = 0; i < oDrag.length; i++){
		if (oDrag[i].isOver)
			oDrag[i].drag = false;
	}
}

function mdown(num){
	x = (n) ? num.pageX : event.x;
	y = (n) ? num.pageY : event.y;
	
	for (var i = 0; i < oDrag.length; i++){
		if (oDrag[i].isOver){
			oDrag[i].drag		= true;
			oDrag[i].clickedX	= x - oDrag[i].getLeft();
			oDrag[i].clickedY	= y - oDrag[i].getTop();
			cZIndex++;
			oDrag[i].css.zIndex	= cZIndex;
		}
	}
}

function mmove(e){
	x = (n) ? e.pageX : event.x;
	y = (n) ? e.pageY : event.y;
	
	for (var i = 0; i < oDrag.length; i++){
		if (oDrag[i].drag)
			oDrag[i].moveIt(x - oDrag[i].clickedX, y - oDrag[i].clickedY);
	}
}

cZIndex		= 10;
initDragBox	= true;
