




// *** (3) EVENTS ***
//
// In JavaScript, there are document 'events' you need to set so any scripts you are using
// are notified of things like page loading/clicking/scrolling. If you've got several menus
// or another JavaScript entirely in your page, you'll need to add all their functions in here.
// For another menu object, call its functions like update() and position() next to pMenu's.
//    The reason for these is that every time you set them, they override a previous setting.
// So make sure you collate all the functions that need to be called in here! Syntax:

//object.onevent = function()
//{
// function1();
// function2();
// ...
//}

// That's similar to: <BODY ONEVENT="function1(); function2(); function3()...">


// The most important event is one used to display the menu by calling one of several methods of
// any menu object(s) you have created. This is where you select the menu creation mode. 'Dynamic'
// mode inserts the menus into the document once it has finished loading and supports features
// like modifying the menu after creation. You create a 'Dynamic' mode menu by just calling the
// .update() method of a menu object like 'pMenu'.
//    'Fast' creation mode writes the menus to the document here and now, which is faster and
// more reliable in older browsers but doesn't allow those fancy tricks -- you do this by passing
// 'true' without quotes to the update function to signal that we're inline.
//    Opera only supports Fast mode and Netscape 4 is only reliable in Dynamic mode, so we use
// browser-detect code here. If you find some browser has troubles with one mode or another, try
// the other menu creation method -- see the "Cross-Browser" code at the very top of the <SCRIPT>
// tag for the variables used.

if (!isNS4)
{
 // Write menus now in non-NS4 browsers, by calling the "Fast" mode .update(true) method.
 pMenu.update(true);
 //anotherMenu.update(true);
}
else
{
 // For Netscape 4, back up the old onload function and make a new one to update our menus.
 // This is the regular "Dynamic" mode menu update, it works in IE and NS6 too.
 var popOldOL = window.onload;
 window.onload = function()
 {
  if (popOldOL) popOldOL();
  pMenu.update();
  //anotherMenu.update();
 }
}


// Other events must be assigned, these are less complicated, just add or remove menu objects.

window.onresize = function()
{
 ns4BugCheck();
 pMenu.position();
 //anotherMenu.position();
}

window.onscroll = function()
{
 pMenu.position();
 //anotherMenu.position();
}

if (isNS4) document.captureEvents(Event.CLICK);
document.onclick = function(evt)
{
 pMenu.click();
 //anotherMenu.click();
 if (isNS4) return document.routeEvent(evt);
}


// A small function that refreshes NS4 on window resize to avoid bugs, called above.
var nsWinW = window.innerWidth, nsWinH = window.innerHeight;
function ns4BugCheck()
{
 if (isNS4 && (nsWinW!=innerWidth || nsWinH!=innerHeight)) location.reload()
}

// Activate the useful 'onscroll' event for non-Microsoft browsers.
if (!isIE || window.opera)
{
 var nsPX=pageXOffset, nsPY=pageYOffset;
 setInterval('if (nsPX!=pageXOffset || nsPY!=pageYOffset) ' +
 '{ nsPX=pageXOffset; nsPY=pageYOffset; window.onscroll() }', 50);
}





// *** (4) ANIMATION ***
//
// Each menu object you create by default shows and hides its menus instantaneously.
// However you can override this behaviour with custom show/hide animation routines.
// I have included an example clipping animation below. Feel free to edit it, or delete
// this entire section if you don't like the animation to turn it off.
//   If you've created several menu objects, you must assign the animation functions to
// each of them to override the default if you want them all to animate. Also note that not
// all browsers can clip happily, such as Opera, so they don't have these functions assigned.

// This is the clipping animation function. Customisers: My lyr.clip() command gets passed the
// parameters (x1, y1, x2, y2) so you might want to adjust the direction etc. Oh, and I'm
// adding 2 to the dimensions to be safe due to different box models in some browsers.
// Another idea: add some if/thens to test for specific menu names...?
function menuClip(menuObj, menuName, dir)
{
 // The array index of the named menu (e.g. 'mFile') in the menu object (e.g. 'pMenu').
 var mD = menuObj.menu[menuName][0];
 // Add timer and counter variables to the menu data structure, we'll need them.
 if (!mD.timer) mD.timer = 0;
 if (!mD.counter) mD.counter = 0;
 with (mD)
 {
  // Stop any existing animation.
  clearTimeout(timer);
  // If the layer doesn't exist (cross-frame navigation) quit.
  if (!lyr || !lyr.ref) return;
  // Show the menu if that's what we're doing.
  if (dir==1) lyr.vis('visible');
  // Also raise showing layers above hiding ones.
  lyr.sty.zIndex = 1001 + dir;
  // Clip the visible area. Tweak this if you want to change direction/acceleration etc.
  lyr.clip(0, 0, menuW+2, (menuH+2)*Math.pow(Math.sin(Math.PI*counter/20),0.75) );
  // Increment the counter and if it hasn't reached the end (10 steps either way) set the timer.
  // Clear the clipping value in DOM browsers as early NS6 versions are quite terrible at this.
  counter += dir;
  if (counter==11) { counter = 10; if (isDOM&&!isIE) lyr.sty.clip='' }
  else if (counter<0) { counter = 0; lyr.vis('hidden') }
  else timer = setTimeout(menuObj.myName+'.'+(dir==1?'show':'hide')+'Menu("'+menuName+'")', 40);
 }
}


// Add the effect to the 'pMenu' menu object for supported browsers. Opera doesn't support clipping
// so we turn it off, neither does IE4/Mac.
if (!window.opera)
{
 pMenu.showMenu = new Function('mN','menuClip(pMenu, mN, 1)');
 pMenu.hideMenu = new Function('mN','menuClip(pMenu, mN, -1)');
 // Add it to other menu objects like this...
 //anotherMenu.showMenu = new Function('mN','menuClip(anotherMenu, mN, 1)');
 //anotherMenu.hideMenu = new Function('mN','menuClip(anotherMenu, mN, -1)');
}
