var version=0; //Browser version - IE only

//Tab navigation//
checkTabs = function() {
	var sfEls = document.getElementById("primary-nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		if(sfEls[i].parentNode.parentNode.nodeName == "LI"){
			sfEls[i].childNodes[0].onfocus = function(){
				 this.parentNode.parentNode.className = "showMe";
				 this.parentNode.parentNode.parentNode.firstChild.className = "selected";
			}
			sfEls[i].childNodes[0].onblur = function(){
				 this.parentNode.parentNode.className = "";
				 this.parentNode.parentNode.parentNode.firstChild.className = "";
			}
		}
	}
	
}
//IE Dropdown navigation
sfHover = function() {
	// Support the standard nav without a class of nav.
	var el = document.getElementById("primary-nav").firstChild;
	el.className ="primary-nav";
	if(!/\bnav\b/.test(el.className) && el.tagName == "UL")
		setHover(el);

	// Find all unordered lists.
	var ieNavs = document.getElementsByTagName('ul');
	for(i=0; i<ieNavs.length; i++) {
		var ul = ieNavs[i];
		// If they have a class of nav add the menu hover.
		if(/\bnav\b/.test(ul.className))
			setHover(ul);
	}
//Load tab navigation
	var ct = checkTabs();
}
//
function setHover(nav) {
	var ieULs = nav.getElementsByTagName('ul');
	if (navigator.appVersion.substr(22,3)!="5.0") {
		// IE script to cover <select> elements with <iframe>s
		for (j=0; j<ieULs.length; j++) {
			var ieMat=document.createElement('iframe');
			if(document.location.protocol == "https:")
				ieMat.src="//0";
			else if(window.opera != "undefined")
				ieMat.src="";
			else
				ieMat.src="javascript:false";
			ieMat.scrolling="no";
			ieMat.frameBorder="0";
			ieMat.style.width=ieULs[j].offsetWidth+"px";
			ieMat.style.height=ieULs[j].offsetHeight+"px";
			ieMat.style.zIndex="-1";
			ieULs[j].insertBefore(ieMat, ieULs[j].childNodes[0]);
			ieULs[j].style.zIndex="101";
		}
		// IE script to change class on mouseover
		var ieLIs = nav.getElementsByTagName('li');
		for (var i=0; i<ieLIs.length; i++) if (ieLIs[i]) {
			// Add a sfhover class to the li.
			ieLIs[i].onmouseover=function() {
				if(!/\bsfhover\b/.test(this.className))
					this.className+=" sfhover";
			}
			ieLIs[i].onmouseout=function() {
				if(!this.contains(event.toElement))
					this.className=this.className.replace(' sfhover', '');
			}
		}
	} else {
		// IE 5.0 doesn't support iframes so hide the select statements on hover and show on mouse out.
		// IE script to change class on mouseover
		var ieLIs = document.getElementById('nav').getElementsByTagName('li');
		for (var i=0; i<ieLIs.length; i++) if (ieLIs[i]) {
			ieLIs[i].onmouseover=function() {this.className+=" sfhover";hideSelects();}
			ieLIs[i].onmouseout=function() {this.className=this.className.replace(' sfhover', '');showSelects()}
		}
	}
}

// If IE 5.0 hide and show the select statements.
function hideSelects(){
	var oSelects=document.getElementsByTagName("select");
	for(var i=0;i<oSelects.length;i++)
		oSelects[i].className+=" hide";
}

function showSelects(){
	var oSelects=document.getElementsByTagName("select");
	for(var i=0;i<oSelects.length;i++)
		oSelects[i].className=oSelects[i].className.replace(" hide","");
}
//

if (navigator.appVersion.indexOf("MSIE")!=-1){
temp=navigator.appVersion.split("MSIE")
version=parseFloat(temp[1])
}
if (version>=7 || version == 0){ //NON IE browser will return 0
document.write("<style>#primary-nav li ul{background-image:url(common/images/dropdown-bg-shadow.png);}</style>")
}
//Load IE6 dropdown

if (version>0 && version < 7){
	if (window.attachEvent) window.attachEvent("onload", sfHover);
	//Write styles
	document.write("<style>ul.primary-nav iframe {position: absolute; left: -0.25em; top: -0.25em; z-index: -1; filter: progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0);} * html ul.primary-nav li { z-index: 201; }</style>");
}
//Load tab navigation for non IE browsers
if (document.addEventListener) {
  document.addEventListener("DOMContentLoaded", checkTabs, false);
}
//

function show(x){
	document.getElementById(x).style.display = "block"
}
function hide(x){
	document.getElementById(x).style.display = "none"
}
//
function getElementsByClassName(classname)
{
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = node.getElementsByTagName("*");
    for(var i=0,j=els.length; i<j; i++)
        if(re.test(els[i].className))a.push(els[i]);
    return a;
}

