/*  Get rid of IE image rollover flickering  */
try {
	document.execCommand('BackgroundImageCache', false, true);
} catch(e) {
}

$(function() {
	// Drop-down navigation
	$('#faq_drop, #advice_drop').change(function() {
		location.href = $(this).val();
	});

	// Input-focus-hide thing
	$('input[type=text]').focus(function() {
		if (this.value == this.defaultValue) {
			this.value = '';
		}
		$(this).css('color', '#666');
	}).blur(function() {
		if (this.value == '') {
			this.value = this.defaultValue;
			$(this).css('color', '#ccc');
		}
	}).each(function() {
		$(this).css('color', '#ccc');
	});

	// AJAX submit of the contact form
	$('input[type=submit], input[type=image], button').click(function() {
		var self = $(this);
		var form = self.parents('form');
		if (!form.validate().form()) {
			alert("The contact form is not valid.");
		} else {
			self.addClass('working');
			$.post('/contact.php', form.serialize(), function(data, textStatus) {
				if (data['status'] == 'OK') {
					form.slideUp(function() {
						var p = $('<p>' + data['message'] + '</p>');
						form.before(p);
						p.hide().slideDown('fast');
					});
				} else {
					form.submit();
				}
			}, 'json');
		}
		return false;
	});

	// Form validation
	$('#enquiry').validate();
});

