/**
 * This is done in a pretty much lame way, with too much repeated code,
 * When I have the time and more skills with jQuery I'll make this right.
 */

//0 means disabled, 1 means enabled
var popup_status = 0;

//load the about popup
function load_popup_about(){
	if (popup_status == 0) {
		$("#background_popup").css({"opacity": "0.7"});
		$("#background_popup").fadeIn("slow");
		$("#about_popup").fadeIn("slow");
		popup_status = 1;
	}
}

//load the disclaimer popup
function load_popup_disclaimer(){
	if (popup_status == 0) {
		$("#background_popup").css({"opacity": "0.7"});
		$("#background_popup").fadeIn("slow");
		$("#disclaimer_popup").fadeIn("slow");
		popup_status = 1;
	}
}

//disable the popup
function disable_popup(){
	if (popup_status == 1){
		$("#background_popup").fadeOut("slow");
		$("#about_popup").fadeOut("slow");
		$("#disclaimer_popup").fadeOut("slow");
		
		popup_status = 0;
	}
}

//center the about popup
function center_popup_about(){
	var window_width = document.documentElement.clientWidth;
	var window_height = document.documentElement.clientHeight;
	var popup_width = $("#about_popup").width();
	var popup_height = $("#about_popup").height();
	
	//center the popup
	$("#about_popup").css({
		"position": "absolute",
		"top": window_height/2-popup_height/2,
		"left": window_width/2-popup_width/2
	});
	
	//of course this has to be different in IE6...
	$("#background_popup").css({
		"height": window_height
	});
}

//center the disclaimer popup
function center_popup_disclaimer(){
	var window_width = document.documentElement.clientWidth;
	var window_height = document.documentElement.clientHeight;
	var popup_width = $("#disclaimer_popup").width();
	var popup_height = $("#disclaimer_popup").height();
	
	//center the popup
	$("#disclaimer_popup").css({
		"position": "absolute",
		"top": window_height/2-popup_height/2,
		"left": window_width/2-popup_width/2
	});
	
	//of course this has to be different in IE6...
	$("#background_popup").css({
		"height": window_height
	});
}

//when DOM is ready...
$(document).ready(function() {
	
	//load the about popup
	$("#about_lnk").click(function(){
		center_popup_about();
		load_popup_about();
	});
	
	$("#disclaimer_lnk").click(function(){
		center_popup_disclaimer();
		load_popup_disclaimer();
	});
	
	$("#close_popup_about").click(function(){
		disable_popup();
	});
	
	$("#close_popup_disc").click(function(){
		disable_popup();
	});
	
	$("#background_popup").click(function(){
		disable_popup();
	});
	
	$(document).keypress(function(e){
		if (e.keyCode == 27 && popup_status==1) {
			disable_popup();
		}
	});
});

