/**
 *		Fill value of input whit title 	
 * 	
 * 		@copyright 2010 iSource B.V.
 *		@version 1.2 
 * 
 */

(function($){
	 $.fn.inputTip = function(options) {  
	       
	   var defaults = {  
			grayClass: 'gray'
	   };  
	     
	   var options = $.extend(defaults, options);
	   
	   return this.each(function() {  
		   var obj = $(this);  
		   var title = obj.attr("title");
		   var value = obj.attr("value");
			   
		   if(title != '' && value == ''){
			   obj.attr("value", title);
			   obj.addClass(options.grayClass);
			   // adding submit check to empty defalt's	
			   var parentForm = obj.parents('form');
				if (parentForm) {
					parentForm.submit(function() {
						if(obj.hasClass(options.grayClass)){
							obj.attr("value", '');
						}
					});
				};
			   
			// actions
			   obj.focus(function() {
				   if(title == $(this).attr("value")){
					   $(this).attr("value", '');
					   $(this).removeClass(options.grayClass);
				   }
			   });
			   
			   obj.blur(function() {
				   if($(this).attr("value") ==  ''){
					   $(this).attr("value", title);
					   $(this).addClass(options.grayClass);
				   }
			   });
		   }
	   });
 };
})(jQuery);