addLoadListener(setRollovers);

var timerID = "";


var whichPict = "";			// this is to grab the name of the pict for the if statements in the xmlHTTPresponse

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 = "currRollImage_" + i;
				myImage = new Image();
				myImage.src = currLink.childNodes[0].src.replace(/(\.[^.]+)$/, '_over$1');;
			}
		}
	}
}		// end setRollovers



function doRollover(e)  {
	var currTarget = findTarget(e);
	if (!currTarget) return;
	var currImage = currTarget.childNodes[0];
	
	//if (currImage.src.indexOf("_current") == -1) {
		currImage.src = currImage.src.replace(/(\.[^.]+)$/, '_over$1');
	//}
	
	// rollover the button exposes the sub-nav
	
	if (currImage.src.indexOf("btn_company") != -1) {
		getSubNav('Company');
	}
	if (currImage.src.indexOf("btn_products") != -1) {
		getSubNav('Products');
	}
	if (currImage.src.indexOf("btn_financial_impact") != -1) {
		getSubNav('Financial');
	}
	if (currImage.src.indexOf("btn_services") != -1) {
		getSubNav('Services');
	}
	if (currImage.src.indexOf("btn_implementations") != -1) {
		getSubNav('Implementations');
	}
	if (currImage.src.indexOf("btn_support_center") != -1) {
		getSubNav('Support');
	}
	if (currImage.src.indexOf("btn_home") != -1) {
		getSubNav('Home');
	}
	
	
}

function restoreImage(e) {
	var currTarget = findTarget(e);
	if (!currTarget) return;	
	var currImage = currTarget.childNodes[0];
	
	//if (currImage.src.indexOf("_current") == -1) {
		currImage.src = currImage.src.replace(/_over(\.[^.]+)$/, '$1');	
		//finishHide();
	//}
}



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() {
	
	// home sub nav table:
	subNavString = '<div id="sub_nav_home" style="display:none">' + '<a href="Home.html">'
	subNavString += '<img src="Images/sub_nav_00.jpg" alt="" width="541" height="23" onmouseout="finishHide();" />'
	subNavString +=	'</div>'
	
	
	// company sub nav table:
	subNavString += '<div id="sub_nav_company" style="display:none">' + '<a href="Company.html">'
	subNavString += '<img src="Images/sub_nav_01.jpg" alt="" width="541" height="23" onmouseout="finishHide();" />'
	subNavString +=	'</a></div>'
	
// products sub nav table:
	subNavString += '<div id="sub_nav_products" style="display:none">'+ '<a href="Products.html">'	
	subNavString += '<img src="Images/sub_nav_02.jpg" alt="" width="541" height="23" onmouseout="finishHide();" />'
	subNavString +=	'</a></div>'	
	
// financial impact sub nav table:
	subNavString += '<div id="sub_nav_financial" style="display:none">'	+ '<a href="FinancialImpact.html">'	
	subNavString += '<img src="Images/sub_nav_03.jpg" alt="" width="541" height="23" onmouseout="finishHide();" />'
	subNavString +=	'</a></div>'
	
// services impact sub nav table:
	subNavString += '<div id="sub_nav_services" style="display:none">' + '<a href="Services.html">'
	subNavString += '<img src="Images/sub_nav_04.jpg" alt="" width="541" height="23" onmouseout="finishHide();" />'
	subNavString +=	'</a></div>'	
	
	// implementations impact sub nav table:
	subNavString += '<div id="sub_nav_implementations" style="display:none">' + '<a href="Implementations.html">'
	subNavString += '<img src="Images/sub_nav_05.jpg" alt="" width="541" height="23" onmouseout="finishHide();" />'
	subNavString +=	'</a></div>'
	
	// support impact sub nav table:
	subNavString += '<div id="sub_nav_support" style="display:none">' + '<a href="SupportCenter.html">'
	subNavString += '<img src="Images/sub_nav_06.jpg" alt="" width="541" height="23" onmouseout="finishHide();" />'
	subNavString +=	'</a></div>'
	
	
	
	return subNavString;
	
}

// this function is needed externally because it is called directly by the page
function getSubNav(which) {
	
		hideAllDivs();
		
		
	switch(which) {
		case 'Home':
			document.getElementById("sub_nav_home").style.display = "inline";
			break;		
		case 'Company':
			document.getElementById("sub_nav_company").style.display = "inline";
			break;
		case 'Products':
			document.getElementById("sub_nav_products").style.display = "inline";
			break;
		case 'Financial':
			document.getElementById("sub_nav_financial").style.display = "inline";
			break;			
		case 'Services':
			document.getElementById("sub_nav_services").style.display = "inline";
			break;
		case 'Implementations':
			document.getElementById("sub_nav_implementations").style.display = "inline";
			break;	
		case 'Support':
			document.getElementById("sub_nav_support").style.display = "inline";
			break;	
			
		default:
			return "sorry, no luck";
		
	}
	
}

function hideAllDivs() {
	// turn them all off:
	document.getElementById("sub_nav_home").style.display = "none";
	document.getElementById("sub_nav_company").style.display = "none";
	document.getElementById("sub_nav_products").style.display = "none";
	document.getElementById("sub_nav_financial").style.display = "none";
	document.getElementById("sub_nav_services").style.display = "none";
	document.getElementById("sub_nav_implementations").style.display = "none";	
	document.getElementById("sub_nav_support").style.display = "none";
}

var whichSubMenu = "";


function finishHide() {
	
	hideAllDivs();	

	
	// re-show the sub nav that belongs on this page:
	if (document.location.href.indexOf("/") != -1 && whichSubMenu == "Company") {
		getSubNav('Company');
	}
	if (document.location.href.indexOf("/") != -1 && whichSubMenu == "Products") {
		getSubNav('Products');
	}
	if (document.location.href.indexOf("/") != -1 && whichSubMenu == "Financial") {
		getSubNav('Financial');
	}
	if (document.location.href.indexOf("/") != -1 && whichSubMenu == "Services") {
		getSubNav('Services');
	}
	if (document.location.href.indexOf("/") != -1 && whichSubMenu == "Implementations") {
		getSubNav('Implementations');
	}
	if (document.location.href.indexOf("/") != -1 && whichSubMenu == "Support") {
		getSubNav('Support');
	}
	if (document.location.href.indexOf("/") != -1) {
		getSubNav('Home');
	}
	
	
}




function addLoadListener(fn) {
  if (typeof window.addEventListener != 'undefined') {
    window.addEventListener('load', fn, false);
  } else if (typeof document.addEventListener != 'undefined') {
    document.addEventListener('load', fn, false);
  } else if (typeof window.attachEvent != 'undefined') {
    window.attachEvent('onload', fn);
  } else {
    var oldfn = window.onload;
    if (typeof window.onload != 'function') {
      window.onload = fn;
    } else {
      window.onload = function() {
        oldfn();
        fn();
      };
    }
  }
}


