var whichPict = "";			// this is to grab the name of the pict for the if statements in the xmlHTTPresponse
var myImage = [];			// for preloading
timerID = null;
theSubNavPict = "";





function setRollovers()  {
	if (!document.getElementsByTagName)  {
		return;
	}
	
	var allLinks = document.getElementsByTagName('a');
	for (var i = 0; i < allLinks.length; i++) {
		var currLink = allLinks[i];
		if (currLink.className && (" " + currLink.className + " ").indexOf(" rollover ") != -1)  {
			if (currLink.hasChildNodes && currLink.childNodes.length == 1 && currLink.childNodes[0].nodeName.toLowerCase() == 'img') {
				currLink.onmouseover = doRollover;
				currLink.onmouseout = restoreImage;			
				
				// preload images:
				myImage[i] = new Image();
				myImage[i].src = currLink.childNodes[0].src.replace(/(\.[^.]+)$/, '_over$1');;
			}
		}
	}
}		// end setRollovers

function exposeSubNav(which) {
	//alert("which = " + which);	
	//we need the id of the image
	if (document.getElementById(which) != null) { 	// if this image really exists in the document:
		var currImage =	document.getElementById(which);
		currImage.src = currImage.src.replace(/(\.[^.]+)$/, '_over$1');
		theSubNavPict = which;			// set this to foil restoreImage functions on curr subNav image
	} else {
		theSubNavPict = "nadaZink"	
	}
}

function doRollover(e)  {
	var currTarget = findTarget(e);
	if (!currTarget) return;
	var currImage = currTarget.childNodes[0];
	
	if (currImage.src.indexOf("_over") == -1) {			// if it's already "over", don't roll it
		currImage.src = currImage.src.replace(/(\.[^.]+)$/, '_over$1');
	}
	
	
	// rollover the button exposes the sub-nav
	
	if (currImage.src.indexOf("btn_about") != -1) {
		getSubNav('About');
	}
	if (currImage.src.indexOf("btn_programs") != -1) {
		getSubNav('Programs');
	}
	if (currImage.src.indexOf("btn_business") != -1) {
		getSubNav('Business');
	}
	if (currImage.src.indexOf("btn_employment") != -1) {
		getSubNav('Employment');
	}
	if (currImage.src.indexOf("btn_employees") != -1) {
		getSubNav('Employees');
	}
	if (currImage.src.indexOf("btn_links") != -1) {
		getSubNav('Links');
	}	
	if (currImage.src.indexOf("btn_home") != -1) {
		getSubNav('Home');
	}
	
	stopTimer();
}


function restoreImage(e) {
	var currTarget = findTarget(e);
	if (!currTarget) return;	
	var currImage = currTarget.childNodes[0];

	 if (currImage.src.indexOf(theSubNavPict) == -1)  {		// if you are not the current sub-nav image, then roll off
	 	//alert("theSubNavPict = " + theSubNavPict + ". indexOf = " + currImage.src.indexOf(theSubNavPict));
		currImage.src = currImage.src.replace(/_over(\.[^.]+)$/, '$1');	
	 }
	
	// NO START HIDE ON SUB-NAV BUTTONS
	
	if (currImage.src.indexOf('sub_btn_') == -1) {		// NOT a sub button, apply start hide... must be a main nav button
		startHide();
	}

}



function findTarget(e) {
  var t; 

  if (window.event && window.event.srcElement) t = window.event.srcElement;
  else if (e && e.target) t = e.target;
  if (!t) return null;
  
  while (t != document.body && t.nodeName.toLowerCase() != 'a') t = t.parentNode;
  if (t.nodeName.toLowerCase() != 'a') return null;
  return t;
}


//



function getSubNavString() {
	
	// story sub nav table:
	subNavString = '<div id="sub_nav_about" style="display:none; height:23px;" onMouseOut="startHide();" onMouseOver="stopTimer();">'		
	subNavString += '<table width="776" border="0" cellspacing="0" cellpadding="0">'
	subNavString +=	'<tr>'
	subNavString +=	'<td><img src="../Images/Global/s.gif" alt=" " width="73" height="1" /></td>'
	subNavString +=	'<td><a href="../About/BoardOfDirectors.aspx" class="rollover"><img id="board" src="../Images/About/sub_btn_board-of-directors.gif" alt="board of directors" width="123" height="23" border="0" /></a></td>'
	subNavString +=	'<td><a href="../About/InsideSocwa.aspx" class="rollover"><img id="inside" src="../Images/About/sub_btn_inside-socwa.gif" alt="inside socwa" width="91" height="23" border="0" /></a></td>'
	subNavString +=	'<td><a href="../About/Contacts.aspx" class="rollover"><img id="contacts" src="../Images/About/sub_btn_contacts.gif" alt="contacts" width="73" height="23" border="0" /></a></td>'
	subNavString +=	'<td><a href="../About/MemberAgencies.aspx" class="rollover"><img id="member_agencies" src="../Images/About/sub_btn_member-agencies.gif" alt="member agencies" width="109" height="23" border="0" /></a></td>'	
	subNavString +=	'<td><img src="../Images/Global/s.gif" alt=" " width="307" height="1" /></td>'
	subNavString +=	'</tr>'
	subNavString +=	'</table>'
	subNavString +=	'</div>'
	
	
	// programs sub nav table:
	subNavString += '<div id="sub_nav_programs" style="display:none" onMouseOut="startHide();" onMouseOver="stopTimer();">'		
	subNavString += '<table width="776" border="0" cellspacing="0" cellpadding="0">'
	subNavString +=	'<tr>'
	subNavString +=	'<td><img src="../Images/Global/s.gif" alt=" " width="174" height="1" /></td>'
	subNavString +=	'<td><a href="../Programs/PublicEducation.aspx" class="rollover"><img id="education" src="../Images/Programs/sub_btn_public-education.gif" alt="public education" width="123" height="23" border="0" /></a></td>'	
	subNavString +=	'<td><a href="../Programs/TreatmentProcess.aspx" class="rollover"><img id="treatment" src="../Images/Programs/sub_btn_treatment-process.gif" alt="treatment process" width="122" height="23" border="0" /></a></td>'	
	subNavString +=	'<td><a href="../Programs/Programs.aspx" class="rollover"><img id="programs" src="../Images/Programs/sub_btn_programs.gif" alt="programs" width="73" height="23" border="0" /></a></td>'		
	subNavString +=	'<td><img src="../Images/Global/s.gif" alt=" " width="284" height="1" /></td>'
	subNavString +=	'</tr>'
	subNavString +=	'</table>'
	subNavString +=	'</div>'	
	
	
	// business sub nav table:
	subNavString += '<div id="sub_nav_business" style="display:none" onMouseOut="startHide();" onMouseOver="stopTimer();">'		
	subNavString += '<table width="776" border="0" cellspacing="0" cellpadding="0">'
	subNavString +=	'<tr>'
	subNavString +=	'<td><img src="../Images/Global/s.gif" alt=" " width="152" height="1" /></td>'
	/*
	subNavString +=	'<td><a href="../Business/Business.aspx" class="rollover"><img id="business" src="../Images/Business/sub_btn_contractors.gif" alt="contractors and consultants" width="167" height="23" border="0" /></a></td>'
	*/
	subNavString +=	'<td><img src="../Images/Global/s.gif" alt=" " width="100" height="23" border="0" /></td>'
	subNavString +=	'<td><a href="../Business/Engineering.aspx" class="rollover"><img id="engineering" src="../Images/Business/sub_btn_engineering.gif" alt="engineering" width="89" height="23" border="0" /></a></td>'
	/*
	subNavString +=	'<td><a href="../Business/Procurement.aspx" class="rollover"><img id="procurement" src="../Images/Business/sub_btn_procurement.gif" alt="procurement" width="94" height="23" border="0" /></a></td>'
	*/
	/*
	subNavString +=	'<td><a href="../Business/Guide.aspx" class="rollover"><img id="guide" src="../Images/Business/sub_btn_guide.gif" alt="guide for commercial &amp; industrial discharges" width="260" height="23" border="0" /></a></td>'
	*/
	subNavString +=	'<td><a href="../Business/Guide.aspx"><img id="guide" src="../Images/Global/s.gif"  width="260" height="23" border="0" /></a></td>'
	
	
	subNavString +=	'<td><img src="../Images/Global/s.gif" alt=" " width="14" height="1" /></td>'
	subNavString +=	'</tr>'
	subNavString +=	'</table>'
	subNavString +=	'</div>'
	
	
	// employment sub nav table:
	subNavString += '<div id="sub_nav_employment" style="display:none" onMouseOut="startHide();" onMouseOver="stopTimer();">'		
	subNavString += '<table width="776" border="0" cellspacing="0" cellpadding="0">'
	subNavString +=	'<tr>'
	subNavString +=	'<td><img src="../Images/Global/s.gif" alt=" " width="367" height="1" /></td>'
	subNavString +=	'<td><a href="../Employment/Jobs.aspx" class="rollover"><img id="jobs" src="../Images/Employment/sub_btn_jobs.gif" alt="jobs" width="48" height="23" border="0" /></a></td>'	
	subNavString +=	'<td><a href="../Employment/OrganizationChart.aspx" class="rollover"><img id="org" src="../Images/Employment/sub_btn_org-chart.gif" alt="organization chart" width="129" height="23" border="0" /></a></td>'	
	subNavString +=	'<td><a href="../Employment/Benefits.aspx" class="rollover"><img id="benefits" src="../Images/Employment/sub_btn_benefits-info.gif" alt="benefits information" width="91" height="23" border="0" /></a></td>'		
	subNavString +=	'<td><img src="../Images/Global/s.gif" alt=" " width="141" height="1" /></td>'
	subNavString +=	'</tr>'
	subNavString +=	'</table>'
	subNavString +=	'</div>'	
	
	
	// employees sub nav table:
	subNavString += '<div id="sub_nav_employees" style="display:none" onMouseOut="startHide();" onMouseOver="stopTimer();">'		
	subNavString += '<table width="776" border="0" cellspacing="0" cellpadding="0">'
	subNavString +=	'<tr>'
	subNavString +=	'<td><img src="../Images/Global/s.gif" alt=" " width="23" height="1" /></td>'
	subNavString +=	'<td><a href="../Employees/Employees.aspx" class="rollover"><img id="employeess" src="../Images/Employees/sub_btn_ehome.gif" alt="Employee Home" width="102" height="23" border="0" /></a></td>'	
	subNavString +=	'<td><a href="../Employees/Benefits.aspx" class="rollover"><img id="benefits_z" src="../Images/Employees/sub_btn_benefits.gif" alt="Benefits" width="62" height="23" border="0" /></a></td>'	
	subNavString +=	'<td><a href="../Employees/Retirement.aspx" class="rollover"><img id="retirement" src="../Images/Employees/sub_btn_retirement.gif" alt="Retirement and Investments" width="157" height="23" border="0" /></a></td>'
	subNavString +=	'<td><a href="../Employees/Forms.aspx" class="rollover"><img id="forms" src="../Images/Employees/sub_btn_forms.gif" alt="Forms" width="52" height="23" border="0" /></a></td>'	
	subNavString +=	'<td><a href="../Employees/JobClass.aspx" class="rollover"><img id="jobClass" src="../Images/Employees/sub_btn_jobClass.gif" alt="Job Classifications and Salary Schedule" width="215" height="23" border="0" /></a></td>'
	subNavString +=	'<td><a href="../Employees/eManMOU.aspx" class="rollover"><img id="Eman" src="../Images/Employees/sub_btn_eManualMOU.gif" alt="Employee Manual and MOU" width="139" height="23" border="0" /></a></td>'	
	subNavString +=	'<td><img src="../Images/Global/s.gif" alt=" " width="26" height="1" /></td>'
	subNavString +=	'</tr>'
	subNavString +=	'</table>'
	subNavString +=	'</div>'	
	
	
	// links sub nav table:
	subNavString += '<div id="sub_nav_links" style="display:none" onMouseOut="startHide();" onMouseOver="stopTimer();">'		
	subNavString += '<table width="776" border="0" cellspacing="0" cellpadding="0">'
	subNavString +=	'<tr>'
	
	// need to shrink up space before the submenu if NOT logged in. This var is set on /Controls/WebUserContr
	if (loggedIn == "true") { 
	    subNavString +=	'<td><img src="../Images/Global/s.gif" alt=" " width="590" height="1" /></td>'
	} else {
	    subNavString +=	'<td><img src="../Images/Global/s.gif" alt=" " width="505" height="1" /></td>'
	}    
	    
	subNavString +=	'<td><a href="../About/MemberAgencies.aspx" class="rollover"><img id="memagencies" src="../Images/Links/sub_btn_mem-agencies.gif" alt="member agencies" width="105" height="23" border="0" /></a></td>'	
	
	
	// need to shrink up space before the submenu if NOT logged in. This var is set on /Controls/WebUserContr
	if (loggedIn == "true") { 
	    subNavString +=	'<td><img src="../Images/Global/s.gif" alt=" " width="81" height="1" /></td>'
	} else {
	    subNavString +=	'<td><img src="../Images/Global/s.gif" alt=" " width="166" height="1" /></td>'
	} 
	
	subNavString +=	'</tr>'
	subNavString +=	'</table>'
	subNavString +=	'</div>'
	
	
	return subNavString;
	
}

// this function is needed externally because it is called directly by the page
function getSubNav(which) {
	
		hideAllDivs();
		
	switch(which) {
		case 'Home':
			// nothing
			break;		
		case 'About':
			// show the appropriate div:
			document.getElementById("sub_nav_about").style.display = "inline";
			break;
		case 'Programs':
			document.getElementById("sub_nav_programs").style.display = "inline";
			break;
		case 'Business':
			document.getElementById("sub_nav_business").style.display = "inline";
			break;			
		case 'Employment':
			document.getElementById("sub_nav_employment").style.display = "inline";
			break;
		case 'Employees':
			document.getElementById("sub_nav_employees").style.display = "inline";
			break;			
		case 'Links':
			document.getElementById("sub_nav_links").style.display = "inline";
			break;			
		default:
			return "sorry, no luck";
		
	}
}


function hideAllDivs() {
	// turn them all off:
	document.getElementById("sub_nav_about").style.display = "none";
	document.getElementById("sub_nav_programs").style.display = "none";
	document.getElementById("sub_nav_business").style.display = "none";
	document.getElementById("sub_nav_employment").style.display = "none";
	document.getElementById("sub_nav_employees").style.display = "none";
	document.getElementById("sub_nav_links").style.display = "none";
}

function startHide() {
	timerID = setTimeout("finishHide()", 1200);	
}

function finishHide() {
	hideAllDivs();	
	
	// re-show the sub nav that belongs on this page:
	if (document.location.href.indexOf("/About/") != -1) {
		getSubNav('About');
	}
	if (document.location.href.indexOf("/Programs/") != -1) {
		getSubNav('Programs');
	}
	if (document.location.href.indexOf("/Business/") != -1) {
		getSubNav('Business');
	}
	if (document.location.href.indexOf("/Employment/") != -1) {
		getSubNav('Employment');
	}
	if (document.location.href.indexOf("/Employees/") != -1) {
		getSubNav('Employees');
	}
	if (document.location.href.indexOf("/Links/") != -1) {
		getSubNav('Links');
	}	
	if (document.location.href.indexOf("/Home/") != -1) {
		getSubNav('Home');
	}
	

	clearTimeout(timerID);
	timerID = null;
}

function stopTimer() {      // if you rolled back onto a button or a layer
	clearTimeout(timerID);
	timerID = null;
}


window.onload = setRollovers;


