function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	} else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		} else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}


// 0 - disabled; 1 - enabled;  
var popupStatus = 0;
	
// Loading popup with jQuery  
function loadPopup() {  
	// Loads popup only if it is disabled
	if(popupStatus == 0) {  
		$("#backgroundPopup").css({  
			"opacity": "0.7"  
		});  
		$("#backgroundPopup").fadeIn("slow");  
		$("#popupContact").fadeIn("slow");  
		popupStatus = 1;  
	}  
}
	
// Disabling popup with jQuery
function disablePopup() {  
	// Disables popup only if it is enabled  
	if(popupStatus == 1) {  
		$("#backgroundPopup").fadeOut("slow");  
		$("#popupContact").fadeOut("slow");  
		popupStatus = 0;  
	}  
}
	
function getScroll() {
	  var scrOfX = 0, scrOfY = 0;
	  if( typeof( window.pageYOffset ) == 'number' ) {
	    //Netscape compliant
	    scrOfY = window.pageYOffset;
	    scrOfX = window.pageXOffset;
	  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
	    //DOM compliant
	    scrOfY = document.body.scrollTop;
	    scrOfX = document.body.scrollLeft;
	  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
	    //IE6 standards compliant mode
	    scrOfY = document.documentElement.scrollTop;
	    scrOfX = document.documentElement.scrollLeft;
	  }
	  return [ scrOfX, scrOfY ];
	}

// Center popup  
function centerPopup(){  
	var scroll = getScroll();
	// Request data for centering  
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = getWindowHeight();
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();  
	// Center  
	$("#popupContact").css({  
		"position": "absolute",
		"z-index": 1000,
		"top": (windowHeight / 2) - (popupHeight / 2) + scroll[1],  
		"left": (windowWidth / 2) - (popupWidth / 2)  
	});    
	$("#backgroundPopup").css({ 
		"width": windowWidth,
		"height": windowHeight
	}); 	
}  

$(document).ready(function(){      
	$("#popupContactClose").click(function(){  
		disablePopup();  
	});  
	
	// Click out event!  
	$("#backgroundPopup").click(function(){  
		disablePopup();  
	});  
	
	// Press Escape event!  
	$(document).keypress(function(e){  
		if(e.keyCode==27 && popupStatus==1){  
			disablePopup();  
		}  
	});
	
	
});



