/* ************************ JQUERY INPUT HINTS **************************** */

(function($){
	
	$.fn.inputHints = function(opts){
		var	o = {
			hintColor:'#999',
			onHint : null,
			onHintOff : null
		}
		$.extend( true, o, opts );
		
		return this.each(function(){
			
			var $this = $(this);
			var hint = $this.relToData().data('inputHint');
			var origColor = $this.css('color');
			$this.data('hintActive', false);
			$this.data('options', o);
			$this.data('hint', hint);

			// Leave defualt val. //
			if( $this.val() == '' || $this.val() == hint ){
				$this.css({'color':o.hintColor}).val(hint);
				$this.data('hintActive', true);
			}
			
			$this.focus(function(){
				if( $this.val() == hint ){
					$this.css({'color':origColor}).val('');
					if( o.onHintOff ) o.onHintOff($this, origColor)
				}
				$this.data('hintActive', false);	
			}).blur(function(){
				if( $this.val() == '' ){
					$this.css({'color':o.hintColor}).val(hint);
					$this.data('hintActive', true);
					if( o.onHint ) o.onHint($this, o.hintColor)
				}
			});
		});
	}
	
	$.fn.inputHints.hintActive = function( $this ){

		

		if($this.data('hintActive')){
			return true;
		}
		return false;
	}

	$.fn.inputHints.restore = function( $this ){
		
		$this.each( function(){
			var $each	= $(this),
				o		= $each.data('options'),
				hint	= $each.data('hint');
				
			if( !o ) return false;
			
			$each.data('hintActive', true);
			$each.css({'color':o.hintColor}).val(hint);
		});

	}
	
	
})(jQuery);
