﻿var popupStatus = 0;
function loadPopup(){
  if(popupStatus==0){
    $("#backgroundPopup").css({
      "opacity": "0.8"
    });
    $("#backgroundPopup").fadeIn("fast");
    $("#popupZip").fadeIn("fast");
    popupStatus = 1;
  }
}
function disablePopup(){
  if(popupStatus==1){
    $("#backgroundPopup").fadeOut("fast");
    $("#popupZip").fadeOut("fast");
    popupStatus = 0;
  }
}
function centerPopup(){
  var windowWidth = document.documentElement.clientWidth;
  var windowHeight = document.documentElement.clientHeight;
  var popupHeight = $("#popupZip").height();
  var popupWidth = $("#popupZip").width();
  $("#popupZip").css({
    "position": "absolute",
    "top": "120px",
    "right": "0px"
  });
  $("#backgroundPopup").css({
    "height": windowHeight
  });
}
$(document).ready(function(){
  $("#popupbutton_locations").click(function(){
    centerPopup();
    loadPopup();
  });
  $("#popupbutton_events").click(function(){
    centerPopup();
    loadPopup();
  });
  $("#backgroundPopup").click(function(){
    disablePopup();
  });
  $(document).keypress(function(e){
    if(e.keyCode==27 && popupStatus==1){
      disablePopup();
    }
  });
});
