
var activeAnchor = null;
try {
	activeAnchor=document.location.hash.slice(1); // the name of the anchor to go to
} catch(e) {}
var tContentDiv=document.getElementById("tContentDiv");
var anchors=tContentDiv.getElementsByTagName("h3");

// shows the correct content panel for the given anchor, if provided
if(null != activeAnchor) {
	var firstAnchor = null;
	var foundAnchor = null;
	for(var i = 0; i < anchors.length; i++) {
		if("tContentSubhead" == anchors[i].className) {
			if(anchors[i].id == activeAnchor) {
				foundAnchor = anchors[i];
			} else 	{
				anchors[i].style.display = "none";
				document.getElementById(anchors[i].id+"body").style.display = "none";
				if(null == firstAnchor) {
					firstAnchor = anchors[i];
				}
			}
		}
	}
	if(null == foundAnchor && null != firstAnchor) {
		document.getElementById(firstAnchor.id+"body").style.display="";
		firstAnchor.style.display="";
	}
}

// places anchors on the left nav
if(anchors.length > 0) {
    var ul = document.createElement("ul");
    for(var i = 0; i < anchors.length; i++) {
        if("tContentSubhead" == anchors[i].className) {
            var li = document.createElement("li"); // place for link on left nav
            var a = document.createElement("a"); // link on left nav
			var atop = document.createElement("a"); // anchor at top of page to prevent scrolling
	            a.href="#";
			if(anchors[i].id) {
				a.href += anchors[i].id;
				atop.name = anchors[i].id;
				atop.id = anchors[i].id;
			}
			if (a.addEventListener){
			  a.addEventListener('click', flipPanel, false); 
			} else if (a.attachEvent){
			  a.attachEvent('onclick', flipPanel);
			}
            a.innerHTML=anchors[i].innerHTML;
			atop.innerHTML="&nbsp;";
			li.style.width="110px";
			li.style.left="0px";
            li.appendChild(a);
            ul.appendChild(li);
			document.getElementById("topAnchors").appendChild(atop);
        }
    }
	document.getElementById("tLeftNavLinks").appendChild(ul);
}

function getAName(e) {
	var targ;
	if (!e) {
		var e=window.event;
	} if (e.target) {
		targ=e.target;
	} else if (e.srcElement) {
		targ=e.srcElement;
	}
	if (targ.nodeType==3) { // defeat Safari bug 
		targ = targ.parentNode;
	}
	var tname;
	tname=targ.tagName;
	if(tname == "SPAN") {
		targ=targ.parentNode;
		tname=targ.tagName;
	}
	if(tname == "A") {
		var href = targ.href;
		var result = href.replace(/.*#/,"");
		return result;
	} else {
		return null;
	}
}

function flipPanel(e) {
	var name=getAName(e);
	var hideList = new Array();
	var foundAnchor = false;
	for(var i = 0; i < anchors.length; i++) {
		if("tContentSubhead" == anchors[i].className) {
			if(anchors[i].id == name) {
				anchors[i].style.display = '';
				document.getElementById(anchors[i].id+"body").style.display = '';
				foundAnchor = true;
			} else 	{
				hideList.push(anchors[i]);
				hideList.push(document.getElementById(anchors[i].id+"body"));
			}
		}
	}
	if(true == foundAnchor) {
		while(hideList.length > 0) {
			hideList.pop().style.display = "none";
		}
	}
}
