function MM_openBrWindow(theURL,winName,features) {
  var win=window.open(theURL,winName,features);
  if (typeof win != 'undefined') win.focus();
  else win=false;
  return win;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

// IE Background Images on links flicker - modify cache settings
try {
  document.execCommand('BackgroundImageCache', false, true);
}
catch(e) {}


function bindPrimaryNav( id) {
	
	function hasClassName( elem, className) {
		return !( !elem || !className || !elem.className || elem.className.search( new RegExp("\\b" + className + "\\b")) == -1);
	}
	
	function addClassName( elem, className) {
		if ( !elem || !className || ( elem.className && elem.className.search( new RegExp( "\\b" + className + "\\b")) != -1))
			return;
		elem.className += (elem.className ? " " : "") + className;
	}
	
	function removeClassName( elem, className) {
		if ( hasClassName( elem, className))
			elem.className = elem.className.replace( new RegExp("\\s*\\b" + className + "\\b", "g"), "");
	}
	
	function pageY( elem) {
		return ( elem.offsetParent
			? elem.offsetTop + pageY( elem.offsetParent)
			: elem.offsetTop
		);
	}
	
	function parentY( elem) {
		return elem.parentNode == elem.offsetParent ? elem.offsetTop : pageY( elem) - pageY( elem.parentNode);
	}
	
	function pageX( elem) {
		return ( elem.offsetParent
			? elem.offsetLeft + pageX( elem.offsetParent)
			: elem.offsetLeft
		);
	}
	
	function parentX( elem) {
		return elem.parentNode == elem.offsetParent ? elem.offsetLeft : pageX( elem) - pageX( elem.parentNode);
	}
	
	function getX(e) {
		e = e || window.event;
		return e.pageX || e.clientX + document.body.scrollLeft;
	}
	
	function getStyle( elem, name) {
		if ( elem.style[ name])
			return elem.style[ name];
		
		else if ( elem.currentStyle && elem.currentStyle[ name])
			return elem.currentStyle[ name];
		
		else if ( document.defaultView && document.defaultView.getComputedStyle) {
			name = name.replace( /([A-Z])/g, "-$1").toLowerCase();
			var s = document.defaultView.getComputedStyle( elem, "");
			return s && s.getPropertyValue( name);
		}
		else
			return null;
	}
	
	function getStyleAsNumber( elem, style) {
		return parseInt( getStyle( elem, style));
	}

	function timerOn( menu) {
		menu.timeout = setTimeout( function() { closeAllSubMenus(); }, 500);
	}
	
	function timerOff( menu) {
		if ( menu.timeout) {
			clearTimeout( menu.timeout);
			menu.timeout = false;
		}
	}
	
	function closeAllSubMenus() {
		var submenus = document.getElementById( 'subNavMenus');
		var s = submenus.firstChild;
		while ( s) {
			timerOff( s);
			fadeOut( s);
			s = s.nextSibling;
		}
	}
	
	function fadeIn( obj) {
		if ( obj.fadeTimeout)
			clearTimeout( obj.fadeTimeout);
		addClassName( obj, 'showMenu');
		obj.fadeTimeout = false;
		obj.fade = 90;
		setFade( obj, obj.fade);
	}
	
	function fadeOut( obj) {
		if ( obj.fadeTimeout) {
			clearTimeout( obj.fadeTimeout);
			obj.fadeTimeout = false;
		}
		if ( !isNaN( obj.fade)) {
			obj.fade -= 5;
			setFade( obj, Math.max( 0, obj.fade));

			if ( obj.fade < 0)
				removeClassName( obj, 'showMenu');
			else
				obj.fadeTimeout = setTimeout( function() { fadeOut( obj); }, 15);
		}
	}
	
	function setFade( obj, value) {
		// if completely faded, don't display
		obj.style.display = ( value == 0 ? 'none' : 'block');
		// CSS3
		obj.style.opacity = Math.min( 99.999, value / 100) + '';
		// IE5.5+
		obj.style.filter = 'alpha(opacity=' + value.toString() + ')';
		// Gecko before CSS3 support
		obj.style.MozOpacity = Math.min( 99.999, value / 100) + '';
		// Konquerer and Safari
		obj.style.KHTMLOpacity = Math.min( 99.999, value / 100) + '';
	}

	try {
		var ul = document.getElementById( id);
		
		// Create a container for all the subnav items found
		var submenus = document.createElement( 'div');
		submenus.id = 'subNavMenus';
		addClassName( submenus, 'subNavMenus');
		
		var div = ul.parentNode;
		var leftPosition = pageX( div);
		var topPosition = pageY( div);
		
		// Stick it at the end of the body
		while ( div.tagName != 'BODY')
			div = div.parentNode;
		div.appendChild( submenus);
		
		var li = ul.firstChild;
		var subul;
		var sibling;
		var first;
		var isempty;
		while ( li) {
			if ( li.tagName == 'LI' && getStyle( li, 'display') != 'none') {
				subul = li.firstChild;
				isempty = true;
				while ( subul) {
					if ( subul.tagName == 'UL') {
						isempty = false;
						// Add new classnames to ul and top level li's
						addClassName( subul, 'subNavMenu');
						sibling = subul.firstChild;
						first = true;
						while ( sibling) {
							if ( sibling.tagName == 'LI') {
								addClassName( sibling, 'subNavMenu');
								if ( first) {
									addClassName( sibling, 'firstSubNav');
									first = false;
								}
							}
							sibling = sibling.nextSibling;
						}
						// Create a new container for the submenu, position it, and add submenu
						div = document.createElement( 'div');
						addClassName( div, 'subNavMenu');
						addClassName( div, li.className);
						div.appendChild( subul);
						
						// Move out of current list into submenus container
						submenus.appendChild( div);
						// Add handlers
						li.submenu = div;
						li.onmouseover = function(e) {
							closeAllSubMenus();
							fadeIn( this.submenu);
							this.submenu.style.top = ( pageY( this) + this.clientHeight).toString() + 'px';
							var submenuWidth = this.submenu.clientWidth;
							var leftPos = pageX( this) + 2;
							var ulRightPos = pageX( this.parentNode) + 825 + 1;
							if ( leftPos + submenuWidth > ulRightPos)
								leftPos = ulRightPos - submenuWidth;
							this.submenu.style.left = leftPos.toString() + 'px';
						};
						li.onmouseout = function(e) {
							timerOn( this.submenu);
						};
						div.onmouseover = function() {
							timerOff( this);
						};
						div.onmouseout = function() {
							timerOn( this);
						};
						break;
					}
					subul = subul.nextSibling;
				}
				// If there is no submenu, need to still do something
				if ( isempty) {
					// Add handlers
					li.onmouseover = function(e) {
						closeAllSubMenus();
					};
				}
				
			}
			li = li.nextSibling;
		}
	}
	catch (error) {
		alert( error);
	}
}
