
	var resizeOptions =
	{
		horizontal: false,
		vertical: false,
		left: false,
		top: false,
		minWidth: 100,
		minHeight: 45,
		maxWidth:	10000,
		maxHeight:	10000,
		complete: undefined,
		resize:	function(element, width, height, left, top)
		{
			$(element)
				.css('left', left + 'px')
				.css('top', top + 'px')
				.width(width)
				.height(height)
		}
	}

	function resizeElement(event, element, options)
	{
		if(options == undefined) options = resizeOptions;
		for(var option in resizeOptions)
			if(options[option] == undefined) options[option] = resizeOptions[option];
			
		event.returnValue = false;
		if(event.preventDefault) event.preventDefault();
			
		var resizing = new Object();
		resizing.startX = event.pageX;
		resizing.startY = event.pageY;
		resizing.startH = $(element).height();
		resizing.startW = $(element).width();
		resizing.startL = $(element).offset().left;
		resizing.startT = $(element).offset().top;
		
		$(element).addClass('resizing');
		
		/*for managedObject*/		
		$(element).parents("div.managedProperty").addClass('resizing');

		// Mousemove handler
		var mousemoveHandler = function(event)
		{
			
			var dx = event.pageX - resizing.startX;
			var dy = event.pageY - resizing.startY;
			
			var width = $(element).width();
			var height = $(element).height();
			var left = $(element).offset().left;
			var top = $(element).offset().top;
			
			if(options.horizontal)
			{
				width = resizing.startW + dx;
				if(width < options.minWidth) width = options.minWidth;
			}

			if(options.vertical)
			{				
				height = resizing.startH + dy;
				if(height < options.minHeight) height = options.minHeight;
			}

			if(options.left)
			{
				left = resizing.startL + dx;
				if(left < 0) left = 0;
				width = resizing.startW - left + resizing.startL;
				if(width < options.minWidth)
				{
					width = options.minWidth;
					left = resizing.startW + resizing.startL - width;
				}
			}

			if(options.top)
			{
				top = resizing.startT + dy;
				if(top < 0) top = 0;
				height = resizing.startH - top + resizing.startT;
				if(height < options.minHeight)
				{
					height = options.minHeight;
					top = resizing.startH + resizing.startT - height;
				}
			}
			
			options.resize(element, width, height, left, top);

			return false;
		}
		
		// Mouseup handler
		var mouseupHandler = function(event)
		{
			$(element).removeClass('resizing');
			/*for managedObject*/		
			$(element).parents("div.managedProperty").removeClass('resizing');	
			
			$(document).unbind('mousemove', mousemoveHandler);
			$(document).unbind('mouseup', mouseupHandler);
			if(options.complete) options.complete();
		}
		
		$(document).mousemove(mousemoveHandler);		
		$(document).mouseup(mouseupHandler);		

		return false;
	}
	
	$(document).bind("update", function() {
		$("div.resizer.vertical").mousedown(function(event) {
			resizeElement(event, $(this).prev().get(0), {vertical: true, minHeight: 45});
		})
	})

