(function(A){jQuery.fn.extend({elastic:function(){var B=["paddingTop","paddingRight","paddingBottom","paddingLeft","fontSize","lineHeight","fontFamily","width","fontWeight","border-top-width","border-right-width","border-bottom-width","border-left-width","borderTopStyle","borderTopColor","borderRightStyle","borderRightColor","borderBottomStyle","borderBottomColor","borderLeftStyle","borderLeftColor"];return this.each(function(){if(this.type!=="textarea"){return false}var H=jQuery(this),C=jQuery("<div />").css({position:"absolute",display:"none","word-wrap":"break-word","white-space":"pre-wrap"}).addClass("elastic-twin-div"),J=parseInt(H.css("line-height"),10)||parseInt(H.css("font-size"),"10"),L=parseInt(H.css("height"),10)||J*3,K=parseInt(H.css("max-height"),10)||Number.MAX_VALUE,D=0;if(K<0){K=Number.MAX_VALUE}var G=A("> .elastic-twin-div",H.parent());if(G.length==1){G.replaceWith(C)}else{C.appendTo(H.parent())}var F=B.length;while(F--){C.css(B[F].toString(),H.css(B[F].toString()))}function I(){var N=Math.floor(parseInt(H.width(),10));if(C.width()!==N){C.css({width:N+"px"});E(true)}}function M(N,P){var O=Math.floor(parseInt(N,10));if(H.height()!==O){H.css({height:O+"px",overflow:P})}}function E(Q){var P=H.val().replace(/&/g,"&amp;").replace(/ {2}/g,"&nbsp;").replace(/<|>/g,"&gt;").replace(/\n/g,"<br />");var N=C.html().replace(/<br>/ig,"<br />");if(Q||P!==N){C.html(P);if(Math.abs(C.height()-H.height())>0){var O=C.height();if(O>=K){M(K,"auto")}else{if(O<=L){M(L,"hidden")}else{M(O,"hidden")}}}}}H.css({overflow:"hidden"});H.bind("keyup change cut paste",function(){E()});A(window).bind("resize",I);H.bind("resize focus",I);H.bind("update",E);H.bind("blur",function(){if(C.height()<K){if(C.height()>L){H.height(C.height())}else{H.height(L)}}});H.bind("input paste",function(N){setTimeout(E,250)});E()})}})})(jQuery);