$(document).ready(function(){

  // clear floats on block element
  $('.clearfix').append('<div class="clearall"><!-- clear floats --></div>')
  
  // remove bottom border from previous anchor on current selected side nav
  $('#nav ul li.current').prev().addClass('no-border');

  // add first and last classes to all lists, table rows, table heads and table cells in the DOM
  $('ul li:first-child,table tr:first-child,tr td:first-child, tr th:first-child').addClass('first');
  $('ul li:last-child,table tr:last-child,tr td:last-child, tr th:last-child').addClass('last');

  // add validation method for password checking
	jQuery.validator.addMethod("password", function( value, element ) {
		var result = this.optional(element) || value.length >= 8 && /\d/.test(value) && /[a-z]/i.test(value);
		if (!result) {
			element.value = "";
			var validator = this;
			setTimeout(function() {
				validator.blockFocusCleanup = true;
				element.focus();
				validator.blockFocusCleanup = false;
			}, 1);
		}
		return result;
	}, "Your password must be at least 8 characters long and contain at least one number and one character.");
	
  // validation of form submissions
  $('.validate-form, #comment_form, #award-entry-form form').validate({
		messages: {
			password2: {
				password_confirm: " ",
				equalTo: "Please enter the same password as above."	
			}
	  }
	});

  $('#cart_checkout_form').validate({
		messages: {
			first_name: "Really need your name for the payment.",
			last_name: "Really need your name for the payment.",
			address: "We are going to need an address too.",
			city: "Did you forget this one. It is important.",
			state: "An address needs a state.",
			zip: "Come on we know you know your post code.",
			phone: "We need your phone number if it goes wrong.",
			email_address: "Can we have your email, need to email you the receipt.",
			credit_card_number: "Its a pain, but we need the credit card number, no spaces please.",
			CVV2: "Oh and the pesky number on the back of the card too."
	  }
	});
  
  // display example input info or field names within input
  $('.input-example').example(function() {
      return $(this).attr('title');
  });

  if ($('#category_id_1').is(':checked')) {
    $('#student-entry-info').slideDown('fast',function(){
     $(this).children('input').addClass('required');
    });
  }
  
  $('#category_id_1').click(function() {
   if ($('#category_id_1').is(':checked')) {
     $('#student-entry-info').slideDown('fast',function(){
      $(this).children('input').addClass('required');
     });
   } else {
     $('#student-entry-info').slideUp('fast',function(){
      $(this).children('input').removeClass('required');
     });
   }
  });  
  
});