//adapted from quirksmode.org
function GetInnerSize () {
	//alert( 'top of GetInnerSize' );
	var x,y;
	if (self.innerHeight) // all except Explorer
	{
		//alert( 'got size for not explorer' );
		x = self.innerWidth;
		y = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		//alert( 'got size for explorer 6 strict' );
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		//alert( 'got size for other explorer' );
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}
	return [x,y];
}

//adapted from http://www.hypergeneric.com/corpus/javascript-inner-viewport-resize/
//with good notes from http://www.bazon.net/mishoo/articles.epl?art_id=408
function ResizeToInner (w, h) {
	var inner, ox, oy;
	inner = GetInnerSize();
	ox = w-inner[0];
	oy = h-inner[1];
	window.resizeBy(ox, oy);

	//IE will not extend past the edge of the screen
	//which could result in getting less than the requested size change
	inner = GetInnerSize();
	ox = Math.max( 0, w-inner[0] );
	oy = Math.max( 0, h-inner[1] );
	
	if( ox > 0 || oy > 0 ) {
		//move and try one last time
		window.moveBy( -ox, -oy );
		window.resizeBy(ox, oy);
	} else if( self.screenX ) {
		//Mozilla will let the window resize off the screen
		//try to bring it back in here
		ox = Math.min( self.screenX, Math.max( 0, self.screenX + self.outerWidth - screen.width ));
		oy = Math.min( self.screenY, Math.max( 0, self.screenY + self.outerHeight - screen.height ));
		if( ox > 0 || oy > 0 ) {
			window.moveBy( -ox, -oy );
		}
	}
}

function ResizeToInnerMinimum( w, h ){
	//var output = '';
	var current_size = GetInnerSize();
	if( current_size[0] >= w && current_size[1] >= h ) {
		//alert( 'current size '+ current_size +' already greater than minimums' );
		return;
	}

	//output += 'Height Before: ' + current_size[0] + "\n";
	//output += 'Width Before: ' + current_size[1] + "\n";
	//alert( output );
	
	var target_width = Math.max( w, current_size[0] );
	var target_height = Math.max( h, current_size[1] );
	ResizeToInner( target_width, target_height );

	//current_size = GetInnerSize();
	//output += 'Height After: ' + current_size[0] + "\n";
	//output += 'Width After: ' + current_size[1] + "\n";
	//alert( output );
}
