/*
 * jQuery Growfield Library 2
 *
 * http://code.google.com/p/jquery-dynamic/
 * licensed under the MIT license
 *
 * autor: john kuindji
 */
(function(C){if(C.support==undefined){C.support={boxModel:C.boxModel}}var A=false;C(window).one("load",function(){A=true});C.fx.prototype.originalUpdate=C.fx.prototype.update;C.fx.prototype.update=false;C.fx.prototype.update=function(){if(!this.options.inline){return this.originalUpdate.call(this)}if(this.options.step){this.options.step.call(this.elem,this.now,this)}(jQuery.fx.step[this.prop]||jQuery.fx.step._default)(this)};var B=function(D){this.dom=D;this.o=C(D);this.opt={auto:true,animate:100,easing:null,min:false,max:false,restore:false,step:false};this.enabled=this.dummy=this.busy=this.initial=this.sizeRelated=this.prevH=this.firstH=false};B.prototype={toggle:function(D){if((D=="disable"||D===false)&&this.enabled){return this.setEvents("off")}if((D=="enable"||D===true)&&!this.enabled){return this.setEvents("on")}return this},setEvents:function(I){var H=this.o,E=this.opt,G=this,D=false;if(I=="on"&&!this.enabled){var F=H.height()==0?true:false;if(!F||A){C(function(){G.prepareSizeRelated()})}else{C(window).one("load",function(){G.prepareSizeRelated()})}if(E.auto){H.bind("keyup.growfield",function(J){G.keyUp(J);return true});H.bind("focus.growfield",function(J){G.focus(J);return true});H.bind("blur.growfield",function(J){G.blur(J);return true});D={overflow:H.css("overflow"),cssResize:H.css("resize")};if(C.browser.safari){H.css("resize","none")}this.initial=D;H.css({overflow:"hidden"});if(!F||A){C(function(){G.createDummy()})}else{C(window).one("load",function(){G.createDummy()})}}else{H.bind("keydown.growfield",function(J){G.manualKeyUp(J);return true});H.css("overflow-y","auto");if(!F||A){C(function(){G.update(H.height())})}else{C(window).one("load",function(){G.update(H.height())})}}H.addClass("growfield");this.enabled=true}else{if(I=="off"&&this.enabled){if(this.dummy){this.dummy.remove();this.dummy=false}H.unbind(".growfield").css("overflow",this.initial.overflow);if(C.browser.safari){H.css("resize",this.initial.cssResize)}this.enabled=false}}return this},setOptions:function(D){var E=this.opt,F=this.o;C.extend(E,D);if(!C.easing){E.easing=null}},update:function(N,G){var D=this.sizeRelated,J=this.o.val(),F=this.opt,M=this.dom,H=this.o,E=this,K=this.prevH;var I=!F.auto,L=F.auto;N=this.convertHeight(Math.round(N),"inner");N=F.min>N?F.min:F.max&&N>F.max?F.max:F.auto&&!J?F.min:N;if(F.max&&F.auto){if(K!=F.max&&N==F.max){H.css("overflow-y","scroll");if(!F.animate){H.focus()}I=true;L=false}if(K==F.max&&N<F.max){H.css("overflow-y","hidden");if(!F.animate){H.focus()}L=false}}if(N==K){return true}this.prevH=N;if(G){E.busy=true;H.animate({height:N},{duration:F.animate,easing:F.easing,overflow:null,inline:true,complete:function(){if(!I){H.css("overflow","hidden")}if(!L){H.focus()}E.busy=false},queue:false})}else{M.style.height=N+"px"}},manualKeyUp:function(D){if(!D.ctrlKey){return }if(D.keyCode!=38&&D.keyCode!=40){return }this.update(this.o.outerHeight()+(this.opt.step*(D.keyCode==38?-1:1)),this.opt.animate)},keyUp:function(D){if(this.busy){return true}if(C.inArray(D.keyCode,[37,38,39,40])!=-1){return true}this.update(this.getDummyHeight(),this.opt.animate)},focus:function(D){if(this.busy){return true}if(this.opt.restore){this.update(this.getDummyHeight(),this.opt.animate)}},blur:function(D){if(this.busy){return true}if(this.opt.restore){this.update(0,false)}},getDummyHeight:function(){var G=this.o.val(),E=0,D=this.sizeRelated,F="\n111\n111";if(C.browser.safari){G=G.substring(0,G.length-1)}if(!D.lh||!D.fs){G+=F}this.dummy.val(G);if(C.browser.msie){this.dummy[0].style.height=this.dummy[0].scrollHeight+"px"}E=this.dummy[0].scrollHeight;if(D.lh&&D.fs){E+=D.lh>D.fs?D.lh+D.fs:D.fs*2}if(C.browser.msie){this.dummy[0].style.height="20px"}return E},createDummy:function(){var F=this.o,E=this.o.val();F.addClass("growfield");var D=F.clone().addClass("growfieldDummy").attr({"name":"","id": F.attr("id")+"-clone"}).attr("tabindex",-9999).css({position:"absolute",left:-9999,top:0,height:"20px",resize:"none"}).insertBefore(F).show();if(!E){D.val("")}this.dummy=D;this.update(!jQuery.trim(E)?0:this.getDummyHeight(),false)},convertHeight:function(F,H){var E=this.sizeRelated,D=(H=="inner"?-1:1),G=C.support.boxModel;return F+(G?E.bt:0)*D+(G?E.bb:0)*D+(G?E.pt:0)*D+(G?E.pb:0)*D},prepareSizeRelated:function(){var F=this.o,D=this.opt;if(!D.min){D.min=parseInt(F.css("min-height"),10)||this.firstH||parseInt(F.height(),10)||20;if(D.min<=0){D.min=20}if(!this.firstH){this.firstH=D.min}}if(!D.max){D.max=parseInt(F.css("max-height"),10)||false;if(D.max<=0){D.max=false}}if(!D.step){D.step=parseInt(F.css("line-height"),10)||parseInt(F.css("font-size"),10)||20}var E={pt:parseInt(F.css("paddingTop"),10)||0,pb:parseInt(F.css("paddingBottom"),10)||0,bt:parseInt(F.css("borderTopWidth"),10)||0,bb:parseInt(F.css("borderBottomWidth"),10)||0,lh:parseInt(F.css("lineHeight"),10)||false,fs:parseInt(F.css("fontSize"),10)||false};this.sizeRelated=E}};C.fn.growfield=function(D){if("destroy"==D){return this.each(function(){var F=C(this).data("growfield");if(F==undefined){return true}F.toggle(false);C(this).removeData("growfield");return true})}if("restart"==D){return this.each(function(){var F=C(this).data("growfield");if(F==undefined){return true}F.toggle(false).toggle(true)})}var E=typeof D;return this.each(function(){if(!/textarea/i.test(this.tagName)||C(this).hasClass("growfield")){return true}var F=false,J=C(this),H=J.data("growfield");if(H==undefined){F=true;J.data("growfield",new B(this));H=J.data("growfield")}if(F){var G=C.extend({},C.fn.growfield.defaults,D);H.setOptions(G)}if(!F&&(!D||E=="object")){H.setOptions(D)}if(E=="string"){if(D.indexOf("!")==0&&C.fn.growfield.presets[D.substr(1)]){J.unbind("."+i+"."+D.substr(1))}else{if(C.fn.growfield.presets[D]){var I=C.fn.growfield.presets[D];H.setOptions(I,D)}}}if(F&&!G.skipEnable){H.toggle(true)}if(!F&&(E=="boolean"||D=="enable"||D=="disable")){H.toggle(D)}})};C.fn.growfield.defaults={};C.fn.growfield.presets={}})(jQuery);

/*
 * Simple Auto Expanding Text Area (0.1.2-dev)
 * by Antti Kaihola (antti.kaihola.fi)
 * akaihol+jquery@ambitone.com
 *
 * Copyright (c) 2009 Antti Kaihola (antti.kaihola.fi)
 * Licensed under the MIT and BSD licenses.
 *
 * NOTE: This script requires jQuery to work.  Download jQuery at
 *       www.jquery.com
 */

(function(jQuery) {

	jQuery.fn.simpleautogrow = function() {
		return this.each(function() { new jQuery.simpleautogrow(this); });
	};

	jQuery.simpleautogrow = function(e) {
		var self = this;
		if (jQuery(e).hasClass("growfield")) return;
		var $e = this.textarea = jQuery(e)
			.css({ overflow: 'hidden', display: 'block' })
			.addClass("growfield")
			.bind('focus', function() {
				this.timer = window.setInterval(function() { self.checkExpand(); }, 200);
			})
			.bind('blur', function() { clearInterval(this.timer); });
		this.border = $e.outerHeight() - $e.innerHeight();
		this.clone = $e.clone().css({ position: 'absolute', visibility: 'hidden' }).attr({ 'name': '', 'id': $e.attr("id") + "-clone" }).addClass("growfieldDummy");
		$e.height(e.scrollHeight + this.border)
			.after(this.clone);
		this.checkExpand();
	};

	jQuery.simpleautogrow.prototype.checkExpand = function() {
		var target_height = this.clone[0].scrollHeight + this.border;
		if (this.textarea.outerHeight() != target_height)
			this.textarea.height(target_height + 'px');
		this.clone.attr('value', this.textarea.attr('value')).height(0);
	};

})(jQuery);

