
	var popupStatus = 0; 
	
	function popupPage(pageURL, clickedElement){
		$("#popupContact").html("");
		$.ajax({
			url: pageURL,
			type: "GET",
			success: function(response){
				$("#popupContact").html(response);
			}
		});
		centerPopup(clickedElement);
		loadPopup();
		//CLOSING POPUP
		//Click out event!
		$("#backgroundPopup").click(function(){
			disablePopup();
		});
		//Press Escape event!
		$(document).keypress(function(e){
			if(e.keyCode==27 && popupStatus==1){
				disablePopup();
			}
		});
	}

//	popup window scripting:
	function loadPopup(){
		//loads popup only if it is disabled
		if(popupStatus==0){
			$("#backgroundPopup").css({
				"opacity": "0.7"
			});
			$("#backgroundPopup").fadeIn("fast");
			$("#popupContact").fadeIn("fast");
			popupStatus = 1;
		}
	}
	
	//disabling popup with jQuery magic!
	function disablePopup(){
		//disables popup only if it is enabled
		if(popupStatus==1){
		$("#backgroundPopup").fadeOut("fast");
		$("#popupContact").fadeOut("fast");
			popupStatus = 0;
		}
	}
	
	//centering popup
	function centerPopup(clickedElement){
		var xy = findPos(clickedElement);
		
		//request data for centering
		var windowWidth = document.documentElement.clientWidth;
		var windowHeight = document.documentElement.clientHeight;
		var popupHeight = $("#popupContact").height();
		var popupWidth = $("#popupContact").width();
		//centering
		$("#popupContact").css({
			"position": "absolute",
			"top": xy[1]-5,
			"left": xy[0]-5
		});
		//only need force for IE6
		
		$("#backgroundPopup").css({
			"height": windowHeight
		});
	
	}

//	cursor position functions
	function mouseX(evt) {
		if (evt.pageX) return evt.pageX;
		else if (evt.clientX)
		   return evt.clientX + (document.documentElement.scrollLeft ?
		   document.documentElement.scrollLeft :
		   document.body.scrollLeft);
		else return null;
	}
	
	function mouseY(evt) {
		if (evt.pageY) return evt.pageY;
		else if (evt.clientY)
		   return evt.clientY + (document.documentElement.scrollTop ?
		   document.documentElement.scrollTop :
		   document.body.scrollTop);
		else return null;
	}


	function findPos(obj) {
	//	this is used to find the position of the element that was clicked, and put the popup there.
		var curleft = curtop = 0;
		if (obj.offsetParent) {
			curleft = obj.offsetLeft
			curtop = obj.offsetTop
			while (obj = obj.offsetParent) {
				curleft += obj.offsetLeft
				curtop += obj.offsetTop
			}
		}
		return [curleft,curtop];
	}
