// JavaScript Document
<!--
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->


//Start Menu declare
var submenu = new Array();
var tmr = new Array();
var adj = new Array();
var last_zIndex = 10000;
var lastOverId = '';

var menuWidth 		= 160;			
var alignSubmenu 	= 'bottom';		
var useLastItemCSS	= true;			
var adjustFirst		= false;		
var adjustTop		= 0;			
var adjustLeft		= 0;			

//About
submenu['menu1'] = new Array();
submenu['menu1'][0] = menuItem('Overiew','a_overview.html','_self');
submenu['menu1'][1] = menuItem('Board of Trustees','a_board.html','_self');
submenu['menu1'][2] = menuItem('History','a_history.html','_self');
submenu['menu1'][3] = menuItem('Staff','a_staff.html','_self');
submenu['menu1'][4] = menuItem('Volunteers','a_volunteers.htm','_self');
submenu['menu1'][5] = menuItem('Education & Outreach','e_EducationandOutreachMission.htm','_self');
	/* submenu['menu1_1'] = new Array();
	submenu['menu1_1'][0] = menuItem('google','http://www.google.nl','demoFrame');
	submenu['menu1_1'][1] = menuItem('/.','http://www.slashdot.org','demoFrame');
	submenu['menu1_1'][2] = menuItem('Open in _BLANK:');
		submenu['menu1_1_2'] = new Array();
		submenu['menu1_1_2'][0] = menuItem('check test','http://www.google.nl','_blank');
		submenu['menu1_1_2'][1] = menuItem('test again','http://www.slashdot.org','_blank'); */

//News

submenu['menu2'] = new Array();
submenu['menu2'][0] = menuItem('General','n_general.html','_self');
submenu['menu2'][1] = menuItem('Events','n_events.html','_self');


//Events
submenu['menu3'] = new Array();
submenu['menu3'][0] = menuItem('Calendar','e_calendar.html','_self');
submenu['menu3'][1] = menuItem('Community','e_community.html','_self');
submenu['menu3'][3] = menuItem('Ellen Eccles','e_eccles.html','_self');
submenu['menu3'][4] = menuItem('Education & Outreach','EducationOutreach.htm','_self');

//Facilities
submenu['menu4'] = new Array();
submenu['menu4'][0] = menuItem('Overview','f_overview.html','_self');
submenu['menu4'][1] = menuItem('Ellen Eccles Theatre','EllenEcclesTheatre.htm','_self');
submenu['menu4'][2] = menuItem('Thatcher-Young Mansion','f_ThatcherYoungMansion.htm','_self');
submenu['menu4'][3] = menuItem('Bullen Center','f_BullenCenter.htm','_self');

//Classes
submenu['menu5'] = new Array();
submenu['menu5'][0] = menuItem('About','c_about.html','_self');
submenu['menu5'][1] = menuItem('Schedule','c_shedule.html','_self');

//build or unhide submenu div...
function buildSubmenu(obj){
	lastOverId = obj.id;

	//get common part of div id
	menuPath = obj.id.split('_');

	//unset mousout of parent menus and make sure they are visible...
	x = "div";
	for(i=0;i<menuPath.length;i++){
		x+= '_' + menuPath[i];
		if(document.getElementById(x)){
			if(tmr[x])
				window.clearTimeout(tmr[x]);
			document.getElementById(x).style.visibility = 'visible';
		}
	}

	//check if we have a submenu of the obj...
	if(submenu[obj.id]){
		//check if allready build...
		c = document.getElementById('div_' + obj.id);
		if(c){
			//unhide...
			c.style.visibility = 'visible';
			c.style.zIndex = last_zIndex++;
		}else{
			//calc position of mouseover
			d = obj;
			if(d){
				L_pos = d.offsetLeft + d.offsetWidth - 1;
				T_pos = d.offsetTop;
				while(d.offsetParent){
					d = d.offsetParent;
					L_pos+= d.offsetLeft;
					T_pos+= d.offsetTop;
				}
			}

			//patch first submenu to go right below the main buttons...
			if(obj.className.indexOf('menuItem') < 0 && alignSubmenu == 'bottom'){
				L_pos-= obj.offsetWidth;
				T_pos+= obj.offsetHeight;
			}

			//move the submenu (overlap?)
			if((adjustTop || adjustLeft) && (adjustFirst || (!adjustFirst && obj.className.indexOf('menuItem') >= 0))){
				L_pos+= adjustLeft;
				T_pos+= adjustTop;
			}

			//build new div
			subObj = document.createElement('div');
			subObj.id = 'div_' + obj.id;
			subObj.className = 'submenu';
			subObj.style.position = 'absolute';
			subObj.style.zIndex = last_zIndex++;
			subObj.style.width = menuWidth;
			subObj.style.top = T_pos + "px";
			subObj.style.left = L_pos + "px";

			//write div to the body...
			document.getElementsByTagName('body')[0].appendChild(subObj);

			//build html for submenu
			content = "";
			m = submenu[obj.id];
			for(i=0;i<m.length;i++){

				//determin target for onclick...
				//	(sorry, I should rewrite this routine...)
				if(!m[i][2] || m[i][2] == '_self')
					act = "self.location.href='" + m[i][1] + "';";
				else if(m[i][2] == '_top')
					act = "top.location.href='" + m[i][1] + "';";
				else if(m[i][2] == '_blank')
                    act = "window.open('" + m[i][1] + "');";
				else
					act = "window.frames['"+m[i][2]+"'].location.href='" + m[i][1] + "';";

				//make item
				content+= "<div onmouseout=\"hideSubmenu(this)\" onmouseover=\"buildSubmenu(this)\" "+ (m[i][1] ? "onclick=\""+ act + "\" " : "") +"class=menuItem" + (i==0 ? 'First' : (i==(m.length -1) && useLastItemCSS ? 'Last' : '')) + " id=\"" + obj.id + "_" + i +"\">" + m[i][0] + "</div>";
				adj[i] = obj.id + "_" + i;
			}

			//insert new menu
			subObj.innerHTML = content;

			//make all just made div's the same width...
			for(i=0;i<adj.length;i++)
				document.getElementById(adj[i]).style.width = subObj.style.width;
		}
	}
}

//hide a submebu div
function hideSubmenu(obj){
	//get common part of div id
	closePath = obj.id.split('_');

	//hide path
	x = "div";
	for(i=0;i<closePath.length;i++){
		x+= '_' + closePath[i];
		if(document.getElementById(x))
			tmr[x] = window.setTimeout("document.getElementById('"+x+"').style.visibility = 'hidden';",500);
		//The timeout above is needed for MSIE browsers... Or else the menu's will disapear on EVERY mousout!!!
		//Please get a normal browser like Firefox, Mozilla or Opera!!
	}
}

//add an menu item to the config array (called in the config lines)
function menuItem(txt,url,tar){
	return new Array(txt,url,tar);
}

//*** Patch for firefox bug with focus on mouseover...
//		This function should be called onMouseOver of every iFrame that's under the menu structure.
function iFramePatch(){
	if(!document.all && lastOverId)
		hideSubmenu(document.getElementById(lastOverId));
}

//*** Now a patch for MSIE lag of CSS2 compliance!!
if(navigator.userAgent.indexOf('MSIE')>=0 && navigator.userAgent.indexOf('Opera')==-1){
	document.onmouseover = function(){
		obj = event.srcElement;
		if(obj.className == 'menuItemFirst' || obj.className == 'menuItem' || obj.className == 'menuItemLast')
			obj.className+='Over';
	}
	document.onmouseout = function(){
		obj = event.srcElement;
		if(obj.className == 'menuItemFirstOver' || obj.className == 'menuItemOver' || obj.className == 'menuItemLastOver')
			obj.className = obj.className.substring(0,(obj.className.length - 4));
	}
}

window.onresize = function(){
	self.location.href = self.location.href;
}
