var popupStatus = 0;

function loadPopup(){
	if(popupStatus==0){
		$("#popup").fadeIn("slow");
		popupStatus = 1;
	}
}

function disablePopup(){
	if(popupStatus==1){
		$("#popup").fadeOut("slow");
		popupStatus = 0;
	}
}

function centerPopup(){
    var scrollTop = document.body.scrollTop;
    if (scrollTop == 0)
    {
        if (window.pageYOffset)
            scrollTop = window.pageYOffset;
        else
            scrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
    }

	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popup").height();
	var popupWidth = $("#popup").width();
	$("#popup").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2 + scrollTop,
		"left": windowWidth/2-popupWidth/2
	});
}

$(document).ready(function(){
	
	$("#map_icon").css("cursor","pointer");
	$("#map_icon").click(function(){
		centerPopup();
		loadPopup();
		return false;
	});

	$("#closemap").click(function(){
		disablePopup();
		return false;
	});

	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});
