var donationStatus = 0;

function loadDonation() {
	if(donationStatus == 0) {
		$("#donate_background").css({
			"opacity": "0.7"
		});
		$("#donate_background").fadeIn("slow");
		$("#donate_block").fadeIn("slow");
		donationStatus = 1;
	}
}


function disableDonation(){
	if(donationStatus == 1) {
		$("#donate_background").fadeOut("slow");
		$("#donate_block").fadeOut("slow");
		donationStatus = 0;
	}
}

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

	$("#donate_background").css({
		"height": windowHeight
	});
}

$(document).ready(function(){  
	$("#donate_link").click(function(){
		centerDonation();
		loadDonation();
	});

	$("#donate_close").click(function(){
		disableDonation();
	});

	$("#donate_background").click(function(){
		disableDonation();
	});

	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus == 1) {
			disableDonation();
		}
	});
});