// ------------------------------------------------------------------------
// ResizeWindow object resizes the browser window so that the client
// area is the dimensions needed, taking into consideration all browser
// chrome.
//
var ResizeWindow = 
{
	// --------------------------------------------------------------------
	// Instance Variables
	//
	target_w: 0,
	target_h: 0,
	firstAttempt: { w: 0, h: 0 },
	
	// --------------------------------------------------------------------
	// Private Functions
	//
	getClientSize: function (){
		var size = { w: 0, h: 0 };
		
		if (typeof(window.innerWidth) == 'number') {
			size.w = window.innerWidth;
			size.h = window.innerHeight;
		}
		else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
			size.w = document.documentElement.clientWidth;
			size.h = document.documentElement.clientHeight;
		} 
		else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
			size.w = document.body.clientWidth;
			size.h = document.body.clientHeight - 24;	// IE Was off by 24?
		}
		
		return size;
	},
	getWindowSize: function(){
		var size = { w: 0, h: 0 };
		
		if (typeof(window.innerWidth) == 'number') {
			size.w = window.outerWidth;
			size.h = window.outerHeight;
		}
		else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
			size.w = document.documentElement.width;
			size.h = document.documentElement.height;
		}
		else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
			size.w = document.body.offsetWidth;
			size.h = document.body.offsetHeight;
		}
		
		return size;
	},
	checkDimensions: function(){
		var client = this.getClientSize();
		
		var wDelta = (this.target_w - client.w);
		var hDelta = (this.target_h - client.h);
		
		var w = this.firstAttempt.w + ((wDelta > 0) ? wDelta : 0);
		var h = this.firstAttempt.h + ((hDelta > 0) ? hDelta : 0);
		
		self.resizeTo(w, h);
	},
	
	// --------------------------------------------------------------------
	// Public API
	//
	setSize: function (w, h){
		this.target_w = w;
		this.target_h = h;
		
		var client = this.getClientSize();
		var window = this.getWindowSize();
		
		this.firstAttempt = {
			w: this.target_w + (window.w - client.w),
			h: this.target_h + (window.h - client.h)
		};
		
		// First attempt at setting the correct browser size
		self.resizeTo(this.firstAttempt.w, this.firstAttempt.h);
		
		// Check the dimensions of the browser and make adjustments
		this.checkDimensions();
	}
}
