// This is a jQuery 'plugin' for adding hint text to text inputs.
// Just add a hint attribute to any input and you get the rest
// for free. This functionality hides and shows the hint text as
// needbe, and ensures that the hint is cleared on form submit.
//
// This requires the jquery.livequery.js file.
//
// <input type="text" hint="Type Something Here" name="something" />
// 
jQuery(document).ready(function($) {
	
	// When input with hint is loaded into DOM,
	// make sure that hint style and text are 
	// added if needed.
	$('input[hint]').each(function(e) {
		blur_with_hint(this);
	});

	$('input[hint]').livequery('blur', function(e) {
		blur_with_hint(this);
	});

	$('input[hint]').livequery('focus', function(e) {
		focus_with_hint(this);
	});
	
	// Ensure that all fields in a submitted form
	// are cleared of hints on submit.
	$('form').livequery('submit', function(e) {
		$(this).find('input[hint]').each(function() { 
			focus_with_hint(this);
		})
	})
});

function blur_with_hint(obj) {
	obj = $(obj);
	if(obj.val() == '') {
		obj.val(obj.attr('hint'));
		obj.addClass('blurred_with_hint');
	}
}

function focus_with_hint(obj) {
	obj = $(obj);
	if(obj.val() == obj.attr('hint')) {
		obj.val('');
		obj.removeClass('blurred_with_hint');
	}
}