
// *** (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)');
}






// *** (5) FRAMESETS ***
//
// Non-frameset users can delete this block of comments if you want. Frameset users, this
// explains what extra code you need to get the menu script to cross over frames. Before you
// go any further, head back to my site and download the prebuilt frameset example from the
// FAQ on the Popup Menu page on my site (scroll down), it will save you a lot of tweaking.
//
// This menu supports frames with a few extensions. Firstly, this script must be located in the
// frameset file. The subframes you use must have all the needed CSS info from the <STYLE> tag
// included in them. I have also moved the above 'Events' section into the subframes along with
// some extra code. I've set up the frameset example using JS and CSS files, so load that up now.
//
// With the SUBFR.JS file, all you have to do is make sure that in the first line pMenu points to
// the correct pMenu -- that is, located within that frame's parent (this script). If you're using
// multiple menu objects across frames, set them up there in the subframe Events lines similar to
// the way I indicated in the comments above in this script. If you're nesting one frameset within
// another, panic, then alter 'parent' to 'top' or similar, or hire me to do the project :).
//
// This file also allows the menus in sub-frames scroll with their windows. All you have to do is
// use the page object in that frame in a formula for the positions of a menu, e.g. for a menu in
// a frame named 'xyz', we would set it to appear in that frame and appear near the top and 100px
// from the left:
//
// startMenu('menuName', false, 'xyz.page.scrollX()+100', 'xyz.page.scrollY()+10', 17, hBar, 'xyz');
//
// Of course, third-level menus in other frames can be positioned relative to their parents
// normally. (Remember: strings as positions mean 'absolute' and are calculated as formulae,
// numbers as positions mean 'relative', offset from its parent).
//    Finally, you'll want to specify target frames for each menu item, in the same fashion as
// you specified them for the menus themselves -- by default URLs will open in the window in
// which the script is located, the topmost frameset.





// *** (6) OPTIONAL CODE ***   DELETE IF YOU'RE NOT USING THESE!
//
// If you want, you can assign functions to handle mouse events like mouse over/out/click.
// You'll want to use these for assigning click actions to 'sm:' items or status messages etc.
// 'with (this)' means use the properties of the menu object, like overM and overI which
// are the current menu name and item number.
// To uncomment and activate, delete the /* and */ at the start and end.

/*
pMenu.onclick = function() { with (this)
{
 // Do actions depending on the item that the mouse was over at the time of the click.
 // You may with to use nested IFs or 'switch' statements etc. if you're familiar with JS.
 if (overM == 'root' && overI == 1) status = 'Congratulations, you\'ve mastered clicking!';
 if (overM == 'root' && overI == 2) location.href = 'edit.html';
}}

// Set the status message to the URL if the 'action type' is nothing, and clear on mouseout.
pMenu.onmouseover = function() { with (this)
{
 // By now, you either have my JS Object Browser script from my site or you need it... try
 // embedding in an IFrame and typing 'pMenu' into its Go To field to see the menu internals.
 with (menu[overM][overI]) if (!type) status = href;
}}
pMenu.onmouseout = function() { status = '' }
*/



// This illustrates changing the contents of the menu -- delete this, it's unnecessary...
// This DOES NOT WORK in Opera yet (as of v6.00 at time of writing) by the way.
function changeMenu() { with (pMenu)
{
 // If your modifications are quite extensive, probably hide the menu before commencing
 // them, as the script relies on the menu array in realtime to handle highlighting etc.
 //over('root', 0);
 //menu.root[0].lyr.vis('hidden');

 // Create a whole new menu...
 startMenu('mNewMenu', true, 0, 22, 130, subM);
 addItem('<b>TwinHelix Designs:</b><br>Extreme DHTML.<br>Small Code.<br>Click to Visit...',
  'window.open("http://www.twinhelix.com")', 'js:', subM, 70);

 // Alter just the 'Visit My Site' menu item to pop it out... setting nextItem tells the
 // addItem() command which item number we are up to in the sequence.
 actMenu = 'root';
 nextItem = 4;
 addItem('&nbsp; Dynamism...', 'mNewMenu', 'sm:', hBar, 80);

 // Call the update function to implement our changes.
 update();
}}


// This is just the moving command called when you click the feature list.
function moveRoot()
{
 with (pMenu.menu.root[0].lyr) x( (x()<100) ? 100 : 10);
}


// End Hide -->
//</SCRIPT>
//<!-- *** STOP EDITING HERE - END OF MENU SECTION *** -->
