

var activeMenu = null;
var currentMenu = null;
var timeOutVal = null;
var timeOutVal2 = null;
var imagesLoaded = false;
var currHigh = '';
var delayTime = 500;
var onMain = false;

if (isNavigator && isDHTML)
{ onResize = reloadPage(true);
  document.captureEvents(Event.MOUSEOVER, Event.MOUSEOUT);
}

function initMouse()
{ for (thisLayer in myLayers)
    if (thisLayer.indexOf("Menu") != -1)
    { with (myLayers[thisLayer])
      { currLayer.onmouseout = checkActive;
        currLayer.onmouseover = setActive;
        if (objGetZIndex() == 0)
          objSetZIndex(30 + menusList[thisLayer].menuLevel);
        else
          objSetZIndex(objGetZIndex() +  menusList[thisLayer].menuLevel);
      }
    }
    menusLoaded = true;
    //alert(menusLoaded);
}

function loadImage(fileName)
{ newImage = new Image();
  newImage.src = fileName;
  //alert(fileName);
  return newImage;
}

function indicatorObj(on, off, width, height)
{ this.on = on;
  this.off = off;
  this.width = width;
  this.height = height;
}



function preloadImages()
{ //alert("In preload");
  if(document.images) 
   {
    ind_on = loadImage(image_folder + indicator.on);
    ind_off = loadImage(image_folder + indicator.off);


// ---------------------------------------------------------------------------------------------------------------------------------------------------
// CUSTOMIZABLE AREA (don't change anything outside this area unless you're sure about it.)
// ---------------------------------------------------------------------------------------------------------------------------------------------------
   
// ----------------------------------------------------------------
// drop-down menu buttons
// ----------------------------------------------------------------

    about_off = loadImage(image_folder + "buttons/about_off.gif");
    about_on = loadImage(image_folder + "buttons/about_on.gif");
   
    messages_off = loadImage(image_folder + "buttons/messages_off.gif");
    messages_on = loadImage(image_folder + "buttons/messages_on.gif"); 
   
    programs_off = loadImage(image_folder + "buttons/programs_off.gif");
    programs_on = loadImage(image_folder + "buttons/programs_on.gif");
    
    prayer_off = loadImage(image_folder + "buttons/prayer_off.gif");
    prayer_on = loadImage(image_folder + "buttons/prayer_on.gif");

    members_off = loadImage(image_folder + "buttons/members_off.gif");
    members_on = loadImage(image_folder + "buttons/members_on.gif");


// ---------------------------------------------------------------------------------------------------------------------------------------------------
// END CUSTOMIZABLE AREA
// ---------------------------------------------------------------------------------------------------------------------------------------------------

    imagesLoaded = true;
    //alert(imagesLoaded);
  }
}





function changeImage(imageIn, imageSrc)
{  //alert(imageIn.width + " " + menuLayer.offsetLeft);
if (!imagesLoaded || !document.images)
    return;

  currImage = eval("document." + imageIn);
  if (!currImage)
  { if (isNavigator)
    { var foundImage = false;
      for (i = 0; 1 < document.layers.length; i++)
      { currImage = eval("document.layers[" + i + "].document." + imageIn);
        if (currImage)
        { foundImage = true;
          break
        }
      }
      if (!foundImage)
        return;
    }
    else
      return;
  }
  currImage.src = eval(imageSrc + ".src");
  //alert(currImage.src);
}

function initMenu(id)
{ this.id = id;
  this.prev = null;
  this.next = null;
  //alert(id);
}	

function CTO(timeIn)
{
  clearTimeout(timeIn);
  return null;
}

function showMenu(whichLayer)
{ 
  if (activeMenu != null)
  { 
    if (isInActiveList(whichLayer))
    { timeOutVal2 = CTO(timeOutVal2);
      clearCurrent();
      clearSubs(whichLayer);
      currentMenu = activeMenu;
      activeMenu = activeMenu.prev;
      currentMenu.prev = null;
      if (activeMenu != null)
        activeMenu.next = null;
    }
    else
    {
      timeOutVal2 = CTO(timeOutVal2);
      clearCurrent();
      if (menusList[whichLayer].menuLevel == 0)
        clearSubs();

      createCurrent(whichLayer);
    }
    
  }
  else
  { 
    if (currentMenu != null)
    { 
      if (currentMenu.id.name == whichLayer)
      { timeOutVal = CTO(timeOutVal);
      }
      else
      {
        clearCurrent();
      }
    }
    
    createCurrent(whichLayer);
    
  }
}

function createCurrent(whichLayer)
{ 
  currentMenu = new initMenu(myLayers[whichLayer]);
  //alert(currentMenu.id);
  if (menusList[whichLayer].left != currentMenu.id.objGetLeft())
  { 
    currentMenu.id.objSetLeft(menusList[whichLayer].left);
    currentMenu.id.objSetTop(menusList[whichLayer].top);
  }
  
  currentMenu.id.objShow();
  
}

function initCheckMenu()
{ timeOutVal = setTimeout("clearCurrent()", delayTime);
}

function clearCurrent()
{ timeOutVal = CTO(timeOutVal);
  if (currentMenu != null)
  { currentMenu.id.objHide();
    currentMenu = null;
  }
  if (activeMenu == null && !onMain)
    clearHighlight();
}

function clearCurrent2(whichLayer)
{ if (currentMenu == null)
    return;

  if (currentMenu.id.name == whichLayer)
    timeOutVal = CTO(timeOutVal);
  else
    clearCurrent();
}

function checkActive()
{ if (!onMain)
    timeOutVal2 = setTimeout("hideMenu()", 20);
}

function setActive()
{ if (timeOutVal2 != null)
  { timeOutVal2 = CTO(timeOutVal2);
  }

  if (activeMenu != null && this.id == activeMenu.id.name)
    return;

  if (isInActiveList(this.id))
  { if (currentMenu != null)
      clearCurrent();
    clearSubs(this.id);
  }
  else
  { if (currentMenu != null)
    { if (currentMenu.id.name == this.id)
      { timeOutVal = CTO(timeOutVal);
        if (activeMenu != null)
        { activeMenu.next = currentMenu;
          currentMenu.prev = activeMenu;
          activeMenu = currentMenu;
          currentMenu = null;
        }
        else
        { activeMenu = currentMenu;
          currentMenu = null;
        }
      }
    }
  }
}

function isInActiveList(checkThis)
{ var isInList = false;

  tempList = activeMenu;
  if (tempList == null)
    return isInList;

  while(tempList.next != null)
    tempList = tempList.next;

  while(tempList != null)
  { if (tempList.id.name == checkThis)
    { isInList = true;
      break;
    }
    tempList = tempList.prev;
  }
  return isInList;
}

function hideMenu(keepShowing)
{ timeOutVal2 = CTO(timeOutVal2);

  if (currentMenu != null)
  { clearCurrent();
  }

  if (activeMenu != null)
  { clearSubs(keepShowing);
  }
  
  if (activeMenu == null)
    clearHighlight();
}

function clearHighlight(keepHigh)
{ if (currHigh != "" && currHigh != null && currHigh != keepHigh)
    changeImage(currHigh, currHigh + "_off");
  currHigh = keepHigh;
  //alert(menusLoaded + " " + currHigh);
}

function clearSubs(clearTo)
{ if (activeMenu != null)
  { while (activeMenu.next != null)
      activeMenu = activeMenu.next;
  
    while (activeMenu != null && activeMenu.id.name != clearTo)
    { activeMenu.id.objHide();
      activeMenu = activeMenu.prev;
      if (activeMenu != null)
        activeMenu.next = null;
    }  
  }
}




function openWin(fileIn, width, height)
{ window.open(fileIn,'BellSouth','toolbar=no,width=' + width + ',height=' + height + ',left=0,top=0,status=no,scrollbars=no,resize=no');
  return false;
}

function openWin2(fileIn, width, height)
{ Scenarios = window.open(fileIn,'Scenarios','toolbar=yes,width=' + width + ',height=' + height + ',left=0,top=0,status=yes,scrollbars=yes,resize=yes');
  Scenarios.focus();
  return false;
}

function openExtFrames(btm) {
  // open external page in bottom frame of  frameset.html
  var theURL = main_folder + "frameset.html?ext=" + btm;
  window.open(theURL,'tcframe','toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes');
  return false;
}

function openSmWin(btm) {
  // open page in small window (alerts, errors, etc.)
  var theURL = main_folder + "frameset_small.html?ext=" + btm;
  window.open(theURL,'smWin','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=400,height=300');
  return false;
}



function reloadPage(init)
{  //reloads the window if Nav4 resized
  if (init == true)
  { document.pageW = innerWidth;
    document.pageH = innerHeight;
    onresize = reloadPage;
  }
  else if (innerWidth != document.pageW || innerHeight != document.pageH)
    location.reload();
}

