$(function()
{
	$("a.modal").click(function()
	{
		if ($("#subscribe").length == 0)
		{
			$("#sidebar").append('<div id="subscribe"></div>');
			$("#subscribe").load($(this).attr("href"), function()
			{
				$("#subscribe").fadeIn(500);
			});
		}
		else
		{
			removeForm();
		}
		return false;
	});
	$("#subscribe input[type=image]").live("click", function()
	{
		$e = $("#subscribe");
		email = $("input[type=text]", $e).val();
		if (email == "" || email == "your email address")
		{
			$("input[type=image]").after('<p class="error">Please enter a valid email address</p>');
		}
		else
		{
			email = "email=" + email + "&check=sent";
			$('p.error', $e).remove();
			$("input[type=image]").after('<span>Sending</span>').remove();
			$.ajax(
			{
				type: "POST",
				url: $("form", $e).attr("action"),
				data: email,
				success: function(msg)
				{
					$("p", $e).before(msg);
					$("input, span", $e).remove();
				}
			});
		}
		return false;
	});
	$("#subscribe a.btn_close").live("click", function()
	{
		removeForm();
		return false;
	});
});

function removeForm()
{
	$("#subscribe").fadeOut(500, function() { $("#subscribe").remove(); });
}