var Drag_collection = new Array ();
var Drag_browser = new checkBrowser ();
var Drag_selObject = void 0;
var Drag_Instance = new Drag ();

function Drag ()
{
	// Global Object only one instance ever allowed.
	if (Drag_collection.length == 0)
	{
		// Properties
		this.instance = Drag_collection.length;
		Drag_collection[this.instance] = this;
		this.name = "Drag_" + this.instance;
		
		this.offsetX = 0;
		this.offsetY = 0;
		
		// Methods
		this.release = Drag_Release;
		this.drag = Drag_Drag;

		// Initialize the event handlers for the document
		if (Drag_browser.ns4) document.captureEvents (Event.MOUSEMOVE | Event.MOUSEUP);
//		if (Drag_browser.ns4) document.captureEvents (Event.MOUSEUP);

		document.onmousemove = this.drag;
		document.onmouseup = this.release;
	}
	else
	{
		return (void 0);
	}
}

function Drag_Release (evt)
{
	if (Drag_selObject != void 0)
	{
		Drag_selObject = void 0;
	}
	else
	{
		if ((Drag_browser.ns4) || (Drag_browser.ns5)) return(document.routeEvent (evt));
	}
	
	return (false);
}

function Drag_Drag (evt)
{
	var clientY = 0;
	var clientX = 0;
	
	if (Drag_selObject != void 0)
	{
		if ((Drag_browser.ns4) || (Drag_browser.ns5))
		{
			clientY = evt.pageY;
			clientX = evt.pageX;
		}
		else
		{
			clientY = window.event.clientY;
			clientX = window.event.clientX;
		}
		
		clientY -= Drag_collection[0].offsetY;
		clientX -= Drag_collection[0].offsetX;
		
		Drag_selObject.setPosition (clientX, clientY);
	}
	else
	{
		if ((Drag_browser.ns4) || (Drag_browser.ns5)) return(document.routeEvent (evt));
	}
		
	return (false);
}

function Drag_Engage (evt)
{
	if (Drag_selObject == void 0) 
	{
		if ((Drag_browser.ns4) || (Drag_browser.ns5))
		{
			Drag_collection[0].offsetX = evt.layerX;
			Drag_collection[0].offsetY = evt.layerY;
		}
		else
		{
			Drag_collection[0].offsetX = window.event.offsetX;
			Drag_collection[0].offsetY = window.event.offsetY;
		}
		
		Drag_selObject = this;
	}
	return (false);
}
