(function($) {
	$.fn.tpLabeledTextfield = function(userOptions) {
		var isEmpty = 'tpLabeledTextfield_empty';
		
		var o = $.extend({
			label : 'label',
			password : false,
			removeLabelTag : true,
			labelCss : {
				'font-style' : 'italic',
				'color' : '#cccccc'
			},
			valueCss : {
				'font-style' : 'normal',
				'color' : '#000000'
			}
		}, userOptions || {});
	
		this.val(o.label)
			.css(o.labelCss)
			.addClass(isEmpty);
		
// Remove original label		
		
		if(o.removeLabelTag) {
			$('label[for='+this.attr('id')+']').hide();
		}	
			
		var that = this;	
		var $form = this.parents('form');
		
		$form.submit(function() {
			if(that.hasClass(isEmpty)) {
				that.val('');
			}
		});
			
		this.focus(function() {
			that.css(o.valueCss);
			if(that.hasClass(isEmpty)) {
				that.val('');
				that.removeClass(isEmpty);
			}
		});	
		
		this.blur(function() {
			if(that.val() == '') {
				that.addClass(isEmpty)
				.css(o.labelCss)
				.val(o.label);
			} else {
				that.removeClass(isEmpty);
			}
			
		});
		
		return this;	
	}
})(jQuery);
