// csNav.js
// clamshell navigation source - v1.1
//
// --  This site was designed and implemented by Miller Systems.
// --  (c) Copyright 2001,2002.  All rights reserved.
// --  http://www.millersystems.com
// --  Miller Systems, Inc. Boston MA 02116
//
// (/* ... */ - indicates custom BSA modifications

var strIEver = parseFloat(navigator.appVersion.substr(navigator.appVersion.indexOf("MSIE")+4));
var isIE500 = ((strIEver<5.01) && (strIEver>4.9))?true:false;
/* X11 browsers not required */
var isX11 = (navigator.appVersion.indexOf("X11")!=-1)?true:false;
/******************************/

var zMax = 3;							// z-index for clamshell nav layer
var csMenu = "csnav";					// name of DIV tag containing clamshell nav layer

var activeNav = -1;						// integer indicating section the currently visible page lives in
var activeSubNav;						// string indicating page currently visible
var pthname = window.location.pathname;	// browser URL string minus host & domain

// set the activeNav based on the current directory
if (pthname.indexOf("/about_the_BSA/")!=-1) activeNav = 0;
else if (pthname.indexOf("/BSA_store/")!=-1) activeNav = 1;
else if (pthname.indexOf("/classifieds/")!=-1) activeNav = 2;
else if (pthname.indexOf("/committees/")!=-1) activeNav = 3;
else if (pthname.indexOf("/design_awards_programs/")!=-1) activeNav = 4;
else if (pthname.indexOf("/directories/")!=-1) activeNav = 5;
else if (pthname.indexOf("/education/")!=-1) activeNav = 6;
else if (pthname.indexOf("/membership/")!=-1) activeNav = 7;
else if (pthname.indexOf("/news/")!=-1) activeNav = 8;
else if (pthname.indexOf("/publications/")!=-1) activeNav = 9;
else if (pthname.indexOf("/quick_links/")!=-1) activeNav = 10;
else if (pthname.indexOf("/shaping_communities/")!=-1) activeNav = 11;
else if (pthname.indexOf("/portals/")!=-1) activeNav = 12;

//menuStateArray.length = menuStateArray.length-1;

// set the menuStateArray based on the activeNav
for (i=0;i<menuStateArray.length;i++) {
	menuStateArray[i] = (activeNav==i)?true:false;
	
	// if top-level menu element has no second-level elements then disable
	//if (i==1) menuStateArray = "disable";
}

var navMenu = new Array(menuStateArray.length);	// array of top-level menu elements
var navSubMenu = new Array(navMenu.length);		// array of second-level menu elements
for (i=0;i<navSubMenu.length;i++) {
	navSubMenu[i] = new Array;
}

// HTML string output before the clamshell nav
var navMenuPre_login = '<a href="/news/signup.cfm" onmouseover="swapCSImages(\'subscribe\',\'/images/level2/btn_subscribe_hl.gif\');" onmouseout="swapCSImages(\'subscribe\',\'/images/level2/btn_subscribe.gif\');"><img src="/images/level2/btn_subscribe.gif" width="108" height="25" border="0" alt="Subscribe" name="subscribe" /></a><a href="/BSA_store/login.cfm" onmouseover="swapCSImages(\'login\',\'/images/level2/btn_login_hl.gif\');" onmouseout="swapCSImages(\'login\',\'/images/level2/btn_login.gif\');"><img src="/images/level2/btn_login.gif" width="67" height="25" border="0" alt="login" name="login" /></a><br /><img src="/images/level2/nav_header.gif" width="175" height="1" border="0" alt="" /><br />';
var navMenuPre_logout = '<a href="/news/signup.cfm" onmouseover="swapCSImages(\'subscribe\',\'/images/level2/btn_subscribe_hl.gif\');" onmouseout="swapCSImages(\'subscribe\',\'/images/level2/btn_subscribe.gif\');"><img src="/images/level2/btn_subscribe.gif" width="108" height="25" border="0" alt="Subscribe" name="subscribe" /></a><a href="/BSA_store/logout.cfm" onmouseover="swapCSImages(\'logout\',\'/images/level2/btn_logout_hl.gif\');" onmouseout="swapCSImages(\'logout\',\'/images/level2/btn_logout.gif\');"><img src="/images/level2/btn_logout.gif" width="67" height="25" border="0" alt="logout" name="logout" /></a><br /><img src="/images/level2/nav_header.gif" width="175" height="1" border="0" alt="" /><br />';
// HTML string output after the clamshell nav
var navMenuPost = '';
navMenuPost += '<img src="/images/level2/nav_spacer.gif" width="175" height="29" border="0" alt="" /><br />';
navMenuPost += '<a href="/request_info/request_1.cfm" onmouseover="swapCSImages(\'requestinfo2\',\'/images/home/btn_requestinfo2_hl.gif\');" onmouseout="swapCSImages(\'requestinfo2\',\'/images/home/btn_requestinfo2.gif\');"><img src="/images/home/btn_requestinfo2.gif" width="175" height="30" border="0" alt="Request Info." name="requestinfo2" /></a><br />';
navMenuPost += '<a href="/search_BSA/index.cfm" onmouseover="swapCSImages(\'searchsite\',\'/images/home/btn_search_hl.gif\');" onmouseout="swapCSImages(\'searchsite\',\'/images/home/btn_search.gif\');"><img src="/images/home/btn_search.gif" width="175" height="31" border="0" alt="Search" name="searchsite" /></a><br />';

var navOpen = '/images/level2/navbtn_minus.gif';	// image source string to indicate an open top-level menu
var navClose = '/images/level2/navbtn_plus.gif';	// image source string to indicate a closed top-level menu

/* - for Resources For: and Services: top-level menus */
var navOpen2 = '/images/level2/navbtn_minus2.gif';
var navClose2 = '/images/level2/navbtn_plus2.gif';
/******************************************************/

///////////////////////////////
// swapHTML(div, markup)
// - will swap the HTML in the indicated containing layer
///////////////////////////////
function swapHTML(div, markup) {
	var objHTML = (isDOM)?document.getElementById(div):(isIE4)?document.all[div]:(isNS4)?document.layers[div]:null;
	if (isDOM || isIE4) {
		objHTML.innerHTML = markup;
	}
	if (isNS4) {
		objHTML.document.open();
		objHTML.document.write(markup);
		objHTML.document.close();
	}
	if(isNS4) objHTML.style = objHTML;
	objHTML.style.zIndex = zMax++;
}

///////////////////////////////
// buildMenu(arr)
// - build clamshell nav based on the menuStateArray
///////////////////////////////
function buildMenu(arr) {
	var strMenu="";
	for (i=0;i<arr.length;i++) {
		strMenu += (menuStateArray[i])?navMenu[i]+buildSubMenu(navSubMenu[i]):navMenu[i];
	}
	navMenuPre = (isMember)?navMenuPre_login:navMenuPre_logout;
	return navMenuPre + strMenu + navMenuPost;
}

///////////////////////////////
// buildSubMenu(arr)
// - called from buildMenu() - builds second-level menu elements
///////////////////////////////
function buildSubMenu(arr) {
	var strSubMenu="";
	if (arr.length==0) return strSubMenu;
	for (j=0;j<arr.length;j++) {
		strSubMenu += arr[j];
	}
	return strSubMenu;
}

///////////////////////////////
// toggleMenuState()
// - sets the menuStateArray, builds the clamshell nav HTML string, and outputs it to the csMenu layer
// - also "re-highlights" appropriate second-level menu element based on activeSubNav
///////////////////////////////
function toggleMenuState(index) {
	if (!initialized) return;
	// detect faulty DHTML implementation in IE 5.00 browser
	// http://support.microsoft.com/support/kb/articles/Q248/6/30.ASP
	if (isIE500) return;
	/* X11 not required browser */
	if (isX11) return;
	/****************************/
	menuStateArray[index] = (menuStateArray[index])?false:true;
	swapHTML(csMenu,buildMenu(navMenu));
	for(j=0;j<menuStateArray.length;j++) {
		if (menuStateArray[j]=="disabled") {
			continue;
		} else if (menuStateArray[j]) {
		/* for Resources For: and Services: top-level menu elements */
			if ((j==12)||(j==13)) {
				swapCSImages("arrow"+j,navOpen2);
			} else {
				swapCSImages("arrow"+j,navOpen);
			}
		/************************************************************/
		}
	}
	
	if (activeSubNav!="") swapCSImages(activeSubNav,activeSubNavImage);
}

///////////////////////////////
// swapCSImages()
// - swap clamshell nav images
///////////////////////////////
function swapCSImages() {
	if (document.images) {
		if (isNS4) {
			for(var i=0;i<arguments.length;i++) {
				eval("document."+csMenu).document.images[arguments[i]].src = arguments[i+1];
				++i;
			}
		} else {
			for(var i=0;i<arguments.length;i++) {
				document.images[arguments[i]].src = arguments[i+1];
				++i;
			}
		}
	}
}
