/** Set the page up for mouse capture */
document.onmousedown = mapTool;
document.onmouseup = chkMouseUp;
document.onmousemove = getMouse;
window.onresize = refreshSpacing;
window.onerror = refreshSpacing;

var mX;
var mY;

// Create a DHTML layer
function createLayer(name, inleft, intop, width, height, visible, content) {
	var layer;
	document.writeln('<div id="' + name + '" style="position:absolute; overflow:hidden; left:' + inleft + 'px; top:' + intop + 'px; width:' + width + 'px; height:' + height + 'px;' + '; z-index:1; visibility:' + (visible ? 'visible;' : 'hidden;') +  '">');
	document.writeln(content);
	document.writeln('</div>');
}
function getLayer(name) {
	var theObj = document.getElementById(name);
	if (theObj && theObj.style) return theObj.style;
	// Try old style
	else {
		var layer = document.all[name];
		if (layer && layer.style) return layer.style;
		else return null;
	}
}
function isVisible(name) {
	var layer = getLayer(name);
	if (layer.visibility == "visible") return(true);
	return(false);
}
function moveLayer(name, x, y) {		
	var layer = getLayer(name);	
	layer.position = "absolute";
	layer.left = x + "px";layer.top  = y + "px";
}
function setLayerBackgroundColor(name, color) {		
	var layer = getLayer(name);		
	layer.backgroundColor = color;
}
function hideLayer(name) {		
	var layer = getLayer(name);		
	if (layer) layer.visibility = "hidden";
}
function showLayer(name) {		
	var layer = getLayer(name);		
	if (layer) layer.visibility = "visible";
}
function clipLayer2(name, clipleft, cliptop, clipright, clipbottom) {		
	var layer = getLayer(name);		
	layer.clip = 'rect(' + cliptop + ' ' +  clipright + ' ' + clipbottom + ' ' + clipleft +')';
}
function clipLayer(name, clipleft, cliptop, clipright, clipbottom) {	
	var layer = getLayer(name);		
	var newWidth = clipright - clipleft;
	var newHeight = clipbottom - cliptop;
	layer.height = newHeight;
	layer.width	= newWidth;
	layer.top	= cliptop + "px";
	layer.left	= clipleft + "px";
}
function getImageXY(e) {
	mouseX=event.clientX + document.body.scrollLeft;
	mouseY=event.clientY + document.body.scrollTop;
	// subtract offsets from page left and top
	mouseX = mouseX-hspc;
	mouseY = mouseY-vspc;		
}
function getLayerObj(name) {
	var theObj = document.getElementById(name);
	return theObj
}
function addMouseDown(theLayer)
{
	theLayer.onmousedown = setInsetZoom;

}
function setInsetZoom() 
{
	mX = event.clientX + document.body.scrollLeft;
	mY = event.clientY + document.body.scrollTop;
 	insetZoom = true;	
}
