﻿/***************************/
//@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 popupStatus = 0;
var popupStatus2 = 0;
var popupStatus3 = 0;
var popupStatus4 = 0;
var popupStatus5 = 0;

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

function loadPopup2(){
	if(popupStatus2==0){
		$("#bgPopupOutpatient").css({
			"opacity": "0.7"
		});
		$("#bgPopupOutpatient").fadeIn("slow");
		$("#popupOutpatient").fadeIn("slow");
		popupStatus2 = 1;
	}
}

function loadPopup3(){
	if(popupStatus3==0){
		$("#bgPopupResidential").css({
			"opacity": "0.7"
		});
		$("#bgPopupResidential").fadeIn("slow");
		$("#popupResidential").fadeIn("slow");
		popupStatus3 = 1;
	}
}

function loadPopup4(){
	if(popupStatus4==0){
		$("#bgPopupGroups").css({
			"opacity": "0.7"
		});
		$("#bgPopupGroups").fadeIn("slow");
		$("#popupGroups").fadeIn("slow");
		popupStatus4 = 1;
	}
}

function loadPopup5(){
	if(popupStatus5==0){
		$("#bgPopupInterventionists").css({
			"opacity": "0.7"
		});
		$("#bgPopupInterventionists").fadeIn("slow");
		$("#popupInterventionists").fadeIn("slow");
		popupStatus5 = 1;
	}
}



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

function disablePopup2(){
	//disables popup only if it is enabled
	if(popupStatus2==1){
		$("#bgPopupOutpatient").fadeOut("slow");
		$("#popupOutpatient").fadeOut("slow");
		popupStatus2 = 0;
	}
}

function disablePopup3(){
	//disables popup only if it is enabled
	if(popupStatus3==1){
		$("#bgPopupResidential").fadeOut("slow");
		$("#popupResidential").fadeOut("slow");
		popupStatus3 = 0;
	}
}

function disablePopup4(){
	//disables popup only if it is enabled
	if(popupStatus4==1){
		$("#bgPopupGroups").fadeOut("slow");
		$("#popupGroups").fadeOut("slow");
		popupStatus4 = 0;
	}
}

function disablePopup5(){
	//disables popup only if it is enabled
	if(popupStatus5==1){
		$("#bgPopupInterventionists").fadeOut("slow");
		$("#popupInterventionists").fadeOut("slow");
		popupStatus5 = 0;
	}
}




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

function centerPopup2(){
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupOutpatient").height();
	var popupWidth = $("#popupOutpatient").width();
	$("#popupOutpatient").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	$("#bgPopupOutpatient").css({
		"height": windowHeight
	});
}

function centerPopup3(){
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupResidential").height();
	var popupWidth = $("#popupResidential").width();
	$("#popupResidential").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	$("#bgPopupResidential").css({
		"height": windowHeight
	});
}

function centerPopup4(){
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupGroups").height();
	var popupWidth = $("#popupGroups").width();
	$("#popupGroups").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	$("#bgPopupGroups").css({
		"height": windowHeight
	});
}

function centerPopup5(){
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupInterventionists").height();
	var popupWidth = $("#popupInterventionists").width();
	$("#popupInterventionists").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	$("#bgPopupInterventionists").css({
		"height": windowHeight
	});
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$(".medical").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});

	$(".outpatient").click(function(){
		centerPopup2();
		loadPopup2();
	});

	$(".residential").click(function(){
		centerPopup3();
		loadPopup3();
	});

	$(".groups").click(function(){
		centerPopup4();
		loadPopup4();
	});

	$(".interventionists").click(function(){
		centerPopup5();
		loadPopup5();
	});



	//CLOSING POPUP
	//Click the x event!
	$("#popupMedicalClose").click(function(){
		disablePopup();
	});

	$("#popupOutpatientClose").click(function(){
		disablePopup2();
	});

	$("#popupResidentialClose").click(function(){
		disablePopup3();
	});

	$("#popupGroupsClose").click(function(){
		disablePopup4();
	});

	$("#popupInterventionistsClose").click(function(){
		disablePopup5();
	});

	
	
	
	//Click out event!
	$("#bgPopupMedical").click(function(){
		disablePopup();
	});

	$("#bgPopupOutpatient").click(function(){
		disablePopup2();
	});

	$("#bgPopupResidential").click(function(){
		disablePopup3();
	});

	$("#bgPopupGroups").click(function(){
		disablePopup4();
	});

	$("#bgPopupInterventionists").click(function(){
		disablePopup5();
	});

	
	
	
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
		if(e.keyCode==27 && popupStatus2==1){
			disablePopup2();
		}
		if(e.keyCode==27 && popupStatus3==1){
			disablePopup3();
		}
		if(e.keyCode==27 && popupStatus4==1){
			disablePopup4();
		}
		if(e.keyCode==27 && popupStatus5==1){
			disablePopup5();
		}
	});

});
