// 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);
	}
}

var currentURL = getPath(location.href);

document.write("<table width='100%' border='0' cellspacing='0' cellpadding='0'>");

var rightFolder=getFolder(currentURL);
rightFolder=rightFolder.substring(1,rightFolder.length-1);
if(rightFolder.indexOf("directory")!=-1){
	
	currentURL=getPath(RIGHT_NAV_NODES[0][1]);
}
	

for(x=0;x<RIGHT_NAV_NODES.length;x++) {
	//check for sub nodes
	if (RIGHT_NAV_NODES[x] == null) break;
	//draw main nodes
	if (currentURL.indexOf(getPath(RIGHT_NAV_NODES[x][1])) != -1 || expandCurrentNode == true) {
		document.write("<tr><td colspan='3'><img src='../../includes/site_images/spacers/spacer.gif' height='6' width='180'></td></tr>");
		document.write("<tr valign='top'><td width='11'><img src='../../includes/site_images/spacers/spacer.gif' width='11' height='5'></td><td width='154'><a href='" + RIGHT_NAV_NODES[x][1] + "' class='right_subsection_active'>" + RIGHT_NAV_NODES[x][0] + "</a></td><td width='15'><img src='../../includes/site_images/spacers/spacer.gif' width='15' height='1'></td></tr>");
		document.write("<tr><td colspan='3'><img src='../../includes/site_images/spacers/spacer.gif' height='7' width='180'></td></tr>");
		document.write("<tr><td colspan='3'><img src='../../includes/site_images/nav/right_nav_divider.gif' height='1' width='180'></td></tr>");
	} else {
		document.write("<tr><td colspan='3'><img src='../../includes/site_images/spacers/spacer.gif' height='6' width='180'></td></tr>");
		document.write("<tr valign='top'><td width='11'><img src='../../includes/site_images/spacers/spacer.gif' width='11' height='5'></td><td width='169'><a href='" + RIGHT_NAV_NODES[x][1] + "' class='nav_subsection'>" + RIGHT_NAV_NODES[x][0] + "</a></td><td width='15'><img src='../../includes/site_images/spacers/spacer.gif' width='15' height='1'></td></tr>");
		document.write("<tr><td colspan='3'><img src='../../includes/site_images/spacers/spacer.gif' height='8' width='180'></td></tr>");
		document.write("<tr><td colspan='3'><img src='../../includes/site_images/nav/right_nav_divider.gif' height='1' width='180'></td></tr>");
	}

}

document.write("</table>");