var miniDrag = {

	obj : null,

	init : function(o)
	{   cursor.change("openhand")
		o.onmousedown	= miniDrag.start;

		o.hmode			= true ;
		o.vmode			= true ;

		o.root = o ;

		if (isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";

		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();

	},

	start : function(e)
	{   cursor.change("closedhand")
		var o = miniDrag.obj = this;
		e = miniDrag.fixE(e);
		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	= miniDrag.Drag;
		document.onmouseup		= miniDrag.end;
		return false;
	},

	Drag : function(e)
	{
		e = miniDrag.fixE(e);

		var o = miniDrag.obj, ey = e.clientY, ex= e.clientX, y = parseInt(o.root.style.top), x = parseInt(o.root.style.left), nx, ny;



		nx = x + (ex - o.lastMouseX)
		ny = y + (ey - o.lastMouseY)

 		miniDrag.obj.root.style.left = nx + "px";
		miniDrag.obj.root.style.top = ny + "px";
		miniDrag.obj.lastMouseX	= ex;
		miniDrag.obj.lastMouseY	= ey;

		miniDrag.obj.root.onDrag(nx, ny);

        nx = (nx < 0) ? 0 : nx;
		ny = (ny < 0) ? 0 : ny;
		nx = (nx > 0 && nx + mini.width >= mini.miniwidth) ? mini.miniwidth - mini.width : nx;
  		ny = (ny > 0 && ny + mini.height >= mini.miniheight) ? mini.miniheight - mini.height : ny;


        miniDrag.obj.root.style.left = nx + "px";
		miniDrag.obj.root.style.top = ny + "px";
		miniDrag.obj.lastMouseX	= ex;
		miniDrag.obj.lastMouseY	= ey;

		miniDrag.obj.root.onDrag(nx, ny);

        mini.drag(nx,ny);

    	return false;
	},

	end : function()
	{  	cursor.change("openhand")

		document.onmousemove = null;
		document.onmouseup   = null;
		miniDrag.obj.root.onDragEnd(	parseInt(miniDrag.obj.root.style.left),
										parseInt(miniDrag.obj.root.style.top));
		miniDrag.obj = null;

       map.getObjects();

	},

	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;
	}
};