var XApp_input_labeled = function(xobj, options) {
	
	var plugin_name = 'filter';
	
	var plugin = function(xobj, options){
		// __construct();
		
		XApp_plugin.apply(this, arguments);
	};
	
	plugin.prototype = $.extend(new XApp_plugin.fn.onload(plugin_name), xobj, {
		
		_label : '',
		_$gray : null,
		_$input : null,
		
		options: {
			ui: true,
			input: 'input',
			label: false
		},
			
		init: function()
		{
			XApp_plugin.fn.init.apply(this, arguments);
			
			var self = this;
			
			self.initLabel();
			self.initInputLabel();
		},
		
		initLabel: function()
		{
			if(! this.options.label) {
				if(this.$el.prev('label').length) {
					this.options.label = this.$el.prev('label');
				}
			}
			
			if( this.options.label ) {
				
				if( typeof this.options.label == 'object' && this.options.label.length ) {
					this.options.label = this.options.label.hide().val();
				} 
				
				if( ! this.options.label ) {
					if( this.$el.prev('label').length ) {
						this.options.label = this.$el.prev('label').hide().text().replace(/: *$/, '');
					}
				}
				
				if( typeof this.options.label == 'string' ) {
					this._label = this.options.label;
				}
				
			}
		},
		
		_checkLabel: function()
		{
			
			var self = this;
			
			if(this._label && this._label.length) {
				if(this._$input.val()) {
					self.$el.addClass('active');
				} else {
					self.$el.removeClass('active');
				}
			}
		},		

		initInputLabel: function()
		{
			if(this._label && this._label.length) {
				var self = this;
				
				this._$input = (typeof this.options.input == 'object' && this.options.input) || this.$el.find(this.options.input);
				
				this._$gray = $('<span></span>')
					.addClass('labeled')
					.text(this._label)
					.click(function(){
						self._$input.focus();
					})
					.css({
						paddingLeft: (parseInt(this._$input.css('paddingLeft')) + 2)+'px',
						paddingTop: this._$input.css('paddingTop'),
						fontSize: this._$input.css('font-size'),
						lineHeight: this._$input.css('line-height')
					});
				
				this._$input.focus(function(){
					self.$el.addClass('focus');
				}).blur(function(){
					self.$el.removeClass('focus');
				}).keyup(function(){self._checkLabel();});
				
				this._$input.wrap($('<div></div>').addClass('labeled-cont'));
				self._checkLabel();
				this._$gray.insertBefore(this._$input);
			}
		}
	});
	
	
	return new plugin(xobj, options);	
};
