/* Credit: Adrian "yEnS" Mato Gondelle // www.yensdesign.com // yensamg@gmail.com */
function initPopup(){
  $("#app-button").click(function(){showPopup();});
  $("#popupClose").click(function(){hidePopup();});
  $("#popupBg").click(function(){hidePopup();});
  $(window).keydown(function(e){if(e.keyCode == 27 && $("#popupBg").is(":visible")) hidePopup();});
}
function showPopup(){
  var ww = document.documentElement.clientWidth;
  var wh = document.documentElement.clientHeight;
  var pw = $("#popupBox").width();
  var ph = $("#popupBox").height();
  $("#popupBox").css({"position": "absolute", "top": wh/2-ph/2, "left": ww/2-pw/2});
  $("#popupBg").css({"height": wh});
  if ($("#popupBg").is(":hidden")){
    $("#popupBg").css({"opacity": "0.6"});
    $("#popupBg").fadeIn("slow");
    $("#popupBox").fadeIn("slow");
  }
}
function hidePopup(){
  if ($("#popupBg").is(":visible")){
    $("#popupBg").fadeOut("slow");
    $("#popupBox").fadeOut("slow");
  }
}
$(document).ready(function(){initPopup();});
