﻿//0 means disabled; 1 means enabled;
var popupStatusMsg = 0;

//loading popup with jQuery magic!
function loadPopupMsg(){
	//loads popup only if it is disabled
	if(popupStatusMsg==0){
		$("#backgroundPopup-message").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup-message").fadeIn("slow");
		$("#popupContact-message").fadeIn("slow");
		popupStatusMsg = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopupMsg(){
	//disables popup only if it is enabled
	if(popupStatusMsg==1){
		$("#backgroundPopup-message").fadeOut("slow");
		$("#popupContact-message").fadeOut("slow");
		popupStatusMsg = 0;
	}
}

//centering popup
function centerPopupMsg(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = 1000;
	var popupHeight = $("#popupContact-message").height();
	var popupWidth = $("#popupContact-message").width();
	//centering
	$("#popupContact-message").css({
		"position": "absolute",
		"top": 100,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup-message").css({
		"height": windowHeight, 
		"width": windowWidth
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$("#button-request1").click(function(){
		//centering with css
		centerPopupMsg();
		//load popup
		loadPopupMsg();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose-message").click(function(){
		disablePopupMsg();
	});
	//Click out event!
	$("#backgroundPopup-message").click(function(){
		disablePopupMsg();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatusMsg==1){
			disablePopupMsg();
		}
	});

});
