(function($) {
	$.fn.blurme = function(options) {
		options = $.extend({
			defaultAttr: "title",
			classFocus: "now-focus",
			classBlur: "now-blur",
			callbackBlur: function(){},
			callbackFocus: function(){},
			callbackLoad: function(){}
		}, options);
		
		this.each(function(){
			var $field = $(this);
			var $replacement = $field.clone();
			var def = $field.attr(options.defaultAttr);
			
			if(typeof options.callbackLoad == 'function'){
        		options.callbackLoad.call(this, $replacement, $field, def);
      		}
			
			$replacement
				.removeAttr("name") // we don`t need replacement field in form
				.val(def)
				.addClass(options.classBlur);
			
			// replacement must have "text" type if field is a password
			if($field.attr("type") == "password") {
				$replacement.attr("type", "text");
			}
			
			$field
				.addClass(options.classFocus)
				.val("")
				.hide()
				.after($replacement); // replacement is going right after original field 
			
			$replacement.bind("focus", function(){
				$replacement.hide();
				$field.show().focus(); // focus on original field
				
				// run callback "callbackFocus"
				if(typeof options.callbackFocus == 'function'){
        			options.callbackFocus.call(this, $replacement, $field);
      			}
			});
				
			$field.bind("blur", function(){
				// run callback "callbackBlur" before field value is checked
				if(typeof options.callbackBlur == 'function'){
        			options.callbackBlur.call(this, $replacement, $field);
      			}
      			
				if($.trim($field.val()) == ''){	
					$field.hide();
					$replacement.show();
				}
			});
		});
	}
})(jQuery);
