// For use with Milonic DHTML Menus, version 5.  http://www.milonic.co.uk
// Written by Kevin C. Clements; use freely, but please leave all comments intact.
// mm_hideDiv.js version 2.02 - updated 11/10/03

// --------------------------------------
// User variables set in next three lines
// --------------------------------------

mm_divHidingEnabled = true;  // enable the hiding system (=false to disable)
mm_initialDelay = 100; // initial wait for menu to open before cycling, should be > _menuOpenDelay in menu_data.js
mm_reshowInterval = 250; // check every ___ msec to see if menus are still open


// ---------------------------------------------------
// Browser detection for "bad" browsers.  Add your own
//  as you see fit, for additional problem browsers.
// ---------------------------------------------------

function snifBrowser()
{
  d = document;
//  this.majorVer = parseInt(navigator.appVersion);  // may be useful for other testing
//  this.minorVer = parseFloat(navigator.appVersion);  // may be useful for other testing
  this.ua = navigator.userAgent.toLowerCase();
  this.dom = d.getElementById ? true : false;

  this.ie4 = (d.all && !this.dom) ? true : false;
  this.ie5 = (d.all && this.dom && !window.createPopup)? true : false;
  this.ns4 = d.layers ? true : false;
  this.op5 = (this.ua.indexOf("opera 5") != -1 || this.ua.indexOf("opera/5") != -1) ? true : false;
  this.op6 = (this.ua.indexOf("opera 6") != -1 || this.ua.indexOf("opera/6") != -1) ? true : false;
  this.safari = ((this.ua.indexOf('safari')!=-1)&&(this.ua.indexOf('mac')!=-1))?true:false;

// To test in your favorite browser here, put a browser test for it here and in the list below.  The example commented
// out below would add ie5.5 and higher to the list.  Take them out of both places before final implementation
//  this.ie55plus = (d.all && this.dom && window.createPopup) ? true : false;

// Add the old browsers that you want to hide divs for to the list below
//  this.hidingOn = (this.ie55plus || this.ie5 || this.ie4 || this.ns4 || this.op5 || this.op6) ? true : false;
  this.hidingOn = (this.safari||this.ie4 || this.ie5 || this.ns4 || this.op5 || this.op6) ? true : false;
}


// --------------------------------------
// May not be wise to mess with the rest!
// --------------------------------------

var mm_is = new snifBrowser();

function mm_hideDiv(divID, menuNames)
{
  if (!mm_divHidingEnabled || !mm_is.hidingOn) return;

  mm_setDivVisibility(divID, false);
  menuNames = menuNames.replace(/, /gi, ","); // remove a space after a comma
  functionStr   = "mm_reshowDiv('"  + divID + "','" + menuNames + "')";
  tID = setTimeout(functionStr, mm_initialDelay); // wait for menu to open
}

function mm_setDivVisibility(divID, state)
{
  if (document.layers && document.layers[divID]) { // ns4
    //document.layers[divID].visibility = state ? "show" : "hide";
	document.layers[divID].display = state ? "block" : "none";
  }
  else if (document.all && !document.getElementById && document.all(divID)) { // ie4
    //document.all[divID].style.visibility = state ? "visible" : "hidden";
	 document.all[divID].style.display = state ? "block" : "none";
  }
  else if (document.getElementById && document.getElementById(divID)) { // dom
  //document.getElementById(divID).style.visibility = state ? "visible" : "hidden";
  	document.getElementById(divID).style.display = state ? "block" : "none";
  }
}

function mm_isOpen(menuName)
{
  menuObj = gmobj("menu" + getMenuByName(menuName));
  if (document.layers) {
    return (menuObj.visibility == "show")
  }
  else {
    return (menuObj.style.visibility != "hidden");
  }
}

function mm_reshowDiv(divID, menuNames)
{
  var menusAreOpen  = false;
  var functionStr   = "mm_reshowDiv('"  + divID + "','" + menuNames + "')";
  var menuNameArr = menuNames.split(',');

  for (var i=0; i < menuNameArr.length; i++) {
    if (mm_isOpen(menuNameArr[i])) {
      menusAreOpen = true;
      setTimeout(functionStr, mm_reshowInterval);
      return;
    }
  }
  if (!menusAreOpen) mm_setDivVisibility(divID, true);
}

