/*
	Set up the overlays. 
	See YUI docs: 
	http://developer.yahoo.com/yui/container/overlay/index.html
*/
var leftNavOverlay = new YAHOO.widget.Overlay("leftNavOverlay"); 
leftNavOverlay.cfg.setProperty("context", ["leftNav"]); 

var headerOverlay = new YAHOO.widget.Overlay("headerOverlay");
headerOverlay.cfg.setProperty("context", ["headerSmall"]);

var headerLinks = new YAHOO.widget.Overlay("headerLinks");
headerLinks.cfg.setProperty("context", ["headerOverlay"]);

leftNavOverlay.render(); 
leftNavOverlay.render(document.body); 

leftNavOverlay.cfg.setProperty("visible", true);
leftNavOverlay.show(); 

headerOverlay.render(); 
headerOverlay.render(document.body); 

headerOverlay.cfg.setProperty("visible", true);
headerOverlay.show(); 

function saa_setupPage () {
	/*
		Set up the overlays. 
		See YUI docs: 
		http://developer.yahoo.com/yui/container/overlay/index.html
	*/
	var leftNavOverlay = new YAHOO.widget.Overlay("leftNavOverlay"); 
	leftNavOverlay.cfg.setProperty("context", ["leftNav"]); 
	
	var headerOverlay = new YAHOO.widget.Overlay("headerOverlay");
	headerOverlay.cfg.setProperty("context", ["headerSmall"]);
	
	var headerLinks = new YAHOO.widget.Overlay("headerLinks");
	headerLinks.cfg.setProperty("context", ["headerOverlay"]);
	
	leftNavOverlay.render(); 
	leftNavOverlay.render(document.body); 
	
	leftNavOverlay.cfg.setProperty("visible", true);
	leftNavOverlay.show(); 
	
	headerOverlay.render(); 
	headerOverlay.render(document.body); 
	
	headerOverlay.cfg.setProperty("visible", true);
	headerOverlay.show(); 
}

/*
	Resizes divs, and pushes the footer to the bottom of the page.
	Also, makes those divs that get pushed around visible (they 
	are invisible by default) -- this avoids flashing.
*/



function matchSwitchChange(){
alert('here');
return;
	switchMenuHeight=document.getElementById('switchmenucontentwrapper').offsetHeight;
	switchMenuHeightAdjust = switchMenuHeight+189;
	contentHeight = switchMenuHeight+312;
	switchMenuFooterAdjust = switchMenuHeightAdjust-30;
	switchMenuContentAdjust = switchMenuHeight+100;

	window.document.getElementById('leftNav').style.height=switchMenuHeight + 'px';
	window.document.getElementById('contentHeaderSmall').style.height=switchMenuContentAdjust + 'px';
	window.document.getElementById('leftBorder').style.height=switchMenuHeight + 'px';
	window.document.getElementById('rightBorder').style.height=switchMenuHeight + 'px';
	window.document.getElementById('footer').style.top=switchMenuHeightAdjust + 'px';
	window.document.getElementById('content-footer').style.top=switchMenuFooterAdjust + 'px';
}

var globalMinHeight = 500;
function matchHeight() {

	var bgDiv = window.document.getElementById('content-small-bg');
	if (bgDiv != null) {
		bgDiv.style.display = 'block';
	}

	 var divHeight,divTop, d;

	 // get all <div> elements in the document
	 var divs=document.getElementsByTagName('div');
	 var contDivs=[];

	 // initialize maximum height value
	 var minHeight = globalMinHeight;
   	 var newMaxHeight=0;
	  
	 newMaxHeight = minHeight;

	 // iterate over all <div> elements in the document
	 for(var i=0;i<divs.length;i++){

		  // make collection with <div> elements with class attribute 'container'                        
		   //if(/\blayout-container\b/.test(divs[i].className)){
		   // if (divs[i].className == 'layout-container') {
		   //if (divs[i].className == /layout-container/) {
		   if (/\blayout-container\b/.test(divs[i].className)) {
				d=divs[i];
				contDivs[contDivs.length]=d;
							 
				// determine height for <div> element
				if (d.offsetHeight != 'undefined') {
					 divHeight=d.offsetHeight;
					 divTop = getOffsetTopFrom(d, 'page-container');
				} else if(d.style.pixelHeight) {
					 divHeight=d.style.pixelHeight;
					 divTop = d.style.pixelTop;
				}
				
				// alert(d.className+':'+divHeight+'/'+newMaxHeight);
				
				// calculate maximum height              
				newMaxHeight=Math.max(newMaxHeight,divHeight+divTop);
		  }     
		  
	 }
	 
	 //alert(newMaxHeight);
	 
	/*
		Adjust the heights of the content area and the left and right borders so that they extend to the bottom of the page.
		For the content, this is just to provide a white background.
		For the left margin area, this is to pfovide the shaded background.
		For the left margin curve, this provides the mask for the curved border between the left margin and the content.
		For the left and right borders, this is to provide the mask on the left side of the left margin, and the right side
		  of the content.
		To calculate the height, we take the maximum height from above, which is relative to the 'page-container' object, our common
	      reference. Then we subtract the distance between the top of the div and the top of the 'page-container' div. However, since
	      there is no guarantee that 'page-container' is the offset parent for the div (unless we ensure that in the code above)
	      we need to also subtract the difference between the offset parent of the div and 'page-container'. This gives us the new height
	      for the div relative to its own offset parent.
	      	newHeight = (maxOffsetHeight - offsetFromPageContainer - (offsetFromPageContaier - offsetFromParent)
	      	newHeight = (maxOffsetHeight - 2*offsetFromPageContainer - offsetFromParent
	*/
	
	var footerDiv = window.document.getElementById('footer');
	var footerHeight = getHeight(footerDiv);
	
	var contentFooterContentDiv = window.document.getElementById('contentFooterContent');
	
	var contentFooterDiv = window.document.getElementById('contentFooter');
	contentFooterDiv.style.top=newMaxHeight  + 'px';
	var contentFooterHeight = getHeight(contentFooterContentDiv);
	
	/*
		The left nav goes to the bottom of the content (max height) and then down with the footer...
	*/
	var leftNavDiv = window.document.getElementById('leftNav');
	var newHeight = newMaxHeight - getOffsetTopFrom(leftNavDiv, 'page-container') + contentFooterHeight;
	leftNavDiv.style.height=newHeight+ 'px'; 
	
	var contentDiv = window.document.getElementById('content-small-bg');
	contentDiv.style.height=(newMaxHeight - getOffsetTopFrom(contentDiv, 'page-container') +footerHeight + contentFooterHeight) + 'px'; 
	// alert(contentDiv.style.height); 
	 
	/* The borders extend all the way down to the bottom of the header. */

	var leftNavOverlay = window.document.getElementById('leftNavOverlay');
	newHeight = newMaxHeight - getOffsetTopFrom(leftNavOverlay, 'page-container') + contentFooterHeight;
	// alert("new leftnavoverlay height = '"+newHeight+"'");
	var lnNewHeight = newHeight;
	if (newHeight > 662) {
		lnNewHeight = 662;
	}
	leftNavOverlay.style.height=lnNewHeight+ 'px'; 
	
	var leftNavOverlayImg = window.document.getElementById('leftNavOverlayImg');
	var oldHeight = leftNavOverlayImg.offsetHeight;
	newHeight = newMaxHeight - getOffsetTopFrom(leftNavOverlayImg, 'page-container') + contentFooterHeight;
	// alert("new leftnavoverlay height = '"+newHeight+"'");
	var lnNewHeight = newHeight;
	if (newHeight > 662) {
		lnNewHeight = 662;
	}
	leftNavOverlayImg.style.height=lnNewHeight+ 'px'; 
	// alert("new height is"+newHeight+", or "+leftNavOverlayImg.offsetHeight+", was "+oldHeight);
	
	var leftBorderDiv = window.document.getElementById('leftBorder');
	newHeight = newMaxHeight - getTop(leftBorderDiv) + contentFooterHeight;
	// alert("new leftBorderDiv height = '"+newHeight+"'");
	leftBorderDiv.style.height=newHeight + 'px';
	
	var rightBorderDiv = window.document.getElementById('rightBorder');
	newHeight = newMaxHeight - getTop(rightBorderDiv) + contentFooterHeight;
	rightBorderDiv.style.height=newHeight + 'px'; 
	
	
	newHeight = newMaxHeight + contentFooterHeight;
	// alert(newHeight);
	footerDiv.style.top=newHeight  + 'px';
	
	/*
		The footer starts just after the new max height.
	*/
	
	// window.document.getElementById('content-footer').style.top=(newMaxHeight - footerFix) + 'px';
	
	contentDiv.style.visibility = 'visible';
	leftNavDiv.style.visibility = 'visible';
	leftNavOverlay.style.visibility = 'visible';
	leftBorderDiv.style.visibility = 'visible';
	rightBorderDiv.style.visibility = 'visible';
	footerDiv.style.visibility = 'visible';
	contentFooterDiv.style.visibility = 'visible';
	
	if ( (BrowserDetect.browser == 'Explorer') && (BrowserDetect.version == 7)) {
		showAllElement('p');
	}
	
	if (window.location.hash) {
		window.location = window.location.hash
	}
	
	
}

// addLoadEvent(matchHeight);
// addDOMLoadEvent(matchHeight);