var curMenu = ''; 	//The currently popped menu
var origTop = 0; 	//The current menu's 
var origLeft = 0;	//original position
var over = false;

//Pops out the sub menus on the left nav bar.
function showSubMenu(section) {
	var scrWidth = 750;
	if(section.length <= 0) {
		return true;
	}

	if(curMenu.length > 0) {
		hideSubMenu(curMenu);
	}
	
	curMenu = section;
	var menu = document.getElementById(section);
	
	//The locations listed in the sub menus are assuming a 
	//non-centered table that bumps right up against the edges 
	//of the window. The following code calculates a new position
	//based upon the resizing of the client window.
	
	origTop = menu.style.top;
	origLeft = menu.style.left;
	
	
	if((window.navigator.userAgent.indexOf('Mac') >= 0)) {
		//Mac MSIE *actually follows the DOM spec* and makes all positioning relative to the
		//parent element. So I had to put a little exception here for it. 
		if(window.navigator.userAgent.indexOf('MSIE') >= 0) {
			newX = parseInt(menu.style.left) + 10;
			//alert("Mac MSIE!");
		} else if ( window.navigator.userAgent.indexOf('KHTML') >= 0 ) {
			if(document.body.clientWidth > scrWidth) {
				//By default, though, just do the calculation
				newX = ((document.body.clientWidth - scrWidth) / 2) + parseInt(menu.style.left);
				//alert("Default!");
			} else {
				newX = parseInt(menu.style.left);
				//alert("Small Screen!");
			}
		}
		//newX += 5;
	} else if (window.navigator.userAgent.indexOf('Gecko') >= 0) {
		//Mozilla... I have no idea what it's doing, but this seems to work.
		newX = ((document.body.clientWidth - scrWidth) / 2) + parseInt(menu.style.left);
		//menu.style.position = 'absolute';
		//alert("Gecko!");
	} else if(document.body.clientWidth > scrWidth) {
		//By default, though, just do the calculation
		newX = ((document.body.clientWidth - scrWidth) / 2) + parseInt(menu.style.left);
		//alert("Default!");
	} else {
		newX = parseInt(menu.style.left);
		//alert("Small Screen!");
	}
	
	//alert("User Agent: " + window.navigator.userAgent + "; NEW X: " + newX);
	
	newX = newX - 3;
	msg = "Screen Width: " + document.body.clientWidth + "\n";
	msg += "Menu Left: " + parseInt(menu.style.left) + "\n";
	msg += "New X: " + newX + "\n";
	msg += "User Agent: " + window.navigator.userAgent + "\n";
	//alert(msg);
	//alert(newX);
	menu.style.left = newX;
	//menu.style.top = newY;
	menu.style.visibility = 'visible';
	//setTimeout("hideSubMenu(curMenu)", 600);
	over = true;
	return true;
}

//Hides the currently popped window
function hideSubMenu(section) {
	//alert("Section: " + section +"; CurMenu: " + curMenu);
	if((curMenu != '')) {
		//alert('section: ' + section);
		var menu = document.getElementById(curMenu);
		menu.style.visibility = 'hidden';
		menu.style.top = origTop;
		menu.style.left = origLeft;
		over = false;
		return true;
	}
}

//Hides all windows
function hideSubMenuAll() {
	if((curMenu != '') && (over == false)) {
		var menu = document.getElementById(curMenu);
		menu.style.visibility = 'hidden';
		menu.style.top = origTop;
		menu.style.left = origLeft;
		over = false;
		return true;
	}
}

//Allows some time for the user to get to the menu before trying to hide it
function timedHide() {
	if((over == true) && (curMenu != '')) {
		over = false;
		setTimeout("hideSubMenuAll()", 900);
	}
}

curLight = '';


//Highlights the subnav
function highlight(id) {
	if(curLight != '') {
		tab = document.getElementById(curLight);
		tab.className = "pop_text";
		tab = document.getElementById(curLight + 'left');
		tab.className = "pop_left_bevel";
		tab = document.getElementById(curLight + 'right');
		tab.className = "pop_right_bevel";
	}
	curLight = id;
	//alert('ID: ' + id);
	tab = document.getElementById(id);
	tab.className = "pop_text_selected";
	tab = document.getElementById(id + 'left');
	tab.className = "pop_text_selected_bevel";
	tab = document.getElementById(id + 'right');
	tab.className = "pop_text_selected_bevel";
}

function lowlight() {
	if(curLight != '') {
		tab = document.getElementById(curLight);
		tab.className = "pop_text";
		tab = document.getElementById(curLight + 'left');
		tab.className = "pop_left_bevel";
		tab = document.getElementById(curLight + 'right');
		tab.className = "pop_right_bevel";
	}
}

function showPhotoCredit() {
	var tag = document.getElementById('photo_credit');
	tag.style.visibility = 'visible';
	return true;
}

function hidePhotoCredit() {
	var tag = document.getElementById('photo_credit');
	tag.style.visibility = 'hidden';
	return true;
}

tertnav = new Array('', '');
//Highlights the tertiary nav
function navHighlight(id, selClass, level) {
	level = level - 1; 
	if(tertnav[level] != '') {
		tab = document.getElementById(tertnav[level]);
		tab.className = selClass;
	}
	tertnav[level] = id;
	//alert('ID: ' + id);
	tab = document.getElementById(id);
	tab.className = selClass + "_sel";
	return true;
}

function navLowlight(selClass, level) {
	level = level - 1; 
	if(tertnav[level] != '') {
		tab = document.getElementById(tertnav[level]);
		tab.className = selClass;
	}
	tertnav[level] = '';
	return true;
}
	

function popWin(url) {
	return popWin(url, 320, 240);
}

function popWin(url, width, height) {
 	window.open(url, 'chdpop', 'width=' + width +',height=' + height + ',scrollbars=yes,toolbar=no,menu=no,location=no,', false);
 	return true;
 }
 
function showSubMenuNew(section) {
	curMenu = section;
	var menu = document.getElementById(section);
	menu.style.visibility = 'visible';
	over = true;
	return true;
}

//Hides the currently popped window
function hideSubMenuNew(section) {
	if((curMenu != '')) {
		var menu = document.getElementById(curMenu);
		menu.style.visibility = 'hidden';
		over = false;
		return true;
	}
}

//Hides all windows
function hideSubMenuAllNew() {
	if((curMenu != '') && (over == false)) {
		var menu = document.getElementById(curMenu);
		menu.style.visibility = 'hidden';
		over = false;
		return true;
	}
}