var Onload = new Array();
window.onload = function(){
    Onload.each(function(OnloadEvents){
        for (key in OnloadEvents){
            eval('OnloadEvents.'+key+'();');
        }
    });
    //controls_toolbar = new Control.TextArea.ToolBar.Html('doccont');
    //controls_toolbar.toolbar.container.id = 'controls_toolbar';
}
ResizeableTextarea = Class.create();
ResizeableTextarea.prototype = {
    initialize: function(element, options) {
        this.element = $(element);
        this.size = parseFloat(this.element.getStyle('height') || '100');
        this.options = Object.extend({
            resizeStep: 10,
	    maxHeight: 600,
            minHeight: this.size
        }, options || {});
        Event.observe(this.element, "keyup", this.resize.bindAsEventListener(this));
        this.element.style.overflow = 'hidden';
        this.element.setAttribute("wrap","virtual");
        this.resize();
    },
    resize : function(){
        this.shrink();
        this.grow();
    },
    shrink : function(){
        if (this.size <= this.options.minHeight){
            return;
        }
        if (this.element.scrollHeight <= this.element.clientHeight) {
            this.size -= this.options.resizeStep;
            this.element.style.height = this.size+'px';
            this.shrink();
        }
    },
    grow : function(){
        if(this.element.scrollHeight > this.element.clientHeight) {
            if(this.size >= this.options.maxHeight) return;
            this.size += (this.element.scrollHeight - this.element.clientHeight) + this.options.resizeStep;
            this.element.style.height = this.size+'px';
            this.grow();
        }
    }
}
var OnloadPage = {
    'resizible_textareas' : function(){
	$$('textarea').each(function(item){
	        new ResizeableTextarea(item);
	});
    }
}
//Onload.push(OnloadPage);
