 /*
     * Auto-growing textareas; technique ripped from Facebook

(function($) {

   
    $.fn.textexpand = function(options) {

        this.filter('textarea').each(function() {

            var $this       = $(this),
                minHeight   = $this.height(),
                lineHeight  = $this.css('lineHeight');

            var shadow = $('<div></div>').css({
                position:   'absolute',
                top:        -10000,
                left:       -10000,
                width:      $(this).width() - parseInt($this.css('paddingLeft')) - parseInt($this.css('paddingRight')),
                fontSize:   $this.css('fontSize'),
                fontFamily: $this.css('fontFamily'),
                lineHeight: $this.css('lineHeight'),
                resize:     'none'
            }).appendTo(document.body);

            var update = function() {

                var times = function(string, number) {
                    for (var i = 0, r = ''; i < number; i ++) r += string;
                    return r;
                };

                var val = this.value.replace(/</g, '&lt;')
                                    .replace(/>/g, '&gt;')
                                    .replace(/&/g, '&amp;')
                                    .replace(/\n$/, '<br/>&nbsp;')
                                    .replace(/\n/g, '<br/>')
                                    .replace(/ {2,}/g, function(space) { return times('&nbsp;', space.length -1) + ' ' });

                shadow.html(val);
                $(this).css('height', Math.max(shadow.height() + 20, minHeight));

            }

            $(this).change(update).keyup(update).keydown(update);

            update.apply(this);

        });

        return this;

    }

})(jQuery);

*/

/**
 *  Another TextArea Autogrow plugin (0.2) alpha's alpha
 *  by Nikolay Borisov aka KOSIASIK
 *  mne@figovo.com
 *
 *  http://figovo.com/
 *
 *  Example:
 *  $('textarea').textexpand();
 *
 *  jQuery required. Download it at http://jquery.com/
 *
 */

(function(jQuery){

	jQuery.fn.textexpand = function(options){

		options = jQuery.extend({
			timer:100
		}, options);

		return this.each(function(i){

			var $t = jQuery(this),
				t = this;

			t.style.resize = 'none';
			t.style.overflow = 'hidden';

                           
			var tVal = t.value;
			t.style.height = '0px';
			t.value = "W\nW\nW";
			var H3 = t.scrollHeight;
			t.value = "W\nW\nW\nW";
			var H4 = t.scrollHeight;
			var H = H4 - H3;
                        t.value = tVal;
			tVal = null;

			$t.before("<div id=\"ataa_"+i+"\"></div>");

			var $c = jQuery('#ataa_'+i),
				c = $c.get(0);

			c.style.padding = '0px';
			c.style.margin = '0px';

			$t.appendTo($c);

			$t.bind('focus', function(){
				t.startUpdating()
			}).bind('blur', function(){
				t.stopUpdating()
			});

			this.heightUpdate = function(){

				if (tVal != t.value){

					tVal = t.value;
					t.style.height = '0px';
					var tH = t.scrollHeight + H;
                                       
                                        if(tH == 0)
                                        {t.style.height = '15px';}else{t.style.height = tH + 'px';}
                                        //t.style.height = tH + 'px';
					c.style.height = 'auto';
                                        if(tH == 0){c.style.height = '21px';}else{c.style.height = c.offsetHeight + 'px';}
                                        
                                        
				}

			}

			this.startUpdating = function(){
				t.interval = window.setInterval(function(){
					t.heightUpdate()
				}, options.timer);
			}

			this.stopUpdating = function(){
				clearInterval(t.interval);
			}

			jQuery(function(){
				t.heightUpdate()
			});

		});

	};

})(jQuery);

