var intCurrentScrollerWidth = 0;
var intCurrentScrollerHeight = 0;
var Drag = {
	obj: null,
	init: function(o, intScrollerWidth, intScrollerHeight)
	{
		intCurrentScrollerWidth = intScrollerWidth;
		intCurrentScrollerHeight = intScrollerHeight;
		o.onmousedown = Drag.start;
		o.root = o;
		o.root.style.left = '0px';
		o.root.style.top = '0px';
		o.root.style.right = '0px';
		o.root.style.bottom = '0px';
		o.root.onDragStart = new Function();
		o.root.onDragEnd = new Function();
		o.root.onDrag = new Function();
	},
	start: function(e)
	{
		var o = Drag.obj = this;
		e = Drag.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 = 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) * 2);
		ny = y + ((ey - o.lastMouseY) * 2);
		// If x or y exceeds 20, lock it to 20.
		if (nx > 0)
		{
			nx = 0;
		}
		if (ny > 0)
		{
			ny = 0;
		}
		// Get the image source, and determine the width and height.
		objImg = document.getElementById('image_scroller_image');
		if (nx * -1 > objImg.width - intCurrentScrollerWidth)
		{
			nx = (objImg.width - intCurrentScrollerWidth) * -1;
		}
		if (ny * -1 > objImg.height - intCurrentScrollerHeight)
		{
			ny = (objImg.height - intCurrentScrollerHeight) * -1;
		}

		Drag.obj.root.style['left'] = nx + 'px';
		Drag.obj.root.style['top'] = ny + 'px';
		Drag.obj.lastMouseX = ex;
		Drag.obj.lastMouseY = ey;
		Drag.obj.root.onDrag(nx, ny);
		return false;
	},
	end: function()
	{
		document.onmousemove = null;
		document.onmouseup = null;
		Drag.obj.root.onDragEnd(parseInt(Drag.obj.root.style['left']), parseInt(Drag.obj.root.style['top']));
		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;
	}
};
