/*!
 * BMIR Form Field Update
 * Copyright (c) 2011 Bryan Mills Iradesso
 * Version: 1.0 (19-AUG-2011)
 * Requires: jQuery v1.6.2 or later
 */

(function($) {

	$.fn.fieldLabel = function(settings) {

		// START PLUGIN PARAMETERS
		var _defaults = {};
		// END PLUGIN PARAMETERS - Don't edit anything below this line.
		// --------------------------------------------------------------

		if(settings)
			$.extend(_defaults, settings);
			
		var $this = jQuery(this);

		$this.each(function() {
			var $object = jQuery(this);

			if($object.val() === '') {
				$object.val($object.attr('title'));
			}

			$object.focus(function() {
				if($object.val().toLowerCase() === $object.attr('title').toLowerCase()) {
					$object.val('').addClass('focused');
				}
			});

			$object.blur(function() {
				if($object.val() === '') {
					$object.val($object.attr('title')).removeClass('focused');
				}
			});
		});

		// Find the form object of this field label
		var $form = this.closest('form');

		$form.submit(function() {
			$this.each(function() {
				var $object = jQuery(this);
				
				if($object.val() === $object.attr('title')) {
					$object.val('');
				}
			});
		});
		
		return $this;

	};
})(jQuery);

