$(function () {
	var textboxes = $('form#contact .input-text');
	textboxes.each(function (index, input) {
		var label = $(input).prev();
		label.wrapInner("<span></span>");
		label.children("span").animate({
			opacity: 0.6
		},
		0);
		if (index == 0) {
			setInterval(function () {
				textboxes.each(function (index, inputX) {
					if (inputX.value != "") {
						$(inputX).prev().children("span").animate({
							opacity: 0
						},
						0)
					}
				})
			},
			100)
		}
		input.onfocus = function () {
			if (input.value == "") {
				label.children("span").animate({
					opacity: 0.2
				},
				200)
			}
		}
		input.onblur = function () {
			if (input.value == "") {
				label.children("span").animate({
					opacity: 0.6
				},
				200)
			}
		}
		if (input.value != "") {
			label.addClass('hastext')
		}
		input.onkeypress = function () {
			$('.error').hide();
			label.children("span").animate({
				opacity: 0
			},
			200)
		}
	});
	$('.error').hide();
	$(".sendBTN").click(function () {});
	$("form#contact").submit(function () {
		$('.input-text').attr("disabled", true);
		$('.error').hide();
		var from = $("input#from").val();
		if (from == "") {
			$("label#from_error").show();
			$('.input-text').attr("disabled", false);
			$("input#from").focus();
			return false
		}
		var email = $("input#email").val();
		if (email == "") {
			$("label#email_error").show();
			$('.input-text').attr("disabled", false);
			$("input#email").focus();
			return false
		}
		var note = $("textarea#note").val();
		if (note == "") {
			$("label#note_error").show();
			$('.input-text').attr("disabled", false);
			$("input#note").focus();
			return false
		}
		var dataString = 'from=' + from.toString() + '&email=' + email.toString() + '&note=' + note.toString();
		$.ajax({
			type: "POST",
			url: "email.php",
			data: dataString,
			success: function (msg) {
				$('#contact').ajaxComplete(function (event, request, settings) {
					if (msg == 'OK') {
						result = "<div id='message'><h3>Email successfully sent!</h3><p><img id='checkmark' src='images/check.gif' />&nbsp; Erin will be in touch soon.</p></div>";
						$("#contact_form").hide();
						$(this).empty()
					} else {
						result = msg;
						$('.input-text').attr("disabled", false)
					}
					$(this).fadeIn(1500, function () {
						$(this).append(result)
					})
				})
			}
		});
		return false
	})
});
