var IDs = new Array(), projNames = new Array(), fileNames = new Array();
var serviceArrays = new Array(12);
for(var i=0; i<serviceArrays.length; i++)
	serviceArrays[i] = new Array();
var serviceNames = new Array('EnvImp','MitMon','PowGen','BioSur','HabRes','AirQua','SysSaf','PubPar','FloCon','HydHyd','AriPro','WatCom');
var servicesGrid = new Array(
		"Environmental Impact Assessment</a></dd>",
		"Mitigation Monitoring, Compliance, & Reporting</a></dd>",
		"Power Generation & Energy Infrastructure</a></dd>",
		"Biological Surveys & Impact Assessment</a></dd>",
		"Habitat Restoration</a></dd>",
		"Air Quality Permitting & Modeling</a></dd>",
		"System Safety & Technology Evaluation</a></dd>",
		"Public Participation & Community Involvement</a></dd>",
		"Flood Control & Watershed Planning Studies</a></dd>",
		"Hydrologic & Hydraulic Modeling & Sediment Transport Studies</a></dd>",
		"Arizona Projects</a></dd>",
		"Water-related Compliance & Permitting</a></dd>"
		);

function addProj(ID,projName,fileName)
{
	IDs.push(ID); projNames.push(projName); fileNames.push(fileName);
	for(var i=3; i<arguments.length; i++)
		serviceArrays[arguments[i]-1].push(ID);
}

function writeProjects()
{
	for(i in IDs)
		document.write("\
			<span class='treeTitle' id='"+IDs[i]+"' onclick='expandServicesGrid(id)'>\
				<img class='treeButton' id='"+IDs[i]+"img' src='../images/common/plus.gif' />"+projNames[i]+"<br />\
				</span><span id='sub"+IDs[i]+"'></span><!-- placeholder for tree data -->");
}

function nameToNumber(name) { for(i in serviceNames) if(serviceNames[i] == name) return i; }
function numberToName(num)  { return serviceNames[num]; }

function buildURL(projID, sNum)
{
	for(i in IDs)
		if(IDs[i] == projID)
			return "../services/" + numberToName(sNum) + "/" + fileNames[i] + ".shtml";
}

function expandServicesGrid(projID)
{
	var g = document.getElementById("sub"+projID);
	if(g.innerHTML == "") //expand new node
	{
		document.getElementById(projID).style.fontWeight = "bold";
		g.innerHTML += "<dl>";
//		for(i in serviceArrays) for(ii in serviceArrays[i]) if(serviceArrays[i][ii] == projID) addServiceArea(g, projID, i);
		for(var i=0; i<serviceArrays.length; i++)
			for(ii=0; ii<serviceArrays[i].length; ii++)
				if(serviceArrays[i][ii] == projID) addServiceArea(g, projID, i);
		g.innerHTML += "</dl><br />";
		document.getElementById(projID+"img").src = "../images/common/minus.gif";
	}
	else
	{
		document.getElementById(projID).style.fontWeight = "normal";
		document.getElementById("sub"+projID).innerHTML = "";
		document.getElementById(projID+"img").src = "../images/common/plus.gif";
	}
}

function addServiceArea(HTMLobj, projID, sNum)
{
	HTMLobj.innerHTML += "<dd><img src='../images/Services/PD.gif' />&nbsp; <a href='" + buildURL(projID, sNum) + "'>" + servicesGrid[sNum];
}
