$(function () {
	$('#primary_nav a').wrapInner('<span/>');
	$('#primary_nav li:last, #primary_nav li:last(-1)').addClass('last');
	$('#primary_nav li').eq(-2).addClass('second-last');
	
	$('.button').wrap('<span class="button_wrap"/>');
	
	$('#event_form').validate();
	$('#contact').validate({
		errorPlacement: function(error, element) {
		    
	 	},
		invalidHandler : function(form, validator) 
		{
			alert('There was some information missing in the form. Please see the highlighted fields.');
		}
	});
	
	$('#event_form').submit(function (e) {
		e.preventDefault();
		
		if ($(this).valid())
		{
			var form = $(this).serialize();
			$.post('/process_registration.php', form, function (text, status) {
				if (text.status == "ok")
				{
					$('#event_form').hide();
					$('.message').removeClass('error').empty().html('Thank you for submitting your request, we&rsquo;ll be in touch soon.');
				}
				else
				{
					$('.message').addClass('error').html('There was a problem sending your registration.');
				}
			});
		}
	});
	
	$('a.submit').click(function (e) {
		e.preventDefault();
		$(this).parent().parent().submit();
	});
});
