﻿/***************************/
//@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 popupStatus1 = 0;

//loading popup with jQuery magic!
function loadPopup1(){
	//loads popup only if it is disabled
	if(popupStatus1==0){
		 jQuery("#backgroundPopup").css({
			"opacity": "0.7"
		});
		 jQuery("#backgroundPopup").fadeIn("slow");
		 jQuery("#popupContact1").fadeIn("slow");
		popupStatus1 = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup1(){
	//disables popup only if it is enabled
	if(popupStatus1==1){
		 jQuery("#backgroundPopup").fadeOut("slow");
		 jQuery("#popupContact1").fadeOut("slow");
		popupStatus1 = 0;
	}
}

//centering popup
function centerPopup1(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight =  jQuery("#popupContact1").height();
	var popupWidth =  jQuery("#popupContact1").width();
	//centering
	 jQuery("#popupContact1").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	 jQuery("#backgroundPopup").css({
		"height": windowHeight
	});
	
}

var popupStatus2 = 0;

//loading popup with jQuery magic!
function loadPopup2(){
	//loads popup only if it is disabled
	if(popupStatus2==0){
		 jQuery("#backgroundPopup").css({
			"opacity": "0.7"
		});
		 jQuery("#backgroundPopup").fadeIn("slow");
		 jQuery("#popupContact2").fadeIn("slow");
		popupStatus2 = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup2(){
	//disables popup only if it is enabled
	if(popupStatus2==1){
		 jQuery("#backgroundPopup").fadeOut("slow");
		 jQuery("#popupContact2").fadeOut("slow");
		popupStatus2 = 0;
	}
}

//centering popup
function centerPopup2(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight =  jQuery("#popupContact2").height();
	var popupWidth =  jQuery("#popupContact2").width();
	//centering
	 jQuery("#popupContact2").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	 jQuery("#backgroundPopup").css({
		"height": windowHeight
	});
	
}
var popupStatus3 = 0;

//loading popup with jQuery magic!
function loadPopup3(){
	//loads popup only if it is disabled
	if(popupStatus3==0){
		 jQuery("#backgroundPopup").css({
			"opacity": "0.7"
		});
		 jQuery("#backgroundPopup").fadeIn("slow");
		 jQuery("#popupContact3").fadeIn("slow");
		popupStatus3 = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup3(){
	//disables popup only if it is enabled
	if(popupStatus3==1){
		 jQuery("#backgroundPopup").fadeOut("slow");
		 jQuery("#popupContact3").fadeOut("slow");
		popupStatus3 = 0;
	}
}

//centering popup
function centerPopup3(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight =  jQuery("#popupContact3").height();
	var popupWidth =  jQuery("#popupContact3").width();
	//centering
	 jQuery("#popupContact3").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	 jQuery("#backgroundPopup").css({
		"height": windowHeight
	});
	
}


var popupStatus4 = 0;

//loading popup with jQuery magic!
function loadPopup4(){
	//loads popup only if it is disabled
	if(popupStatus4==0){
		 jQuery("#backgroundPopup").css({
			"opacity": "0.7"
		});
		 jQuery("#backgroundPopup").fadeIn("slow");
		 jQuery("#popupContact4").fadeIn("slow");
		popupStatus4 = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup4(){
	//disables popup only if it is enabled
	if(popupStatus4==1){
		 jQuery("#backgroundPopup").fadeOut("slow");
		 jQuery("#popupContact4").fadeOut("slow");
		popupStatus4 = 0;
	}
}

//centering popup
function centerPopup4(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight =  jQuery("#popupContact4").height();
	var popupWidth =  jQuery("#popupContact4").width();
	//centering
	 jQuery("#popupContact4").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	 jQuery("#backgroundPopup").css({
		"height": windowHeight
	});
	
}




var popupStatus5 = 0;

//loading popup with jQuery magic!
function loadPopup5(){
	//loads popup only if it is disabled
	if(popupStatus5==0){
		 jQuery("#backgroundPopup").css({
			"opacity": "0.7"
		});
		 jQuery("#backgroundPopup").fadeIn("slow");
		 jQuery("#popupContact5").fadeIn("slow");
		popupStatus5 = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup5(){
	//disables popup only if it is enabled
	if(popupStatus5==1){
		 jQuery("#backgroundPopup").fadeOut("slow");
		 jQuery("#popupContact5").fadeOut("slow");
		popupStatus5 = 0;
	}
}

//centering popup
function centerPopup5(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight =  jQuery("#popupContact5").height();
	var popupWidth =  jQuery("#popupContact5").width();
	//centering
	 jQuery("#popupContact5").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	 jQuery("#backgroundPopup").css({
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
 jQuery(document).ready(function(){
	jQuery("div").click(function(e){ /*  */
		switch(e.target.id){
			case "popup1":
				centerPopup1();
				loadPopup1();
			break
				case "popup2":
					centerPopup2();
			loadPopup2();
			break
				case "popup3":
					centerPopup3();
				loadPopup3();
			break
					case "popup4":
					centerPopup4();
				loadPopup4();
			break
			case "popup5":
					centerPopup5();
				loadPopup5();
			break
		}
		
	
	});
				
	//CLOSING POPUP
	//Click the x event!
	 jQuery("#popupContactClose1").click(function(){
		disablePopup1();
		disablePopup2();
		disablePopup3();
		disablePopup4();
			disablePopup5();
	});
	 	 jQuery("#popupContactClose2").click(function(){
		disablePopup1();
		disablePopup2();
		disablePopup3();
		disablePopup4();
		disablePopup5();
	});
		 	 jQuery("#popupContactClose3").click(function(){
		disablePopup1();
		disablePopup2();
		disablePopup3();
		disablePopup4();
		disablePopup5();
	});
			 	 	 jQuery("#popupContactClose4").click(function(){
		disablePopup1();
		disablePopup2();
		disablePopup3();
		disablePopup4();
		disablePopup5();
	});
					  	 jQuery("#popupContactClose5").click(function(){
		disablePopup1();
		disablePopup2();
		disablePopup3();
		disablePopup4();
		disablePopup5();
	});
	//Click out event!
	 jQuery("#backgroundPopup").click(function(){
	disablePopup1();
		disablePopup2();
		disablePopup3();
		disablePopup4();
		disablePopup5();
	});
	//Press Escape event!
	 jQuery(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup1();
		disablePopup2();
		disablePopup3();
		disablePopup4();
		disablePopup5();
		}
	});

});
