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

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

function loadPopup2(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact2").fadeIn("slow");
		popupStatus = 1;
	}
}

function loadPopup3(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact3").fadeIn("slow");
		popupStatus = 1;
	}
}

function loadPopup4(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact4").fadeIn("slow");
		popupStatus = 1;
	}
}

function loadPopup5(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact5").fadeIn("slow");
		popupStatus = 1;
	}
}

function loadPopup6(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact6").fadeIn("slow");
		popupStatus = 1;
	}
}

function loadPopup7(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact7").fadeIn("slow");
		popupStatus = 1;
	}
}

function loadPopup8(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact8").fadeIn("slow");
		popupStatus = 1;
	}
}

function loadPopup9(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact9").fadeIn("slow");
		popupStatus = 1;
	}
}

function loadPopup10(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact10").fadeIn("slow");
		popupStatus = 1;
	}
}

function loadPopup11(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact11").fadeIn("slow");
		popupStatus = 1;
	}
}

function loadPopup12(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact12").fadeIn("slow");
		popupStatus = 1;
	}
}

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

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $(".popupContact").height();
	var popupWidth = $(".popupContact").width();
	//centering
	$(".popupContact").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2,
		"border-radius": "10px"
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
	$("html, body").animate({ scrollTop: 0 }, "slow");
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$(".dbutton1").click(function(){		
		centerPopup();
		loadPopup1();
	});	
	
	$(".dbutton2").click(function(){
		centerPopup();
		loadPopup2();
	});
	
	$(".dbutton3").click(function(){
		centerPopup();
		loadPopup3();
	});
	
	$(".dbutton4").click(function(){
		centerPopup();
		loadPopup4();
	});
	
	$(".dbutton5").click(function(){
		centerPopup();
		loadPopup5();
	});
	
	$(".dbutton6").click(function(){
		centerPopup();
		loadPopup6();
	});
	
	$(".dbutton7").click(function(){
		centerPopup();
		loadPopup7();
	});
	
	$(".dbutton8").click(function(){
		centerPopup();
		loadPopup8();
	});
	
	$(".dbutton9").click(function(){
		centerPopup();
		loadPopup9();
	});
	
	$(".dbutton10").click(function(){
		centerPopup();
		loadPopup10();
	});
	
	$(".dbutton11").click(function(){
		centerPopup();
		loadPopup11();
	});
	
	$(".dbutton12").click(function(){		
		centerPopup();
		loadPopup12();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#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();
		}
	});

});
