(function($) {
	
	// jqSmallForm class

	var jqSmallForm = function(form)
	{
		this.form = $(form);
		this.fields = form.find('input[type=text], input[type=password]');
		this.error = form.find('p.error');
		
		if(this.fields.length) this.initFields();
	};
	
	jqSmallForm.prototype.initFields = function()
	{
		var self = this;
		
		this.fields.each(function() {
			self.initField($(this).closest('li'));
		});
	};
	
	jqSmallForm.prototype.initField = function(container)
	{
		var self = this;
		var input = container.children('input');
		var label = container.children('label').css('line-height', input.outerHeight() + 'px');
		
		container.css('position', 'relative');
		label.css({cursor: 'text', position: 'absolute', top: 0, left: 0}).click(function() { input.focus(); });
		input.focus(function() { self.hideLabel(label, this); }).blur(function() { self.showLabel(label, this); });
		input.after(label);
		
		if(input.val() != '') this.hideLabel(label, input);
	};
	
	jqSmallForm.prototype.hideLabel = function(label, input)
	{
		label.css('display', 'none');
	};
	
	jqSmallForm.prototype.showLabel = function(label, input)
	{
		if($(input).val() == '')
			label.css('display', 'inline');
	};
	
	// jquery plugin
	
	$.fn.smallform = function(options)
	{
		if(this.length < 1) return this;
		
		if(this.length > 1) this.each(function() { $(this).smallform(options); });
		else if(this.get(0).tagName.toLowerCase() != 'form') this.find('form').smallform(options);
		else this.data('smallform', new jqSmallForm(this));
		
		return this;
	}

})(jQuery);
