/* uiState jQuery Plugin,
 * version: 1.0
 * Copyright (c) 2010, Vasile Giorgi
 * Licensed under the MIT License
 *
 * examples:
 * $(selector).uiState('active' || 'default' || 'disabled' || 'error' || 'errorText' ||'highlight' || 'hover' || 'none');
 * $(selector).uiStateError() is similar with: $(selector).uiState('error') and so on...
 */

(function($)
{
	$.fn.uiState = function(state)
	{
		switch(state.toLowerCase())
		{
		case 'active':
			state = 'active';
			break;
		case 'default':
			state = 'default';
			break;
		case 'disabled':
			state = 'disabled';
			break;
		case 'error':
			state = 'error';
			break;
		case 'errortext':
		case 'error-text':
		case 'error_text':
			state = 'error-text';
			break;
		case 'highlight':
			state = 'highlight';
			break;
		case 'hover':
			state = 'hover';
			break;
		case 'none':
			state = 'none';
			break;
		default:
			return(false);
			break;
		}
		return this.each(function()
		{
			if(state == 'none')
			{
				if($(this).find('.text').length > 0)
				{
					var text=$(this).find('.text').text();
					$(this).empty();
					$(this).text(text);
				}
			}
			else
			{
				var text = $(this).text();
				$(this).empty();
				$(this).html(
					'<div class="ui-widget">'
						+'<div class="ui-state-'+state+' ui-corner-all">'
							+'<p class="text" style="padding:4px">'+text+'</p>'
						+'</div>'
					+'</div>');
			}
		})
	};

	$.fn.uiStateActive = function()
	{
		return this.each(function()
		{
			$(this).uiState('active');
		})
	};

	$.fn.uiStateDefault = function()
	{
		return this.each(function()
		{
			$(this).uiState('default');
		})
	};

	$.fn.uiStateDisabled = function()
	{
		return this.each(function()
		{
			$(this).uiState('disabled');
		})
	};

	$.fn.uiStateError = function()
	{
		return this.each(function()
		{
			$(this).uiState('error');
		})
	};

	$.fn.uiStateErrorText = function()
	{
		return this.each(function()
		{
			$(this).uiState('errorText');
		})
	};

	$.fn.uiStateHighlight = function()
	{
		return this.each(function()
		{
			$(this).uiState('highlight');
		})
	};

	$.fn.uiStateHover = function()
	{
		return this.each(function()
		{
			$(this).uiState('hover');
		})
	};

	$.fn.uiStateNone = function()
	{
		return this.each(function()
		{
			$(this).uiState('none');
		})
	};

	$.fn.uiStateRemove = function()
	{
		return this.each(function()
		{
			$(this).uiState('none');
		})
	};

})(jQuery);
