<!-- DO NOT EDIT THIS FILE -->
// Left Navigation Script for NYC.gov Agency Templates

// Returns path with folder and file, else -1.
// ex. /folder/file.html
function getPath(thePath) {
	if (thePath == null) { return -1; }
	var startSlash = thePath.lastIndexOf("/");
	startSlash = thePath.lastIndexOf("/",startSlash -1);

	if (startSlash == -1) {
		return -1;
	} else {
		return thePath.substr(startSlash, thePath.length - startSlash);
	}
}

// Returns folder, else -1.
// ex. /folder/
function getFolder(thePath) {
	if (thePath == null) { return -1; }
	var startSlash = thePath.lastIndexOf("/");
	startSlash2 = thePath.lastIndexOf("/",startSlash -1);

	if(startSlash == startSlash2) { return -1; }
	if (startSlash == -1 || startSlash2 == -1) {
		return -1;
	} else {
		return thePath.substr(startSlash2, startSlash - startSlash2 + 1);
	}
}

function convertURL(theUrl){
	var underscore=theUrl.lastIndexOf("_");
	var per=theUrl.lastIndexOf(".");
	return(theUrl.substr(0,underscore)+theUrl.substr(per));
}

var currentURL = getPath(location.href);
var convertedURL = convertURL(currentURL);
var expandCurrentNode = false;
var haveNodes = false;

document.write("<table width='180' border='0' cellspacing='0' cellpadding='0'>\n");

for(x=0;x<NAV_NODES.length;x++) {
	expandCurrentNode = false;
	haveNodes = false;

	//check for sub nodes
	if (NAV_NODES[x] == null) break;
	if (NAV_NODES[x].length > 2) {
		if (currentURL.indexOf(getFolder(NAV_NODES[x][1])) != -1) {
			expandCurrentNode = true;
		}
		for(y=2;y<NAV_NODES[x].length;y++) {
			if (NAV_NODES[x][y] == null) break;
			if (NAV_NODES[x][y][1] != null) haveNodes = true;
			if (currentURL.indexOf(getPath(NAV_NODES[x][y][1])) != -1) {
				expandCurrentNode = true;
			}
		}
	}
	var theFolder=getFolder(NAV_NODES[x][1]);
	theFolder=theFolder.substring(1,theFolder.length-1);
	
	if (theFolder == "nycgov" && NAV_NODES[x][0] == "Community Calendar") {
		expandCurrentNode = true;
	}
	
	//draw main nodes
	if (currentURL.indexOf(getPath(NAV_NODES[x][1])) != -1 || expandCurrentNode == true) {
		if(theFolder=="home"){
			MM_preloadImages("http://www.milliontreesnyc.org/includes/site_images/nav/"+theFolder+"_1.gif");
			document.write("<tr valign='top'><td><a href='" + NAV_NODES[x][1] + "' onmouseout='MM_swapImgRestore()' onmouseover='MM_swapImage(\""+theFolder+"\",\"\",\"http://www.milliontreesnyc.org/includes/site_images/nav/"+theFolder+"_1.gif\",1)'><img src='http://www.milliontreesnyc.org/includes/site_images/nav/"+theFolder+"_0.gif' width='180' alt='"+NAV_NODES[x][0]+"' name='"+theFolder+"' border='0'></a></td></tr>\n");
		}else{
			MM_preloadImages("http://www.milliontreesnyc.org/includes/site_images/nav/"+theFolder+"_3.gif");
			document.write("<tr valign='top'><td><a href='" + NAV_NODES[x][1] + "' onmouseout='MM_swapImgRestore()' onmouseover='MM_swapImage(\""+theFolder+"\",\"\",\"http://www.milliontreesnyc.org/includes/site_images/nav/"+theFolder+"_3.gif\",1)'><img src='http://www.milliontreesnyc.org/includes/site_images/nav/"+theFolder+"_2.gif' width='180' alt='"+NAV_NODES[x][0]+"' name='"+theFolder+"' border='0'></a></td></tr>\n");
		}
		expandCurrentNode = true;
	} else {
		MM_preloadImages("http://www.milliontreesnyc.org/includes/site_images/nav/"+theFolder+"_1.gif");
		document.write("<tr valign='top'><td><a href='" + NAV_NODES[x][1] + "' onmouseout='MM_swapImgRestore()' onmouseover='MM_swapImage(\""+theFolder+"\",\"\",\"http://www.milliontreesnyc.org/includes/site_images/nav/"+theFolder+"_1.gif\",1)'><img src='http://www.milliontreesnyc.org/includes/site_images/nav/"+theFolder+"_0.gif' width='180' alt='"+NAV_NODES[x][0]+"' name='"+theFolder+"' border='0'></a></td></tr>\n");
	}

	if (NAV_NODES[x].length > 2 && expandCurrentNode == true) {
		var hasSub=(!(NAV_NODES[x][2] == null));
		if(hasSub){
		}
		for(y=2;y<NAV_NODES[x].length;y++) {
			if (NAV_NODES[x][y] == null) break;
			if (currentURL.indexOf(getPath(NAV_NODES[x][y][1])) != -1) {
				document.write("<tr valign='top' class='white_bg'><td align='right'><a href='" + NAV_NODES[x][y][1] + "' class='nav_subsection_active'>" + NAV_NODES[x][y][0] + "</a></td></tr>\n");
			} else if(convertedURL.indexOf(getPath(NAV_NODES[x][y][1])) != -1) {
				document.write("<tr valign='top' class='white_bg'><td align='right'><a href='" + NAV_NODES[x][y][1] + "' class='nav_subsection_active'>" + NAV_NODES[x][y][0] + "</a></td></tr>\n");
			} else {
				document.write("<tr valign='top' class='white_bg'><td align='right'><a href='" + NAV_NODES[x][y][1] + "' class='nav_subsection'>" + NAV_NODES[x][y][0] + "</a></td></tr>\n");
			}
		}
		if(hasSub){
			if(theFolder!="home"){
				document.write("<tr valign='top' class='white_bg'><td><img src='http://www.milliontreesnyc.org/includes/site_images/spacers/spacer.gif' height='8' width='180' alt='' border='0'></td></tr>\n");
			}
		}else{
			if(theFolder!="home"){
				document.write("<tr valign='top' class='white_bg'><td><img src='http://www.milliontreesnyc.org/includes/site_images/spacers/spacer.gif' height='1' width='180' alt='' border='0'></td></tr>\n");
			}
		}
	}
}
document.write("<tr valign='top' class='white_bg'><td><img src='http://www.milliontreesnyc.org/includes/site_images/spacers/spacer.gif' height='2' width='180' alt='' border='0'></td></tr>\n");
document.write("</table>");

// The following DW JS is used for imageover effects

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function show(){
	var theIds=show.arguments;
	for(var i=0;i<theIds.length;i++){
		document.getElementById(theIds[i]).style.display="";
	}
}

function showInline(){
	var theIds=showInline.arguments;
	for(var i=0;i<theIds.length;i++){
		document.getElementById(theIds[i]).style.display="inline";
	}
}

function hide(){
	var theIds=hide.arguments;
	for(var i=0;i<theIds.length;i++){
		document.getElementById(theIds[i]).style.display="none";
	}
}