
var ie4 = (document.all && !document.getElementById) ? true : false;
var ie5 = (document.all && document.getElementById) ? true : false;
var ns6 = (!document.all && document.getElementById) ? true : false;
var ns4 = (document.layers) ? true : false;

var info_mouseDownX = -1, info_mouseDownY = -1, info_mapLeft = 0, info_mapTop = 0;
var info_bgLyr;
var info_started = false;
var info_handlerFunction = null;

function InfoTool (mapLeft, mapTop, mapWidth, mapHeight) {
	info_mapLeft = mapLeft;
	info_mapTop = mapTop;
	
	var	info_bgLyrContent = '<img border=0  src="images/spacer.gif" vspace="0" hspace="0"' +
				' width=' + mapWidth + ' height=' + mapHeight + 
				' style="POSITON:ABSOLUTE;  LEFT:' + mapLeft + '; TOP: ' + mapTop + 
				';">';
	createLayer('info_bgLyr', null, mapLeft, mapTop, mapWidth, mapHeight, info_bgLyrContent, '', 'hidden');
	
	if (ie4 || ie5) {
		info_bgLyr = document.all['info_bgLyr'];
	} else if (ns6) {
		info_bgLyr = document.getElementById('info_bgLyr');
	} else if (ns4) {
		info_bgLyr = document.layers['info_bgLyr'];	
		info_bgLyr.captureEvents(Event.MOUSEUP | Event.MOUSEDOWN);
	}
	info_bgLyr.onmousedown = infotoolMouseDown;
	info_bgLyr.onmouseup = infotoolMouseUp;

	this.addListener = infotoolAddListener;
	this.start = infotoolStart;
	this.stop = infotoolStop;
	this.getPoint = infotoolGetClickedPoint;
	this.getPointX = infotoolGetClickedPointX;
	this.getPointY = infotoolGetClickedPointY;
	
}

function infotoolStart () {
	infotoolShowHideDrawingLyr(true);
	info_started = true;
}
function infotoolStop () {
	infotoolShowHideDrawingLyr(false);
	info_started = false;
}
function infotoolAddListener (handlerFunction) {
	if (handlerFunction != null || handlerFunction != '') {
		info_handlerFunction = handlerFunction;
		if (info_handlerFunction.lastIndexOf(')') == -1) {
			info_handlerFunction += '()';
		} 
	}
}
function infotoolGetClickedPoint () {
	return new Array(info_mouseDownX-info_mapLeft, info_mouseDownY-info_mapTop);
}
function infotoolGetClickedPointX () {
	return (info_mouseDownX-info_mapLeft);
}
function infotoolGetClickedPointY () {
	return (info_mouseDownY-info_mapTop);
}
function infotoolShowHideDrawingLyr (show) {
	if (ie4 || ie5 || ns6) {
		info_bgLyr.style.visibility = (show)? 'visible' : 'hidden';
	} else if (ns4) {
		info_bgLyr.visibility = (show) ? 'show' : 'hide'; 
	} 
}

function infotoolMouseDown (e) {
	if ((ns4 && e.which == 1) || (ns6 && e.button == 0) || ((ie4 || ie5) && window.event.button == 1)) {
    	var x = (ns4 || ns6)? e.pageX : event.x;
        var y = (ns4 || ns6)? e.pageY : event.y+document.body.scrollTop;
		if (info_started) {
			info_mouseDownX = x;
			info_mouseDownY = y;
		}
		return false;
	}
	return true;
}
function infotoolMouseUp (e) {
	if ((ns4 && e.which == 1) || (ns6 && e.button == 0) || ((ie4 || ie5) && window.event.button == 1)) {
    	var x = (ns4 || ns6)? e.pageX : event.x;
        var y = (ns4 || ns6)? e.pageY : event.y+document.body.scrollTop;
		if (info_started && x == info_mouseDownX && y == info_mouseDownY) {
			if (info_handlerFunction != null) {
				eval (info_handlerFunction);
			}
		} else {
			info_mouseDownX = -1;
			info_mouseDownY = -1;
		}
		return false;
	}
	return true;
}


