/*****************************************************************************/
/* 	Controls Global Navigation for IE	 */
/*****************************************************************************/
// Nav Toggle
function navOn(id){document.getElementById(id).style.display='block';}
function navOff(id){document.getElementById(id).style.display='none';}

function NavWidget(debug,defer,allowFocus) {
	// debug (true/false): enables debugging mode
	// defer (true/false): defers init() call (will have to be called manually)
	// noNetscapeBlur (true/false): allows buttons to get and keep focus (annoying inner border shown - workaround for Netscape 7.0
	// when buttons in fieldset tags, ie. demo page)
	var self = this;
	this.debugEnabled = (debug?1:0);
	this.defer = (defer?1:0);
	this.noFocus = (allowFocus?0:1);
	this.useSingleTimeout=false;//see comment on self.mainNav.onmouseout before changing
	
	this.timeDout=false;
	this.timeout;
	this.mainNav = document.getElementById('main-nav');
	this.b = document.getElementById('main-nav').getElementsByTagName("li");
	this.init = function() {
//		self.mainNav.onmouseout = function(e) {//This function must be completed before useSingleTimeout can be set to true
//			console.log(e);
//			var target=e.relatedTarget||event.toElement;
//			console.log(target);
//		};
		// Main loop (assigns nav event handlers etc.)
		for (var i=0; i < this.b.length; i++) {
			if(this.b[i].className=='nav-section'){
				this.b[i].htmlMouseDownHandler = (this.b[i].onmouseover?this.b[i].onmouseover:function(){});
				this.b[i].htmlMouseUpHandler = (this.b[i].onmouseup?this.b[i].onmouseup:function(){});
				this.b[i].htmlMouseOutHandler = (this.b[i].onmouseout?this.b[i].onmouseout:function(){});
				this.b[i].onmouseover = function() {
					if(this.className=="nav-section"){//Only showmenu if the menu is not already displayed
						if (self.useSingleTimeout && self.timeDout){
							this.showMenu();
						}else{ 
							this.timeout = setTimeout('document.getElementById("'+this.id+'").showMenu()',400);
						}
					}
				};
				this.b[i].onmouseup = function() {
					this.id = this.id.replace(/\-over/,'');
					this.className = this.className.replace(/\-over/,'');
					if (self.debugEnabled){this.debug();}
					this.htmlMouseUpHandler();
				};
				if (this.noFocus) {
					this.b[i].onfocus = function() {
						this.blur();
					};
				}
				this.b[i].onmouseout = function(e) {
					clearTimeout(this.timeout);
					showSelects();
					this.id = this.id.replace(/\-over/,'');
					this.className = this.className.replace(/\-over/,'');
					if (self.debugEnabled){this.debug();}
					this.htmlMouseOutHandler();
				};
				this.b[i].showMenu = function() {
					navWidget.timeoutCompleted=true;
					hideSelects();
					this.className = this.className+'-over';
					if(this.id.indexOf('-over')==-1){this.id = this.id+'-over';}
					if (self.debugEnabled){this.debug();}
					self.timeDout=true;
					this.htmlMouseDownHandler();
				};
				if (self.debugEnabled) {
					this.b[i].onmouseover = function() {
						this.debug();
					};
				}
				this.b[i].debug = function() {
					window.status = 'NavWidget(): '+this.className;
				};
			}else if (this.b[i].parentNode.className=='sub-section'){
				this.b[i].onmouseover = function() {
					var navSection = this.parentNode.parentNode;
					if(navSection.className=="nav-section"){
						navSection.showMenu();
					}
				};
			}
		}
	}
	if (!this.defer) {this.init();}
}
var navWidget = null;
onloadHandlers[onloadHandlers.length] = 'navWidget = new NavWidget()';
