/* drop down menu script */

function showMenu(menuName) {
  	hideAllMenus(menuName);
  	//show iframe
	if(document.getElementById(menuName)) {
	  document.getElementById(menuName).style.visibility='visible';
	}
	//adjust corresponding iframe height
	if(document.getElementById(menuName + "-iframe")) {
	  document.getElementById(menuName + "-iframe").style.height = document.getElementById(menuName).offsetHeight - 13; 
	}
	//document.getElementById(menuName + "-iframe").style.height = document.getElementById(menuName).offsetHeight - 13; 
	if(document.getElementById(menuName + "-iframe")) {
	  document.getElementById(menuName + "-iframe").style.visibility='visible';
	}
  	//document.getElementById(menuName + "-iframe").style.visibility='visible';
} 
  
function hideAllMenus(menuName) {
	 if(document.getElementById(menuName)) {
   	 	document.getElementById(menuName).style.visibility='hidden';
	 }
	 if(document.getElementById(menuName + "-iframe")) {
   	  	document.getElementById(menuName + "-iframe").style.visibility='hidden';
	 }	 
} 


//sfHovers
function findPos(obj) {
	var curleft = curtop = curwidth = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		curwidth = obj.offsetWidth
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
			curwidth += obj.offsetWidth
		}
	}
	//alert (curleft);
	return [curleft,curtop,curwidth];
}

function globalNav(className) {
	var sfEls;
	if (document.getElementById(className)) {
		sfEls = document.getElementById(className).getElementsByTagName("li");
	}
	//Detect IE6.0<
	version=0;
	if (navigator.appVersion.indexOf("MSIE")!=-1){
		temp=navigator.appVersion.split("MSIE");
		version=parseFloat(temp[1]);
	}
	if (sfEls.length) {
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				var compareTo;
				this.className+=" sfhover";
				if (navigator.appVersion.indexOf("MSIE")!=-1){
					temp=navigator.appVersion.split("MSIE");
					version=parseFloat(temp[1]);
				}
				if (version<=6.0 && navigator.appName == "Microsoft Internet Explorer") { //NON IE browser will return 0
					var sfSelects = document.getElementsByName('hidethis');
					if(sfSelects.length) {
						for(var s=0; s<sfSelects.length; s++) {
							//alert(sfSelects[s].className);
							var classnames = sfSelects[s].className.split(" ");
							var compareToArr = compareTo.split(" ");
							//alert(classnames.length);
							if (compareToArr.length) {
								for(var ct=0; ct<compareToArr.length; ct++) {
									if(classnames.length) {
										for(var j=0; j<classnames.length; j++) {
											if(sfSelects[s].id == "hideme" && classnames[j] == compareToArr[ct])
												sfSelects[s].style.visibility = "hidden";
										}
									}
								}
							}
						}
					}
				}
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp("sfhover\\b"), "");
				var sfSelects = document.getElementsByName('hidethis');
				if (sfSelects.length) {
					for(var s=0; s<sfSelects.length; s++) {
						sfSelects[s].style.visibility = "visible";
					}
				}
			}
		}
	}
}

function footerNav() {
	//if ((OS == "Windows") && (browser == "Internet Explorer")) {	
		if (document.all&&document.getElementById) {
			var navRoot = document.getElementById("footernav");						
			if (navRoot != null) {								
				for (i=0; i<navRoot.childNodes.length; i++) {
					node = navRoot.childNodes[i];					
					if (node.nodeName=="LI") {
						node.onmouseover=function() {
							this.className+=" over";
						}
						node.onmouseout=function() {
							this.className=this.className.replace(" over", "");
						}
					}
				}
			}
		}
	//}
}

var detect = navigator.userAgent.toLowerCase();
var OS,browser,total,thestring;
var version = 0;

if (checkIt('konqueror'))
{
	browser = "Konqueror";
	OS = "Linux";
}
else if (checkIt('safari')) browser = "Safari";
else if (checkIt('omniweb')) browser = "OmniWeb";
else if (checkIt('opera')) browser = "Opera";
else if (checkIt('webtv')) browser = "WebTV";
else if (checkIt('icab')) browser = "iCab";
else if (checkIt('msie')) browser = "Internet Explorer";
else if (!checkIt('compatible'))
{
	browser = "Netscape Navigator";
	version = detect.charAt(8);
}
else browser = "An unknown browser";

if (!version) version = detect.charAt(place + thestring.length);

if (!OS)
{
	if (checkIt('linux')) OS = "Linux";
	else if (checkIt('x11')) OS = "Unix";
	else if (checkIt('mac')) OS = "Mac";
	else if (checkIt('win')) OS = "Windows"
	else OS = "an unknown operating system";
}

function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}

function rememberParent(childId)
{
	var elem;
	if (document.getElementById(childId)) {
		elem = document.getElementById(childId);
	}
	if (document.getElementById(childId))  {
		elem.style.color = "#fff";
	} else {
		alert("none found");
	}
}

function forgetParent(childId)
{
	if (document.getElementById(childId))  {
		var elem = document.getElementById(childId);
		elem.style.color = "";
	} else {
		alert("none found");
	}
}
/************************ IE Dropdown iframe fix ******************************/
sfHover = function() {	
	// Support the standard nav without a class of nav.
	var el = null;
	if (document.getElementById("header-menu-tab")){
		el = document.getElementById("header-menu-tab");
	}
	
	if(el == null) {
		if (document.getElementById("order-menu-tab")) {
	    	el = document.getElementById("order-menu-tab");	
		}
	}	
	
	if(el != null) {
	    if(!/\bnav\b/.test(el.className) && el.tagName == "ul") {	    	        
	        setHover(el);
	    }
	    // Find all unordered lists.
	    var ieNavs = document.getElementsByTagName('ul');
	    if (ieNavs.length) {
			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);
				}
			}
		}
	}
}

function pauseFor(millis)
{
	var date = new Date();
	var curDate = null;
	
	do { curDate = new Date(); }
	while(curDate-date < millis);
} 

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
		if (ieULs.length) {
			for (j=0; j<ieULs.length; j++) {
				var ieMat=document.createElement('iframe');
				if(document.location.protocol == "https:")
					ieMat.src="javascript:false";
				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 + 2 + "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');
		if(ieLIs.length) {
			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;
		if (document.getElementById('nav').getElementsByTagName('li')) {
			ieLIs = document.getElementById('nav').getElementsByTagName('li');	
		}
		if(ieLIs.length) {
			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()}
			}
		}
	}
}

// Run this only for IE.
if (window.attachEvent) window.attachEvent('onload', sfHover);
// end

