var showTimer;
var hideTimer;
var mapTop;
var mapLeft;

function mapPopup() 
{
	var url = "map.php";
	var mapWindow = window.open(url,"map","width=430,height=440");
}

function setTopDimension() {

	var buttonObj = document.getElementById('mapButton');
	var mapObj = document.getElementById('map');
	
	(mapObj.style.display == "block") ? null : mapObj.style.display = "block";

	//var mapImgHeight = document.getElementById('mapImage').height;
	var mapImgHeight = 259;
	var capHeight = 28;
	var mapHeight = (capHeight * 2) + mapImgHeight;
	var carrotHeight = 72;
	var mapButtonOffset = 13 / 2; // Map button height  / 2

	var top = findPosY(buttonObj) - (mapHeight / 2) - carrotHeight + mapButtonOffset;

	mapTop = top;
	
	mapObj.style.top = mapTop + "px";
}

function setLeftDimension() {
	
	var buttonObj = document.getElementById('mapButton');
	var mapObj = document.getElementById('map');
	
	(mapObj.style.display == "block") ? null : mapObj.style.display = "block";
	
	var mapWidth = 390;
	var offset = 5;
	var left = findPosX(buttonObj) - mapWidth + offset; 
	
	mapLeft = left;
	
	mapObj.style.left = mapLeft + "px";
}

function showMap() {
		
	clearTimeout(hideTimer);

	(mapTop == undefined) ? setTopDimension() : null;
	(mapLeft == undefined)? setLeftDimension() : null;	

	//showTimer = setTimeout("changeVisibility('visible')", 100);
	changeVisibility('visible');
}

function hideMap() {
	clearTimeout(showTimer);
	hideTimer = setTimeout("changeVisibility('hidden')", 200);
}

function changeVisibility(state) {
	document.getElementById('map').style.visibility = state;
}

/////////////////////////////////////////////////////////////////////
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

