$(document).ready(function(){

	$(".admin_table tr:odd").addClass("odd");

	$("#logo img").hover(function(){
		$(this).attr("src", "/images/love_poke_red.jpg");
	}, function(){
		$(this).attr("src", "/images/love_poke_black.jpg");
	});

	var hoverLinkMap = {
		1: "/pdf/FFFAR_issue_1.pdf",
		2: "/pdf/FFFAR_issue_2.pdf",
		3: "/pdf/FFFAR_issue_3.pdf",
		4: "/pdf/FFFAR_issue_4.pdf"
	};

	$(".comic_loader").hover(function(){
		id = $(this).attr("rel");
		src = "/images/comic_" + id + ".jpg";
		$("#full_version_link").attr("href", hoverLinkMap[id]);
		$("#comic_container").css("background-image", "url(" + src + ")");
		$("#comic_info #title span").html(id);
	},
	function(){
		
	});
	
	$("#add_pledge").click(function(){
		$("#compendium").animate({
				height: '180px'
			},
			
			100,
			
			"linear", 
			
			function(){
				$("#pledge_form").fadeIn();
			}
		);
	});
	
	$("#signup_email").focus(function(){
		$(this).val("");
		$(this).css("color", "black");
	});
	
	$("#join_list_button").click(function(){
		$.get("/signup.php", {"email": $("#signup_email").val()}, function(data){
			response = JSON.parse(data);
			if(response.status == "OK"){
				$("#signup_email").val("You've been added - thanks!");
			}
		});
	});
	
	$("#add_pledge_button").click(function(){
		name = $("#pledge_name").val();
		email = $("#pledge_email").val();
		email_valid = false;
		name_valid = false;

		if(name === ""){
			$("#pledge_name_error").html("Please enter your name");
		}
		else {
			name_valid = true;
			$("#pledge_name_error").html("");
		}
		
		if(email === ""){
			$("#pledge_email_error").html("Please enter your email");
		}
		else {
			email_valid = true;
			$("#pledge_email_error").html("");
		}
		
		if(name_valid && email_valid){
			$.get("/pledge.php", {'email': email, 'name': name}, function(data){
				response = JSON.parse(data);
				if(response.status == "OK"){
					$("#pledge_form").html("Your pledge has been added - thanks!");
					$("#compendium").animate({'height': '125px'	}, 100);
				}
			});
		}
		
	});
	
	$("#close_compendium").click(function(){
		$("#pledge_form").fadeOut(100, function(){
			$("#compendium").animate({
					height: '95px'
				}
			);
		});
	});
	
});