var is_clicked = false;

function handle_result(server) {
	$('#response').html(server.response);	
	
	if(server.status == "spam" || server.status == "failed") {
		//do nothing
		}
	else {
		if(is_clicked == false) {
			$('#response').click(function() {
				$('#response').hide("slide", { direction: "down" }, 500);
				$('#name').removeAttr("disabled");
				$('#email').removeAttr("disabled");
				$('#message').removeAttr("disabled");
				$('#send').removeAttr("disabled");
				$('#send').animate({
						opacity: 1
						},
					400,
					function() { //done
					}
					);
				
				});
			is_clicked = true;
			}			
		}
	}

$(document).ready(function(){
	$("#contact").submit(function(){
	
		$('#name').attr("disabled", true);
		$('#email').attr("disabled", true);
		$('#message').attr("disabled", true);
		$('#send').attr("disabled", true);
		$('#send').animate({
				opacity: 0.1
				},
			400,
			function() { //done
			}
		);
					
		$('#response').html("Contacting server...");
		$('#response').show("slide", { direction: "down" }, 500);
		
		$.post("/backend/send_email", {
				name: $("#name").val(),
				email: $("#email").val(),
				message: $("#message").val()
				},
				function(data) {
					handle_result(data);
					},
				"json");
		
		return(false);
		});
	
	//stupid IE. I seriously hate you.
	$('#showcase a').animate({opacity: 0.0}, 200, function(){});
		
	$('#showcase a')
		.mouseover(function() {
			$(this).animate({opacity: 0.8}, 200, function(){});
			})
		.mouseout(function() {
			$(this).animate({opacity: 0.0}, 200, function(){});
			});
			
	$('input[type="image"]')
		.mouseover(function() {
			$(this).attr("src", "/media/img/send-over.png");
			})
		.mouseout(function() {
			$(this).attr("src", "/media/img/send.png");
			});
			
	$("a#single_image").fancybox({
		'titlePosition': 'inside'
		});
			
	$("a.inline").fancybox({
		'scrolling': 'no',
		'hideOnContentClick': true
		});
	});