/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatusThree = 0;

//loading popup with jQuery magic!
function loadPopupThree(){
	//loads popup only if it is disabled
	if(popupStatusThree==0){
		$("#backgroundPopupThree").css({
			"opacity": "0.7"
		});
		$("#backgroundPopupThree").fadeIn("slow");
		$("#popupContactThree").fadeIn("slow");
		popupStatusThree = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopupThree(){
	//disables popup only if it is enabled
	if(popupStatusThree==1){
		$("#backgroundPopupThree").fadeOut("slow");
		$("#popupContactThree").fadeOut("slow");
		popupStatusThree = 0;
	}
}

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


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$("#buttonThree").click(function(){
		//centering with css
		centerPopupThree();
		//load popup
		loadPopupThree();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactCloseThree").click(function(){
		disablePopupThree();
	});
	//Click out event!
	$("#backgroundPopupThree").click(function(){
		disablePopupThree();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatusThree==1){
			disablePopupThree();
		}
	});

});
