﻿var popupStatus = 0;

function loadPopup(){

	if(popupStatus==0){
		$("#popupbg").css({
			"opacity": "0.9"
		});
		$("#popupbg").fadeIn("fast");
		$("#popup").fadeIn("fast");
		popupStatus = 1;
	}
}

function disablePopup(){

	if(popupStatus==1){
		$("#popupbg").fadeOut("fast");
		$("#popup").fadeOut("fast");
		popupStatus = 0;
		
	}
}

function centerPopup(){

	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popup").height();
	var popupWidth = $("#popup").width();
	//centering
	$("#popup").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	
}


var popup=function(){
   
	//centerPopup();
	loadPopup();

	$('#close').click(function(){
		disablePopup();
	});

	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});
}
