// Frameset support. This finds the right window containing a PopupMenu object.
var scFr=window.PopupMenu?window:(parent.PopupMenu?parent:top);

// This runs functions for a list of PopupMenu objects.
// You pass it a string to evaluate in the context of a menu object (e.g. 'position()')
// and optionally a second parameter to eval that string for each menu in that object
// appearing in this frame (e.g. to position all frame menus on scroll etc.).
// You can use 'mN' which is the current menuName in eval'd strings for the page events.
function popEvt(str, each)
{
 var PML=scFr.PopupMenu.list, mN;
 for (var objName in PML) with (PML[objName])
 {
  if (scFr!=window && each) for (mN in menu) with (menu[mN][0])
  {
   if (par.substring(par.lastIndexOf('.')+1)==window.name) eval(str);
  }
  else eval(str);
 }
}

// Backup a whole load of page events, and get NS/Opera window sizes.
var scrFn, popOL=window.onload, popUL=window.onunload, popOR=window.onresize, popOS=window.onscroll,
 nsWinW=window.innerWidth, nsWinH=window.innerHeight, nsPX=window.pageXOffset, nsPY=window.pageYOffset;
document.popOC=document.onclick;


// Only run this next code if we've found the core menu script in this or a parent window!
if (scFr.PopupMenu)
{


// Import a local copy the 'page' object from the main menu window into this frame.
// I'm also grabbing isNS4 as it's used a lot here.
if (!window.page)
{
 var isNS4=scFr.isNS4, page=new Object();
 for (var f in scFr.page) page[f]=scFr.page[f];
 page.win=window;
}

// Import the menu names into this window, i.e. create window.pMenu = parent.pMenu;
popEvt('window[objName]=PML[objName]',0);


// PAGE EVENTS:
// Most functions here will set a page event, and run one of the backed up functions in the
// list above once the event fires (so when you mix this with other scripts, they work too).
// If you're really tweaking for speed, feel free to remove the backup code.


// MENU CREATION: We have creation modes on a per-browser basis, using the update() function.
// In non-NS4 browsers, we document.write() a menu by passing 'true' as the first parameter.
// In NS4, we have to create menus dynamically on page load completion using update(false,...);
// Other browsers like MSIE, NS6+, Op7+ also support dynamic mode, use it if you want.
// Dynamic mode is independent of script postion in the document (i.e. it can be in the HEAD).
// We also run our scrFn scroll-detector every 50ms and set an onunload to clear menus.
if (!isNS4) popEvt('update(true,mN)',1);
window.onload=function()
{
 if (popOL) popOL();
 if (isNS4) { popEvt('update(false,mN)',1); setInterval(scrFn,50) }
 window.onunload=new Function('if(popUL)popUL();popEvt("lyr=null",1)');
}

// WINDOW SCROLLING: In IE and some Moz versions window.onscroll works, so we capture that to
// call position(). In other browsers we have to create an interval to sniff the scroll position.
if (popOS||(''+popOS!='undefined'))
window.onscroll=function()
{
 if (popOS) popOS();
 popEvt('position(mN)',1);
}
else
{
 scrFn='if (nsPX!=pageXOffset || nsPY!=pageYOffset)' +
  '{nsPX=pageXOffset;nsPY=pageYOffset;popEvt("position(mN)",1)}';
 if (!isNS4) setInterval(scrFn,50);
}

// WINDOW RESIZE: NS4 and Opera 5/6 do horrible things on resize, so we check the window
// dimensions and reload this page/frame on window resize. Other browsers: call position().
// Opera 5/6 require a setInterval as they (stupidly!) don't support window.onresize().
function resizeBugCheck(){ if (nsWinW!=innerWidth || nsWinH!=innerHeight) location.reload() }
if (scFr.isOp&&!document.documentElement&&!window.opFix)
 window.opFix=setInterval('resizeBugCheck()',500);
window.onresize=function()
{
 if (popOR) popOR();
 if (isNS4) resizeBugCheck();
 popEvt('position(mN)',1);
}

// DOCUMENT CLICKING: Only required by NS4. Find which menu has been clicked.
if (isNS4)
{
 document.captureEvents(Event.CLICK);
 document.onclick=function(evt)
 {
  popEvt('if (overI) click(overM,overI)',0);
  return document.popOC?document.popOC(evt):document.routeEvent(evt);
 }
}


// End of 'if (scFr.PopupMenu)'
}
