var Drag =
{
	obj		    : null,
	fx		    : null,
	fy		    : null,
	
	init : function(o, oRoot)
	{
		o.onmousedown	= Drag.start;
		o.style.cursor	= 'move';
		o.root = oRoot && oRoot != null ? oRoot : o ;
		o.ondblclick = function() {o.root.style.display = 'none'}

		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
	},

	start : function(e)
	{
		e = Drag.fixE(e);
		var o = Drag.obj = this;
		var y = parseInt(o.root.style.top );
		var x = parseInt(o.root.style.left);

		o.root.onDragStart(x, y);

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

		document.onmousemove	= Drag.drag;
		document.onmouseup		= Drag.end;

		return false;
	},

	drag : function(e)
	{
		e = Drag.fixE(e);
		var o = Drag.obj;

		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.root.style.top);
		var x = parseInt(o.root.style.left);
		var nx, ny;

		nx = x + ex - o.lastMouseX;
		ny = y + ey - o.lastMouseY;

		ny = ny < 0 ? 0 : ny;
		nx = nx < 0 ? 0 : nx;

		o.root.style["left"] = nx + "px";
		o.root.style["top"] = ny + "px";
		o.lastMouseX	= ex;
		o.lastMouseY	= ey;

		o.root.onDrag(nx, ny);
		return false;
	},

	end : function()
	{
		var o = Drag.obj;
		document.onmousemove = null;
		document.onmouseup   = null;
		o.root.onDragEnd(	parseInt(o.root.style["left"]), 
							parseInt(o.root.style["top"]));
		
		fy = parseInt( o.root.style.top );
		fx = parseInt( o.root.style.left );
		
		Drag.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};

Drag.init( my_getbyid("f_p_side_menu_head"), my_getbyid("fo_leftnav") );