// filename: dealer-locator.js
// functions for the dealer locator
// version 1.01 - 2004-08-09
// Distributed under the terms of the GNU Library General Public License
// author: martin dot kliehm at gpm dot de

if (is.ns4) window.captureEvents(Event.MOUSEMOVE)
window.onmousemove = showCoords;

function showCoords(e) {
	if (is.ns4up) window.status = "x: " + e.pageX + '; y: ' + e.pageY;
}

function msover(num) {
	var refObj, refX, refY, refWidth, refHeight, obj, xOffset, x, y, info, infoWidth, infoHeight, unit;
	if (is.dom) {
		refObj = document.getElementById('mapDeutschland');
		refX = refObj.offsetLeft;
		refY = refObj.offsetTop;
		refWidth = refObj.offsetWidth;
		refHeight = refObj.offsetHeight;
		
		obj = (num) ? document.getElementById('locDealer' + num) : document.getElementById('myLocation');
		xOffset = obj.offsetWidth;
		yOffset = obj.offsetHeight;
		x = obj.offsetLeft;
		y = obj.offsetTop;
		
		info = (num) ? document.getElementById('infoDealer' + num) : document.getElementById('myLocationInfo');
		infoCSS = (num) ? document.getElementById('infoDealer' + num).style  : document.getElementById('myLocationInfo').style;
		infoWidth = info.offsetWidth;
		infoHeight = info.offsetHeight;
		
		unit = 'px';
	}
	else if (is.ns4) {
		refObj = document.layers['mapDeutschland'];
		refX = refObj.left;
		refY = refObj.top;
		refWidth = refObj.clip.width;
		refHeight = refObj.clip.height;
		
		obj = (num) ? document.layers['locDealer' + num] : document.layers['myLocation'];
		xOffset = obj.clip.width;
		yOffset = obj.clip.height;
		x = obj.left;
		y = obj.top;
		
		info = (num) ? document.layers['infoDealer' + num] : document.layers['myLocationInfo'];
		infoCSS = (num) ? document.layers['infoDealer' + num] : document.layers['myLocationInfo'];
		infoWidth = info.clip.width;
		infoHeight = info.clip.height;

		unit = '';
	}
	diffX = (xOverflow || refX + refWidth > x + xOffset + infoWidth) ? 0 : infoWidth + xOffset;
	diffY = (yOverflow || refY + refHeight > y + infoHeight) ? 0 : infoHeight - yOffset;
	
	infoCSS.visibility = 'visible';
	infoCSS.zIndex = 2000;
	if(popups_absolute){
		infoCSS.left = popups_absolute_x + unit;
		infoCSS.top =  popups_absolute_y + unit;
	} else {
		infoCSS.left = (x - diffX + xOffset) + unit;
		infoCSS.top = (y - diffY) + unit;
	}
}

function msout(num) {
	if (is.dom) infoCSS = (num) ? document.getElementById('infoDealer' + num).style : document.getElementById('myLocationInfo').style;
	else if (is.ns4) infoCSS = (num) ? document.layers['infoDealer' + num] : document.layers['myLocationInfo'];
	infoCSS.visibility = 'hidden';
	infoCSS.zIndex = 0;
}

function show(num) {
	msover(num);
}