/* vertigro v1.0 - Automatically grow your textarea vertically.
   Copyright (C) 2008 Paul Pham <http://aquaron.com/~jquery/vertigro>

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
(function($){
   $.fn.vertigro = function() {
      return this.filter('textarea').each(function() {
         var grow = function(e) {
            var h = parseInt($(this).css('lineHeight')
               .replace(/px$/,''))||20;
						$(this).height('20px');
            if (this.clientHeight < this.scrollHeight){
              $(this).height(this.scrollHeight + h + 'px');
						}
						
         };
				 
				 
				 var h2 = parseInt($(this).css('lineHeight').replace(/px$/,''))||20;
				 $(this).height('20px');
				 if(this.clientHeight < this.scrollHeight)
					$(this).height(this.scrollHeight + h2 + 'px');
				 
         $(this).css('overflow','hidden')
            .keydown(grow).keyup(grow).change(grow);
      });
   };
})(jQuery);
