// Left Navigation Script for NYC.gov Agency Templates

// Returns path with folder and file, else -1.
// ex. /folder/file.html
var drawnSub = false;
var currentId;
var element;
var x=0;

function Over(element) { 
	var curr = document.getElementById('arrow_' + element);
	curr.className= 'nav_cell_arrow_hover';
	curr = document.getElementById('elem_' + element);
	curr.className= 'nav_cell_hover';
}

function Out(element) { 
	
	var curr = document.getElementById('arrow_' + element);
	curr.className= 'nav_cell_arrow';
	var curr = document.getElementById('elem_' + element);
	curr.className= 'nav_cell';

  
}

function OverContact(element) { 
	var curr = document.getElementById('arrow_' + element);
	curr.className= 'nav_cell_arrow_hover';
	curr = document.getElementById('elem_' + element);
	curr.className= 'nav_cell_contact_hover';
}

function OutContact(element) { 
	var curr = document.getElementById('arrow_' + element);
	curr.className= 'nav_cell_arrow';
	var curr = document.getElementById('elem_' + element);
	curr.className= 'nav_cell_contact';
}

function go(toelement)
{
// Open new window code was added here
 if(toelement.options[toelement.selectedIndex].value.length>0){
	 var openlink = window.open(toelement.options[toelement.selectedIndex].value);
 //location = toelement.options[toelement.selectedIndex].value;
 }
}



function getPath(thePath) {
	if (thePath == null) { return -1; }
	var startSlash = thePath.lastIndexOf("/");
	startSlash = thePath.lastIndexOf("/",startSlash -1);

	if (startSlash == -1 && thePath.indexOf("#") != -1) {
		return "#";	
	}
		
	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 == -1 && thePath.indexOf("#") != -1) {
		return "#";	
	}

	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);
var expandCurrentNode = false;
var haveNodes = false;


document.write("<table width='180' border='0' cellpadding='0' cellspacing='0' bgcolor='FFFFFF'>");
document.write("<form action='http://search1.nyc.gov/search?' method='GET' name='gs' style='margin-bottom:0px'>");
document.write("<tr><td align='center' class='border'><img src='includes/site_images/spacers/spacer.gif' border='0' width='20' height='15'><br>");
document.write("<img src='includes/site_images/spacers/spacer.gif' width='12' height='1' border='0'><input name='q' type='text' class='search-box' id='q' size='12' style='width : 108px' align='left'>");
document.write("<input value='xml_no_dtd' name='output' type='hidden'><input value='default_collection' name='site' type='hidden'><input value='agency_frontend' name='proxystylesheet' type='hidden'><input value='agency_frontend' name='client' type='hidden'><input value='www.nyc.gov/html/dot' name='sitesearch' type='hidden'>");
document.write("<input name='go' type='image' id='go' onMouseOut='MM_swapImgRestore()' onMouseOver=\"MM_swapImage('go','','includes/site_images/misc/search_button_over.gif',1)\" src='includes/site_images/misc/search_button.gif'  alt='Search' width='60' height='21' border='0'><br><img src='includes/site_images/spacers/spacer.gif' width='1' height='10' border='0'></td></tr></form></table>");

document.write('<table width="180" border="0" cellspacing="0" cellpadding="0">');


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) {
			//alert(getFolder(NAV_NODES[x][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;
			}
		}
	}

	//if (x != 0) {
	//	document.write('<img src="../../includes/site_images/nav/divider.gif" width="136" height="9"><br>');
	//}
	
	//draw main nodes
	if (currentURL.indexOf(getPath(NAV_NODES[x][1])) != -1 || expandCurrentNode == true) {
		document.write("<tr><td width='175' valign='top'><table width='175' border='0' cellspacing='0' cellpadding='0'><tr><td width='21' onClick=\"window.location='" + NAV_NODES[x][1] + "'\"  class='nav_cell_arrow_hover' id='arrow_" + currentId + "' valign='bottom'><img src='includes/site_images/spacers/spacer.gif' width='20' height='25' id='nav_cell_arrow_hover'></td><td width='154' class='nav_cell_hover' onClick=\"window.location='" + NAV_NODES[x][1] + "'\" id='elem_" + currentId + "'><img src='includes/site_images/spacers/spacer.gif' width='1' height='5'><br>" + NAV_NODES[x][0] + "<br><img src='includes/site_images/spacers/spacer.gif' width='1' height='4'></td></tr></table></td><td><img src='includes/site_images/spacers/spacer.gif' width='5' height='25'></td></tr>");
		document.write("<tr><td width='175' bgcolor='FFFFFF'><img src='includes/site_images/spacers/spacer.gif' width='175' height='2'></td><td><img src='includes/site_images/spacers/spacer.gif' width='5' height='2'></td></tr>");
		expandCurrentNode = true;
	} 
	else if (NAV_NODES[x][0]=='Contact DOT') {
		//x++;
		currentId = x;
		
		//alert(x);
		//alert('elem_' + currentId)
		document.write("<tr><td width='175'><table width='175' border='0' cellspacing='0' cellpadding='0'><tr><td width='21' onClick=\"window.location='" + NAV_NODES[x][1] + "'\"  class='nav_cell_arrow' onmouseover='OverContact(" + currentId + ")' onmouseout='OutContact(" + currentId + ")' id='arrow_" + currentId + "' valign='top'><img src='includes/site_images/spacers/spacer.gif' width='20' height='25' align='absmiddle' id='nav_cell_arrow'></td><td width='154' class='nav_cell_contact' onClick=\"window.location='" + NAV_NODES[x][1] + "'\" onmouseover='OverContact(" + currentId + ")' onmouseout='OutContact(" + currentId + ")'  id='elem_" + currentId + "'><img src='includes/site_images/spacers/spacer.gif' width='1' height='5'><br>" + NAV_NODES[x][0] + "<br><img src='includes/site_images/spacers/spacer.gif' width='1' height='4'></td></tr></table></td><td><img src='includes/site_images/spacers/spacer.gif' width='5' height='25'></td></tr>");
		document.write("<tr><td width='175' bgcolor='FFFFFF'><img src='includes/site_images/spacers/spacer.gif' width='175' height='2'></td><td><img src='includes/site_images/spacers/spacer.gif' width='5' height='2'></td></tr>");
		
	}
	
	else {
		//x++;
		currentId = x;
		
		//alert(x);
		//alert('elem_' + currentId)
		document.write("<tr><td width='175'><table width='175' border='0' cellspacing='0' cellpadding='0'><tr><td width='21' onClick=\"window.location='" + NAV_NODES[x][1] + "'\"  class='nav_cell_arrow' onmouseover='Over(" + currentId + ")' onmouseout='Out(" + currentId + ")' id='arrow_" + currentId + "' valign='top'><img src='includes/site_images/spacers/spacer.gif' width='20' height='25' align='absmiddle' id='nav_cell_arrow'></td><td width='154' class='nav_cell' onClick=\"window.location='" + NAV_NODES[x][1] + "'\" onmouseover='Over(" + currentId + ")' onmouseout='Out(" + currentId + ")'  id='elem_" + currentId + "'><img src='includes/site_images/spacers/spacer.gif' width='1' height='5'><br>" + NAV_NODES[x][0] + "<br><img src='includes/site_images/spacers/spacer.gif' width='1' height='4'></td></tr></table></td><td><img src='includes/site_images/spacers/spacer.gif' width='5' height='25'></td></tr>");
		document.write("<tr><td width='175' bgcolor='FFFFFF'><img src='includes/site_images/spacers/spacer.gif' width='175' height='2'></td><td><img src='includes/site_images/spacers/spacer.gif' width='5' height='2'></td></tr>");
		
	}

	//draw sub nodes
	if (NAV_NODES[x].length > 2 && expandCurrentNode == true) {
		for(y=2;y<NAV_NODES[x].length;y++) {
			if (NAV_NODES[x][y] == null) break;
			//alert(getPath(NAV_NODES[x][y][1]));
			if (currentURL.indexOf(getPath(NAV_NODES[x][y][1])) != -1) {
				
			//alert(currentURL.indexOf(getPath(NAV_NODES[x][y][1])));
			if (y==2) { document.write("<tr><td width='175' bgcolor='FFFFFF'><img src='includes/site_images/spacers/spacer.gif' width='175' height='9'></td><td><img src='includes/site_images/spacers/spacer.gif' width='5' height='9'></td></tr><tr><td width='175'><table border='0' cellspacing='0' cellpadding='0' width='175'><td width='20'><img src='includes/site_images/spacers/spacer.gif' width='20' height='2'></td><td width='155' valign='top' align='left'>");
						document.write("<a href='" + NAV_NODES[x][y][1] + "' class='nav_subsection_active'>" + NAV_NODES[x][y][0] + "</a><br>");
						drawnSub = true;
			}
			
			else { document.write("<a href='" + NAV_NODES[x][y][1] + "' class='nav_subsection_active'>" + NAV_NODES[x][y][0] + "</a><br>");
						drawnSub = true;
			}
			
			
			} 
			else {
			
			if (y==2){
			document.write("<tr><td width='20' bgcolor='FFFFFF'><img src='includes/site_images/spacers/spacer.gif' width='175' height='9'></td><td><img src='includes/site_images/spacers/spacer.gif' width='5' height='9'></td></tr><tr><td width='175'><table border='0' cellspacing='0' cellpadding='0' width='175'><tr><td width='20'><img src='includes/site_images/spacers/spacer.gif' width='20' height='1'></td><td width='155' valign='top' align='left'>");
				document.write("<a href='" + NAV_NODES[x][y][1] + "' class='nav_subsection'>" + NAV_NODES[x][y][0] + "</a><br>");
				drawnSub = true;
			}
			else{
				document.write("<a href='" + NAV_NODES[x][y][1] + "' class='nav_subsection'>" + NAV_NODES[x][y][0] + "</a><br>");
				drawnSub = true;

			}
			
				
			}
		}
		if (drawnSub == true) {
			  
			document.write("</td></tr></table></td></tr><tr><td width='175' bgcolor='FFFFFF'><img src='includes/site_images/spacers/spacer.gif' width='175' height='17'></td><td><img src='images/spacer.gif' width='5' height='17'></td></tr>");
			
			drawnSub = false;
			
		}
	}
}

//document.write('</td><td width="14" bgcolor="#FFCB30"><img src="images/spacer.gif" width="14" height="15"></td></tr>');
//document.write('<tr valign="top"><td width="15" bgcolor="#870505"><img src="images/spacer.gif" width="15" height="15"></td>');
//document.write('<td width="15" bgcolor="#FFCB30"><img src="images/spacer.gif" width="15" height="15"></td>');
//document.write('<td width="136" bgcolor="#FFCB30"><img src="images/spacer.gif" width="136" height="15"></td>');
//document.write('<td width="14" bgcolor="#FFCB30"><img src="images/spacer.gif" width="14" height="15"></td></tr></table>');
document.write('</table>');
document.write('<table width="180" border="0" cellspacing="0" cellpadding="0"><form name="menuform" style="margin-bottom:0;">');
document.write('<tr><td width="10"><img src="includes/site_images/spacers/spacer.gif" width="10" height="1"></td><td width="170">');
document.write('<img src="includes/site_images/spacers/spacer.gif" width="1" height="12"><br><select style="width : 164px" name="bytopic" id="by_topic" onChange="go(this.form.bytopic)" class="dropdown">');
document.write('<option value="" selected>Other Transportation Links</option>');
document.write('<option value="http://www.nyc.gov/cgi-bin/exit.pl?url=http://www.mta.info">Metropolitan Transportation Authority </option>');
document.write('<option value="http://www.nyc.gov/cgi-bin/exit.pl?url=https://www.nysdot.gov/portal/page/portal/index">NY State DOT</option>');
document.write('<option value="http://www.nyc.gov/cgi-bin/exit.pl?url=http://www.nydmv.state.ny.us">NY State Dept of Motor Vehicles</option>');
document.write('<option value="http://www.nyc.gov/cgi-bin/exit.pl?url=http://www.panynj.gov">Port Authority of NY & NJ</option>');
document.write('<option value="http://www.nyc.gov/cgi-bin/exit.pl?url=http://www.e-zpassny.com">E-Z Pass Information</option>');
document.write('<option value="http://www.nyc.gov/cgi-bin/exit.pl?url=http://www.trips123.com">Trips 123</option>');
document.write('<option value="http://nyc.gov/html/nypd/html/transportation/newpage7.html">NYPD Traffic Control</option>'); 
document.write('<option value="http://nyc.gov/html/nypd/html/transportation/parking.html">NYPD Parking Enforcement</option>'); 
document.write('<option value="http://www.nyc.gov/html/tlc/html/home/home.shtml">Taxi & Limousine Commission</option>'); 
document.write('<option value="http://www.nyc.gov/cgi-bin/exit.pl?url=http://www.lowermanhattan.info">Lower Manhattan</option>'); 
document.write('<option value="http://www.nyc.gov/cgi-bin/exit.pl?url=http://www.trafficsafetyfornyc.org">Traffic Safety for New York City Inc.</option>'); 
document.write('<option value="http://www.nyc.gov/cgi-bin/exit.pl?url=http://www.nymtc.org">NY Metropolitan Transportation Council</option>'); 
document.write('<option value="http://www.nyc.gov/cgi-bin/exit.pl?url=http://www.gridlocksam.com">Gridlock Sam</option>'); 
document.write('<option value="http://www.nyc.gov/cgi-bin/exit.pl?url=http://www.commuterlink.com">Commuter Link</option>'); 
document.write('<option value="http://www.nyc.gov/cgi-bin/exit.pl?url=http://www.njtransit.com">NJ Transit</option>'); 
document.write('</select></td><td width="22"></td></tr></form></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];}
}

