var hoverColour = "#FFF";

$(function(){
	$("a.hoverBtn").show("fast", function() {
		$(this).wrap("<div class=\"hoverBtn\">");
		$(this).attr("class", "");
	});

	//display the hover div
	$("div.hoverBtn").show("fast", function() {
		//append the background div
		$(this).append("<div></div>");

		//get link's size
		var wid = $(this).children("a").width();
		var hei = $(this).children("a").height();

		//set div's size
		$(this).width(wid);
		$(this).height(hei);
		$(this).children("div").width(wid);
		$(this).children("div").height(hei);

		//on link hover
		$(this).children("a").hover(function(){
			//store initial link colour
			if ($(this).attr("rel") == "") {
				$(this).attr("rel", $(this).css("color"));
			}
			//fade in the background
			$(this).parent().children("div")
			.stop()
			.css({"display": "none", "opacity": "1"})
			.fadeIn("fast");
			//fade the colour
			$(this)	.stop()
			.css({"color": $(this).attr("rel")})
			.animate({"color": hoverColour}, 350);
		},function(){
			//fade out the background
			$(this).parent().children("div")
			.stop()
			.fadeOut("slow");
			//fade the colour
			$(this)	.stop()
			.animate({"color": $(this).attr("rel")}, 250);
		});
	});

	$('#contact_form').validate({
		rules: {
			name: {
				required: true
			},
			company: {
				required: true
			},
			city: {
				required: true
			},
			telephone: {
				required: true,
				number: true
			},
			email: {
				email: true,
				required: true
			},
			enquiry: {
				required: true
			}
		},
		messages: {
			name: '',
			company: '',
			city: '',
			email: {
				required: '',
				email: 'Please enter a valid email address'
			},
			telephone: {
				required: '',
				number: 'Please enter digits only'
			},
			enquiry: ''
		},
		highlight: function(element, errorClass, validClass) {
			$(element).addClass(errorClass).removeClass(validClass);
		},
		unhighlight: function(element, errorClass, validClass) {
			$(element).removeClass(errorClass).addClass(validClass);
		},
		submitHandler: function() {
			$('#error_msg').html('Please wait...');
			$('#error_msg').css("color","green");
			$('#error_msg').show();
			$.ajax({
				type: "POST",
				url: base_url + "contact/post_form",
				data: $('#contact_form').serializeArray(),
				success: function(msg){
					if (msg == 'success'){
						$('#error_msg').html('Your email has been sent successfully ... we will be in touch very soon. Thank you');
					}else{
						$('#error_msg').html(msg);
						$('#error_msg').css("color","#FF0000");
						$('#error_msg').show();
					}
				}
			});
		}
	});
});

