﻿/***************************/
//@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 currentDiv;

//loading popup with jQuery magic!
function loadPopup(mydiv){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.3"
		});
		$("#backgroundPopup").fadeIn("fast");
		$(mydiv).fadeIn("fast");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("fast");
		$(currentDiv).fadeOut("fast");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(myDiv){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $(myDiv).height();
	var popupWidth = $(myDiv).width();
	//centering
	$(myDiv).css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$("#betterButton").click(function(){
		currentDiv = "#betterUp";
		centerPopup(currentDiv);
		loadPopup(currentDiv);
	});
	
	$("#waterButton").click(function(){
		currentDiv = "#waterUp";
		centerPopup(currentDiv);
		loadPopup(currentDiv);
	});
	
	$("#healthButton").click(function(){
		currentDiv = "#healthUp";
		centerPopup(currentDiv);
		loadPopup(currentDiv);
	});
	
	$("#skillsButton").click(function(){
		currentDiv = "#skillsUp";
		centerPopup(currentDiv);
		loadPopup(currentDiv);
	});
	
	$("#educationButton").click(function(){
		currentDiv = "#educationUp";
		centerPopup(currentDiv);
		loadPopup(currentDiv);
	});
	
	$("#moneyButton").click(function(){
		currentDiv = "#moneyUp";
		centerPopup(currentDiv);
		loadPopup(currentDiv);
	});
	
	$("#visitButton").click(function(){
		currentDiv = "#visitUp";
		centerPopup(currentDiv);
		loadPopup(currentDiv);
	});
	
	$("#communicateButton").click(function(){
		currentDiv = "#communicateUp";
		centerPopup(currentDiv);
		loadPopup(currentDiv);
	});
	
	$("#communitiesButton").click(function(){
		currentDiv = "#communitiesUp";
		centerPopup(currentDiv);
		loadPopup(currentDiv);
	});
	
	$("#getButton").click(function(){
		currentDiv = "#getUp";
		centerPopup(currentDiv);
		loadPopup(currentDiv);
	});
	
	$("#ilungaButton").click(function(){
		currentDiv = "#ilungaUp";
		centerPopup(currentDiv);
		loadPopup(currentDiv);
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#closeButton1").click(function(){
		disablePopup();
	});
	$("#closeButton2").click(function(){
		disablePopup();
	});
	$("#closeButton3").click(function(){
		disablePopup();
	});
	$("#closeButton4").click(function(){
		disablePopup();
	});
	$("#closeButton5").click(function(){
		disablePopup();
	});
	$("#closeButton6").click(function(){
		disablePopup();
	});
	$("#closeButton7").click(function(){
		disablePopup();
	});
	$("#closeButton8").click(function(){
		disablePopup();
	});
	$("#closeButton9").click(function(){
		disablePopup();
	});
	$("#closeButton10").click(function(){
		disablePopup();
	});
	$("#closeButton11").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});