/*
name			: Layout Guard
update			: 20040721
author			: Maurice van Creij
dependencies	: app_layoutguard.js
info			: /content/details.asp?id=20040721134238
*/

	// constants/configuration
		var objOverflow		= document.body;			// element containing the scrollbar
		var objDocument		= document.body;			// element containing everything
		var intLayoutCorr	= (document.all) ? 8 : 0 ;	// possible MSIE adjustment for the offsetHeight
		var arrLayoutHyst	=	new Array(
									//	new Array(strResizeId,new Array(intXmin,intXmax,intXoff),new Array(intYmin,intYmax,intYoff)),
									new Array('content0',	null,	new Array(0,9999,270))
								);
	// functionality
		// guess/measure the width of the document
		function getDocWidth(){
			var intMaxWidth = 9999;
			// choose the smallest value for the width
//			if(objOverflow.scrollWidth<intMaxWidth || intMaxWidth==0)	intMaxWidth = objOverflow.scrollWidth;
			if(objDocument.offsetWidth<intMaxWidth || intMaxWidth==0)	intMaxWidth = objDocument.offsetWidth;
			if(window.innerWidth<intMaxWidth || intMaxWidth==0)			intMaxWidth = window.innerWidth;
			// pass the value back
			return intMaxWidth;
		}
		// guess/measure the height of the document
		function getDocHeight(){
			var intMaxHeight = 0;
			// choose the biggest value for the height
			if(objOverflow.scrollHeight>intMaxHeight || intMaxHeight==0)	intMaxHeight = objOverflow.scrollHeight;
			if(objDocument.offsetHeight>intMaxHeight || intMaxHeight==0)	intMaxHeight = objDocument.offsetHeight-intLayoutCorr;
			if(window.innerHeight>intMaxHeight || intMaxHeight==0)			intMaxHeight = window.innerHeight;
			// pass the value back
			return intMaxHeight;
		}
		// set the elements' dimensions if the window dimensions pass a treshold
		function setDimensions(){
			var strResizeId, strWidth, strHeight;
			// document dimensions
			var intWidthDoc = getDocWidth();
			var intHeightDoc = getDocHeight();
			// for all listed elements
			for(var intA=0; intA<arrLayoutHyst.length; intA++){
				if(document.getElementById(arrLayoutHyst[intA][0])!=null){
					// width limits
					if(arrLayoutHyst[intA][1]!=null){
						// pick element width by limit
						if		(intWidthDoc<arrLayoutHyst[intA][1][0]){	strWidth = (arrLayoutHyst[intA][1][0]-arrLayoutHyst[intA][1][2]) + 'px';}
						else if	(intWidthDoc>arrLayoutHyst[intA][1][1]){	strWidth = (arrLayoutHyst[intA][1][1]-arrLayoutHyst[intA][1][2]) + 'px';}
						else {												strWidth = (intWidthDoc-arrLayoutHyst[intA][1][2]) + 'px';}
						// set element width
						document.getElementById(arrLayoutHyst[intA][0]).style.width = strWidth;
					}
					// height limits
					if(arrLayoutHyst[intA][2]!=null){
						// pick element height by limit
						if		(intHeightDoc<arrLayoutHyst[intA][2][0]){	strHeight = (arrLayoutHyst[intA][2][0]-arrLayoutHyst[intA][2][2]) + 'px';}
						else if	(intHeightDoc>arrLayoutHyst[intA][2][1]){	strHeight = (arrLayoutHyst[intA][2][1]-arrLayoutHyst[intA][2][2]) + 'px';}
						else {												strHeight = (intHeightDoc-arrLayoutHyst[intA][2][2]) + 'px';}
						// set element height
						document.getElementById(arrLayoutHyst[intA][0]).style.height = strHeight;
					}
				}
			}
		}
	// constructors


	// event handlers 
		function handleResize(){
			setTimeout("setDimensions()",128);
		}

	// executed inline
		//  if there's DOM support capture the resize event
		if(typeof(document.getElementById)!='undefined'){
			setDimensions();
			if(document.body.getAttribute('onload')==null) onload = handleResize;
			onresize = handleResize;
		}
