/////////////////////////////////////////////////////////////////////////////
////// these functions define the behaviors for the divs that get built below

// This "tag" fools editors into syntax coloring for javascript: <script>

	function mainRollover(theDiv) {
		// clear the timer we don't wipe everything
		clearTimeout(timerID);

		// set all other items to lo state
		setBaseState();

		// set this item to hi state
		theItem = getDivRef(theDiv);
		theItem.background = hiColor;
		theItem.color = hiText;

		// split the id of this div into array so we can access it's number
		baseName = theDiv.split("_");

		// ignore the home button (first item)
		if (baseName[1] != 1) {
			// show the submenu
			showSub = "menu_" + baseName[1];
			showSubMenu(showSub);
		}

	}

	function mainRollout(theDiv) {
		// start wipe timer
		timerID = setTimeout("setBaseState()",wipeDelay);
	}

	function mainClick(theDiv,theURL) {
		// submenu item click
		//alert(theURL);
		document.location = theURL;
	}

	function showSubMenu(theSubID) {
		theSub = getDivRef(theSubID);
		theSub.visibility = "visible";
	}

	function hideSubMenu(theSubID) {
		theSub = getDivRef(theSubID);
		theSub.visibility = "hidden";
	}

	function doRollover(theDiv) {
		// clear the timer we don't wipe everything
		clearTimeout(timerID);

		// spliut name into array so we can access components
		nameItems = theDiv.split("_");

		// clear the curent submenu
		clearSubMenu(theDiv);

		// set the bg of calling item to hi
		theItem = getDivRef(theDiv);
		//theItem.background = hiColor;
		theItem.color = hiText;

	}

	function doRollout(theDiv) {
		// set the bg of calling div to lo
		theItem = getDivRef(theDiv);
		//theItem.background = loColor;
		theItem.color = loText;

		// start wipe timer
		timerID = setTimeout("setBaseState()",wipeDelay);
	}

	function doClick(theDiv,theURL) {
		// submenu item click
		//alert(theURL);
		document.location=theURL;
	}

	function clearSubMenu(theDiv) {
		nameItems = theDiv.split("_");
		// set entire calling submenu to lo
		currMenu = nameItems[1];
		numItems = menuItems[currMenu].length
		for (i=1;i<numItems;i++) {
			currDiv = nameItems[0] + "_" + nameItems[1] + "_" + i;
			theItem = getDivRef(currDiv);
			//theItem.background = loColor;
			theItem.color = loText;
		}
	}

	function setBaseState() {
		// hide all submenus & set all menus to lo state
		clearTimeout(timerID);
		numItems = baseMenu.length;
		for (i=1;i<numItems;i++) {
			currDiv = "item_" + i;
			theItem = getDivRef(currDiv);
			theItem.background = loColor;
			theItem.color = loText;
			hideSub = "menu_" + i;
			hideSubMenu(hideSub);

		}
	}

//////////////////////////////////////////////
////// these functions build out the menu divs

// parent function - this basically just calls other functions to build out menus
// so that we only need a single call in the html to build menus
function initMenus(currHi) {

	// builds the base menu (duh)
	buildBaseMenu(theLeft,theTop,currHi);

	// builds out the submenus
	// first item (home) doesn't have a submenu so start at 2
	for (subCounter=1;subCounter<baseMenu.length;subCounter++) {
		currTop = (subCounter*subTopOffset)+subTopShift;
		currMenu = subCounter;
		buildSubMenu(currTop,currMenu,1);
	}

}


// this function builds the nav menu given a top and left
function buildBaseMenu(theLeft,theTop,currHi) {

	theZindex = 20;
	theBG = "#FFFFFF";

	theDiv  = "<DIV ";
	theDiv += "ID=\"basemenu\" ";
	//theDiv += "ID=\"leftnav\" ";
	theDiv += "STYLE=\"";
	theDiv += "position:fixed; ";
	theDiv += "left:" + theLeft +"px; ";
	theDiv += "top:" + theTop +"px; ";
	theDiv += "width:" + theWidth +"px; ";
	//theDiv += "height:" + theHeight +"px; ";
	theDiv += "z-index:" + theZindex +"; ";
	theDiv += "background-color:" + theBG +"; ";
	theDiv += "layer-background-color:" + theBG +"; ";
	//theDiv += "border:" + theBorder +"; ";
	theDiv += "\">";

	numItems = (baseMenu.length);
	//theDiv += "<span class=\"menuitemtext\">menu ID: " + theMenuID + "</span>";
	//theDiv += "<span class=\"menuitemtext\">menu length: " + numItems + "</span>";

	for (itemCounter=1;itemCounter<numItems;itemCounter++) {
		currText  = baseMenu[itemCounter][1];
		midURL    = baseMenu[itemCounter][2];
		rtURL     = baseMenu[itemCounter][3];
		currName  = baseMenu[itemCounter][4];
		theDiv += buildItem(itemCounter,currHi,midURL,rtURL,currName);
		theDiv += "<img src='images/spacer.gif' width='15' height='3'>";
		theDiv += "<a href=\"" + midURL + "\">" + currText + "</a>";
		theDiv += "<img src='images/spacer.gif' width='5' height='3'>";
		theDiv += "</DIV>";
	}

	theDiv +="<div class=\"mainmenu\" style='padding-bottom:0px;'><form name='newsform' onsubmit='return checkEMail();' action=\"index.php\" method=\"post\">";
	theDiv +="<img src='images/spacer.gif' width='15' height='3'>"
	theDiv +="newsletter</div>";
	theDiv +="<img src='images/spacer.gif' width='15' height='3'>"
	theDiv +="<input class='newsbox' onclick='if (this.value==\"enter e-mail\") this.value=\"\";' style='margin-left:10px;width:75px' value='enter e-mail' type=\"text\" name=\"newsemail\">"
	theDiv +="<span style='position:relative;top:-2px;' class='gobutton' onclick='if (checkEMail()) {document.all.newsform.submit();}'><span style='position:relative;top:-2px;'>go</span></span><br></div>";
	theDiv +="</form>";

	theDiv += "<div class=\"address\" style=\"margin-left:10px;margin-top:25px;\">";
	theDiv += "<nobr>The Hurley School</nobr><br />";
	theDiv += "<nobr><a href=\"http://www.mapquest.com/maps/map.adp?zoom=9&mapdata=EifUonSP7c1zSeQlYqRM1KUAdIGr8CYmZGw%2f1rD3t7F%2foMQnAIMvmKCvaDTXjkNqD6IGNybrMNqSsk7Qr%2fgnUtiX04zos5cvSS9FHJ49wB7pWIkOnyPsYYYscAAjf5tTsiYg0MTF6aNKyTcvFkd41StvhffsNqEZ44Os7%2bG1LTdEkkb6xkfo5zxsokEWWgAhVziZR2TR6LZ4i4xixkgt1OzG%2bZi3Cgs15mYbgbnC1utVoE%2ft1EwW2pKeUjbi4lRO0%2fZLiMGOm5ekumBjGylodNdTdzD5c%2bJxI6l8zu%2fuOD1Kp3jM7GxL0NJpQ89EVoYk1j4kQMJzE4zuED9MTu%2f9Tjh9Av%2f1FCnimGWFCX7xFgE%3d\" target=\"_new\" style='text-decoration:underline'>70 Worcester St.</a></nobr><br />";
	theDiv += "<nobr>Boston, MA 02118</nobr><br />";
	theDiv += "<nobr>617.635.8489</nobr><br />";
	theDiv += "<!-- <a href=\"mailto:email@hurleyschool.com\">email@hurleyschool.com</a> -->";
	theDiv += "</div>";

	theDiv += "</DIV>";

	document.write(theDiv);
}

function checkEMail()
{
if (document.all.newsemail.value.indexOf('@') > 0)
	return true;
else
	{
	alert('Please enter a valid e-mail address.');
	return false;
	}
}

function buildItem(theItemID,currHi,midURL,rtURL,currName) {

	//alert(theItemID);

	theSq  = "<img src='images/";
	//if (theItemID == currHi) {
	if (theItemID == 1) {
		theSq += "sq_red.gif'";
	} else {
		theSq += "spacer.gif'";
	}
	 theSq += "width='10' height='10' name='sq_" + currName + "' style='margin-left:0px;margin-right:15px;vertical-align:middle;>"

	theDiv  = "<DIV ";
	theDiv += "id=\"item_" + theItemID +"\" ";
	theDiv += "class=\"mainmenu\" ";
	theDiv += "style=\"";
	theDiv += "width:100%; ";
	if (theItemID == currHi) {
		theDiv += "background-color: " + hiColor + "; ";
	} else {
		theDiv += "background-color: " + loColor + "; ";
	}
	theDiv += "padding-top: " + vPad + "; ";
	theDiv += "padding-bottom: " + vPad + "; ";
	theDiv += "padding-left: 0; ";
	theDiv += "padding-right: 0; ";
	theDiv += "cursor: pointer; ";
	if (theItemID == currHi) {
		theDiv += "color: " + hiText;
	} else {
		theDiv += "color: " + loText;
	}
	theDiv += "\" ";
	theDiv += "onMouseOver=\"setHi('sq_" + currName + "');\" ";
	theDiv += "onMouseOut=\"setLo('sq_" + currName + "');\" ";
	//theDiv += "onMouseOver=\"setHi('sq_" + currName + "');mainRollover(this.id);\" ";
	//theDiv += "onMouseOut=\"setLo('sq_" + currName + "');mainRollout(this.id);\" ";
	//theDiv += "onClick=\"loadFrame('" + midURL + "','" + rtURL + "','sq_" + currName + "');\" ";
	theDiv += "onClick=\"this.location='" + midURL + "';\" ";

	/*
	if (theItemID == 1) {
		// home button so set an onClick
		theDiv += "onClick=\"mainClick(this.id,'index.html');\" ";
	} else {
		// don't know if we'll use this, but just in case
		//theDiv += "onClick=\"mainClick(this.id,'" + currURL + "');\" ";
	}
	*/
	theDiv += ">";

	return(theDiv + theSq);


}

// this function builds the submenus
function buildSubMenu(theTop,theMenuID,activeItem) {

	theDiv  = "<DIV ";
	theDiv += "ID=\"menu_" + theMenuID + "\" ";
	theDiv += "STYLE=\"";
	theDiv += "position:absolute; ";
	theDiv += "left:" + eval(theLeft+subLeftOffset) +"px; ";
	theDiv += "top:" + theTop +"px; ";
	theDiv += "width:" + subWidth +"px; ";
	//theDiv += "height:" + theHeight +"px; ";
	theDiv += "z-index:" + theZindex +"; ";
	//theDiv += "background-color: " + loColor + "; ";
	//theDiv += "layer-background-color: " + loColor + "; ";
	//theDiv += "border:" + theBorder +"; ";
	theDiv += "visibility:hidden; ";
	//theDiv += "visibility:visible; ";
	theDiv += "\" ";
	//theDiv += "onMouseOut=\"subMenuOut(this.id);\" ";
	theDiv += ">";

	currMenu = menuItems[theMenuID];
	numItems = (currMenu.length);

	if (numItems) {
		theDiv  += "<DIV style=\"width:100%; background-color: " + hiColor + "; border-bottom: " + theBorder + "padding-top: " + subvPad + "padding-bottom: " + subvPad + "padding-left: 0; padding-right: " + hPad + "; " + subfontFamily + subfontSize + subfontWeight + "color: " + loText + "\">&nbsp;</DIV>";
		for (i=1;i<numItems;i++) {
			currText = menuItems[theMenuID][i][1];
			currURL = menuItems[theMenuID][i][2];
			theDiv += buildSubmenuItem(theMenuID,i,currURL);
			//theDiv += "<img src='images/spacer.gif' width='5' height='3'>" + currText + "<img src='images/spacer.gif' width='5' height='3'>";
			theDiv += "<img src='images/spacer.gif' width='15' height='3'>" + currText;
			//theDiv += currText;
			theDiv += "</DIV>";
		}

		theDiv  += "<DIV style=\"width:100%; background-color: " + hiColor + "; border-bottom: " + theBorder + "padding-top: " + subvPad + "padding-bottom: " + subvPad + "padding-left: 0; padding-right: " + hPad + "; " + subfontFamily + subfontSize + subfontWeight + "color: " + loText + "\">&nbsp;</DIV>";
	}
	theDiv += "</DIV>";

	document.write(theDiv);
}

function buildSubmenuItem(theMenuID,theItemID,currURL) {

	theColor = "#000000";
	//theBorder = "1px solid #999999";

	theDiv  = "<DIV ";
	theDiv += "id=\"item_" + theMenuID + "_" + theItemID +"\" ";
	theDiv += "style=\"";
	theDiv += "width:100%; ";
	theDiv += "background-color: " + hiColor + "; ";
	//theDiv += "layer-background-color: " + loColor + "; ";
	theDiv += "border-bottom: " + theBorder + "; ";
	theDiv += "padding-top: " + subvPad + "; ";
	theDiv += "padding-bottom: " + subvPad + "; ";
	theDiv += "padding-left: 0; ";
	theDiv += "padding-right: " + hPad + "; ";
	theDiv += "cursor: pointer; ";
	theDiv += subfontFamily;
	theDiv += subfontSize;
	theDiv += subfontWeight;
	theDiv += "color: " + loText;
	theDiv += "\" ";
	theDiv += "onMouseOver=\"doRollover(this.id);\" ";
	theDiv += "onMouseOut=\"doRollout(this.id);\" ";
	theDiv += "onClick=\"doClick(this.id,'" + currURL + "');\" ";
	theDiv += ">";

	return(theDiv);


}



///// utility functions

// get browser version
isNS4 = (document.layers) ? true : false;
isIE4 = (document.all && !document.getElementById) ? true : false;
isIE5 = (document.all && document.getElementById) ? true : false;
isNS6 = (!document.all && document.getElementById) ? true : false;
//divCap = (isIE4 || isIE5 || isNS6) ? true : false;
oldBrowser = (isNS4 || isIE4 || isIE5 || isNS6) ? false : true;

//alert(oldBrowser);

// goddamn Netscape
function netscapeResize(theURL) {
	if (isNS4) {
		self.nav.location.reload()
		self.content.location.href = theURL
	}
}

function getDivRef(theName){
	if (window.document.layers) {								// NN4
		theObj = eval("window.document." + theName);

	} else if (document.all && !document.getElementById) {		// IE4
		theObj = eval("document.all." + theName + ".style");

	} else if (document.all && document.getElementById) {		// IE5
		//theObj = eval("document.all." + theName + ".style");
		// try the new way
		theObj = document.getElementById(theName).style;

	} else if (!document.all && document.getElementById) {		// NN6
		theObj = document.getElementById(theName).style;

	} else {													// Who knows? try IE's format & hope for best
		theObj = eval("document.all." + theName + ".style");
	}
	return theObj;
}
