// JavaScript Document

(function( $ ){
	var methods = {
		init : function( options ) { 
			var settings = {
				'text'		: '',
				'width'		: '400',
				'top'		: -28,
				'left'		: 4
			};
			
			return this.each(function() {        
				if ( options ) { 
					$.extend( settings, options );
				}
				$(this).after('<div class="hpr" style="width:'+settings.width+'px"><div class="hint" style="top:'+settings.top+'px;left:'+settings.left+'px"></div></div>');
				var o=$(this).next().children(".hint");
				o.html(settings.text);				
				$(this).EMPSHint('show');
				$(this).bind('focus.EMPSHint',methods.hide);
				$(this).next().children(".hint").bind('click.EMPSHint',function(){
					var o=$(this).parent().prev();
					o.EMPSHint('hide');
					o.focus();
				});
				$(this).bind('blur.EMPSHint',methods.show);
			});
		
		},
		show : function( ) {
			if ($(this).val() == '' ){
				var o=$(this).next().children(".hint");		
				o.css('display','block');
			}
		},
		hide : function( ) {
			var o=$(this).next().children(".hint");				
			o.css('display','none');				
		},
	};
	
	$.fn.EMPSHint = function( method ) {
		if ( methods[method] ) {
			return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
		} else if ( typeof method === 'object' || ! method ) {
			return methods.init.apply( this, arguments );
		} else {
			$.error( 'Method ' +  method + ' does not exist on jQuery.EMPSHint' );
		}    
	};
})( jQuery );

