var minWidth = 760;			// the minimum and maximum widths you want the page displayed at
var maxWidth = 1100;		// <-
var headerHeight = 150;		//the height everything on the page above the content div including any padding
var isPdf = 0;

var sURL = unescape(window.location.pathname);

//functions to execute every time the page loads as soon as the Document Object Model is loaded
ELO.functionsToCallOnload.push("PdfSetup()");
ELO.functionsToCallOnload.push("WindowSizeChanged()");		//size and possition page elements
ELO.functionsToCallOnload.push("initMenu()");				//initialize the menu system only after the page has been sized and possitioned based on window size

function PageReload() {
    setTimeout( "window.location.reload(false)", 0 );
}

window.onresize = PageReload;		//when the window changes size reload the page so the menu is reloaded and appears in the correct location

// This function replicates proper behavior of min-width and max-width CSS properties on most browsers.
function WindowSizeChanged() {
	
	// create short references to the various divs and the pdf inline frame 
	var mainDiv = document.getElementById("main");
	var contentDiv = document.getElementById("content");
	var leftDetectDiv = document.getElementById("leftside_mouse_detector");
	var menuDetectDiv = document.getElementById("menu_mouse_detector");
	var pdfDisplay = document.getElementById("pdfDisplay");


	if (document.body.clientWidth < (minWidth - 1)) {		//when the window is as wide as or narrower than the minimum width we want for page:
		mainDiv.style.width = minWidth + "px";				//	set the main div to the minimum width we want for the page
		document.body.style.paddingLeft = "0px";			//	remove any padding and margin so the left edge of the page is aligned with the left edge of the window
		mainDiv.style.marginLeft = "0px";					//  <-
		if (isPdf) {
			leftDetectDiv.style.width = "10px";
			menuDetectDiv.style.left = "10px";
		}
	} else {													
		if (document.body.clientWidth > maxWidth) {							//when the window is wider than the maximim width we want for the page:
			mainDiv.style.width = maxWidth + "px";							//	set the main div to the maximum width we want for the page
			document.body.style.paddingLeft = "50%";						//	center the page horizontally in the window:  move the left edge of the page right to the center of the window
			mainDiv.style.marginLeft = -(mainDiv.offsetWidth / 2) + "px";	//		then move the left edge back left by half the width of the page (offsetWidth/Height: best cross browser test of width/height)
			if (isPdf) {
				leftDetectDiv.style.width = ((document.body.clientWidth - maxWidth) / 2) + 20 + "px";	
				menuDetectDiv.style.left = ((document.body.clientWidth - maxWidth) / 2) + 20 + "px";
			}
		} else {
			mainDiv.style.width = "100%";				//when the window width is between the max and min widths we want for the page set the page width to 100% of the available space
			document.body.style.paddingLeft = "0px";		//	remove any padding or margin so the left edge of the page is aligned with the left edge of the window
			mainDiv.style.marginLeft = "0px";				//  <-
			if (isPdf) {
				leftDetectDiv.style.width = "10px";	
				menuDetectDiv.style.left = "10px";
			}
		}
	}
	
	if (document.body.clientWidth < 900) {						//if the window is too wide for the title bar image use a narrower version (image width 880px + two 10px side bar stripes)
		TitleImageChange(titleImageNarrow, "740");
	} else {
		TitleImageChange(titleImage, "880");
	}
	

	// make the content display area the width of the page less the width of the menu and boarders
	contentDiv.style.width = mainDiv.offsetWidth - 220 + "px"; //was 220
	if (contentDiv.offsetHeight < document.body.clientHeight - headerHeight) {
		contentDiv.style.height = (document.body.clientHeight - headerHeight) + "px";
	}

	if (isPdf) {
		menuDetectDiv.style.width = "210px";
		document.getElementById("behindPdf").style.width = mainDiv.offsetWidth - 220 + "px";
		pdfDisplay.style.height = document.body.clientHeight - headerHeight + "px";
		pdfDisplay.style.width = mainDiv.offsetWidth - 220 + "px";
	}
	
	mainDiv.style.visibility = "visible";
}

// Image swapping function
function TitleImageChange(image, width) {
	document.titleImage.src = image;
	document.titleImage.width = width;
}

function PdfSetup() {
var locationString = unescape(window.location);			//unescape the location string to change spaces and puctuation back from escaped versions ("%21" == "!" etc)
	if (locationString.indexOf("pdf.shtml") != -1) {							//if the address includes "pdf.shtml?" the content div needs to load a pdf and the other pdf setup needs to be done
		pdfDisplay.location = location.search.substring(1) + ".pdf";	//get the name of the pdf from the query string and load it in the inline frame
		//pdfDisplay.location = "test.pdf";
		isPdf = 1;
	} 
}

function PdfHide() {
	if (isPdf) {
		document.getElementById("menu_mouse_detector").style.width = "0";
		document.getElementById("pdfDisplay").style.width = "0";
	}
}

function PdfShow() {
	if (isPdf) {
		document.getElementById("menu_mouse_detector").style.width = "210";
		document.getElementById("pdfDisplay").style.width = document.getElementById("main").offsetWidth - 220;
	}
}