/*
Requires prototype.lite.js
*/

var Resizer = Class.create();

Resizer.prototype = {
	
	initialize: function(instance_name) {
		this.instance_name = instance_name;
	},

	toggle: function(elem_id) {
		
		clearTimeout(this.timeout);
		
		this.elem = $(elem_id);
		//this.elem.style.height = "1px";
		this.dimensions = Element.getDimensions(this.elem);
		this.height = Element.getHeight(this.elem);
		//alert(this.height);
		
		if(this.dimensions.height <= 1) {
			
			this.grow();
			
		} else {
			
			this.shrink();
			
		}
		
		
	},
	
	shrink: function() {
		
		this.dimensions = Element.getDimensions(this.elem);
		
		if(this.dimensions.height > 0) {
		
			var newHeight = (this.dimensions.height / 2);
			if(newHeight <= 5) {
				newHeight = 0;
			}
			this.elem.style.height = newHeight + "px";
			this.loop(this.instance_name+".shrink()");
	
		} else {
			//clearInterval(this.interval);
			//alert("Shrunk");
		}
		
	},
	
	grow: function() {
		
		this.dimensions = Element.getDimensions(this.elem);
				
		var curr_height = this.dimensions.height;
		
		if(curr_height <= 0) {
			
			curr_height = 1;
			
		}
		
		if(curr_height <= 80) {
		
			var newHeight = (curr_height * 2);
			this.elem.style.height = newHeight + "px";
			this.loop(this.instance_name+".grow()");
	
		} else if(curr_height > 80) {
			this.elem.style.height = "auto";
		} else {
			//alert("Grew");
		}
		
	},
	
	loop: function(str_func) {
		
		//alert("Loop");
		this.timeout = setTimeout(str_func, 30);
		//eval(str_func);
		
	}	
}