var DragObjects = new Array();

function getDragObject(text, x, y)
{
	var i;

	for(i=0 ; i<DragObjects.length ; i++)
		if( !DragObjects[i].isVisible() )
		{
			DragObjects[i].setContent(text);
			DragObjects[i].moveTo(x,y);
			return(DragObjects[i]);
		}
	DragObjects[i] = new xLayer(text,x,y);
	DragObjects[i].addEventHandler("onmousedown", mouseClick);
	DragObjects[i].addEventHandler("onmousemove", mouseMove);
	DragObjects[i].addEventHandler("ondblclick", mouseDel);
	DragObjects[i].setzIndex(i);
	return(DragObjects[i]);
}

function addDragObject(text,x,y,w,h)
{
	var dragObject = getDragObject(text, x, y);

	dragObject.x = x;
	dragObject.y = y;
	dragObject.lx = 0;
	dragObject.ly = 0;
	dragObject.dragging = false;
	dragObject.clip(0,0,w,h);
	dragObject.show();
}

function mouseClick(xl,ev)
{
	if(ev.button==1)
	{
		xl.dragging=!xl.dragging;
		xl.lx=ev.layerX;
		xl.ly=ev.layerY;
	}
	else
		mouseDel(xl, ev);
}

function mouseDel(xl,ev)
{
	xl.moveTo(-100,-100);
	xl.hide();
}

function mouseMove(xl,ev)
{
	if(xl.dragging)
		xl.moveTo(ev.clientX-xl.lx,ev.clientY-xl.ly);
}

