var x = 0, y = 0, w = 0, h = 0;
var bg;
var popup;

init = function (){
	bg = document.getElementById('overlay');
}

correct = function (){
	w = document.body.scrollWidth;
	h = document.body.scrollHeight;

	if (popup.style.display=="block") {
		bg.style.width = w + "px";
		bg.style.height = h + "px";
	}
}
function showPopup(e,popupID) {
	popup = document.getElementById(popupID);

	if (!e) e = window.event;
	if (e.pageX || e.pageY) {
		x = window.innerWidth/2+window.pageXOffset;
		y = window.innerHeight/2+window.pageYOffset;
		w = document.width;
		h = document.height;
	}
	else if (e.clientX || e.clientY) {
		if (document.documentElement.clientWidth>0) {
			x = document.documentElement.clientWidth/2+document.documentElement.scrollLeft;
			y = document.documentElement.clientHeight/2+document.documentElement.scrollTop;
		}
		else {
			x = document.body.clientWidth/2+document.body.scrollLeft;
			y = document.body.clientHeight/2+document.body.scrollTop;
		}
		w = document.body.scrollWidth;
		h = document.body.scrollHeight;
	}
	bg.style.width = w + "px";
	bg.style.height = h + "px";
	
	popup.style.top = y - 300 + "px";
	popup.style.left = x - 165 + "px";

	bg.style.display = "block";
	popup.style.display = "block";

	correct();
	popup.style.top = y - parseInt(popup.offsetHeight/2) + "px";

	return false;
}

function hideQuest() {
	bg.style.display = "none";
	popup.style.display = "none";
	return false;
}

window.onload = init;
window.onresize = correct;

