$(document).ready(function() {
	$("#s").focus(function() {
		if ($(this).val() == "word") {
			$(this).val("");
		}
	});
	$("#s").blur(function() {
		if ($(this).val() == "") {
			$(this).val("word");
		}
	});
	$("#message").focus(function() {
		if ($(this).val() == "write to AAIR") {
			$(this).val("");
		}
	});
	$("#message").blur(function() {
		if ($(this).val() == "") {
			$(this).val("write to AAIR");
		}
	});
	$("#email").focus(function() {
		if ($(this).val() == "your email") {
			$(this).val("");
		}
	});
	$("#email").blur(function() {
		if ($(this).val() == "") {
			$(this).val("your email");
		}
	});
	/*
	$("a.play").click(function () {
		$("#player").replaceWith('<object id="player" type="application/x-shockwave-flash" data="http://wp.aair.fm/wp-content/plugins/podpress/players/xspf_player.swf?song_url=http://wp.aair.fm' + $(this).attr('href') + '&song_title=' + $(this).attr('title') + '&autoplay=true" height="25" width="170"><param name="movie" value="http://wp.aair.fm/wp-content/plugins/podpress/players/xspf_player.swf?song_url=http://wp.aair.fm' + $(this).attr('href') + '&song_title=' + $(this).attr('title') + '&autoplay=true"></object>\n');
		return false;
	});
	*/
	$("form#contact").submit(function() {
		var cErrorMsg = '<p id="e-cf" class="error"><strong>Whoops!</strong> There&#8217;s something wrong. Please check the highlighted fields.</p>\n';
		if ($("#contact > p.response").length > 0) { $("#contact > p.response").remove(); }
		$("#contact > div").removeClass('error');
		var ok = true;
		if ($("#email").val() == "" || $("#email").val() == "your email") {
			$("#email").parent().addClass('error');
			ok = false;
		}
		if ($("#message").val() == "" || $("#message").val() == "write to AAIR") {
			$("#message").parent().addClass('error');
			ok = false;
		}
		if (ok == true) {
			$("#contactSubmit").hide();
			$("#contactSubmit").after('<div id="l-cf" class="loading inline">&nbsp;</div>\n');
			$.post('/wp-content/themes/aair/sendMessage.php', {email: $("#email").val(), message: $("#message").val(), ajax: 1}, function(r) {
				$("#l-cf").hide().remove();
				$("#contactSubmit").show();
				if (r.success == "1") {
					$("#contact > div").slideUp();
					$("#contact").append('<p class="response">Your message was sent.<br>\n<br>\n<a href=\"#\" onclick=\"$(\'#contact > div\').slideDown(); $(this).parent().hide(); return false;\">Send another?</a></p>\n');
					$("#contact > p.response").css({'background-color': 'yellow'}).animate({ backgroundColor: 'white' }, 'slow');
				} else {
					r = r.errors.split(',');
					$.each(r, function(r, e) {
						$('#' + e).parent().addClass('error');
					});
					if ($('#e-cf').length > 0) {
						$('#e-cf').css({'background-color': 'yellow'}).animate({ backgroundColor: 'white' }, 'slow');
					} else {
						$('#contact').append(cErrorMsg);
					}
				}
			}, 'json');
		}
		return false;
	});
});