/*
	jQuery plugin placeHolder by Jakob Givoni
	
	PURPOSE:
	- Helps the user easily identify input fields and what to type in them.
	- Visual hint: Prefills your input or textarea field with the value of your title attribute (the tooltip becomes the initial value)
	- Removes the hint on focus
	- Reenters the hint on blur of field is left empty
	- Styling: Adds a class when the field contains the hint. Use it to i.e. style the text dimmed, lightening the color
	- Hint not submitted: Removes the name attribute while the hint is displayed so that the hint won't be submitted if case of form submission
	
	USAGE:
	jQuery('input').inputFieldHelper(options); // options is an optional object
	- optional options: 
		- dimmedClass: the class name to add when the field is showing the hint

*/

jQuery.fn.placeHolder = function(options) {

	settings = jQuery.extend({
		dimmedClass: 'dimmed'
	}, options);
	
	return this.each(function(){
		var $this = jQuery(this);
		$this.data('origName',$this.attr('name'));
		// Copying the title value to input value
		$this.val($this.attr('title')).addClass(settings.dimmedClass).removeAttr('name');
		
		// On focus, remove the default text
		$this.focus(function(){
			if ($this.val() == $this.attr('title')) {
				$this.val('').removeClass(settings.dimmedClass).attr('name', $this.data('origName'));
			}
		});
		
		// On blur, add default text if field is empty
		$this.blur(function(){
			if ($this.val() == '') {
				$this.val($this.attr('title')).addClass(settings.dimmedClass).removeAttr('name');
			}
		});
	});
}