
// DivToggler functionality
var DivToggler = Class.create();

DivToggler.prototype = {
	isShown: false,
	initialize: function(options)
	{
		this.options = {
			toggleDivID : null,
			onHide : null, //  an array of elements that this class can use to calculate the amount of page taken up thus far
			onRestore : null,
			horizontal : false,
			afterResize : null,
			minimumSize : 0
		}
		Object.extend(this.options, options || {});
		
		style=$(this.options.toggleDivID).style;
		this.previousStyle = {
			overflowY: style.overflowY,
			overflowX: style.overflowX,
			height: style.height,
			width: style.width,
			display: style.display
		};
		
//			Event.observe(window, 'load', this.maximizeTopDiv.bindAsEventListener(this), false);
	},
	restore: function ()
	{
		this.resizeTopDiv(true);
	},
	hide: function ()
	{
		this.resizeTopDiv(false);
	},
	toggle: function ()
	{
		this.resizeTopDiv(! this.isShown);

	},
	resizeTopDiv: function(fullSize)
	{
		this.isShown=fullSize;

		style=$(this.options.toggleDivID).style;
		
		if (this.options.horizontal)
		{
			style.width = fullSize ? this.previousStyle.width : this.options.minimumSize + "px";
			style.overflowX = fullSize ? this.previousStyle.overflowX : "hidden";
			
		}
		else
		{
			style.height = fullSize ? this.previousStyle.height : this.options.minimumSize + "px";
			style.overflowY = fullSize ? this.previousStyle.overflowY : "hidden";
		}
		
		if (this.options.minimumSize==0)
		{
			style.display = fullSize ? this.previousStyle.display : "none";
		}
		callback=fullSize ?  this.options.onRestore : this.options.onHide;
		if (callback) callback();
		
		if (this.options.afterResize) this.options.afterResize();
	}
}

