--- misc/textarea.js	13 Mar 2009 23:15:08 -0000	1.27
+++ misc/textarea.js	13 Apr 2009 20:23:15 -0000
@@ -35,6 +35,52 @@ Drupal.behaviors.textarea = {
         textarea.css('opacity', 1);
       }
     });
+
+    $('textarea.resizable').each(function() {
+      $(this).bind("keypress input beforepaste", {currId: this.id}, resizeEventHandler);
+      resizeRefresh(this.id); // Initial refresh
+    });
+    
+    $('input.teaser-button').bind("click", resizeRefreshAll); // Fire on a click on the teaser split/join button 
+
+    function resizeEventHandler(event) {
+      resizeRefresh(event.data.currId);
+    }
+
+    function resizeRefreshAll() { // Split/join teaser has been clicked, refresh textareas
+      $('textarea.resizable').each(function() {
+        resizeRefresh(this.id);
+      });
+    }
+
+    function resizeRefresh(currId) {
+      resizeTextarea($('textarea#' + currId));
+    }
+
+    function resizeTextarea(textarea) {
+      var defaultHeight = 150; // We default to 150px. Possible to calculate this by current line-height? In IE too?
+      var lines = textarea.val().split("\n");
+      var count = lines.length;
+      $.each(lines, function() { 
+        count += parseInt(this.length / 70); 
+      });
+      var currHeight = parseInt(textarea.css("height"));
+      var rows = parseInt(currHeight / 20) - 1;
+
+      if (count > rows) { // Increase height
+        textarea.css("height", (currHeight + (defaultHeight/2)));
+      }
+      else if (((count + 7) <= rows) && (currHeight > defaultHeight) && (count > 5)) { // Decrease height
+        textarea.css("height", (currHeight - (defaultHeight/2)));
+      }
+      else if ((count <= rows) && (count <= 5)) { // Use default height
+        textarea.css("height", defaultHeight);
+      }
+      else if (count <= rows) { // No change
+//        textarea.css("height", currHeight);
+      }
+    }
+    
   }
 };
 
