// THIS SECTION CREATES/DEFINES ALL MENU ELEMENTS FOR PAGE.
//
// Functions Defined:
// styleName = new ItemStyle(length of items, spacing to next item, 'popout indicator HTML',
//   popout indicator position, padding of text within item, 'out background colour or image',
//   'over background colour or image', 'out text stylesheet class', 'over text class',
//   'out border stylesheet class', 'over border class');
//
// 'horizontal Bar' style: items are 40px long, 10px between, no popout indicator or popout
//   indicator position, 0px padding within items, a transparent background '', a hover colour
//   of #669999, 'itemText' is the class used for the menu text both normally and highlighted,
//   and no border class. See the '<style>' section below for the classes used...

var hBar = new ItemStyle(40, 10, '', 0, 0, '', '696969', 'itemText', 'itemHover', '', '');

// The 'sub Menu' items: 22px long, 0px spacing, a 'greater than' sign for a popout indicator
// (you may wish to use an image tag?), the popout indicator is positioned 15px from the right
// edge of the item, items have 3px padding, some colours, it uses 'itemText' as the dimmed text
// class but 'itemHover' when it is moused over, and 'itemBorder' as the border stylesheet class.
//var subM = new ItemStyle(22, 0, '&gt;', -15, 3, '#BEBEBE', '#333366', 'itemText', 'itemHover','itemBorder', 'itemBorder');
var subM = new ItemStyle(22, 0, '&gt;', -15, 3, '#BEBEBE', '#696969', 'itemText', 'itemHover','itemBorder', 'itemBorder');

// The purplish 'crazy' style, same length but extra 1px spacing (to show up the fancy border) and
// different colours/text and less padding.
var crazy = new ItemStyle(22, 1, '&gt;', -15, 2, '#666699', '#CC6600', 'crazyText', 'crazyHover','crazyBorder', 'crazyBorderOver');

// The first menu for each menu object you create must always be named 'root'.
// Functions Defined:
// startMenu('menu name', Vertical menu? (true/false), left, top, width, default ItemStyle,
//   optional parent frame/window or layer in which this menu resides);
//   Vertical Menu setup, which is a 'true' or 'false' without quotes passed as the second 
//     parameter to startMenu(). Pass 'true' is you want that menu to
//     be vertical, or 'false' to have a horizontal bar (like the root menu below).
//   The 'width' depends on the orientation of the menu -- for vertical menus it's the width,
//     for horizontal menus it is the height. Basically, it's the dimension constant for all the 
//     items. The parent window or layer parameter is optional, if not specified the current 
//     window is used -- this example does not use frames. See the FRAMESET README below if 
//     you're using them.
// addItem('Text', 'URL', 'action type', optional ItemStyle, length, spacing to next item,
//   'popout indicator HTML', popout indicator position);
//   Items themselves are passed 3 compulsory parameters -- the text to display in the
//     item, the action or URL the item has when clicked, and the type of the action/target frame.
//   All other parameters are optional -- you can override the menu's default ItemStyle with the
//     item's own, and optionally override that was well with its own dimensions/popout indicator.
//   The 'action type' needs explaining. This tells the script what to do with the URL. You
//     leave this a blank string '' to open the URL in the current window -- the default action.
//     Or, you can set this to 'js:' to specify that the URL is a JavaScript function that gets
//     executed when the item is clicked. Thirdly, you can pass a string containing a valid
//     reference to a window/frame from the window/frameset in which this script is located,
//     e.g. 'top.leftFrame' or 'parent.popupWin', to make the URL load in there when clicked --
//     think of 'parent.main' as similar to <a target="main">.
//   Most importantly, you pass 'sm:' to specify that the URL is the name of a submenu to pop
//     out when moused over. See the example below if this seems complicated, it's quite easy 
//     once you get the hang of it. Thanks to Martin J. Cole for originally suggesting the syntax!
//
// If you want more information, there's a FAQ (Frequently Asked Questions) section on my
// site: http://www.twinhelix.com, on the 'Popup Menus' page.

// A PopupMenu() object must be passed its own name so it can reference itself when the menu
// is active. We also use a 'with' block to work with its properties and functions below.
var pMenu = new PopupMenu('pMenu');
with (pMenu)
{
// *** MOVE OR CENTRE THE MENU HERE ***
// The 'root' menu is horizontal, positioned at (x = 10, y = 0) and is 17px high, and items
// by default use the colours and dimensions in the 'hBar' ItemStyle defined above.
// To centre it, or scroll with the window etc, just include a global variable as one of the
// positions -- this script includes 'winWidth', 'winHeight', 'scrollYpos' and 'scrollXpos'.
//startMenu('root', false, 'winWidth/2 - 120', 'scrollYpos', 17, hBar); // Centres & floats.
//startMenu('root', false, 10, 0, 17, hBar, 'frameName'); // To create in subframe.
startMenu('root', false, 10, 1, 17, hBar);

// The text is a space then 'File', and this item pops out the 'mFile' submenu when moused over
// as we've set 'sm:' as the action type. If you want to assign an action (i.e. navigating to
// a file) to one of these 'sm:' items, see the 'Optional Code' section below.
addItem('&nbsp; File', 'mFile', 'sm:', hBar, 55);

// Next is an example of a Javascript function embedded in the menu, to open a new window...
// Also extra optional parameters at the end -- ItemStyle and longer length.
// To open a file in a frame named 'main' we would use the following syntax:
// addItem('Text', 'file.html', 'parent.main');
// If this is a frameset file, pass 'window.main' or similar as the target, as the frames are
// located in this window not its parent frameset window.
//addItem('&nbsp; About', 'window.open("http://156.123.66.245")', 'js:', hBar, 50);
// This is a vertical menu positioned 0px across and 22px down from its trigger, and is 80px wide.

startMenu('mFile', true, 0, 22, 60, subM);
addItem('&nbsp; Close', 'window.close()', 'js:');


// Popout slightly left of its trigger
// Instead of using spaces to indent, consider a special text stylesheet in an ItemStyle?
// startMenu('mReports', true, -10, 22, 120, subM);

// You can also assign hide or show delays (in milliseconds) to the menus. Defaults are:
//showDelay = 0;
//hideDelay = 500;
// Specify hideDelay as zero if you want to disable hiding.

// End of 'with (menu Object)' block. That's one menu object created, now activate it...
}

// Finally, we handle some global events, calling the proper functions for each menu (or
// other script, e.g. my DHTML Scroller) that needs to be notified of these events.
// Make sure there is no BODY ONLOAD="..." tag in the document, it overrides these!
// Back up the onload event in case other scripts use it. You may wish to use the same
// technique to back up some of the other events captured here.
var popOldOL = window.onload;

// One note: We call pMenu.update() on load to create the menus. Optionally, pass it the name
// of one menu, e.g. pMenu.update("root") to create only that menu -- the others are created
// as needed. This is good for very large menus, use if you want.
window.onload = new Function('if (popOldOL) popOldOL(); updateVars(); pMenu.update()');
window.onresize = new Function('ns4BugCheck(); updateVars(); pMenu.position()');
window.onscroll = new Function('updateVars(); pMenu.position()');

if (isNS4) document.captureEvents(Event.CLICK);
document.onclick = new Function('evt', 'pMenu.click(); ' +
 'if (isNS4) return document.routeEvent(evt)');

// Manage window sizing and scrolling variables for you to use in positioning formulae.
// These aren't strictly necessary, you may wish to add some more?
var winWidth, winHeight, scrollYpos, scrollXpos;
function updateVars()
{
 winWidth = (isIE ? document.body.clientWidth : window.innerWidth);
 winHeight = (isIE ? document.body.clientHeight : window.innerHeight);
 scrollYpos = (isIE ? document.body.scrollTop : window.pageYOffset);
 scrollXpos = (isIE ? document.body.scrollLeft : window.pageXOffset);
}

// A small function that refreshes NS4 on horizontal resize, called above.
var origWinWidth = window.innerWidth;
function ns4BugCheck()
{
 if (isNS4 && origWinWidth != window.innerWidth) location.reload()
}

// Activate the onscroll event for NS browsers.
if (!isIE) setInterval('if (scrollYpos!=pageYOffset || scrollXpos!=pageYOffset) ' +
 'window.onscroll()', 50);

// This is just the moving command called when you click the feature list.
moveRoot = new Function('with(pMenu.menu.root[0].lyr) x( (x()<100) ? 100 : 5);');

