var pageHold;
var secondary=false;
//grab current file name (page)
var loc=String(this.location.href);
var httppath = loc.split("/")[2];
if (httppath == "trww")
	loc=loc.split("trww/")[1];
else if(httppath == "saturn:8099")
	loc=loc.split("saturn:8099/")[1];
else if(httppath == "trww.pipitonegroup.com")
	loc=loc.split("trww.pipitonegroup.com/")[1];
else if(httppath == "www.3riverswetweather.org")
	loc=loc.split("www.3riverswetweather.org/")[1];
else if(httppath == "www.3riverswetweather.com")
	loc=loc.split("www.3riverswetweather.com/")[1];
else if(httppath == "web.teragon.com:4520")
	loc=loc.split("web.teragon.com:4520/")[1];
else if(httppath == "web.3riverswetweather.org:4500")
	loc=loc.split("web.3riverswetweather.org:4500/")[1];
else if(httppath == "web.3riverswetweather.org")
	loc=loc.split("web.3riverswetweather.org/")[1];
else
	loc=loc.split("trww_redesign/")[1];
	
//loc=loc.split("3riverswetweather.org/")[1];
	if(loc.indexOf("+")>=0) { loc=(loc.split("+")[0]) }
	if(loc.indexOf("#")>=0) { loc=(loc.split("#")[0]) }
	if(loc.indexOf("?")>=0) { loc=(loc.split("?")[0]) }
	if(loc.indexOf(".stm")==-1) loc=loc+"index.stm"
loc=loc.split("/");var levels=loc.length;
var root="";
for(i=0;i<levels;i++) {loc[i]=loc[i].split(".")[0];if((loc[i]=="undefined")) loc[i]="";if(i>0) root=root+"../" }
file=loc[levels-1];folder=loc[levels-2];domain=loc[levels-3];
	//alert("file "+file);
	//alert("folder "+folder);
	//alert("domain "+domain);
	//alert(folder);
var aSecondary = new Array('a_about', 'b_news', 'c_muni', 'd_weather', 'e_contracting', 'f_resources', 'g_home');
var NoOfFolders = aSecondary.length;
//if((folder==undefined)||(folder=="undefined")){ //kills Mac IE -don't use
	for (var i=0; i<NoOfFolders;i++){
		if (folder==aSecondary[i]){
			//alert("Secondary");
			secondary=true;
		}
	}
	if((folder=="projects")&&(!secondary)){ //highlight for sub folder in f_resources
		folder="f_resources";
		//alert("folderProjects");
	}
	else if(!secondary){ //detect root level page
		folder="root";
		//alert("folderUndefined");
	}
	
	/*if((domain=="web.teragon.com:4520")||(domain=="web.3riverswetweather.org:4500")){
		alert("rain");
		if((folder=="trp:Main.login_html")||(folder=="trp:Main.login_html;trp:")){
		alert("login");
		file="login";
		}
		else if(folder=="trp:Main.overview_jump_html;trp:,"){
		alert("overview");
		file="overview";
		}
		else if(folder=="trp:Main.history_jump_html;trp:,"){
		alert("history");
		file="history";
		}
	}
	if((folder=="web.teragon.com:4520")||(folder=="web.3riverswetweather.org:4500")){
		alert("rain");
		if((file=="trp:Main.login_html")||(file=="trp:Main.login_html;trp:")){
		alert("login");
		file="login";
		}
		else if(file=="trp:Main.overview_jump_html;trp:,"){
		alert("overview");
		file="overview";
		}
		else if(file=="trp:Main.history_jump_html;trp:,"){
		alert("history");
		file="history";
		}
	}*/
	
	//trying to capture jordie's section
	var hURL=String(this.location.href);
	hURL = hURL.split("/");
	lvl =  hURL.length;
	var hdomain = hURL[2];		// get the current domain
	var hfolder = hURL[lvl - 2];// get the file containing folder
	var hfile = hURL[lvl - 1]; 	// get the file name

	/*#######spit to avoid slashes with numbers*/
	var hURL_new_split=String(this.location.href);
	hURL_new_split = hURL_new_split.split("/trp:");
	lvl_new =  hURL_new_split.length;
	var hfile_new = hURL_new_split[lvl_new - 1]; 	// get the file name



	if((hdomain=="web.teragon.com:4520")||(hdomain=="web.3riverswetweather.org:4500")||(hdomain=="web.3riverswetweather.org")){
		//alert("calibrated radar");
		folder="f_resources";
		secondary=true;
		if((hfile_new.indexOf("Main.login_html")==0)||(hfile_new.indexOf("Main.newuser_html")==0)||(hfile_new.indexOf("Main.forgotten_password_htm")==0)){ //||(hfile_new.indexOf("Main.main_html")==0)
			//if((hfile=="trp:Main.login_html")||(hfile=="trp:Main.login_html;trp:")){
			//alert("login2");
			file="login";
		}
		else if(hfile_new.indexOf("Main.history_jump_html")==0){
			//alert("history2");
			file="history";
		}
		else if(hfile_new.indexOf("Main.overview_jump_html")==0){
			//else if((hfile=="trp:Main.overview_jump_html;trp:,")||(hfile=="trp:Main.overview_jump_html;trp:")){
			//alert("overview2");
			file="overview";
		}
		else{
			file="overview";
		}
	}
	
/*
	written by Chris Heilmann (http://icant.co.uk)
	Please refer to the yadm homepage for updates: http://www.onlinetools.org/tools/yadm/
	Free for non-commercial use. Changes welcome, but no distribution without 
	the consent of the author.
*/
function yadm()
{

// Variables, change these in case you need to set other class names (mmhide_ for 
// contribute users for example)
	var parentClass='isParent';				//gets applied when the LI has a nested UL
	var activeParentClass='isActive';		//gets applied when the nested UL is visible
	var preventHoverClass='nohover';		//denotes a navigation that should not get any hover effects
	var indicateJSClass='dhtml';			//gets applied to the main navigation when Javascript is available
	var toHideClass='hiddenChild';			//gets applied to hide the nested UL
	var toShowClass='shownChild';			//gets applied to show the nested UL
	var currentClass='current';				//denotes the current active sub element and prevents collapsing
	var d=document.getElementById('nav');	//denotes the navigation element 

// if DOM is not available stop right here.
	if(!document.getElementById && !document.createTextNode){return;}

// if the navigation element is available, apply the class denoting DHTML capabilities
	if(d)
	{
		d.className+=d.className==''?indicateJSClass:' '+indicateJSClass;
		var lis,i,firstUL,j,apply;

// loop through all LIs and check which ones have a nested UL
		lis=d.getElementsByTagName('li');
		for(i=0;i<lis.length;i++)
		{
			firstUL=lis[i].getElementsByTagName('ul')[0]
// if there is a nested UL, deactivate the first nested link and apply the class to show 
// there is a nested list
			if(firstUL)
			{
				//lis[i].childNodes[0].onclick=function(){return false;}//think this is for auto-pop
				lis[i].className+=lis[i].className==''?parentClass:' '+parentClass;
// check if there is a "current" element 
				apply=true;
				if(new RegExp('\\b'+currentClass+'\\b').test(lis[i].className)){apply=false;}
				if(apply)
				{
					for(j=0;j<firstUL.getElementsByTagName('li').length;j++)
					{
						if(new RegExp('\\b'+currentClass+'\\b').test(firstUL.getElementsByTagName('li')[j].className)){apply=false;break}
					}
				}
// if there is no current element, apply the class to hide the nested list
				if(apply)
				{
					firstUL.className+=firstUL.className==''?toHideClass:' '+toHideClass;
// check if there is a class to prevent hover effects and only apply the function
// onclick if that is the case, otherwise apply it onclick and onhover
					if(new RegExp('\\b'+preventHoverClass+'\\b').test(d.className))
					{
						lis[i].onclick=function(){doyadm(this);}
					} else {
						lis[i].onclick=function(){doyadm(this);}
						lis[i].onmouseover=function(){doyadm(this);}
						lis[i].onmouseout=function(){doyadm(null);}
					}
// if there is a current element, define the list as being kept open and apply the 
// classes to show the nested list and define the parent LI as an active one
				} else {
					lis[i].keepopen=1;
					firstUL.className+=firstUL.className==''?toShowClass:' '+toShowClass;
					lis[i].className=lis[i].className.replace(parentClass,activeParentClass);
				}
			}
		}
	}
// function to show and hide the nested lists and add the classes to the parent LIs
	function doyadm(o)
	{
		var childUL,isobj,swap;

// loop through all LIs of the navigation		
		lis=d.getElementsByTagName('li');
		for(i=0;i<lis.length;i++)
		{
			isobj=lis[i]==o;
// function to exchange class names in an object
			swap=function(tmpobj,tmporg,tmprep)
			{
				tmpobj.className=tmpobj.className.replace(tmporg,tmprep)		
			}
// if the current LI does not have an indicator to be kept visible
			if(!lis[i].keepopen)
			{
				childUL=lis[i].getElementsByTagName('ul')[0];
// check if there is a nested UL and if the current LI is not the one clicked on
// and exchange the classes accordingly (ie. hide all other nested lists and 
// make the LIs parent rather than active.
				if(childUL)	
				{	
					if(new RegExp('\\b'+preventHoverClass+'\\b').test(d.className))
					{
						if(new RegExp('\\b'+activeParentClass+'\\b').test(lis[i].className))
						{
							swap(childUL,isobj?toShowClass:toHideClass,isobj?toHideClass:toShowClass);		
							swap(lis[i],isobj?activeParentClass:parentClass,isobj?parentClass:activeParentClass);		
						} else {
	
							swap(childUL,isobj?toHideClass:toShowClass,isobj?toShowClass:toHideClass);		
							swap(lis[i],isobj?parentClass:activeParentClass,isobj?activeParentClass:parentClass);		
						}
					} else {
							swap(childUL,isobj?toHideClass:toShowClass,isobj?toShowClass:toHideClass);		
							swap(lis[i],isobj?parentClass:activeParentClass,isobj?activeParentClass:parentClass);		
					}
				} 
			}
		}
	}
}

/*
===================================================
XHTML/CSS/DHTML Semantically correct drop down menu 
===================================================
Author: Sam Hampton-Smith
Site: http://www.hampton-smith.com
Modified 04/10/04 SPD
Credits: Inspiration/Code borrowed from Dave Lindquist (http://www.gazingus.org)
Menu hide functionality was aided by some code I found on http://www.jessett.com/
Modified 4/15/04 SPD
edited timer (in milliseconds) to 800 in line 150 (well, line 177 as of this exact second).
*/

	var currentMenu = null;
	var mytimer = false;
	//var mytimer = null;
	var timerOn = false;
	var IE4up = document.all && window.external ? true : false;
	var Opera = window.opera ? true : false;
	// netscape browsers
	var NN  = (navigator.userAgent.indexOf("Netscape") != -1) && !Opera;
	var is_nn6 = (navigator.product == 'Gecko') && (!window.find)?true:false;
	var is_nn7 = (navigator.product == 'Gecko') && (window.find)?true:false;

	var Moz = (navigator.userAgent.indexOf("Mozilla") != -1) && !NN;
	var is_mac = navigator.userAgent.indexOf("Mac") != -1;
	
	if (!document.getElementById)
		document.getElementById = function() { return null; }
	
	function stopTime() {
		//alert("stoptime");
		if (mytimer) {
		//alert("stoptime");
			//clearInterval(mytimer);
		 	 clearTimeout(mytimer);
			 mytimer = false;
			 //mytimer = null;
			 timerOn = false;
		}
	}
	
	function initialiseMenu(menu, starter, root) {
		var leftstarter = false;
	
		if (menu == null || starter == null) return;
			currentMenu = menu;
	
		starter.onmouseover = function() {
			if (currentMenu) {
				//alert(this.parentNode.parentNode.id + ' ' + currentMenu.id);
				if (this.parentNode.parentNode!=currentMenu) {
					currentMenu.style.visibility = "hidden";
				}
				if (this.parentNode.parentNode==root) {
					tempCurrentMenu = currentMenu
					while (tempCurrentMenu.parentNode.parentNode!=root) {
						tempCurrentMenu.parentNode.parentNode.style.visibility = "hidden";
						tempCurrentMenu = tempCurrentMenu.parentNode.parentNode;
					}
				}
				currentMenu = null;
				this.showMenu();
	        	}
		}
	
		menu.onmouseover = function() {
			if (currentMenu) {
				currentMenu = null;
				this.showMenu();
	        	}
		}	
	
		starter.showMenu = function() {
			menu.style.paddingTop=4+"px";
			if (IE4up) {
				if (is_mac){
					if (this.parentNode.parentNode==root) {
						menu.style.left = this.offsetLeft+1 + "px";
						menu.style.top = this.offsetTop+20 + "px";
						//menu.style.top = this.offsetTop + this.offsetHeight + "px";
					}
					else {
						menu.style.left = this.offsetLeft + this.offsetWidth + "px";
						menu.style.top = this.offsetTop+20 + "px";
					}
				}
				else{
					if (this.parentNode.parentNode==root) {
						menu.style.left = this.offsetLeft+0 + "px";
						menu.style.top = this.offsetTop + 39 + "px";
					}
					else {
						menu.style.left = this.offsetLeft+0 + this.offsetWidth + "px";
						menu.style.top = this.offsetTop + "px";
					}
				}
			}
			else if (Opera) {
				if (this.parentNode.parentNode==root) {
					menu.style.left = this.offsetLeft + "px";
					menu.style.top = this.offsetHeight + "px";
				}
				else {
				 	menu.style.left = this.offsetWidth + "px";
				 	menu.style.top = this.offsetTop + "px"; //menu.style.top - menu.style.offsetHeight + "px";
				}

			}
			else if (Moz) {
			//alert("moz");
				if (this.parentNode.parentNode==root) {
					menu.style.left = this.offsetLeft+0 + "px";
					menu.style.top = this.offsetHeight+9 + "px";
				}
				else {
				 	menu.style.left = this.offsetWidth + "px";
				 	menu.style.top = this.offsetTop+9 + "px";
				}

			}
			else if (NN) {
				if (is_mac){
				//alert("macNet");
					if (this.parentNode.parentNode==root) {
							menu.style.left = this.offsetLeft+0 + "px";
							menu.style.top = this.offsetHeight+9 + "px";
						}
						else {
							menu.style.left = this.offsetWidth + "px";
							menu.style.top = this.offsetTop+9 + "px";
						}
					}
				else if (is_nn7){
				//alert("net7");
					if (this.parentNode.parentNode==root) {
						menu.style.left = this.offsetLeft+0 + "px";
						menu.style.top = this.offsetHeight+9 + "px";
					}
					else {
						menu.style.left = this.offsetWidth + "px";
						menu.style.top = this.offsetTop+9 + "px";
					}
				}
				else {
				//alert("net6");
					if (this.parentNode.parentNode==root) {
						menu.style.left = this.offsetLeft + "px";
						menu.style.top = this.offsetHeight+9 + "px";
					}
					else {
						menu.style.left = this.offsetWidth + "px";
						menu.style.top = this.offsetTop+9 + "px";
					}
				}
			}
			else {
					if (this.parentNode.parentNode==root) {
						menu.style.left = this.offsetLeft + "px";
						menu.style.top = this.offsetHeight+9 + "px";
					}
					else {
						menu.style.left = this.offsetWidth + "px";
						menu.style.top = this.offsetTop+9 + "px";
					}
				}

			menu.style.visibility = "visible";
			currentMenu = menu;
		}
		
		menu.hideMenu = function()  {
		//alert("hide started");
			if (!timerOn) {
				//alert(this.id);
				//mytimer = setInterval("killMenu('" + this.id + "', '" + root.id + "');", 800);
				mytimer = setTimeout("killMenu('" + this.id + "', '" + root.id + "');", 800);
				timerOn = true;
				//alert("timer set to true");
				for (var x=0;x<menu.childNodes.length;x++) {
					if (menu.childNodes[x].nodeName=="LI") {
						if (menu.childNodes[x].getElementsByTagName("UL").length>0) {
							menuItem = menu.childNodes[x].getElementsByTagName("UL").item(0);
							menuItem.style.visibility = "hidden";
						}
					}
				}
			}
		}
		
		starter.onfocus	= function() {
			starter.onmouseover();
		}

		menu.showMenu = function() {
		//alert("show");
			menu.style.visibility = "visible";
			currentMenu = menu;
			stopTime();
		}

		menu.onmouseout = function(event) {
		//alert("onmouseout");
		timerOn = false;
			this.hideMenu();
		}

		starter.onmouseout = function() {
		//alert("starter.onmouseout");
			for (var x=0;x<menu.childNodes.length;x++) {
				if (menu.childNodes[x].nodeName=="LI") {
					if (menu.childNodes[x].getElementsByTagName("UL").length>0) {
						menuItem = menu.childNodes[x].getElementsByTagName("UL").item(0);
						menuItem.style.visibility = "hidden";
					}
				}
			}
			menu.style.visibility = "hidden";
			//menu.hideMenu();
		}
}

function getMenus(elementItem, root) {
	var selectedItem;
	var menuStarter;
	var menuItem;
	//alert("in getmenus");
	//alert(elementItem.childNodes.length);
	for (var x=0;x<elementItem.childNodes.length;x++) {
		//alert(elementItem.childNodes[x].nodeName);
		if (elementItem.childNodes[x].nodeName=="LI") {
			//alert("Yes!");
			if (elementItem.childNodes[x].getElementsByTagName("UL").length>0) {
				//alert("Set up");
				menuStarter = elementItem.childNodes[x].getElementsByTagName("A").item(0);
				menuItem = elementItem.childNodes[x].getElementsByTagName("UL").item(0);
				getMenus(menuItem, root);
				initialiseMenu(menuItem, menuStarter, root);
			}
		}
	}
	//return true;
}

	function killMenu(menu, root) {
	//alert("killstarted");
		var menu = document.getElementById(menu);
		var root = document.getElementById(root);
		menu.style.visibility = "hidden";
		for (var x=0;x<menu.childNodes.length;x++) {
			if (menu.childNodes[x].nodeName=="LI") {
				if (menu.childNodes[x].getElementsByTagName("UL").length>0) {
					menuItem = menu.childNodes[x].getElementsByTagName("UL").item(0);
					menuItem.style.visibility = "hidden";
				}
			}
		}
		while (menu.parentNode.parentNode!=root) {
			menu.parentNode.parentNode.style.visibility = "hidden";
			menu = menu.parentNode.parentNode;
		}
		stopTime();
	}

function NewWindow(mypage, myname, w, h, scroll) 
{
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	var winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable';
	var win = window.open(mypage, myname, winprops);
	if (parseInt(navigator.appVersion) >= 4) 
		win.window.focus();
}

function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}

window.onload=function()
{
	var root = document.getElementById("menuList");
	getMenus(root, root);
	
	if (folder=="root"){""}
	else {
	document.getElementById(folder).style.backgroundColor='#000000';  //dynamically assign highlight (first level)
	document.getElementById(folder).style.color='#FFFFFF';
	}
	
	if (folder=="g_home"){//Fix Homeowners link highlight | text highlight is in g_home.inc
		document.getElementById(folder).style.backgroundColor='#FFFFFF';
	}
	if (folder=="root"){ //footer highlight
	document.getElementById(file).style.backgroundColor='#99CEFF';
	}
	else if (pageHold!=null){ //handle 4th level link highlights | var is set on individual pages
	document.getElementById(pageHold).className='current';
	}
	else{
	
	document.getElementById(file).className='current'; //dynamically assign highlight (secondary)
	}
	yadm();
	//alert(screen.height);
	//alert(document.body.clientHeight);

		if((Moz)||(is_nn6)){ //fix page height issue in firefox
		document.getElementById('net6fix').style.height="100%"; //fixes footer prob in net6 (wouldn't appear in some cases)
			howTall = 0;
			howTall = document.body.clientHeight;
			outer.style.height = howTall + 'px';
			//alert(howTall);
		}
	//alert(screen.availHeight);
	//document.getElementById('content').style.height='100%'; //width was causing net 6 to hide footer on some pages
	//document.getElementById('content').style.width='100%';
	
	//document.getElementById('index').childNode.onclick = function() {
	//	window.location="http:www.3riverswetweather.org";
	//}

	/*if(getElementsByClassName(document, 'a', 'substarter')){
		//alert(getElementsByClassName(document, 'a', 'substarter'));
		getElementsByClassName(document, 'a', 'substarter')[0].onclick = function() {
			window.location="http:www.3riverswetweather.org";
		};
	}*/

	if(document.getElementById('index')){
		document.getElementById('index').innerHTML="<a href='http://www.3riverswetweather.org' class='substarter'>Home</a>"
	}
	if(document.getElementById('animated')){
		document.getElementById('animated').innerHTML="<a href='#' class='substarter' onClick=NewWindow(\'http://www.3riverswetweather.org/home_diagram.swf\',\'popup\',\'549\',\'375\',\'no\');return false;>Animated Overview</a>"
	}

}

