;(function() {		
	window.overlay = function() {
		var overlay = document.getElementById("overlay") || document.createElement("div");
		overlay.id = "overlay";
		$(overlay).css({
			"background":"#000",
			"opacity":"0.2",
			"position":"absolute",
			"top":"0px","left":"0px",
			"width":"100%", 
			"height":"100%",
			"z-index":"99",
			"cursor":"pointer",
			"cursor": "hand",
			"display":"block" });
		overlay.onlick = hideOverlay;
		overlay.style.width = pageWidth() + "px";
		overlay.style.height = pageHeight() + "px";
		document.body.appendChild(overlay);
	};
	window.hideOverlay = function() {
		var overlay = document.getElementById("overlay");
		overlay.style.display = "none";
	};
	//overlay();
	$(".cancel").live("click", function(event) {
		//console.log($(this));
		hideOverlay();
		$(".popup").remove();
		return false;
	});
	$(".pop").click(function(event) {
		var $e = $.get($(this).attr("href"),{},function(popup) { 
			var $body = $("body");
			var $popup = $("<div />").append(popup).find(".popup");
			$body.prepend($popup);
			$popup.get(0).style.left = pageWidth() /2 - $popup.width() / 2 + "px";
			$popup.get(0).style.top = pageHeight() / 8 + "px";
			overlay();
			window.scrollTo(0,0);
		});
		return false;
	});
})();
function pageWidth() {
	return document.body.scrollWidth;
};
function pageHeight() {
	return document.body.scrollHeight;
};
window.onresize = function () {
	if ($(".popup").length) {
		$(".popup").get(0).style.left = pageWidth() / 2 - $(".popup").width() / 2 + "px";
		$("#overlay").get(0).style.width = pageWidth() + "px";
	}
	//console.log("r");	
};
