function initResizableTextareas()
{
	var textareas = $A(document.getElementsByTagName("textarea"));
	textareas.each(function(textarea) { new ResizeableTextarea(textarea).build() });
}

var ResizeableTextarea = Class.create();
ResizeableTextarea.prototype = {
	initialize: function(obj)
	{
		if(obj.className == 'noresize') {
			return;
		}
		this.max_height = 500;
		this.min_height = 50;
		this.element = obj;
	},
	build: function() {
		// Add wrapper
		this.wrapper = document.createElement('div');
		this.wrapper.className = 'resizable-textarea';
		this.element.parentNode.insertBefore(this.wrapper, this.element);
		
		// Add resizer
		this.resizer = document.createElement('div');
		this.resizer.className = 'resizer';
		this.wrapper.appendChild(this.resizer);
	
		// Set formats
		this.element.style.marginBottom = '0px';
		this.wrapper.style.width = this.element.offsetWidth + 'px';

		// Wrap textarea
		this.element.parentNode.removeChild(this.element);
		this.wrapper.insertBefore(this.element, this.resizer);

		Event.observe(this.resizer, "mousedown", this.startDrag.bindAsEventListener(this), false);
	},
	startDrag: function(e)
	{
		this.element.style.opacity = 0.5;
	
		// Capture mouse
		var th = this;
		document.onmousemove = function(e) { th.doDrag(e); };
		document.onmouseup = function(e) { th.stopDrag(e); };		

		// Store drag offset
		this.dragOffset = e.clientY - this.resizer.offsetTop;
	},
	doDrag: function(event) 
	{
		event = event || window.event;
		var y = event.clientY - this.element.offsetTop;

		// Use min/max height when too small/big
		var height = Math.max(this.min_height, y - this.dragOffset);
		var height = Math.min(this.max_height, height);
		
		// Apply height
		this.wrapper.style.height = height + this.resizer.offsetHeight + 'px';
		this.element.style.height = height + 'px';
	},
	stopDrag: function(e)
	{
		this.element.style.opacity = 1.0;
		
		// Reset event handlers
		document.onmousemove = 'undefined';
		document.onmouseup = 'undefined';
	}
}

Event.observe(window, "load", initResizableTextareas , false);