//<!--
//===== BEGIN OF EDITABLE/CONFIGURABLE SECTION =============================
// list the id's (i.e., id="category") of the main categories/buttons/links
// in the left navigation column
var categories = new Array('researchlink');

// specify the how much time (in milliseconds) to delay after the mouse leaves
// a popup menu (and does not mouseover another navigation button/category)
// before the popup menu is made hidden - this makes the popup menus a little
// easier to use
var delay = 500;  // milliseconds
//===== END OF EDITABLE/CONFIGURABLE SECTION =============================

//=========== !! DO NOT MODIFY ANYTHING BELOW THIS LINE !! =================
var mutils = new MiscUtils();
var url = window.location.href;
var isHomePage = false;
if (url == 'http://cimss-test.ssec.wisc.edu/index.html' || 
    url == 'http://cimss-test.ssec.wisc.edu/' || 
	url == 'http://cimss-test.ssec.wisc.edu/index.bill.html' || 	  
    url == 'http://cimss.ssec.wisc.edu/index.html' || 
	url == 'http://cimss.ssec.wisc.edu/' || 
	url == 'http://cimss.ssec.wisc.edu/index.bill.html') {
  isHomePage = true;
}
var showsubmenu = 'table';                  // SET TO DISPLAY: TABLE; FOR ALL NON-IE BROWSERS
if (document.all&&document.getElementById) {  // IE ONLY
  showsubmenu = 'block';                   // SET TO DISPLAY: BLOCK; FOR IE ONLY
}
var timerID;

//===============================================================================
// BEGIN OF FUNCTION SECTION 
//===============================================================================
//-------------------------------------------------------------------------------
function showMenu(menu) {
  window.clearTimeout(timerID);  // REMOVE ANY DELAY TIMERS
  hideAll();                    // HIDE ALL MENUS FIRST, BEFORE SHOWING DESIRED POPUP MENU
  var exists = 'true';
  try { var node = menu.firstChild.nextSibling.nextSibling; } 
  catch(excptn) { exists = 'false';  }
  finally {
    if (exists == 'true') {
      node.style.display=showsubmenu;
    }
  }
}

//-------------------------------------------------------------------------------
function hideAll() {
  // hide all popup menus
  for (i in categories) {
    var exists = 'true';
    try { var node = document.getElementById(categories[i]).firstChild.nextSibling.nextSibling; } 
    catch(excptn) { exists = 'false';  }
    finally {
      if (exists == 'true') {
        node.style.display="none";
      }
    }
  }
}

//-------------------------------------------------------------------------------
function hideMenu() {
  // hide popup menu, after the specified delay
  timerID = setTimeout('hideAll()', delay);
}

//--------------------------------------------------------------------------------
function startList() {
  // Set onMouseOver and onMouseOut events for navigation categories/buttons/links
  var command;
  for (i=0; i < categories.length; i++) {
    command = 'document.getElementById(categories[' + i + ']).onmouseover=function() {showMenu(document.getElementById(categories[' + i + ']));}';
    eval(command);
    command = 'document.getElementById(categories[' + i + ']).onmouseout=function() {hideMenu();}';
    eval(command);
  }
}

//--------------------------------------------------------------------------------
function fixHeight() {
	
  // fix Firefox 3.0 bug	
  var whiteborderContainer = document.getElementById("whiteborder");
  var blackborderContainer = document.getElementById("blackborder");
  var pageContainer = document.getElementById("pageContainer");
  var contentContainer = document.getElementById("contentContainer");
//  mutils.resizeTo100PercentHeight(pageContainer);	
  
  var viewportDim = mutils.getViewportDimensions();
  // if 1, then page resizes everytime window is resized but doesn't work when window is maximized
  // if 2 then page only resizes when window is made taller but DOES work when window is maximized
//  var contentHeight = document.getElementById("contentDiv").offsetHeight;  // 1
//  var contentHeight = contentContainer.offsetHeight; // 2
  if (!isHomePage) {
    var titlePadding = 8;
    var contentHeight = document.getElementById("contentDiv").offsetHeight + document.getElementById("banner").offsetHeight + titlePadding;;  // 3
  } else {
	var contentHeight = 0;
  }
  if (isHomePage || viewportDim[1] > contentHeight) { 
    whiteborderContainer.style.height = viewportDim[1] + "px";
    blackborderContainer.style.height = viewportDim[1] + "px";  
    pageContainer.style.height = viewportDim[1] + "px";
    contentContainer.style.height = viewportDim[1] + "px";	
  }
    
  if (isIE && isHomePage) {
	var pageContainerHeight = pageContainer.offsetHeight;
	var contentContainerHeight = contentContainer.offsetHeight;
	
    var ff = 30;  // fudge factor - not sure why this is needed
	
	contentContainer.style.height = pageContainerHeight - ff + "px";
	var bannerHeight = document.getElementById("banner").offsetHeight;
    document.getElementById("news").style.height = pageContainerHeight - bannerHeight - ff + "px";
	document.getElementById("maincategories").style.height = pageContainerHeight - bannerHeight - ff + "px";	
	document.getElementById("popular_sites").style.height = pageContainerHeight - bannerHeight - ff + "px";		
  }   
  
  
  
/*  
  if (isIE) {
    contentContainer.style.height = document.getElementById("maincategories_p2").offsetHeight + "px";
	alert(contentHeight + " " + document.getElementById("maincategories_p2").offsetHeight + " " + contentContainer.offsetHeight);	
  }
*/  

  
/*  
  if (isIE) {
	// news maincategories popular_sites
	var pageContainerHeight = pageContainer.offsetHeight;
	var contentContainerHeight = contentContainer.offsetHeight;
	
    var ff = 30;  // fudge factor - not sure why this is needed
	
	contentContainer.style.height = pageContainerHeight - ff + "px";
	var bannerHeight = document.getElementById("banner").offsetHeight;
	if (isHomePage) {
  	  document.getElementById("news").style.height = pageContainerHeight - bannerHeight - ff + "px";
	  document.getElementById("maincategories").style.height = pageContainerHeight - bannerHeight - ff + "px";	
	  document.getElementById("popular_sites").style.height = pageContainerHeight - bannerHeight - ff + "px";		
	} else {
      var contentDiv = document.getElementById("contentDiv");
	  if (contentDiv.offsetHeight > viewportDim[1]) {
  	    var newHeight = contentDiv.offsetHeight + "px";	
//	    document.getElementById("maincategories_p2").style.height = newHeight;					
//	    document.getElementById("content").style.height = newHeight;
        whiteborderContainer.style.height = newHeight;
        blackborderContainer.style.height = newHeight;		
        pageContainer.style.height = newHeight;				
	  }
	}
  }   
*/  
  
}

//--------------------------------------------------------------------------------
function onWindowLoad() {
  if (isHomePage) {
    startList();
  }
	  
  fixHeight();
  window.onresize = fixHeight;
}

//===============================================================================
// END OF FUNCTIONS
//===============================================================================

window.onload=onWindowLoad;
//-->