/* GLOBALS */
var outmax = 10;
var outside = outmax;
var res = 0;
var browser_switch = 0;

/* IE HOVER WORKAROUND */
startList = function() {
 if (document.all&&document.getElementById) {
  navRoot = document.getElementById("nav");
  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", "");
    }
   }
  }
 }
/* IE BG TREATMENT */
try { document.execCommand('BackgroundImageCache', false, true); } catch(e) {} 
}

/* BROWSER SELECTION */
browserSelect = function(){
	var browser=navigator.appName;
	var is_mac = 0;
	var os = navigator.platform.substring(0,3).toLowerCase();
	if (os == 'mac')
		is_mac = 1;
	if ((browser=="Opera")||(browser=="Microsoft Internet Explorer"))
		browser_switch = 1;
	else
		browser_switch = 0;
/* SAFARI MARGIN CORRECTION */
	if ((navigator.vendor) || (is_mac == 1)){
		if((navigator.vendor.charAt(0)=="A") || ((is_mac == 1) && browser_switch == 0)){
			browser_switch = 2;
			var saf = document.getElementById('topnav').style.marginTop='15px';
		}
	}
}

/* INIT */
window.onload=function(){
	browserSelect();
	startList();
	replaceClass();
}


/* TURN CURRENT ITEM ON/OFF */
changeElementsStyleByClass = function (p,q){
	var e = "li";
	if(document.getElementsByTagName)
	{
		var nodes = document.getElementsByTagName(e);
		var max = nodes.length;
		for(var i = 0;i < max;i++)
		{
			var nodeObj = nodes.item(i);
			var attrMax = nodeObj.attributes.length;
			for(var j = 0; j < attrMax; j++)
			{
			if(nodeObj.attributes.item(j).nodeName == 'class')
				{
					if(nodeObj.attributes.item(j).nodeValue == p)
					{	
						nodeObj.attributes.item(j).nodeValue = q;
					}
				}
			}	
		}
	}
}

/* CURRENT MOUSEOVER - RESET MENU (IE) */
rep2 = function(){
	if (browser_switch == 1){
		changeElementsStyleByClass("om2","on1");
		res++;
	}
}

/* MENU RESET TIMER (IE) */
resetMenu = function(x)
{
	if(x == outside)
	{
		if (x>0) {
			x--;
			outside--;
			setTimeout("resetMenu("+x+")", 150);
		}
		 else if (x < 1){
			changeElementsStyleByClass("om2","on1");
		}
	}
}

/* MENU MOUSEOVERS */
replaceClass = function()
{	
	var navlinks = document.getElementById("nav").getElementsByTagName("li");
	for (var i = 0, j = navlinks.length; i < j; i++) {
		var t1 = navlinks[i];

		if(navlinks[i].className == "off")
		{
			// Mozilla & Safari
			if (browser_switch == 0||browser_switch == 2)
			{
				t1.onmouseover=function()
				{
					changeElementsStyleByClass("on1","om2");
				}
				t1.onmouseout=function()
				{
					changeElementsStyleByClass("om2","on1");
				}
			}
			// IE & Opera
			if (browser_switch == 1)
			{
				var link=navlinks[i].getElementsByTagName("A");
				
				for (var m = 0, n = link.length; m < n; m++) {
					var t2 = link[m];
					
					t2.onmouseover=function()
					{
						changeElementsStyleByClass("on1","om2");
						outside = outmax;
					}
					t2.onmouseout=function()
					{
						outside = outmax;
						resetMenu(outmax);
					}
			   }
		   }
		}
	}
}

