//SETTING UP OUR POPUP //0 means disabled; 1 means enabled; var popupStatus = 0; //loading popup with jQuery magic! function loadQuotePopup(){ //loads popup only if it is disabled if(popupStatus==0){ $("select").css({ "visibility": "hidden" }); $("#backgroundQuotePopup").css({ "opacity": "0.8" }); $("#backgroundQuotePopup").fadeIn("slow"); $("#popupQuote").fadeIn("slow"); popupStatus = 1; } } function loadBrochurePopup(){ //loads popup only if it is disabled if(popupStatus==0){ $("select").css({ "visibility": "hidden" }); $("#backgroundBrochurePopup").css({ "opacity": "0.8" }); $("#backgroundBrochurePopup").fadeIn("slow"); $("#popupBrochure").fadeIn("slow"); popupStatus = 1; } } //disabling popup with jQuery magic! function disableQuotePopup(){ //disables popup only if it is enabled if(popupStatus==1){ $("#backgroundQuotePopup").fadeOut("slow"); $("#popupQuote").fadeOut("slow"); popupStatus = 0; $("select").css({ "visibility": "visible" }); } } function disableBrochurePopup(){ //disables popup only if it is enabled if(popupStatus==1){ $("#backgroundBrochurePopup").fadeOut("slow"); $("#popupBrochure").fadeOut("slow"); popupStatus = 0; $("select").css({ "visibility": "visible" }); } } //centering popup function centerQuotePopup(){ //request data for centering var windowWidth = document.documentElement.clientWidth; var windowHeight = document.documentElement.clientHeight; var popupHeight = $("#popupQuote").height(); var popupWidth = $("#popupQuote").width(); //centering $("#popupQuote").css({ "position": "absolute", "top": windowHeight/2-popupHeight/2, "left": windowWidth/2-popupWidth/2 }); //only need force for IE6 $("#backgroundQuotePopup").css({ "height": windowHeight }); } function centerBrochurePopup(){ //request data for centering var windowWidth = document.documentElement.clientWidth; var windowHeight = document.documentElement.clientHeight; var popupHeight = $("#popupBrochure").height(); var popupWidth = $("#popupBrochure").width(); //centering $("#popupBrochure").css({ "position": "absolute", "top": windowHeight/2-popupHeight/2, "left": windowWidth/2-popupWidth/2 }); //only need force for IE6 $("#backgroundBrochurePopup").css({ "height": windowHeight }); } //CONTROLLING EVENTS IN jQuery $(document).ready(function(){ //LOADING POPUP //Click the button event! $("#quote").click(function(){ //centering with css centerQuotePopup(); //load popup loadQuotePopup(); }); $("#brochure").click(function(){ //centering with css centerBrochurePopup(); //load popup loadBrochurePopup(); }); //CLOSING POPUP //Click the x event! $("#popupQuoteClose").click(function(){ disableQuotePopup(); }); //Click out event! $("#backgroundQuotePopup").click(function(){ disableQuotePopup(); }); $("#popupBrochureClose").click(function(){ disableBrochurePopup(); }); //Click out event! $("#backgroundBrochurePopup").click(function(){ disableBrochurePopup(); }); //Press Escape event! $(document).keypress(function(e){ if(e.keyCode==27 && popupStatus==1){ disableQuotePopup(); disableBrochurePopup(); } }); });