var popupStatusr = 0;

//loading popup with jQuery magic!
function loadPopupr(){
	//loads popup only if it is disabled
	if(popupStatusr==0){
		$("#backgroundPopupr").css({
			"opacity": "0.7"
		});
		$("#backgroundPopupr").fadeIn("slow");
		$("#popupContactr").fadeIn("slow");
		popupStatusr = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopupr(){
	//disables popup only if it is enabled
	if(popupStatusr==1){
		$("#backgroundPopupr").fadeOut("slow");
		$("#popupContactr").fadeOut("slow");
		popupStatusr = 0;
	}
}

//centering popup
function centerPopupr(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContactr").height();
	var popupWidth = $("#popupContactr").width();
	//centering
	$("#popupContactr").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopupr").css({
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!

	
	$("#buttonr").click(function(){
		//centering with css
		centerPopupr();
		//load popup
		loadPopupr();
	});
	
	$("#buttonr1").click(function(){
		//centering with css
		centerPopupr();
		//load popup
		loadPopupr();
	});
	
	$("#buttonr2").click(function(){
		//centering with css
		centerPopupr();
		//load popup
		loadPopupr();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactCloser").click(function(){
		disablePopupr();
	});
	//Click out event!
	$("#backgroundPopupr").click(function(){
		disablePopupr();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatusr==1){
			disablePopupr();
		}
	});

});
