(function(a){a.fn.extend({elastic:function(){var b=["paddingTop","paddingRight","paddingBottom","paddingLeft","fontSize","lineHeight","fontFamily","width","fontWeight"];return this.each(function(){if(this.type!="textarea"){return false}var g=a(this),c=a("<div />").css({position:"absolute",display:"none","word-wrap":"break-word"}),h=parseInt(g.css("line-height"),10)||parseInt(g.css("font-size"),"10"),k=parseInt(g.css("height"),10)||h*3,j=parseInt(g.css("max-height"),10)||Number.MAX_VALUE,d=0,f=0;if(j<0){j=Number.MAX_VALUE}c.appendTo(g.parent());var f=b.length;while(f--){c.css(b[f].toString(),g.css(b[f].toString()))}function l(i,m){curratedHeight=Math.floor(parseInt(i,10));if(g.height()!=curratedHeight){g.css({height:curratedHeight+"px",overflow:m})}}function e(){var n=g.val().replace(/&/g,"&amp;").replace(/  /g,"&nbsp;").replace(/<|>/g,"&gt;").replace(/\n/g,"<br />");var i=c.html();if(n+"&nbsp;"!=i){c.html(n+"&nbsp;");if(Math.abs(c.height()+h-g.height())>3){var m=c.height()+h;if(m>=j){l(j,"auto")}else{if(m<=k){l(k,"hidden")}else{l(m,"hidden")}}}}}g.css({overflow:"hidden"});g.keyup(function(){e()});g.live("input paste",function(i){setTimeout(e,250)});e()})}})})(jQuery);
