(function($) {
	$.Kphp = $.Kphp || {};

	$.fn.resizable = function()
	{
		if(!$(this).is(".resizable-processed")) $.Kphp.resizable($(this));
		return this;
	};

	$.fn.resizableEnable = function()
	{
		if ($(this).is(".resizable-processed"))
			$(this).parent().removeClass('resizable-disabled');
	};

	$.fn.resizableDisable = function()
	{
		if ($(this).is(".resizable-processed"))
			$(this).parent().addClass('resizable-disabled');
	};

	$.Kphp.resizable = function(element)
	{
		var staticOffset = null;
		var textarea = $(element).wrap('<div class="resizable"><span></span></div>');
		var xresizable = $('<div class="xresizable"></div>').mousedown(startDrag);

		xresizable
			.insertAfter(element)
			.css('margin-left', xresizable.width() - (element.width() + 6));

		function startDrag(e)
		{
			staticOffset = element.height() - e.pageY;
			element.css('opacity', 0.25);
			$(document).mousemove(performDrag).mouseup(endDrag);
			return false;
		}

		function performDrag(e)
		{
			element.height(Math.max(32, staticOffset + e.pageY) + 'px');
			return false;
		}

		function endDrag(e)
		{
			$(document).unbind('mousemove');
			$(document).unbind('mouseup');
			element.css('opacity', 1);
		}

		element.addClass('resizable-processed');
	};
})(jQuery);