var popupStatus = 0;

function loadPopup(){
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupWindow").fadeIn("slow");
		popupStatus = 1;
	}
}

function disablePopup(){
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupWindow").fadeOut("slow");
		popupStatus = 0;
	}
}

function centerPopup(){
	document.getElementById('popUpTitle').innerHTML = document.getElementById('popUpValue').value;
	$("#popUpBody").load(document.getElementById('popUpType').value);
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupWindow").height();
	var popupWidth = $("#popupWindow").width();
	$("#popupWindow").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}


$(document).ready(function(){
	
	for (i = 0; i < 5; i++) {
		$("#popUpClick" + i).click(function(){
			centerPopup();
			loadPopup();
		});
	}
				
	$("#popupWindowClose").click(function(){
		disablePopup();
	});
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});