var nav = new Object();

nav.init = function() {
  try {
    // this class used in the ff_dw_ function for team name and team alias to apply the boldness
    document.write('<style>.teamId' + ff.teamId + '{font-weight:bold}</style>');
    var pathName = window.location.pathname;
    var queryString = window.location.search;
    queryString = queryString.substring(1);       
    
    if(isOwner){  
      // lets not highlight the team tab if it is not your team
      if (pathName.indexOf("/team/home") != -1) {
        navOnId = 'false';
        navSubOnId = 'false';
      }
    }
       
  document.getElementById(navOnId).className = "mainOn";
    document.getElementById(navOnId).setAttribute("originalClass", "mainOn");
    var fsMenu = document.getElementById("fsMenu");
    var fanMenu = document.getElementById("fanMenu");
    if(fsMenu){
	 fsMenu.className = "mainOn";
	 fsMenu.setAttribute("originalClass", "mainOn");
    }
    if(fanMenu){
	 fanMenu.className = "mainOn";
	 fanMenu.setAttribute("originalClass", "mainOn"); 
    }   
     
    //document.getElementById(navOnId + "NavSub").style.display = "block";    
    var subnav = document.getElementById(navOnId + "NavSub");
    if(subnav){     
       subnav.style.display = "block";           
       var aTags = subnav.getElementsByTagName("A");
        var args = GetArgs();
    		
        for (var i=0; i < aTags.length; i++) {
          // if the a tag href is a match to the path						
    			if(args && args.type){			 
    			 if((args.type == "standingsBreakdown" && aTags[i].id == "standings-breakdown") ||(args.type == "dtl" && aTags[i].id == "standings-details")){// || (args.type == "scl" && aTags[i].id == "standings-scaled") ){			  			  			
    			  aTags[i].className = 'on';
             break;	
    			 }		 				
    			}else{			
    					var aTagHref = aTags[i].href;
    					if (navSubOnId == aTags[i].id) {
    						aTags[i].className = 'on';
    						break;
    					}
    			}		
    			
        }
    }
		

  }
  catch(e) {
    ////////// ignore error
  }
}

var widgetNav = {};
widgetNav.init = function() {
	$$("#navBar .navBarList li.main, #navBarFscomLinks ul.fsBarList li.mainOn, #navBarFscomLinks ul.fsBarList li.main").each(function(node){   
	   if (node.getElementsByTagName('ul').length > 0) {             
	        fim.events.addEvent(node, 'mouseover', widgetNav.getMoverFor(node), false);
	        fim.events.addEvent(node, 'mouseout', widgetNav.getMoutFor(node), false);
	   }
	});
}

widgetNav.showSelects = function(type) {
  // this is only a problem in IE6 and lower.  let's not hide the selects unless we have since it is a little jarring to the user
  if (!IE) return;
  if (IE7) return;
  var selects = document.getElementsByTagName('select');
  for (var i = 0; i < selects.length; i++) {
    selectNode = selects[i];
    if (type) {
      selectNode.style.visibility = "visible";
    }
    else {
      selectNode.style.visibility = "hidden";
    }
  }
}

fim.events.addEvent(window, 'load', widgetNav.init, false);

widgetNav.getMoverFor = function(node) {
  return function(e) { widgetNav.mover(e, node); };
}

widgetNav.getMoutFor = function(node) {
  return function(e) { widgetNav.mout(e, node); };
}

widgetNav.mover = function(e, targetElement) {        
  var el = window.event ? targetElement : e ? e.currentTarget : null;  
  if (!el) return;
  clearTimeout(el.outTimeout);
  el.className = "mainOver";
  var nextNav = $(el).next(0);   
  if(nextNav && $(nextNav).readAttribute("originalclass") && $(nextNav).readAttribute("originalclass") == "mainOn"){  
    nextNav.className = 'mainOnBorder';   
  }  
  el.down("ul",0).style.display = 'block';   
 hideSelectForNav(el);
}

widgetNav.mout = function(e, targetElement) {  
  //widgetNav.showSelects(true);
  var el = window.event ? targetElement : e ? e.currentTarget : null;
  if (!el) return;
  el.outTimeout = setTimeout(function() { widgetNav.mout2(el); }, 500);
}

widgetNav.mout2 = function(el) {
  //widgetNav.showSelects(true);
  var originalClass = "main";
  var elOriginalClass = el.getAttribute("originalClass"); // this gets set in the nav.init function
  if (elOriginalClass == "mainOn") {
    originalClass = elOriginalClass;
  }
  el.className = originalClass;
  var nextNav = $(el).next(0);  
  if(nextNav && $(nextNav).readAttribute("originalclass") && $(nextNav).readAttribute("originalclass") ==  "mainOn") {
     nextNav.className = 'mainOn';
  } 
  el.down("ul",0).style.display = 'none';    
  unhideSelectForNav(el);
}


// Hide all select boxes
function hideSelectForNav(el) {
	var listTag  = el.getElementsByTagName("UL")[0]; 
	  if(el.id == "league-home"){               
	      listTag.className = "sm_170";      
	  } 
	  if(el.id == "team-home"){            
	     listTag.className = "m_195";          
	  }   
	  if(el.id == "standings-home"){   
	     listTag.className = "m_190";      
	  }     
	  if(el.id == "players-home"){     
	     listTag.className = "sm_180";        
	  }
	  if(el.id == "research-home"){// || el.id == "draft-home"
	     listTag.className = "sm_165";
	  }    
	  
	  if(el.id == "draft-home"){
	    listTag.className = "m_196";
	  }
	  	
  if (document.all && (navigator.appVersion.substr(22,3)=="5.0" || navigator.appVersion.substr(22,3)=="6.0")) {     
   var iFrame = document.getElementById(el.id+"Iframe");               
   var menuItems = el.getElementsByTagName("UL")[0].getElementsByTagName("LI");      
   var height = 0;
   var width = 0;
   for(var i=0; i< menuItems.length;i++){
    if(el.id == "fsMenu" || el.id == "fanMenu"){
     height += (menuItems[i].offsetHeight); 
     width = menuItems[i].offsetWidth+1;
    }else{
     height += (menuItems[i].offsetHeight-1);//*0.9;//0.8  
    }    
   } 
                     
   var coords =  calculatePosition(el);       
   iFrame.style.top = (parseInt(coords[1])-201)+"px"; 
   iFrame.style.height = (parseInt(height)-10)+"px"; 
   iFrame.style.backgroundColor = "transparent";
       if(el.id == "team-home"|| el.id == "draft-home"){        
	     iFrame.style.width = "198px"; 
	   }  
	   if(el.id == "league-home"){     
	      iFrame.style.left += 1;          
	      iFrame.style.width = "167px";
	      iFrame.style.height = (parseInt(height)+1)+"px";  
	   } 
	   if(el.id == "standings-home"){
	     iFrame.style.width = "178px"; 
	   }     
	   if(el.id == "players-home"){
	     iFrame.style.width = "174px"; 
	   }
	   if(el.id == "research-home"){    // || el.id == "draft-home" 
	     iFrame.style.width = "157px";         
	   }                              
	   
	   if(el.id == "draft-home"){ 
	     iFrame.style.width = "196px";         
	   }  
   iFrame.style.left = document.getElementById("navBarList").style.left;
   
   if(el.id == "fsMenu" || el.id == "fanMenu"){
    iFrame.style.height = (height-17)+"px"; 
    iFrame.style.width = (width-2)+"px";
    iFrame.style.left = document.getElementById("navBarFscomLinks").style.left+1;
    if(el.id == "fanMenu"){
     iFrame.style.top = (parseInt(coords[1])-234)+"px";  
     iFrame.style.left = document.getElementById("navBarFscomLinks").style.left+60;   
    }
    //iFrame.style.border = "1px solid red";
   }         
   iFrame.style.visibility ="visible";
     
  }     
}

// Unhide all select boxes
function unhideSelectForNav(el) {
  if (document.all && (navigator.appVersion.substr(22,3)=="5.0" || navigator.appVersion.substr(22,3)=="6.0")) {  
  document.getElementById(el.id+"Iframe").style.visibility = "hidden";  
  document.getElementById(el.id+"Iframe").style.height = "0px";
  }
}