﻿
var popupStatus = 0;
var seminarPopupStatus = 0;
var lecturePopupStatus = 0;
var mapPopupStatus = 0;

       function loadSeminarPopup() {
           if (seminarPopupStatus == 0) {
               $("#BackgroundPopup").css({ "opacity": "0.7" });
               $("#BackgroundPopup").fadeIn("slow");
               $("#SeminarPopupDiv").fadeIn("slow");
               seminarPopupStatus = 1;
           }
       }
       
       function loadLecturePopup() {
           if (lecturePopupStatus == 0) {
               $("#BackgroundPopup").css({ "opacity": "0.7" });
               $("#BackgroundPopup").fadeIn("slow");
               $("#LecturePopupDiv").fadeIn("slow");
               lecturePopupStatus = 1;
           }
       }
       function loadMapPopup() {
           if (mapPopupStatus == 0) {
               $("#BackgroundPopup").css({ "opacity": "0.7" });
               $("#BackgroundPopup").fadeIn("slow");
               $("#MapPopupDiv").fadeIn("slow");
               mapPopupStatus = 1;
           }
       }
       
       function loadPopup() {
           if (popupStatus == 0) {
               $("#BackgroundPopup").css({ "opacity": "0.7" });
               $("#BackgroundPopup").fadeIn("slow");
               $("#PopupDiv").fadeIn("slow");
               popupStatus = 1;
           }
       }
       function disableSeminarPopup() {
           if (seminarPopupStatus == 1) {
               $("#BackgroundPopup").fadeOut("slow");
               $("#SeminarPopupDiv").fadeOut("slow");
               seminarPopupStatus = 0;
           }
       }
       function disableLecturePopup() {
           if (lecturePopupStatus == 1) {
               $("#BackgroundPopup").fadeOut("slow");
               $("#LecturePopupDiv").fadeOut("slow");
               lecturePopupStatus = 0;
           }
       }
       function disablePopup() {
           if (popupStatus == 1) {
               $("#BackgroundPopup").fadeOut("slow");
               $("#PopupDiv").fadeOut("slow");
               popupStatus = 0;
           }
       }
       function disableMapPopup() {
           if (mapPopupStatus == 1) {
               $("#BackgroundPopup").fadeOut("slow");
               $("#MapPopupDiv").fadeOut("slow");
               mapPopupStatus = 0;
           }
       }

       function centerMapPopup() {
           var windowWidth = document.documentElement.clientWidth;
           var windowHeight = document.documentElement.clientHeight;
           var popupHeight = $("#MapPopupDiv").height();
           var popupWidth = $("#MapPopupDiv").width();
           $("#MapPopupDiv").css({ "position": "absolute",
               "top": windowHeight / 2 - popupHeight / 2,
               "left": windowWidth / 2 - popupWidth / 2
           });
           $("#BackgroundPopup").css({ "height": windowHeight });
       }
       
       function centerPopup() {
           var windowWidth = document.documentElement.clientWidth;
           var windowHeight = document.documentElement.clientHeight;
           var popupHeight = $("#PopupDiv").height();
           var popupWidth = $("#PopupDiv").width();
           $("#PopupDiv").css({ "position": "absolute",
               "top": windowHeight / 2 - popupHeight / 2,
               "left": windowWidth / 2 - popupWidth / 2
           });
           $("#BackgroundPopup").css({ "height": windowHeight });
       }
       function centerLecturePopup() {
           var windowWidth = document.documentElement.clientWidth;
           var windowHeight = document.documentElement.clientHeight;
           var popupHeight = $("#LecturePopupDiv").height();
           var popupWidth = $("#LecturePopupDiv").width();
           $("#LecturePopupDiv").css({ "position": "absolute",
               "top": windowHeight / 2 - popupHeight / 2,
               "left": windowWidth / 2 - popupWidth / 2
           });
           $("#BackgroundPopup").css({ "height": windowHeight });
       }
       function centerSeminarPopup() {
           var windowWidth = document.documentElement.clientWidth;
           var windowHeight = document.documentElement.clientHeight;
           var popupHeight = $("#SeminarPopupDiv").height();
           var popupWidth = $("#SeminarPopupDiv").width();
           $("#SeminarPopupDiv").css({ "position": "absolute",
               "top": windowHeight / 2 - popupHeight / 2,
               "left": windowWidth / 2 - popupWidth / 2
           });
           $("#BackgroundPopup").css({ "height": windowHeight });
       }

       $(document).ready(function() {
           $("a[id=ShowPopupButton]").click(function() {
               centerPopup();
               loadPopup();
           });
           $("a[id=ShowPopupButtonMap]").click(function() {
               centerMapPopup();
               loadMapPopup();
           });
           $("a[id=ShowLecturePopupButton]").click(function() {
               centerLecturePopup();
               loadLecturePopup();
           });
           $("a[id=ShowSeminarPopupButton]").click(function() {
               centerSeminarPopup();
               loadSeminarPopup();
           });
           $("#PopupDivClose").hover(function() {
               $(this).addClass("XHover");
           });
           $("#MapPopupDivClose").hover(function() {
               $(this).addClass("XHover");
           });
           $("#LecturePopupDivClose").hover(function() {
               $(this).addClass("XHover");
           });
           $("#SeminarPopupDivClose").hover(function() {
               $(this).addClass("XHover");
           });
           $("#PopupDivClose").unbind('mouseenter, mouseleave');
           $("#MapPopupDivClose").unbind('mouseenter, mouseleave');
           $("#LecturePopupDivClose").unbind('mouseenter, mouseleave');
           $("#SeminarPopupDivClose").unbind('mouseenter, mouseleave');
           $("#PopupDivClose").click(function() {
               disablePopup();
           });
           $("#MapPopupDivClose").click(function() {
               disableMapPopup();
           });
           $("#LecturePopupDivClose").click(function() {
               disableLecturePopup();
           });
           $("#SeminarPopupDivClose").click(function() {
               disableSeminarPopup();
           });
           $("#BackgroundPopup").click(function() {
               disablePopup();
               disableMapPopup();
               disableLecturePopup();
               disableSeminarPopup();
           });
           $(document).keypress(function(e) {
               if (e.keyCode == 27 && popupStatus == 1) {
                   disablePopup();
               }
               if (e.keyCode == 27 && mapPopupStatus == 1) {
                   disableMapPopup();
               }
               if (e.keyCode == 27 && lecturePopupStatus == 1) {
                   disableLecturePopup();
               }
               if (e.keyCode == 27 && seminarPopupStatus == 1) {
                   disableSeminarPopup();
               }
           });

       });
        
   