var popupStatus = 0;

function loadPopup(){
  if(popupStatus==0){
    $("#popupBackground").css({
      "opacity": "0.7"
    });
    $("#popupBackground").show();
    $("#popupDialog").show("slow");
    popupStatus = 1;
  }
}

function disablePopup(){
  if(popupStatus==1){
    $("#popupBackground").fadeOut("normal");
    $("#popupDialog").fadeOut("normal");
    popupStatus = 0;
  }
}

function centerPopup(){
  var windowWidth = document.documentElement.clientWidth;
  var windowHeight = document.documentElement.clientHeight;
  var popupHeight = $("#popupDialog").height();
  var popupWidth = $("#popupDialog").width();
  $("#popupDialog").css({
    "position": "fixed",
    "top": windowHeight/2-popupHeight/2,
    "left": windowWidth/2-popupWidth/2
  });

  $("#popupBackground").css({
    "height": windowHeight
  });
}

function popupInit() {
  $("#popupCloseButton").click(function(){
    disablePopup();
  });

  $("#popupBackground").click(function(){
    disablePopup();
  });

  $(document).keypress(function(e){
    if(e.keyCode==27){
      disablePopup();
    }
  });
}

