jQuery(function($){
	$("#contactPersonOverlay").click(hide_contact_lightwindow);
	$("#contact_submit").val('Submit!');
	$("#contactPersonForm").validate({
		submitHandler: function(form){
			jQuery("#contact_submit").attr('disabled', 'disabled');
			jQuery.ajax({
				url: 'proc/contact_person_handler.php',
				type: 'POST',
				data: jQuery("#contactPersonForm").serialize(),
				success: function(resp){
					if (resp == 'invalid') message = "<p>Error in processing form data!  Please try again or use the form below to contact us.</p>";
					else if (resp == 'OK') message = "Email sent successfully. Thank you!";
					else if (resp == 'emailError') message = "There was an error in sending your message, plase try again or use the form below.";
					else message = "There was an error in sending your message, plase try again or use the form below."; //unknown failure
					jQuery("#contactPersonResponse").show().html(message);
				}
			});
			return false;
		}
	});
});

function show_contact_lightwindow(event, name){
	jQuery("#contactPersonLightbox, #contactPersonOverlay, #contactPersonForm").show();
	jQuery("#contactPersonLightbox").css({top: "50%;", left: "50%"})
	jQuery("#contactPersonResponse").hide();
	jQuery("#contactPersonForm :input").val('');
	jQuery("#contact_to").val(name);
	jQuery("#contact_submit").attr('disabled', '');
	jQuery("#fullName").html(jQuery(event.target).attr('alt'));
	jQuery("#contact_img").attr('src', event.target.src);
	jQuery("#contact_submit").val('Submit!');
}

function hide_contact_lightwindow(){
	jQuery("#contactPersonLightbox, #contactPersonOverlay").hide();
}
