$(document).ready(function(){

   var isIE = (navigator.appName == "Microsoft Internet Explorer");
   var newWin = '';
   var windowWidth = document.documentElement.clientWidth;
   var windowHeight = document.documentElement.clientHeight;
   var popupHeight = 500;
   var popupWidth = 625;
   var newTop = windowHeight/2-popupHeight/2;
   var newLeft = windowWidth/2-popupWidth/2;
   
   $('#backgroundPopup').css({
      "opacity": "0.7"
   });
   
   $('p.popbutton a').click(function(){
      $("#backgroundPopup").fadeIn("slow");
      newWin = window.open(this.href,"_blank","top="+newTop+",left="+newLeft+",width=625,height=500,scrollbars=1,resizeable=1,location=1,status=0,toolbar=0,menubar=0");
      return false;
   });
   
   //Click out event
   $("#backgroundPopup").click(function(){
      $("#backgroundPopup").fadeOut("slow");
   });
   
   if (isIE)   {
      document.onfocusin = function() {$("#backgroundPopup").fadeOut("slow");}
   }   else {
      window.onfocus = function() {$("#backgroundPopup").fadeOut("slow");}
   }

   $(document).focus(function(){
      $("#backgroundPopup").fadeOut("slow");
   });
   
   //Press Escape event
   $(document).keypress(function(e){
      if(e.keyCode==27){
         $("#backgroundPopup").fadeOut("slow");
      }
   });

});
