var sTab = getParameter("tab");
execOnLoad = function() {
 an_ActivateNav();
   if (sTab!="") {
    an_toggleDisplay(sTab);
  }
  else {
  	an_toggleDisplay();
  }
}
window.onload=execOnLoad;

function an_ActivateNav() {
 // This function checks for a version of Internet Explorer less than 7, and
 //  parses through a navigation structure adding mouseOver and mouseOut events.
 // These mouse events add/remove a class 'hover' to that element.
 // The purpose is to simulate CSS' :hover
  var v = an_GetIEVersion();
  if (v >= 0 && v < 7) {
    var navRoot = document.getElementById("sites");  // First level <ul>
    if (navRoot) {
	  var nodes = navRoot.getElementsByTagName("LI");
	  for (i = 0; i < nodes.length; i++) {
		if (nodes[i].nodeName=="LI") { an_IE_SetHover(nodes[i]); }
	  }
	}
  }
}

function an_IE_SetHover(n) {
  // This function take a node and:
  //   - adds a mouseover function which adds 'hover' class
  //   - adds a mouseout function which removes the previous 'hover' class
  // It does not remove existing classes
  if(n) {
	n.onmouseover=function() { this.className+=" hover"; }
	n.onmouseout=function() { this.className=this.className.replace(" hover", ""); }
  }
}

function an_GetIEVersion() {
	// This function returns:
	//   -1   For non-IE browsers
	//   x.x  Style version number for IE browsers.
	// This isn't complete browser detection, it only cares about IE, irrespective of OS.
	var version = -1;
	var agent = navigator.userAgent.toLowerCase();
	var position = agent.indexOf("msie");
	if (position > -1 && !window.opera && navigator.vendor != 'KDE') { // Untested: navigator.vendor might work to not detect Safari
		var versionSegment = agent.substring(position);
		var versionStart = versionSegment.indexOf(' ')+1;
		var versionEnd = versionSegment.indexOf(';');
	    version = versionSegment.substring(versionStart, versionEnd);
		// 'version' now should be in the form of '6.0'
	}
	return version;
}


function getElementsByClass(searchClass,node,tag) {
  // This function gets the elements that all share a class name
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}


function an_toggleDisplay(theid) {
	// This function toggles between the tabs and the corresponding content for the tabs.  The tabs <li> must correspond 1-1 with the order of the content UL content elements.
	// if your 3rd tab is "tab for content z" then ensure that your UL for the content is placed as the 3rd element.
	// we could give the tabs an id in order to match the id of the actual content, but it was kept this way in order to save on logic processing time and added code to the HTML (yet more id's to keep track of).
  
var contentelmt = getElementsByClass('tab_contents');
var tabelmt = getElementsByClass('litab');
var match = false;
//if(contentelmt != null) {
if (contentelmt.length>0) {	
for (i = 0; i < contentelmt.length; i++) {
if (theid == contentelmt[i].id) {
match = true;
contentelmt[i].style.display = "block";
tabelmt[i].className ="litab active";
sTab = theid;

}
else {
contentelmt[i].style.display = "none";
tabelmt[i].className = "litab"; 
} 
}
if (!match) {
contentelmt[0].style.display = "block";
tabelmt[0].className="litab active";
}
}
return sTab;  // we return the value of the tab id so it can be used to navigate to other pages.
}


// This function returns the page in the pulldown and adds the proper active tab.
function changePage(pagename) {
		pageandtab = pagename + "?tab=" + sTab;
		location.href= pageandtab;
}

/*function an_toggleDisplay(theid) {
	// This function toggles between the tabs and the corresponding content for the tabs.  The tabs <li> must correspond 1-1 with the order of the content UL content elements.
	// if your 3rd tab is "tab for content z" then ensure that your UL for the content is placed as the 3rd element.
	// we could give the tabs an id in order to match the id of the actual content, but it was kept this way in order to save on logic processing time and added code to the HTML (yet more id's to keep track of).
  
	var contentelmt = getElementsByClass('tab_contents');
	var tabelmt = getElementsByClass('litab');
	var match = false;
		for (i = 0; i < contentelmt.length; i++) {
			if (theid == contentelmt[i].id) {
				match = true;
				contentelmt[i].style.display = "block";
				tabelmt[i].className ="litab active";
			}
			else {
				contentelmt[i].style.display = "none";
				tabelmt[i].className = "litab";			
			}		
		}
		if (!match) {
			contentelmt[0].style.display = "block";
			tabelmt[0].className="litab active";
		}
}
*/

function getParameter(szName)
{
    // Get value out of supplied parameter
    var szUrl = window.location.search;
    szUrl = szUrl.toLowerCase();
    szName = szName.toLowerCase();
    var szValue = "";
    var nBegin = szUrl.indexOf(szName);
    if (nBegin != -1)
    {
     szValue = szUrl.substring(nBegin + (szName.length + 1));
    }
    var nEnd = szValue.indexOf("&");
    if (szValue != "" && nEnd != -1)
    {
     szValue = szValue.substring(0, nEnd);
    }
    //	if (szValue == "")
	//	szValue = "About"; // Set the default here if you like
    //alert(szValue);                                        
    return szValue;
}

function ShowPull() {
 var thepulldown = document.getElementById("filter");
 if (thepulldown) {
   thepulldown.style.visibility = "visible";
 }
}
function HidePull() {
 var thepulldown = document.getElementById("filter");
 if (thepulldown) {
   thepulldown.style.visibility = "hidden";
 }
}

