// JavaScript Document
var ccollect;   // array of all nav section elements
var cel;  // current link element

function getElementbyClass(classname){
	ccollect=new Array();
	var inc=0;
	var alltags=document.all? document.all : document.getElementsByTagName("*")
	for (i=0; i<alltags.length; i++){
		if (alltags[i].className==classname)
		  ccollect[inc++]=alltags[i];
	}
}

function contractall() {
  for (var i=0; i<ccollect.length; i++)
    ccollect[i].style.display="none";
}
function expandcontent(sectionid){
  var div;
  for (var i=0; i<ccollect.length; i++) {
    div = ccollect[i];
		if (div.id==sectionid)
		  div.style.display  = (div.style.display == "block")? "none":"block";
	  else
	    div.style.display="none";
	}
}

function iterate() {
  var sectionid, linkname;
  for (var j=0; j<ccollect.length; j++) {
    //alert(ccollect[j].id);
		for (var i = ccollect[j].firstChild; i != null; i = i.nextSibling) {
			if (i.nodeType == 1) {
				linkname = i.getAttribute("href");
        //alert(linkname);
			}
		}
	}
}

function getsectionid() {
	var sectionid, linkname, pagename;
	pagename = window.location.pathname + window.location.search;
	cel = null;
	for (var j=0; j<ccollect.length; j++) {
		for (var i = ccollect[j].firstChild; i != null; i = i.nextSibling) {
			if (i.nodeType == 1) {
				if (i.tagName=="A") {
					linkname = i.pathname + i.search;
					// section found if:
					//   1. linkname is part of page name OR
					//   2. page is part of /products and the string '?=t=xx' is part of the page name
					if ((pagename.indexOf(linkname) != -1 && (linkname != "") && (linkname != "/")) ||
					    (pagename.indexOf("/products/") != -1 && linkname.indexOf("products/") != -1 && pagename.indexOf(i.search+"&") != -1)) {
						cel = i;
						return ccollect[j].id;
					}
				}
// THIS SECTION IS THE OPPOSITE OF THE ABOVE
// THIS WILL MATCH (SUBSTRING) THE URL TO THE LINK
//
//				linkname = i.getAttribute("href");
//				if (linkname != null) {
//				  if (linkname.indexOf(pagename) != -1) {
//				    cel = i;
//				    return ccollect[j].id;
//				  }
//				}
			}
		}
	}
}

function do_onload() {
  var sectionid;
	getElementbyClass("switchcontent");
	contractall();  // necessary because initial value of style.display is empty string, not 'none' as expected
	sectionid = getsectionid();
	expandcontent(sectionid);
	if (cel != null) {
	  cel.className = "selectedlink";
	  cel.href = "javascript:void(0);";
	}
}

if (window.addEventListener)
	window.addEventListener("load", do_onload, false)
else if (window.attachEvent)
	window.attachEvent("onload", do_onload)
else if (document.getElementById)
	window.onload=do_onload