var Drag = {

	obj : null,

	init : function(o, minY, maxY)
	{
		o.onmousedown = Drag.start;
		o.root = o.parentNode;
		o.startDragY=0;
		o.direction=1;

		if (isNaN(parseInt(o.root.style.paddingTop))) o.root.style.paddingTop = "0px";

		o.minY = typeof minY != 'undefined' ? minY : null;
		o.maxY = typeof maxY != 'undefined' ? maxY : null;

		o.root.onDrag = new Function();
	},

	start : function(e)
	{
		var o = Drag.obj = this;
		e = Drag.fixE(e);
		e.cancelBubble = true;

		var y = parseInt(o.root.style.paddingTop);
		if (isNaN(y)) y=0;

		o.lastMouseY = o.startDragY= e.clientY;

		if (o.minY != null) o.minMouseY = e.clientY - y + o.minY;
		if (o.maxY != null) o.maxMouseY = o.minMouseY + o.maxY - o.minY;

//		document.getElementById("blabla").innerHTML="min="+o.minMouseY+"  clickY="+e.clientY+"  y="+y;

		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 y = parseInt(o.root.style.paddingTop);
		if (isNaN(y)) y=0;
		var ny;

		if (o.minY != null) ey = Math.max(ey, o.minMouseY);
		if (o.maxY != null) ey = Math.min(ey, o.maxMouseY);

		ny = y + (ey - o.lastMouseY);
//		document.getElementById("blabla").innerHTML="y="+y+"-> clickY="+ey+" - lastY="+o.lastMouseY;


		Drag.obj.root.style["paddingTop"] = ny + "px";
		o.direction=((ey- o.startDragY)>0)?1:((ey- o.startDragY)<0)?0:-1;
	//	document.getElementById("blabla").innerHTML= " currentY="+ey+" - startY="+o.startDragY+" = "+(ey- o.startDragY)+" >> direction: "+o.direction;

		Drag.obj.lastMouseY = ey;

		Drag.obj.onDrag(o.root.getAttribute("contentId"),ny,o.direction);
		return false;
	},

	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;
		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;
	}
};