$().ready(function(){
	var hasFocus = null;
	
	$('.button').hover(function() {
		$(this).animate({
			borderTopColor:'#e60004',
			borderRightColor:'#e60004',
			borderBottomColor:'#e60004',
			borderLeftColor:'#e60004'
		}, 250);
	}, function() {
		$(this).stop().animate({
			borderTopColor:'#ffffff',
			borderRightColor:'#ffffff',
			borderBottomColor:'#ffffff',
			borderLeftColor:'#ffffff'
		}, 400);
	});	
	 
	$('label').hover(function() {
		if (hasFocus != $(this).attr('for')) {
			$(this).children('strong').animate({color: '#e60004'}, 250);
		}
	}, function() {
		if (hasFocus == $(this).attr('for')) {
			$(this).stop();
			$(this).children('strong').stop();
		} else {
			$(this).children('strong').stop().animate({color: '#000000'}, 400);
		}
	});

	$('input[type="text"]').add('textarea').focus(function() {
		$(this).animate({borderTopColor: '#e60004', borderRightColor: '#e60004', borderBottomColor: '#e60004', borderLeftColor: '#e60004'}, 250);
		hasFocus = $(this).parent().attr('for');
	});
	
	$('input[type="text"]').add('textarea').blur(function() {
		$(this).animate({borderTopColor: '#a8aaac', borderRightColor: '#a8aaac', borderBottomColor: '#a8aaac', borderLeftColor: '#a8aaac'}, 250);
		$(this).parent().children('strong').stop().animate({color: '#000000'}, 250);
		hasFocus = null;
	});

	var container = $('ul#error');	
	// validate the form when it is submitted
	$("#contact").validate({
		errorLabelContainer: "#formError",
		errorElement: "em",
		wrapper: 'span',
		rules: {
			name: {
				required: true,
				minlength: 3
			},
			company: "required",
			email: {
				required: true,
				email: true
			},
			telephone: {
				required: true,
				minlength: 6
			},
			subject: "required",
			message: "required"
		},
		messages: {
			name: {
				required: "Enter your name"
			},
			company: "Enter your company name",
			email: {
				required: "Enter your email address",
				email: "You've entered an invalid email address"
			},
			telephone: {
				required: "Enter your telephone number"
			},
			subject: "Enter a subject",
			message: "Enter a message"
		}
	});
	
});