

var isDOM = (document.getElementById ? true : false); 
var isIE4 = ((document.all && !isDOM) ? true : false);
var isNS4 = (document.layers ? true : false);
function getRef(id) {
if (isDOM) return document.getElementById(id);
if (isIE4) return document.all[id];
if (isNS4) return document.layers[id];
}
function getSty(id) {
return (isNS4 ? getRef(id) : getRef(id).style);
} 
// Hide timeout.
var popTimer = 0;
// Array showing highlighted menu items.
var litNow = new Array();
function popOver(menuNum, itemNum) {
clearTimeout(popTimer);
hideAllBut(menuNum);
litNow = getTree(menuNum, itemNum);
changeCol(litNow, true);
targetNum = menu[menuNum][itemNum].target;
if (targetNum > 0) {
thisX = parseInt(menu[menuNum][0].ref.left) + parseInt(menu[menuNum][itemNum].ref.left);
thisY = parseInt(menu[menuNum][0].ref.top) + parseInt(menu[menuNum][itemNum].ref.top);
with (menu[targetNum][0].ref) {
left = parseInt(thisX + menu[targetNum][0].x);
top = parseInt(thisY + menu[targetNum][0].y);
visibility = 'visible';
      }
   }
}
function popOut(menuNum, itemNum) {
if ((menuNum == 0) && !menu[menuNum][itemNum].target)
hideAllBut(0)
else
popTimer = setTimeout('hideAllBut(0)', 500);
}
function getTree(menuNum, itemNum) {

// Array index is the menu number. The contents are null (if that menu is not a parent)
// or the item number in that menu that is an ancestor (to light it up).
itemArray = new Array(menu.length);

while(1) {
itemArray[menuNum] = itemNum;
// If we've reached the top of the hierarchy, return.
if (menuNum == 0) return itemArray;
itemNum = menu[menuNum][0].parentItem;
menuNum = menu[menuNum][0].parentMenu;
   }
}

// Pass an array and a boolean to specify colour change, true = over colour.
function changeCol(changeArray, isOver) {
for (menuCount = 0; menuCount < changeArray.length; menuCount++) {
if (changeArray[menuCount]) {
newCol = isOver ? menu[menuCount][0].overCol : menu[menuCount][0].backCol;
// Change the colours of the div/layer background.
with (menu[menuCount][changeArray[menuCount]].ref) {
if (isNS4) bgColor = newCol;
else backgroundColor = newCol;
         }
      }
   }
}
function hideAllBut(menuNum) {
var keepMenus = getTree(menuNum, 1);
for (count = 0; count < menu.length; count++)
if (!keepMenus[count])
menu[count][0].ref.visibility = 'hidden';
changeCol(litNow, false);
}

// *** MENU CONSTRUCTION FUNCTIONS ***

function Menu(isVert, popInd, x, y, width, overCol, backCol, borderClass, textClass) {
// True or false - a vertical menu?
this.isVert = isVert;
// The popout indicator used (if any) for this menu.
this.popInd = popInd
// Position and size settings.
this.x = x;
this.y = y;
this.width = width;
// Colours of menu and items.
this.overCol = overCol;
this.backCol = backCol;
// The stylesheet class used for item borders and the text within items.
this.borderClass = borderClass;
this.textClass = textClass;
// Parent menu and item numbers, indexed later.
this.parentMenu = null;
this.parentItem = null;
// Reference to the object's style properties (set later).
this.ref = null;
}

function Item(text, href, frame, length, spacing, target) {
this.text = text;
this.href = href;
this.frame = frame;
this.length = length;
this.spacing = spacing;
this.target = target;
// Reference to the object's style properties (set later).
this.ref = null;
}

function writeMenus() {
if (!isDOM && !isIE4 && !isNS4) return;

for (currMenu = 0; currMenu < menu.length; currMenu++) with (menu[currMenu][0]) {
// Variable for holding HTML for items and positions of next item.
var str = '', itemX = 5, itemY = 170;

// Remember, items start from 1 in the array (0 is menu object itself, above).
// Also use properties of each item nested in the other with() for construction.
for (currItem = 1; currItem < menu[currMenu].length; currItem++) with (menu[currMenu][currItem]) {
var itemID = 'menu' + currMenu + 'item' + currItem;

// The width and height of the menu item - dependent on orientation!
var w = (isVert ? width : length);
var h = (isVert ? length : width);

// Create a div or layer text string with appropriate styles/properties.
// the width must be a miniumum of 3 for it to work in that browser.
if (isDOM || isIE4) {
str += '<div id="' + itemID + '" style="position: absolute; left: ' + itemX + '; top: ' + itemY + '; width: ' + w + '; height: ' + h + '; visibility: inherit; ';
if (backCol) str += 'background: ' + backCol + '; ';
str += '" ';
}
if (isNS4) {
str += '<layer id="' + itemID + '" left="' + itemX + '" top="' + itemY + '" width="' +  w + '" height="' + h + '" visibility="inherit" ';
if (backCol) str += 'bgcolor="' + backCol + '" ';
}
if (borderClass) str += 'class="' + borderClass + '" ';

// Add mouseover handlers and finish div/layer.
str += 'onMouseOver="popOver(' + currMenu + ',' + currItem + ')" onMouseOut="popOut(' + currMenu + ',' + currItem + ')">';

// Add contents of item (default: table with link inside).
// In IE/NS6+, add padding if there's a border to emulate NS4's layer padding.
// If a target frame is specified, also add that to the <a> tag.

str += '<table width="' + (w - 8) + '" border="0" cellspacing="0" cellpadding="' + (!isNS4 && borderClass ? 3 : 0) + '"><tr><td align="left" height="' + (h - 7) + '">' + '<a class="' + textClass + '" href="' + href + '"' + (frame ? ' target="' + frame + '">' : '>') + text + '</a></td>';
if (target > 0) {

// Set target's parents to this menu item.
menu[target][0].parentMenu = currMenu;
menu[target][0].parentItem = currItem;

// Add a popout indicator.
if (popInd) str += '<td class="' + textClass + '" align="right">' + popInd + '</td>';
}
str += '</tr></table>' + (isNS4 ? '</layer>' : '</div>');
if (isVert) itemY += length + spacing;
else itemX += length + spacing;
}
if (isDOM) {
var newDiv = document.createElement('div');
document.getElementsByTagName('body').item(0).appendChild(newDiv);
newDiv.innerHTML = str;
ref = newDiv.style;
ref.position = 'absolute';
ref.visibility = 'hidden';
}

// Insert a div tag to the end of the BODY with menu HTML in place for IE4.
if (isIE4) {
document.body.insertAdjacentHTML('beforeEnd', '<div id="menu' + currMenu + 'div" ' + 'style="position: absolute; visibility: hidden">' + str + '</div>');
ref = getSty('menu' + currMenu + 'div');
}

// In NS4, create a reference to a new layer and write the items to it.
if (isNS4) {
ref = new Layer(0);
ref.document.write(str);
ref.document.close();
}

for (currItem = 1; currItem < menu[currMenu].length; currItem++) {
itemName = 'menu' + currMenu + 'item' + currItem;
if (isDOM || isIE4) menu[currMenu][currItem].ref = getSty(itemName);
if (isNS4) menu[currMenu][currItem].ref = ref.document[itemName];
   }
}
with(menu[0][0]) {
ref.left = x;
ref.top = y;
ref.visibility = 'visible';
   }
}


var menu = new Array();

// Default colours passed to most menu constructors (just passed to functions, not
// a global variable - makes things easier to change later in bulk). for N.M. #ccccff is background color #cc99ff rollover color for 2nd and other level of menu
var defOver = '#C5C9CD', defBack = '#EEEFF0';

// Default 'length' of menu items - item height if menu is vertical, width if horizontal.
var defLength = 30;

// Menu 0 is the special, 'root' menu from which everything else arises.
menu[0] = new Array();
// A non-vertical menu with a few different colours and no popout indicator, as an example.
// *** MOVE ROOT MENU AROUND HERE ***  it's positioned at (5, 0) and is 20px high now.
menu[0][0] = new Menu(true, '>', 5, 0, 120, '#F0F1F1', '#DCDDDF', '', 'itemText');
// Notice how the targets are all set to nonzero values...
// The 'length' of each of these items is 120, and there is spacing of 1 to the next item.

menu[0][1] = new Item('  Company ', 'http://www.appliedmagnettechnology.com/company/company.htm', '', 20, 1, 1);
menu[0][2] = new Item('  Partners ', 'http://www.appliedmagnettechnology.com/company/partners.htm', '', 20, 1, 2);
menu[0][3] = new Item('  Services ', 'http://www.appliedmagnettechnology.com/service/services.htm', '', 20, 1, 3);
menu[0][4] = new Item('  Products ', 'http://www.appliedmagnettechnology.com/products/products.htm', '', 20, 1, 4);
menu[0][5] = new Item('  Technologies ', 'http://www.appliedmagnettechnology.com/tech/technologies.htm', '', 20, 1, 5);
menu[0][6] = new Item('  Contact Us ', 'http://www.appliedmagnettechnology.com/contacts/contacts.htm', '', 20, 1, 0);
menu[0][7] = new Item('  Site Map ', 'http://www.appliedmagnettechnology.com/sitemap/sitemap.htm', '', 20, 1, 0);

// Company menu.
menu[1] = new Array();
// for N.M. The File menu is positioned 115px across and -160 down from its trigger, and is 150 wide.
// All text in this menu has the stylesheet class 'item' -- see the <style> section above.

menu[1][0] = new Menu(true, '>', 115, -170, 160, defOver, defBack, 'itemBorder', 'itemText');
menu[1][1] = new Item('About Us', 'http://www.appliedmagnettechnology.com/company/about_us.htm', '', defLength, 0, 0);
menu[1][2] = new Item('What We Are Doing Differently ', 'http://www.appliedmagnettechnology.com/company/doing_differently.htm', '', defLength, 0, 0);
menu[1][3] = new Item('International Engineering Company ', 'http://www.appliedmagnettechnology.com/company/engineering_company.htm', '', defLength, 0, 0);
menu[1][4] = new Item('AMT Management ', 'http://www.appliedmagnettechnology.com/company/amt_management.htm', '', defLength, 0, 6);
menu[1][5] = new Item('Company Policy ', 'http://www.appliedmagnettechnology.com/company/company_policy.htm', '', defLength, 0, 0);

// Partners menu
menu[2] = new Array();
menu[2][0] = new Menu(true, '>', 115, -170, 160, defOver, defBack, 'itemBorder', 'itemText');
menu[2][1] = new Item('Manufacturers ', 'http://www.appliedmagnettechnology.com/company/manufacturers.htm', '', defLength, 0, 10);
menu[2][2] = new Item('R&D Centers ', 'http://www.appliedmagnettechnology.com/company/randdcen.htm', '', defLength, 0, 7);
menu[2][3] = new Item('Individuals ', 'http://www.appliedmagnettechnology.com/company/individs.htm', '', defLength, 0, 8);
menu[2][4] = new Item('Consultants ', 'http://www.appliedmagnettechnology.com/company/consultants.htm', '', defLength, 0, 9);

// Services menu
menu[3] = new Array();
menu[3][0] = new Menu(true, '>', 115, -170, 160, defOver, defBack, 'itemBorder', 'itemText');
menu[3][1] = new Item('Pilot supply of samples', 'http://www.appliedmagnettechnology.com/services/pilot_scale.htm', '', defLength, 0, 0);
menu[3][2] = new Item('Metrology and testing', 'http://www.appliedmagnettechnology.com/services/metrology.htm', '', defLength, 0, 0);
menu[3][3] = new Item('Designing, simulation, prototyping', 'http://www.appliedmagnettechnology.com/services/designing.htm', '', defLength, 0, 0);
menu[3][4] = new Item('Searching suppliers of unique materials', 'http://www.appliedmagnettechnology.com/services/searching_suppliers.htm', '', defLength, 0, 0);
menu[3][5] = new Item('Consulting', 'http://www.appliedmagnettechnology.com/services/consulting.htm', '', defLength, 0, 0);
menu[3][6] = new Item('R&D', 'http://www.appliedmagnettechnology.com/randd/randdprj.htm', '', defLength, 0, 0);

// Products menu
menu[4] = new Array();
menu[4][0] = new Menu(true, '>', 115, -400, 160, defOver, defBack, 'itemBorder', 'itemText');
menu[4][1] = new Item('AlNiCo magnets', 'http://www.appliedmagnettechnology.com/products/alnico_magnets.htm', '', defLength, 0, 0);
menu[4][2] = new Item('FeCrCo magnets ', 'http://www.appliedmagnettechnology.com/products/fecrco_magnets.htm', '', defLength, 0, 0);
menu[4][3] = new Item('Ferrit/iron powders ', 'http://www.appliedmagnettechnology.com/products/ferrite_powders.htm', '', defLength, 0, 0);
menu[4][4] = new Item('NdFeB powders ', 'http://www.appliedmagnettechnology.com/products/ndfeb_powders.htm', '', defLength, 0, 0);
menu[4][5] = new Item('Ready-to-use compounds ', 'http://www.appliedmagnettechnology.com/products/compounds.htm', '', defLength, 0, 0);
menu[4][6] = new Item('NdFeB sintered magnets ', 'http://www.appliedmagnettechnology.com/products/ndfeb_sintered_magnets.htm', '', defLength, 0, 0);
menu[4][7] = new Item('SmCo magnets ', 'http://www.appliedmagnettechnology.com/products/smco_magnets.htm', '', defLength, 0, 0);
menu[4][8] = new Item('Ferrite magnets ', 'http://www.appliedmagnettechnology.com/products/ferrite_magnets.htm', '', defLength, 0, 0);
menu[4][9] = new Item('NdFeB bonded magnets ', 'http://www.appliedmagnettechnology.com/products/based_on_ndfeb.htm', '', defLength, 0, 0);
menu[4][10] = new Item('Ferrite bonded magnets ', 'http://www.appliedmagnettechnology.com/products/based_on_srferrites.htm', '', defLength, 0, 0);
menu[4][11] = new Item('Electric engineering products ', 'http://www.appliedmagnettechnology.com/products/machines.htm', '', defLength, 0, 0);
menu[4][12] = new Item('Thyratron motors ', 'http://www.appliedmagnettechnology.com/products/thyratron.htm', '', defLength, 0, 0);
menu[4][13] = new Item('Software ', 'http://www.appliedmagnettechnology.com/products/software.htm', '', defLength, 0, 0);
menu[4][14] = new Item('Customized devices and system ', 'http://www.appliedmagnettechnology.com/products/custom_magnets.htm', '', defLength, 0, 0);
menu[4][15] = new Item('Magnet based lifters ', 'http://www.appliedmagnettechnology.com/products/permanent_lifters.htm', '', defLength, 0, 0);
menu[4][16] = new Item('Smart devices ', 'http://www.appliedmagnettechnology.com/products/smart_devices.htm', '', defLength, 0, 0);

// Technology menu
menu[5] = new Array();
menu[5][0] = new Menu(true, '>', 115, -270, 160, defOver, defBack, 'itemBorder', 'itemText');
menu[5][1] = new Item('Rapid-solidification of powders ', 'http://www.appliedmagnettechnology.com/tech/rapidquenched_powders.htm', '', defLength, 0, 0);
menu[5][2] = new Item('Single crystal Alnico ', 'http://www.appliedmagnettechnology.com/tech/single_crystal.htm', '', defLength, 0, 0);
menu[5][3] = new Item('Magnetic pseudo-liquids ', 'http://www.appliedmagnettechnology.com/tech/pseudo_liquid.htm', '', defLength, 0, 0);
menu[5][4] = new Item('Spherical magnets ', 'http://www.appliedmagnettechnology.com/tech/spherical_magnets.htm', '', defLength, 0, 0);
menu[5][5] = new Item('Corrosion protection ', 'http://www.appliedmagnettechnology.com/tech/corrosion_protection.htm', '', defLength, 0, 0);
menu[5][6] = new Item('Others ', 'http://www.appliedmagnettechnology.com/tech/technologies.htm', '', defLength, 0, 0);

// Company/AMT Management menu.
menu[6] = new Array();
menu[6][0] = new Menu(true, '>', 150, -170, 160, defOver, defBack, 'itemBorder', 'itemText');
menu[6][1] = new Item('J. DuPlessis ', 'http://www.appliedmagnettechnology.com/company/dupless.htm', '', defLength, 0, 0);
menu[6][2] = new Item('H. Gerber ', 'http://www.appliedmagnettechnology.com/company/howard.htm', '', defLength, 0, 0);
menu[6][3] = new Item('Yu. Rabinovich ', 'http://www.appliedmagnettechnology.com/company/rabinovi.htm', '', defLength, 0, 0);

// Partners/RD menu
menu[7] = new Array();
menu[7][0] = new Menu(true, '>', 145, -270, 160, defOver, defBack, 'itemBorder', 'itemText');
menu[7][1] = new Item('Bochvar Institute', 'http://www.appliedmagnettechnology.com/company/bochvar.htm', '', defLength, 0, 0);
menu[7][2] = new Item('Electrotechnical Institute', 'http://www.appliedmagnettechnology.com/company/electrotechnical.htm', '', defLength, 0, 0);
menu[7][3] = new Item('Institute of metal physics', 'http://www.appliedmagnettechnology.com/company/metal_physics.htm', '', defLength, 0, 0);
menu[7][4] = new Item('Moscow Power Engineering Institute', 'http://www.appliedmagnettechnology.com/company/power_engineering.htm', '', defLength, 0, 0);
menu[7][5] = new Item('Institute of Super Hard Materials', 'http://www.appliedmagnettechnology.com/company/hard_materials.htm', '', defLength, 0, 0);
menu[7][6] = new Item('Magnetest', 'http://www.appliedmagnettechnology.com/company/magnetest.htm', '', defLength, 0, 0);
menu[7][7] = new Item('Net-Shape', 'http://www.appliedmagnettechnology.com/company/netshape.htm', '', defLength, 0, 0);
menu[7][8] = new Item('Polytechnika Czestohowska', 'http://www.appliedmagnettechnology.com/company/polytechnika.htm', '', defLength, 0, 0);

// Partners/Individuals menu
menu[8] = new Array();
menu[8][0] = new Menu(true, '>', 145, -400, 160, defOver, defBack, 'itemBorder', 'itemText');
menu[8][1] = new Item('Bala, Henryk', 'http://www.appliedmagnettechnology.com/company/bala.htm', '', defLength, 0, 0);
menu[8][2] = new Item('Ermolenko, Alexander', 'http://www.appliedmagnettechnology.com/company/ermolenko.htm', '', defLength, 0, 0);
menu[8][3] = new Item('Gerber, Howard', 'http://www.appliedmagnettechnology.com/company/howard.htm', '', defLength, 0, 0);
menu[8][4] = new Item('Tulchinsky, Leonid', 'http://www.appliedmagnettechnology.com/company/tulchink.htm', '', defLength, 0, 0);
menu[8][5] = new Item('Kurbatov, Pavel', 'http://www.appliedmagnettechnology.com/company/kurbatov.htm', '', defLength, 0, 0);
menu[8][6] = new Item('Lukin, Alexander', 'http://www.appliedmagnettechnology.com/company/lukin.htm', '', defLength, 0, 0);
menu[8][7] = new Item('Maystrenko, Anatoly', 'http://www.appliedmagnettechnology.com/company/maystrenko.htm', '', defLength, 0, 0);
menu[8][8] = new Item('Nesterin, Valeri', 'http://www.appliedmagnettechnology.com/company/nesterin.htm', '', defLength, 0, 0);
menu[8][9] = new Item('Pawlowska, Grazina', 'http://www.appliedmagnettechnology.com/company/pawlowska.htm', '', defLength, 0, 0);
menu[8][10] = new Item('Pierson, Edward S', 'http://www.appliedmagnettechnology.com/company/pierson.htm', '', defLength, 0, 0);
menu[8][11] = new Item('Podolsky, Igor', 'http://www.appliedmagnettechnology.com/company/podolsky.htm', '', defLength, 0, 0);
menu[8][12] = new Item('Rabinovich, Yuri', 'http://www.appliedmagnettechnology.com/company/rabinovi.htm', '', defLength, 0, 0);
menu[8][13] = new Item('Sokolov, Vladislav', 'http://www.appliedmagnettechnology.com/company/sokolov.htm', '', defLength, 0, 0);
menu[8][14] = new Item('Szymura, Stefan', 'http://www.appliedmagnettechnology.com/company/szymura.htm', '', defLength, 0, 0);
menu[8][15] = new Item('Kolesnichenko, Anastasia', 'http://www.appliedmagnettechnology.com/company/kolesnic.htm', '', defLength, 0, 0);

// Partners/Consultants menu
menu[9] = new Array();
menu[9][0] = new Menu(true, '', 145, -200, 160, defOver, defBack, 'itemBorder', 'itemText');
menu[9][1] = new Item('Buchin, Gregory', 'http://www.appliedmagnettechnology.com/company/buchin.htm', '', defLength, 0, 0);;
menu[9][2] = new Item('DuPlessis, John', 'http://www.appliedmagnettechnology.com/company/dupless.htm', '', defLength, 0, 0);
menu[9][3] = new Item('Fenix Technology Inc.', 'http://www.appliedmagnettechnology.com/company/fenixtec.htm', '', defLength, 0, 0);
menu[9][4] = new Item('IBTI', 'http://www.appliedmagnettechnology.com/company/ibti.htm', '', defLength, 0, 0);
menu[9][5] = new Item('Zoglmann, Robert', 'http://www.appliedmagnettechnology.com/company/zoglmann.htm', '', defLength, 0, 0);

// Partners/Manufacturing menu
menu[10] = new Array();
menu[10][0] = new Menu(true, '', 145, -350, 160, defOver, defBack, 'itemBorder', 'itemText');
menu[10][1] = new Item('ATLIS', 'http://www.appliedmagnettechnology.com/company/atlis.htm', '', defLength, 0, 0);
menu[10][2] = new Item('AvtoElectronica', 'http://www.appliedmagnettechnology.com/company/avtoele.htm', '', defLength, 0, 0);
menu[10][3] = new Item('Cheboksary Electric Apparatus Plant', 'http://www.appliedmagnettechnology.com/company/cheboksa.htm', '', defLength, 0, 0);
menu[10][4] = new Item('ELMAG', 'http://www.appliedmagnettechnology.com/company/elmag.htm', '', defLength, 0, 0);
menu[10][5] = new Item('AvtoPribor', 'http://www.appliedmagnettechnology.com/company/avtoprib.htm', '', defLength, 0, 0);
menu[10][6] = new Item('ELMAT', 'http://www.appliedmagnettechnology.com/company/elmatpm.htm', '', defLength, 0, 0);
menu[10][7] = new Item('FERROCERAM', 'http://www.appliedmagnettechnology.com/company/ferrocer.htm', '', defLength, 0, 0);
menu[10][8] = new Item('MAGNETON', 'http://www.appliedmagnettechnology.com/company/magneton.htm', '', defLength, 0, 0);
menu[10][9] = new Item('MAGNIT', 'http://www.appliedmagnettechnology.com/company/magnit.htm', '', defLength, 0, 0);
menu[10][10] = new Item('Magnets and Magnetic Technologies', 'http://www.appliedmagnettechnology.com/company/magnets.htm', '', defLength, 0, 0);
menu[10][11] = new Item('NAUKA-M', 'http://www.appliedmagnettechnology.com/company/naukam.htm', '', defLength, 0, 0);
menu[10][12] = new Item('SPETSMAGNIT', 'http://www.appliedmagnettechnology.com/company/spetsmagn.htm', '', defLength, 0, 0);
menu[10][13] = new Item('Yuhong Magnetic Powder Corporation', 'http://www.appliedmagnettechnology.com/company/yuhongco.htm', '', defLength, 0, 0);



// These two lines handle the window resize bug in NS4. See <body onResize="...">.
// I recommend you leave this here as otherwise when you resize NS4's width menus are hidden.

var popOldWidth = window.innerWidth;
nsResizeHandler = new Function('if (popOldWidth != window.innerWidth) location.reload()');


// This is a quick snippet that captures all clicks on the document and hides the menus
// every time you click. Use if you want.

if (isNS4) document.captureEvents(Event.CLICK);
document.onclick = clickHandle;

function clickHandle(evt)
{
 if (isNS4) document.routeEvent(evt);
 hideAllBut(0);
}


// This is just the moving command for the example.

function moveRoot()
{
 with(menu[0][0].ref) left = ((parseInt(left) < 100) ? 100 : 5);
}
