/*! Copyright (c) 2008 Brandon Aaron (http://brandonaaron.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * Based on Making Compact Forms More Accessible by Mike Brittain (http://alistapart.com/articles/makingcompactformsmoreaccessible)
 */

(function($){
	
	$.fn.overlabel = function() {
		return this.each(function() {
			var $label = $(this).addClass('overlabel-applied'), $input = $('#' + $label.attr('for'));
			$input
				.bind('focus blur', function(event) {
					var state = $input.val() || event.type == 'focus' ? 'hidden' : 'visible';
					$label.removeClass('overlabel-visible overlabel-hidden').addClass( 'overlabel-' + state );
				}).trigger('focus').trigger('blur');
		});
	};

})(jQuery);
