/* MEGA MENU LOAD AND HANDLER */
var megamenu_info = Array();
function load_megamenu(){
    // determine whether if in foundation mode
	var inFoundationMode = false;
	var pageMeta = document.getElementsByTagName('meta');
    for(var i in pageMeta){
        if(pageMeta[i].name != null){
            if(pageMeta[i].name.toLowerCase() == 'foundation'){
                if(pageMeta[i].content != null){
                    if (pageMeta[i].content.toLowerCase() == 'nolinks')
                    {
                        inFoundationMode = true;
                        
                        var issuesLink = document.getElementById('menu-nfib-issues-elections');
                        if ((issuesLink != null) && (issuesLink != undefined))
                        {
                            issuesLink.href = '#';
                            issuesLink.onclick = 'return false;';
                            issuesLink.title = '';
                            if(issuesLink.className == ''){
                                issuesLink.className = 'main-btn-off'
                            }else{
                                issuesLink.className += ' main-btn-off';
                            } 
                        }
                    }
                }
            }  
        }
    }

    /* FF will not see the proper nodes if any white space separates the elements */
	var megamenu = document.getElementById('main-navigation');
	for(var z = 0; z < megamenu.childNodes[0].childNodes.length; z++){
		if(megamenu.childNodes[0].childNodes[z].nodeName.toUpperCase() == 'LI'){
			var span = null;
			var ul = null;
			var div = null;
			for(var y = 0; y < megamenu.childNodes[0].childNodes[z].childNodes.length; y++){
				if(megamenu.childNodes[0].childNodes[z].childNodes[y].nodeName.toUpperCase() == 'SPAN'){
					span = megamenu.childNodes[0].childNodes[z].childNodes[y];
				}else if(megamenu.childNodes[0].childNodes[z].childNodes[y].nodeName.toUpperCase() == 'DIV' && megamenu.childNodes[0].childNodes[z].childNodes[y].className=='wrapper'){
					ul = megamenu.childNodes[0].childNodes[z].childNodes[y].childNodes[0];		
				}else if(megamenu.childNodes[0].childNodes[z].childNodes[y].nodeName.toUpperCase() == 'DIV'){
					div = megamenu.childNodes[0].childNodes[z].childNodes[y];		
				}
			}
			
			// disable 'mybusiness magaizine item
			if(span != null){
			    if (span.childNodes[0].id == 'menu-nifb-mybusiness-magazine') {
			        span = null;
			    }
			}
			
			// remove issues and elections if needed
            if (inFoundationMode){
    			if(span != null){
    			    if (span.childNodes[0].id == 'menu-nfib-issues-elections') {
			            span = null;
			        }
    			}
            }
			
			// process normal
			if(span != null){
				if(ul != null){
					ul.style.display = 'none';
					span.ul = ul;
					span.count = z;
					span.ul.count = z;
					span.show = function(){
						this.id = 'currentmega';
						this.ul.style.display = 'block';
					}
					span.hide = function(){
						this.id = '';
						this.ul.style.display = 'none';
					}
					span.onmouseover = function(){
						clearTimeout(megamenu_info[this.count].display);
						megamenu_info[this.count].display = setTimeout('megamenu_info['+this.count+'].show();',500);
					}
					span.onmouseout = function(){
						clearTimeout(megamenu_info[this.count].display);
						megamenu_info[this.count].display = setTimeout('megamenu_info['+this.count+'].hide();',500);
					}
					span.ul.onmouseover = span.onmouseover;
					span.ul.onmouseout = span.onmouseout;
				}
				megamenu_info[z] = span;
			}			
		}
	}
}


if(typeof window.onload == 'function'){
	var tmponload = window.onload;
	window.onload = function(){
		tmponload();
		load_megamenu();
	};
}else{
	window.onload = load_megamenu;
}
