/** Resizing **/

function isArray(obj) { if(!obj.constructor) { return false}; return (obj.constructor.toString().indexOf("Array") != -1); }

var FillSizer = Class.create();
FillSizer.prototype = {
	// FillSizer is used to make an element fill the rest of the page.
	// This can be accomplished by using a table 100%
	initialize: function (options) 
	{
		this.options = {
			targetElement : [],
			otherElement : [], //  an array of elements that this class can use to calculate the amount of page taken up thus far
			minimumTargetSize : 100,
			afterResize: null, 
			netscapeError: 0, 
			onTooSmall: null, // Called when the window is too small to show the element below minimum size
			onSuffice: null // Called when the window is big enough
		}
		Object.extend(this.options, options || {});

		if (!isArray(this.options.targetElement) ) this.options.targetElement = [ this.options.targetElement ];
		if (!isArray(this.options.otherElement) ) this.options.otherElement = [ this.options.otherElement ];
		
		this.options.targetElement=$A(this.options.targetElement);
		this.options.otherElement=$A(this.options.otherElement);
		
		Event.observe(window, "resize", this.correctSize.bindAsEventListener(this), false);
		this.correctSize();
	},
	correctSize: function ()
	{
		// Fix the size
		if (navigator.appName=="Opera")
		{
			browserError = 5;
			windowHeight = document.body.clientHeight;
		} else
		if (navigator.appName=="Netscape")
		{
			browserError = this.options.netscapeError;
			windowHeight = document.documentElement.clientHeight;
		}
		else // everything else.  Hope Safari likes this.
		{
			browserError = 0;
			windowHeight = document.documentElement.clientHeight;
		}
		// Calculate the size of the "other stuff" on the page
		otherStuffHeight = browserError;
		this.options.otherElement.each( function (element) {
			otherStuffHeight+=element.offsetHeight;
		});
		
		newSize = windowHeight - otherStuffHeight;
		if (newSize < this.options.minimumTargetSize) 
		{			
			newSize=this.options.minimumTargetSize;
			this.tooSmall=true; // the window is too small for the element
		}
		else
			this.tooSmall=false;

		
		thisthis=this;
		this.options.targetElement.each( function (element) {
			element.style.height= newSize + 'px';
		});
		
		if (this.afterResize)
			this.afterResize(this);
			
		if (this.wasTooSmall!=this.tooSmall) // did the tooSmall value change?
		{
			callBack=this.tooSmall ? this.options.onTooSmall : this.options.onSuffice ;
			if (callBack!=null)
				callBack(this);
		}
		this.wasTooSmall=this.tooSmall;
	}
}
