// Cambiado por Eric

(function(jQuery){

	jQuery.fn.ata = function(options){

		options = jQuery.extend({
			timer:100
		}, options);
	
		return this.each(function(i){
	
var $t = jQuery(this),
				t = this;

			t.style.resize = 'none';
			t.style.overflow = 'hidden';

			var tVal = t.value;			
			t.style.height = '0px';
			t.value = "W\nW\nW";
			var H3 = t.scrollHeight;
			t.value = "W\nW\nW\nW";
			var H4 = t.scrollHeight;
			var H = H4 - H3;
			t.value = tVal;
			tVal = null;

			$t.bind('focus', function(){
				t.startUpdating()
			}).bind('blur', function(){
				t.stopUpdating()
			});

			this.heightUpdate = function(){

				var t = $(this)[0];
				
				if (tVal != t.value){

					tVal = t.value;
					t.style.height = '0px';
					var tH = t.scrollHeight + H;
					t.style.height = tH + 'px';

				}

			}

			this.startUpdating = function(){
				t.interval = window.setInterval(function(){
					t.heightUpdate()
				}, options.timer);
			}

			this.stopUpdating = function(){
				clearInterval(t.interval);	
			}

			jQuery(function(){
				t.heightUpdate()
			});

		});

	};

})(jQuery);
