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);	
	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_story") != -1) {
		getSubNav('Story');
	}
	if (currImage.src.indexOf("btn_people") != -1) {
		getSubNav('People');
	}
	if (currImage.src.indexOf("btn_portfolio") != -1) {
		getSubNav('Portfolio');
	}
	if (currImage.src.indexOf("btn_jobs") != -1) {
		getSubNav('Jobs');
	}
	if (currImage.src.indexOf("btn_contact") != -1) {
		getSubNav('Contact');
	}
	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_story" style="display:none" onMouseOut="startHide();" onMouseOver="stopTimer();">'		
	subNavString += '<table width="673" border="0" cellspacing="0" cellpadding="0">'
	subNavString +=	'<tr>'
	subNavString +=	'<td><img src="../Images/Global/s.gif" alt=" " width="58" height="1" /></td>'
	subNavString +=	'<td><a href="../Story/Vision.html" class="rollover"><img id="vision" src="../Images/Story/sub_btn_vision.gif" alt="vision" width="92" height="22" border="0" /></a></td>'
	subNavString +=	'<td><img src="../Images/Story/vert_btn_separator.gif" alt=" " /></td>'
	subNavString +=	'<td><a href="../Story/Select.html" class="rollover"><img id="select" src="../Images/Story/sub_btn_select.gif" alt="select" border="0" /></a></td>'
	subNavString +=	'<td><img src="../Images/Story/vert_btn_separator.gif" alt=" " /></td>'
	subNavString +=	'<td><a href="../Story/Plan.html" class="rollover"><img id="plan" src="../Images/Story/sub_btn_plan.gif" alt="plan" border="0" /></a></td>'
	subNavString +=	'<td><img src="../Images/Story/vert_btn_separator.gif" alt=" " /></td>'
	subNavString +=	'<td><a href="../Story/Launch.html" class="rollover"><img id="launch" src="../Images/Story/sub_btn_launch.gif" alt="launch" border="0" /></a></td>'
	subNavString +=	'<td><img src="../Images/Story/vert_btn_separator.gif" alt=" " /></td>'
	subNavString +=	'<td><a href="../Story/Grow.html" class="rollover"><img id="grow" src="../Images/Story/sub_btn_grow.gif" alt="grow" border="0" /></a></td>'
	subNavString +=	'<td><img src="../Images/Story/vert_btn_separator.gif" alt=" " /></td>'
	subNavString +=	'<td><a href="../Story/Exit.html" class="rollover"><img id="exit" src="../Images/Story/sub_btn_exit.gif" alt="exit" border="0" /></a></td>'
	subNavString +=	'<td><img src="../Images/Global/s.gif" alt=" " width="254" height="1" /></td>'
	subNavString +=	'</tr>'
	subNavString +=	'</table>'
	subNavString +=	'</div>'
	
	
	// people sub nav table:
	subNavString += '<div id="sub_nav_people" style="display:none" onMouseOut="startHide();" onMouseOver="stopTimer();">'		
	subNavString += '<table width="673" border="0" cellspacing="0" cellpadding="0">'
	subNavString +=	'<tr>'
	subNavString +=	'<td><img src="../Images/Global/s.gif" alt=" " width="58" height="1" /></td>'
	subNavString +=	'<td><a href="../People/Board.html" class="rollover"><img id="board" src="../Images/People/sub_btn_board.gif" alt="Board of Directors" width="112" height="22" border="0" /></a></td>'
	subNavString +=	'<td><img src="../Images/People/vert_btn_separator.gif" alt=" " /></td>'
	subNavString +=	'<td><a href="../People/Management.html" class="rollover"><img id="management" src="../Images/People/sub_btn_management.gif" alt="Management team" width="84" height="22" border="0" /></a></td>'
	subNavString +=	'<td><img src="../Images/People/vert_btn_separator.gif" alt=" " /></td>'
	subNavString +=	'<td><a href="../People/Resource.html" class="rollover"><img id="resource" src="../Images/People/sub_btn_resource.gif" alt="Resource team members" width="113" height="22" border="0" /></a></td>'
	subNavString +=	'<td><img src="../Images/People/vert_btn_separator.gif" alt=" " /></td>'
	//subNavString +=	'<td><a href="../People/PortfolioBoardMembers.html" class="rollover"><img id="port_members" src="../Images/People/sub_btn_port_members.gif" alt="Portfolio board members" width="102" height="22" border="0" /></a></td>'
	//subNavString +=	'<td><img src="../Images/People/vert_btn_separator.gif" alt=" " /></td>'
	subNavString +=	'<td><a href="../People/PortfolioPersonnel.html" class="rollover"><img id="port_personnel" src="../Images/People/sub_btn_port_personnel.gif" alt="Portfolio company personnel" width="134" height="22" border="0" /></a></td>'
	subNavString +=	'<td><img src="../Images/Global/s.gif" alt=" " width="54" height="1" /></td>'
	subNavString +=	'</tr>'
	subNavString +=	'</table>'
	subNavString +=	'</div>'	
	
	// portfolio sub nav table:
	subNavString += '<div id="sub_nav_portfolio" style="display:none" onMouseOut="startHide();" onMouseOver="stopTimer();">'		
	subNavString += '<table width="673" border="0" cellspacing="0" cellpadding="0">'
	subNavString +=	'<tr>'
	subNavString +=	'<td><img src="../Images/Global/s.gif" alt=" " width="211" height="1" /></td>'
	subNavString +=	'<td><a href="../Portfolio/Companies.html" class="rollover"><img id="companies" src="../Images/Portfolio/sub_btn_companies.gif" alt="Companies" width="70" height="22" border="0" /></a></td>'
	subNavString +=	'<td><img src="../Images/Portfolio/vert_btn_separator.gif" alt=" " /></td>'
	subNavString +=	'<td><a href="../Portfolio/UniversityPartners.html" class="rollover"><img id="university_partners" src="../Images/Portfolio/sub_btn_university_partners.gif" alt="University partners" width="126" height="22" border="0" /></a></td>'
	subNavString +=	'<td><img src="../Images/Global/s.gif" alt=" " width="262" height="1" /></td>'
	subNavString +=	'</tr>'
	subNavString +=	'</table>'
	subNavString +=	'</div>'	
	
	// jobs sub nav table:
	subNavString += '<div id="sub_nav_jobs" style="display:none" onMouseOut="startHide();" onMouseOver="stopTimer();">'		
	subNavString += '<table width="673" border="0" cellspacing="0" cellpadding="0">'
	subNavString +=	'<tr>'
	subNavString +=	'<td><img src="../Images/Global/s.gif" alt=" " width="285" height="1" /></td>'
	subNavString +=	'<td><a href="../Jobs/Careers.html" class="rollover"><img id="careers" src="../Images/Jobs/sub_btn_careers.gif" alt="Careers" width="58" height="22" border="0" /></a></td>'
	subNavString +=	'<td><img src="../Images/Global/s.gif" alt=" " width="330" 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 'Story':
			// show the appropriate div:
			document.getElementById("sub_nav_story").style.display = "inline";
			break;
		case 'People':
			document.getElementById("sub_nav_people").style.display = "inline";
			break;
		case 'Portfolio':
			document.getElementById("sub_nav_portfolio").style.display = "inline";
			break;			
		case 'Jobs':
			document.getElementById("sub_nav_jobs").style.display = "inline";
			break;
		case 'Contact':
			// nothing
			break;			
			
		default:
			return "sorry, no luck";
		
	}
}


function hideAllDivs() {
	// turn them all off:
	document.getElementById("sub_nav_story").style.display = "none";
	document.getElementById("sub_nav_people").style.display = "none";
	document.getElementById("sub_nav_portfolio").style.display = "none";
	document.getElementById("sub_nav_jobs").style.display = "none";
	//document.getElementById("sub_nav_contact").style.display = "none";	
}

function startHide() {
	timerID = setTimeout("finishHide()", 1999);	
}

function finishHide() {
	hideAllDivs();	
	
	// re-show the sub nav that belongs on this page:
	if (document.location.href.indexOf("/Story/") != -1) {
		getSubNav('Story');
	}
	if (document.location.href.indexOf("/People/") != -1) {
		getSubNav('People');
	}
	if (document.location.href.indexOf("/Portfolio/") != -1) {
		getSubNav('Portfolio');
	}
	if (document.location.href.indexOf("/Jobs/") != -1) {
		getSubNav('Jobs');
	}
	if (document.location.href.indexOf("/Contact/") != -1) {
		getSubNav('Contact');
	}
	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;


