﻿
var popupStatus = 0;
function loadPopup(){
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}

function disablePopup(){
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		popupStatus = 0;
	}
}

function getScrollXY() { 
var scrOfX = 0, scrOfY = 0; 
if( typeof( window.pageYOffset ) == 'number' ) { 
  scrOfY = window.pageYOffset; 
  scrOfX = window.pageXOffset; 
} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) { 
  scrOfY = document.body.scrollTop; 
  scrOfX = document.body.scrollLeft; 
} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) { 
  scrOfY = document.documentElement.scrollTop; 
  scrOfX = document.documentElement.scrollLeft; 
} 
return {X:scrOfX, Y:scrOfY}; 
} 

function getWindowSize() { 
 var myWidth = 0, myHeight = 0; 
 if( typeof( window.innerWidth ) == 'number' ) { 
   myWidth = window.innerWidth; 
   myHeight = window.innerHeight; 
 } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { 
   myWidth = document.documentElement.clientWidth; 
   myHeight = document.documentElement.clientHeight; 
 } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { 
   myWidth = document.body.clientWidth; 
   myHeight = document.body.clientHeight; 
 } 
 return{X:myWidth, Y:myHeight} 
} 


function centerPopup(){ 
var windowDim = getWindowSize(); 
var popupHeight = $("#popupContact").height(); 
var popupWidth = $("#popupContact").width(); 
var scroll = getScrollXY(); 
$("#popupContact").css({ 
"position": "absolute", 
"top": windowDim.Y/2-popupHeight/2 + scroll.Y-15, 
"left": windowDim.X/2-popupWidth/2 + scroll.X-15 
}); 
$("#backgroundPopup").css({ 
"height": windowDim.Y 
}); 
} 

$(document).ready(function(){
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	$("#popupContact").click(function(){
		disablePopup();
	});
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});