(function($){
	
	$.fn.jHintInput = function(o){
		
		return this.each(function(){
			var $this = $(this), value = $this.val();
			
			if (!$this.hasClass('ui-hint-input')) $this.addClass('ui-hint-input');
			
			function _showHint(){
				if ($this.val() == '' && value != ''){
					$this.val(value).addClass('ui-hint-input');
				}
			}
			
			function _hideHint(){
				if ($this.val() == value) $this.val('');
				$this.removeClass('ui-hint-input');
			}
			
			$this.bind('removeHint', function(){
				_hideHint();
				value = '';
			});
			
			$this.bind('hideHint', function(){
				_hideHint();
			});
			
			$this.bind('showHint', function(){
				_showHint();
			});
			
			$this.click(function(){
				_hideHint();
			});
			
			$this.focus(function(){
				_hideHint();
			});
			
			$this.blur(function(){
				_showHint();
			});
			
			$this.change(function(){
				_hideHint();
			});
			
			if ($this.hasClass('no-spaces')){
				$this.keyup(function(){
					$(this).val($(this).val().replace(' ', ''));
				});
			}
			
			$this.data('jHintInput', {
				val : function(){
					return $this.val() == value ? '' : $this.val();
				}
			});
			
		});
		
	}
	
})(jQuery);

