//figure out what page I'm on
var url = document.URL;
//strip the path up to the root level (special search&replaces added in to chop teamsite's path... with & without smart context edit bar, in a workarea or in staging)
var rootpath = url.replace(/(\w+):\/\/teamsite(\.getty\.edu)?\/iw\/cci\/meta\/no-injection\/iw-mount\/\w+\/main\/\w+\/WORKAREA\/\w+|(\w+):\/\/teamsite(\.getty\.edu)?\/iw-mount\/\w+\/main\/\w+\/WORKAREA\/\w+|(\w+):\/\/teamsite(\.getty\.edu)?\/iw\/cci\/meta\/no-injection\/iw-mount\/\w+\/main\/\w+\/STAGING|(\w+):\/\/teamsite(\.getty\.edu)?\/iw-mount\/\w+\/main\/\w+\/STAGING|(\w+):\/\/(\w+)/, "");
var dirs = rootpath.split("/");
///////////////////////////////////////////////////////////////////////////
//these are the 7 tabs across the top
//figure out which tab should be on based on the dirs[1] value; set all others to off
var tabs = new Array("home", "visit", "museum", "research", "conservation", "foundation", "about"); //these values should reflect the actual dir. (the trust tab is really about, because that's the dir everything lives in)
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//NOTE: To place a message across the very top of all pages on the site that use this nav_writer.js file
//////  edit the document write section below as needed, uncomment and deploy. Be sure to check the graphic height (28 px for one-line and 43 px for two-line.)
//
//document.write("<TABLE BGCOLOR='#FFFFFF' WIDTH='100%' CELLPADDING='0' CELLSPACING='0' BORDER='0'>");
//        document.write("<TR>");
//		document.write("<TD ALIGN='center'><IMG SRC='/global/visualmenu/site_down_mssg_Jan14-15.gif' WIDTH='820' HEIGHT='43' BORDER='0' ALT=''></TD>");
//	  document.write("</TR>");
document.write("</TABLE>");
//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
document.write("<TABLE WIDTH='100%' CELLPADDING='0' CELLSPACING='0' BORDER='0'>");
	document.write("<TR>");
		document.write("<TD BACKGROUND='/global/images/nav_bg.gif' BGCOLOR='#999999'>");
		document.write("<TABLE WIDTH='922' CELLPADDING='0' CELLSPACING='0' BORDER='0'>");
		document.write("<FORM NAME='seek1' METHOD='GET' ACTION='http://www.getty.edu/Search/SearchServlet?la=en'>");
			document.write("<TR>");
				document.write("<TD ROWSPAN='4' VALIGN='bottom'><A HREF='/'><IMG SRC='/global/images/nav_logo.gif' ALT='The Getty' WIDTH='168' HEIGHT='64' BORDER='0'></A></TD>");
				document.write("<TD COLSPAN='7'><IMG SRC='/global/images/ghost.gif' ALT='' WIDTH='1' HEIGHT='3' BORDER='0'></TD>");
			document.write("</TR>");
			document.write("<TR><TD COLSPAN='7' ALIGN='right'>");
				document.write("<input type=hidden name=col value='getty'><input type=hidden name=nh value='10'><INPUT TYPE=TEXT NAME=qt SIZE=18 VALUE='' MAXLENGTH=2033>");
				document.write("<IMG SRC='/global/images/ghost.gif' ALT='' WIDTH='5' HEIGHT='1' BORDER='0'><INPUT TYPE=IMAGE SRC='/global/images/global_go.gif' ALIGN='absmiddle' ALT='Go' WIDTH='17' HEIGHT='14' BORDER='0' NAME='SUBMIT'>");
				document.write("<BR><A HREF='/Search/'><IMG SRC='/global/images/nav_advanced_search.gif' ALT='Advanced Search' WIDTH='92' HEIGHT='13' BORDER='0'></A><IMG SRC='/global/images/ghost.gif' ALT='' WIDTH='22' HEIGHT='1' BORDER='0'>");
				document.write("</TD>");
			document.write("</TR>");
			document.write("<TR><TD COLSPAN='7'><IMG SRC='/global/images/ghost.gif' ALT='' WIDTH='1' HEIGHT='3' BORDER='0'></TD></TR>");
			document.write("<TR>");
		if (dirs[1].match(/\.html/)||dirs[1] == ""||dirs[1].match(/\?newsletter/)){
			dirs[1] = "home";
			}
		if (url.match(/search\.getty\.edu/)) { //an exception for search pages
			var is_search = "yes";
			var actual_dir = dirs[1];
			if (dirs[1] == "special_collections"){
				dirs[1] = "research";
				}
			else if (dirs[1] == "news"){
				dirs[1] = "about";
				}
			else if (dirs[1] == "museum"){
				actual_dir = null;
				}
			else if (dirs[1] == "art"){
				dirs[1] = "museum";
				}
			else if (dirs[1] == "calendar"){
				dirs[1] = "visit";
				}
			else if (dirs[1] == "education_search"){
				dirs[1] = "education";
				}
			}
		if (dirs[1] == "cgi-bin"){  //an exception for cgi-bin files
			var actual_dir = dirs[1];
			if (dirs[2] == "trippack"){
				dirs[1] = "education";
				}
			else if (dirs[2] == "gli"){
				dirs[1] = "foundation";
				}
			else if (dirs[2] == "box_lunch"){
				dirs[1] = "visit";
				}
			}
		if (dirs[1].match(/art|mygetty|education|publications/)){
			var actual_dir = dirs[1]; //since we're going to reset dirs[1] for tab purposes, keep track of the dir we're actually in
			dirs[1] = "museum";
			}
		if (dirs[1].match(/news/)){
			var actual_dir = dirs[1]; //since we're going to reset dirs[1] for tab purposes, keep track of the dir we're actually in
			dirs[1] = "about";
			}
		//if (dirs[1].match(/grants|leadership|foundation/)){
		if ((dirs[1].match(/leadership/)) ||(dirs[1].match(/grants/)) ){
			var actual_dir = dirs[1];
			dirs[1] = "foundation";
			}


		for (var i=0; i < tabs.length; i++) {
			if (dirs[1].match(tabs[i])) {
				//if (((actual_dir == "foundation")&&(dirs[2] == "")||(dirs[2] == "index.html"))||(dirs[1] == "home")) { var state = "on"; } //make sure foundation is on the "at" state only in /foundation/
				//else if ((dirs[2] != "")||(dirs[2] == "index.html")||(actual_dir != null)){ var state = "at"; } //use the tab's "at" state if we're not on the section landing page
				if ((dirs[2] != "")||(dirs[2] == "index.html")||(actual_dir != null)){ var state = "at"; } //use the tab's "at" state if we're not on the section landing page
				else { var state = "on"; }
				var current_tab = tabs[i]; //keep track of what section we're in to figure out the subnav later
				}
			else { 
				var state = "off";
				}
			document.write("<TD VALIGN='bottom' BGCOLOR='#999999'>");
			if (state == "off"||state == "at") {
				if (tabs[i] == "home") { 
					document.write("<A HREF='/'>");
					}
				else {
					document.write("<A HREF='/" + tabs[i] + "/'>");
					}
				}
			if (tabs[i] == "about") { tabs[i] = "trust"; }
			var tab_img = "/global/images/nav_" + tabs[i] + "_" + state + ".gif";
			document.write("<IMG SRC='" + tab_img + "' ' BORDER='0' HSPACE='0' VSPACE='0' ALT='" + tabs[i] + "'>");
			if (state == "off"||state == "at") { 
				document.write("</A>");
				}
			document.write("</TD>");
			}
			document.write("</TR>");
		document.write("</FORM>");
		document.write("</TABLE>");
		document.write("</TD>");
		document.write("<TD><IMG SRC='/global/images/ghost.gif' WIDTH='1' HEIGHT='38' BORDER='0' ALT=''></TD>");
	document.write("</TR>");
	document.write("<TR>");
		document.write("<TD BACKGROUND='/global/images/nav_bg_secondary.gif' BGCOLOR='#EFEFEF'>");
///////////////////////////////////////////////////////////////////////////

//open up a 2nd level nav table
		document.write("<TABLE WIDTH='986' CELLPADDING='0' CELLSPACING='0' BORDER='0'>");
			document.write("<TR>");
				document.write("<TD BGCOLOR='#EFEFEF'><IMG SRC='/global/images/ghost.gif' WIDTH='90' HEIGHT='20' BORDER='0' ALT=''></TD>");
				document.write("<TD ALIGN='center'>");
				document.write("<TABLE WIDTH='896' CELLPADDING='0' CELLSPACING='0' BORDER='0'><TR>");
				
//any DHTML menus needed have been built with VisualMenu
//figure out the current subnav based on the current tab
if (dirs[1] == "visit") { var subnav = new Array("exhibitions", "calendar", "hours", "see_do", "groups", "espanol"); }
else if (dirs[1].match(/art|museum|mygetty|gettyguide|publications|education/)) { var subnav = new Array("exhibitions", "collections", "education", "conservation", "publications", "programs", "museum"); }
else if (dirs[1] == "research") { var subnav = new Array("exhibitions", "conducting_research", "scholarly_activities", "institute"); }
else if (dirs[1] == "conservation") { var subnav = new Array("science", "field_projects", "education", "publications", "research_resources", "public_programs", "institute"); }
//else if (dirs[1] == "foundation") { var subnav = new Array("grants", "leadership", "institute"); }
else if (dirs[1] == "foundation") { var subnav = new Array("funding", "apply", "grants","news","about"); }
else if (dirs[1] == "leadership") { var subnav = new Array("funding", "apply", "grants","news","about"); }
//else if (dirs[1] == "leadership") { var subnav = new Array("grants", "leadership", "foundation"); }
//add this in to about section when Special Events gets approved... "events", 
else if (dirs[1].match(/about|news/)) { var subnav = new Array("governance", "opportunities", "news", "contact", "about"); }
//blank 2nd level nav for home page, about, & any others without tabigation
if (subnav == null) {
	document.write("<TD BGCOLOR='#EFEFEF'><IMG SRC='/global/images/ghost.gif' WIDTH='1' HEIGHT='20' BORDER='0' VSPACE='0' HSPACE='0' ALT=''></TD>");
	}
else {
	for (var i=0; i < subnav.length; i++) {
		if (actual_dir != null) {
			//if (actual_dir == "grants" && dirs[2] == "research") { //exception for /grants/research/
			//	var style_override = "menu0";
			//	}
			//if (actual_dir == "leadership" && dirs[1] == "foundation") { //exception for /leadership
			//	var style_override = "menu1";
			//	}
			if (subnav[i] == dirs[2]){
				var style_override = "menu" + i;
				}
			else if (actual_dir == subnav[i]){
				var style_override = "menu" + i;
				if ((actual_dir == "education")&&(dirs[2] == "")) {
					style_override = "menu2";
					}
				}
			else if ((dirs[2] == "gettyguide")||(actual_dir == "mygetty")) { //highlight Explore Art for /art/gettyguide/ (Collections)
				var style_override = "menu1";
				}
			else if ((actual_dir == "art")&&((dirs[2] == "")||(dirs[2] == "index.html")||(dirs[2] == "acquisitions"))) { //highlight Explore Art for /art/[index.html] (Explore Art overview)
				var style_override = "menu1";
				}
			else if (actual_dir == "subscribe"){  //an exception for lists.getty.edu/subscribe/profile (TAE account settings page)
				var style_override = "menu5";
				}
			//else if ((actual_dir == "foundation")&&(dirs[2] == "about.html")) { //highlight institute for /foundation/about.html (Philanthropy)
			//	var style_override = "menu2";
			//	}
			//else if ((actual_dir == "leadership")&&(dirs[2] == "about.html")) { //highlight institute for /foundation/about.html (Philanthropy)
			//	var style_override = "menu1";
			//	}
			else if (actual_dir == "bookstore_redesign") { //highlight bookstore for bookstore search (Museum)
				var style_override = "menu4";
				}
			else if (actual_dir == "special_collections") { //highlight conducting research for finding aids search (Research)
				var style_override = "menu0";
				}
			else if (actual_dir == "calendar") { //highlight conducting research for finding aids search (Research)
				var style_override = "menu1";
				}
			else if (actual_dir == "news") { //highlight Press Room for news search (The Trust)
				var style_override = "menu2";
				}
			else if (dirs[2].match(/query\.html/)){ //highlight Explore Art for searches on the collections
				var style_override = "menu2";
				}
			else if (actual_dir == "cgi-bin"){  //an exception for cgi-bin files
				if (dirs[2] == "trippack"){
					var style_override = "menu0";
					}
				else if (dirs[2] == "gli"){
					var style_override = "menu1";
					}
				else if (dirs[2] == "box_lunch"){
					var style_override = "menu3";
					}
				}
			}
		else {
			if (dirs[2] == "research" && subnav[i] == "conservation") {
				var style_override = "menu3";
				}
			else if ((dirs[1] == "museum")&&(dirs[2].match(/query\.html/))) { //highlight Explore Art collections search
				var style_override = "menu1";
				}
			else if ((dirs[1] == "museum")&&(dirs[2] == "symposia")) { //highlight Museum Research and Conservation for /museum/symposia/
				var style_override = "menu3";
				}
			else if ((dirs[2] == "about.html" && subnav[i] == "museum")) { //exception for /museum/about.html
				var style_override = "menu6";
				} 
			else if ((dirs[1] == "about")&&(dirs[2] == "contact_us.html")) { //highlight Contact Us for /about/contact_us.html (The Trust)
				var style_override = "menu3"; //change to 5 when Special Events gets approved
				}
			else if ((dirs[1] == "about")&&(dirs[2] == "trust.html")) { //highlight About The JPGT for /about/trust.html (The Trust)
				var style_override = "menu4"; //change to 6 when Special Events gets approved
				}
			else if (dirs[2] == "espanol.html") { //highlight En Espanol for /visit/espanol.html (Visit)
				var style_override = "menu5";
				}
			else if (subnav[i] == dirs[2]){
				var style_override = "menu" + i;
				}
			}
		}
	}

//override the style of whichever menu should be highlighted
if (style_override != null) {
	document.write("<style type='text/css'> ." + style_override + ", ." + style_override + "-over { background: #FFFFFF; }</style>");
	}
if (current_tab == dirs[1]&&dirs[1] != "home") {
	if (is_search == "yes") { current_tab = current_tab + "_search"; }
	//this part pulls in the 2nd level nav, along with the DHTML pulldown menus from _NAV_DATA.js, if they exist
	document.write("<TD ALIGN='center' VALIGN='middle'><DIV ID='id_top_nav'></DIV></TD>");
	if ((current_tab == "foundation" && actual_dir == "leadership")||(current_tab == "foundation" && actual_dir == "grants") ) {
		document.write("<SCRIPT language='javascript' type='text/javascript'>new VisualMenu('id_top_nav', _leadership)<\/SCRIPT>");
		}
	else {
		document.write("<SCRIPT language='javascript' type='text/javascript'>new VisualMenu('id_top_nav', _" + current_tab + ")<\/SCRIPT>");
		}
	}

//close the 2nd level nav table out
document.write("</TR></TABLE></TD>");
document.write("</TR>");
			document.write("<TR>");
				document.write("<TD COLSPAN='2' BGCOLOR='#888888'><IMG SRC='/global/images/ghost.gif' WIDTH='1' HEIGHT='1' BORDER='0' ALT=''></TD>");
			document.write("</TR>");
		document.write("</TABLE>");
		document.write("</TD>");
		document.write("<TD BACKGROUND='/global/images/nav_bg_secondary.gif'><IMG SRC='/global/images/ghost.gif' WIDTH='1' HEIGHT='20' BORDER='0' ALT=''></TD>");
	document.write("</TR>");
	document.write("<TR>");
		document.write("<TD COLSPAN='2' BGCOLOR='#FFFFFF'><IMG SRC='/global/images/ghost.gif' WIDTH='1' HEIGHT='18' BORDER='0' ALT=''></TD>");
	document.write("</TR>");
document.write("</TABLE>");


