// Global root path for use with images:
///////////////////////////////////////
//var root_path = "/ESCXSLASP/";  // for use with local ASP Development Server
var root_path = "/XMLEdit/";  // for use with deployed website

// Global number for total menus:
///////////////////////////////////////
var totalmenus = 7;

// Global string for menu output:
///////////////////////////////////////
var menutxt = '';

// Global array for menu data:
///////////////////////////////////////
var menu = new makeArray(totalmenus);

// Custom array constructor,
// indexed from 1:
///////////////////////////////////////
function makeArray(n){
  this.size = n;
  for(i=1; i<=n; i++){
    this[i] = 0;
  }
  return(this);
}

function createImageTag( menuImage, altText )
{
		return( '<img src="'  + root_path        + 'images/' + menuImage.FileName + '" ' + 
						'alt="'       + altText          + '" ' +
						'width="'     + menuImage.Width  + '" ' +
						'height="'    + menuImage.Height + '" ' +
						'border="0">' );
}

// Menu group constructor:
///////////////////////////////////////
function menuObject(n,MenuTitle,MenuURL){
  this.size =       n;
  this.MenuTitle =  MenuTitle;
  this.MenuURL =    MenuURL;
  this.Bullet =     new makeArray(n);
}

// Menu item constructor:
///////////////////////////////////////
function bulletObject(BulletTitle,BulletURL){
  this.BulletTitle =  BulletTitle;
  this.BulletURL =    BulletURL;
}

// Define menus. Add new items by
// increasing menu bullets argument
// and adding a new indexed bullet
// object to the end of the list.
//
// Menu arguments:
// 1 = No. of bullets
// 2 = Menu title
// 3 = Menu URL

// Bullet arguments:
// 1 = Bullet title
// 2 = Bullet URL
///////////////////////////////////////

// First menu
////////////////////////////////////
menu[1] = new menuObject( 4, createImageTag( menu1_image, 'What&#39;s New' ), 'whatsnew.html' );
menu[1].Bullet[1] = new bulletObject('Trains&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;','whatsnew_trains.html');
menu[1].Bullet[2] = new bulletObject('Plastic&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;','whatsnew_plastic.html');
menu[1].Bullet[3] = new bulletObject('Die&nbsp;Cast&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;','whatsnew_diecast.html');
menu[1].Bullet[4] = new bulletObject('Other&nbsp;Neat&nbsp;Stuff&nbsp;','whatsnew_otherneatstuff.html');


// Second menu
////////////////////////////////////
menu[2] = new menuObject( 6, createImageTag( menu2_image, 'Trains' ), 'trains.html' );
menu[2].Bullet[1] = new bulletObject('N&nbsp;Scale&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;','trains_nscale.html');
menu[2].Bullet[2] = new bulletObject('HO&nbsp;Scale&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;','trains_hoscale.html');
menu[2].Bullet[3] = new bulletObject('Lionel&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;','trains_lionel.html');
menu[2].Bullet[4] = new bulletObject('K&nbsp;Line&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;','trains_kline.html');
menu[2].Bullet[5] = new bulletObject('Atlas&nbsp;O&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;','trains_atlas.html');
menu[2].Bullet[6] = new bulletObject('Other&nbsp;Related&nbsp;','trains_otherrelated.html');


// Third menu
///////////////////////////////////////
menu[3] = new menuObject( 5, createImageTag( menu3_image, 'Models' ), 'models.html' );
menu[3].Bullet[1] = new bulletObject('Planes&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;','models_planes.html');
menu[3].Bullet[2] = new bulletObject('Cars&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;','models_cars.html');
menu[3].Bullet[3] = new bulletObject('Armor&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;','models_armor.html');
menu[3].Bullet[4] = new bulletObject('Ships&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;','models_ships.html');
menu[3].Bullet[5] = new bulletObject('Other&nbsp;Related&nbsp;','models_otherrelated.html');


// Fourth menu
///////////////////////////////////////
menu[4] = new menuObject( 4, createImageTag( menu4_image, 'Rockets' ), 'rockets.html' );
menu[4].Bullet[1] = new bulletObject('Ready&nbsp;To&nbsp;Fly&nbsp;&nbsp;','rockets_readytofly.html');
menu[4].Bullet[2] = new bulletObject('Kits&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;','rockets_kits.html');
menu[4].Bullet[3] = new bulletObject('Accessories&nbsp;&nbsp;&nbsp;&nbsp;','rockets_accessories.html');
menu[4].Bullet[4] = new bulletObject('Other&nbsp;Related&nbsp;','rockets_otherrelated.html');


// Fifth menu
///////////////////////////////////////
menu[5] = new menuObject( 2, createImageTag( menu5_image, 'Metal Detectors' ), 'metaldetectors.html' );
menu[5].Bullet[1] = new bulletObject('Accessories&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;','metaldetectors_accessories.html');
menu[5].Bullet[2] = new bulletObject('Other&nbsp;Related&nbsp;&nbsp;','metaldetectors_otherrelated.html');

// Sixth menu
///////////////////////////////////////
menu[6] = new menuObject( 3, createImageTag( menu6_image, 'Thomas the Tank' ), 'thomasthetank.html' );
menu[6].Bullet[1] = new bulletObject('What&#39;s&nbsp;New!&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;','thomasthetank.html#whatsnew');
menu[6].Bullet[2] = new bulletObject('What&#39;s&nbsp;on&nbsp;Sale!&nbsp;&nbsp;','thomasthetank.html#whatsonsale');
menu[6].Bullet[3] = new bulletObject('Other&nbsp;Related&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;','thomasthetank.html#otherrelated');

menu[7] = new menuObject(0,'','');


// Compile the static menu headings:
///////////////////////////////////////
menutxt += '<div id="LinkBar">\n';
  for(i=1;i<=totalmenus;i++){
    menutxt += '<div id="Link' + i + '">\n';
    menutxt += '<a href="' + root_path + menu[i].MenuURL + '"';
    
    // Only compile the event handlers if able to handle them
    if(document.getElementById){// DOM1 compliant   
      menutxt += ' onmouseover="menuOver(\'Menu' + i + '\'); return true;"';
      menutxt += ' onmouseout="menuOut(\'Menu' + i + '\'); return true;"';
    }
    menutxt += '>' + menu[i].MenuTitle + '</a>';
    menutxt += '<\/div>\n';
  }
menutxt += '<\/div>\n';

// If DOM1 compliant, add the
// drop-down menus:
///////////////////////////////////////
if(document.getElementById){// DOM1 compliant
  menutxt += '<div id="MenuBar">\n';
  for(i=1;i<=totalmenus;i++){
    menutxt += '<div id="Menu' + i + '">\n';
    // Build the bullet list
    for(j=1;j<=menu[i].size;j++){
      menutxt += '<div id="MenuB' + j +'">\n';
      menutxt += '<a href="' + root_path + menu[i].Bullet[j].BulletURL + '"';
      menutxt += ' onmouseover="stayOpen(\'Menu' + i + '\'); return true;"';
      menutxt += ' onmouseout="menuOut(\'Menu' + i + '\'); return true;">';
      menutxt += menu[i].Bullet[j].BulletTitle;
      menutxt += '<\/a><BR>';
      menutxt += '<\/div>\n';
    }
    menutxt += '<\/div>\n';
  }
  menutxt += '<\/div>\n';
}

// Global menu element handle:
///////////////////////////////////////
var LiveMenu = null;

// Global menu timeout handle:
///////////////////////////////////////
var Timeout_ID = null;

// Opens or keeps open a given menu
// and shuts any previous menu:
///////////////////////////////////////
function menuOver(MenuID){
  // If DOM1 supported and element exists ...
  if((document.getElementById)&&(document.getElementById(MenuID)!=null)){
    // If this menu is already open ...
    if(LiveMenu==document.getElementById(MenuID)){
      // Do not close it
      clearTimeout(Timeout_ID);
    }
    // Another might still be open ...
    else{
      // If another menu is open ...
      if(LiveMenu!=null){
        // Do not wait, shut it now
        clearTimeout(Timeout_ID);
        hideNow();
      }
    }
    // This is the new 'live' menu, make it visible
    LiveMenu = document.getElementById(MenuID);
    // LiveMenu.style.visibility is
    // initially empty in IE5 until
    // it is assigned by these
    // functions, so must check that
    // it's not null before proceeding...
    if((LiveMenu.style)&&(LiveMenu.style.visibility!=null))
    {
      //LiveMenu.style.visibility = 'visible';
      WM_changeVisibility( MenuID, szVisible );
    }
  }
}

// Stops menu links from opening menu
// onmouseover when shut to
// workaround mouse events which are
// not hidden by z-index in Opera 4!
///////////////////////////////////////
function stayOpen(MenuID){
  // If menuOver has not been called or the menu is hidden, do nothing
  if((LiveMenu==null)||((LiveMenu.style)&&(LiveMenu.style.visibility)&&(LiveMenu.style.visibility=='hidden')))return;
  else menuOver(MenuID);
}

// Shuts a given menu in 250
// milliseconds, unless timeout is
// cleared by menuOver()
///////////////////////////////////////
function menuOut(MenuID){
  // If DOM1 supported and a menu is open ...
  if((document.getElementById)&&(document.getElementById(MenuID)!=null)){
    // Get the current live menu
    LiveMenu = document.getElementById(MenuID);
    // Prepare to shut it in 250 milliseconds
    Timeout_ID = window.setTimeout('hideNow();',250);
  }
}

// Called by menu handlers to shut
// previous menu immediately
///////////////////////////////////////
function hideNow(){
  if((LiveMenu.style)&&(LiveMenu.style.visibility)){
    LiveMenu.style.visibility = 'hidden';
  }
}

var isDOM = ( document.getElementById ? true : false );
var isIE4 = ( ( document.all && !isDOM ) ? true : false );
var isNS4 = ( document.layers ? true : false );

TrainsSubmenu					= "<span class=\"smalllinks\">Trains:&nbsp;"																			 +
													"<a href=\"" + root_path + "trains_nscale.html\">N Scale<\/a>&nbsp;|&nbsp;"    +
													"<a href=\"" + root_path + "trains_hoscale.html\">HO Scale<\/a>&nbsp;|&nbsp;"  +
													"<a href=\"" + root_path + "trains_lionel.html\">Lionel<\/a>&nbsp;|&nbsp;"		 +
													"<a href=\"" + root_path + "trains_kline.html\">K Line<\/a>&nbsp;|&nbsp;"			 +
													"<a href=\"" + root_path + "trains_atlas.html\">Atlas O<\/a>&nbsp;|&nbsp;"		 +
													"<a href=\"" + root_path + "trains_otherrelated.html\">Other Related<\/a>"		 +
												"<\/span>";

ModelsSubmenu					= "<span class=\"smalllinks\">Models:&nbsp;"																	 +
								 					"<a href=\"" + root_path + "models_planes.html\">Planes<\/a>&nbsp;|&nbsp;" + 
							 						"<a href=\"" + root_path + "models_cars.html\">Cars<\/a>&nbsp;|&nbsp;"     +
													"<a href=\"" + root_path + "models_armor.html\">Armor<\/a>&nbsp;|&nbsp;"   +
													"<a href=\"" + root_path + "models_ships.html\">Ships<\/a>&nbsp;|&nbsp;"   +
													"<a href=\"" + root_path + "models_otherrelated.html\">Other Related<\/a>" +
												"<\/span>";

RocketsSubmenu				= "<span class=\"smalllinks\">Rockets:&nbsp;"																							+
													"<a href=\"" + root_path + "rockets_readytofly.html\">Ready-to-Fly<\/a>&nbsp;|&nbsp;" +
													"<a href=\"" + root_path + "rockets_kits.html\">Kits<\/a>&nbsp;|&nbsp;"							  +
													"<a href=\"" + root_path + "rockets_accessories.html\">Accessories<\/a>&nbsp;|&nbsp;" +
													"<a href=\"" + root_path + "rockets_otherrelated.html\">Other Related<\/a>"					  +
												"<\/span>";

MetalDetectorsSubmenu = "<span class=\"smalllinks\">Metal Detectors:&nbsp;"																						 +
													"<a href=\"" + root_path + "metaldetectors_accessories.html\">Accessories<\/a>&nbsp;|&nbsp;" + 
													"<a href=\"" + root_path + "metaldetectors_otherrelated.html\">Other Related<\/a>"           +
			 								  "<\/span>";

WhatsNewSubmenu       = "<span class=\"smalllinks\">What&#39;s New in:&nbsp;"																+
													"<a href=\"" + root_path + "whatsnew_trains.html\">Trains<\/a>&nbsp;|&nbsp;"      +
													"<a href=\"" + root_path + "whatsnew_plastic.html\">Plastic<\/a>&nbsp;|&nbsp;"    +
													"<a href=\"" + root_path + "whatsnew_diecast.html\">Die-Cast<\/a>&nbsp;|&nbsp;"   +
													"<a href=\"" + root_path + "whatsnew_otherneatstuff.html\">Other Neat Stuff<\/a>" +
												"<\/span>";

function WriteMenuText()
{
  /*{
    title = "Menu Text";
		if( typeof displayWin == "undefined" || displayWin == null || displayWin.closed )
		{
			displayWin = window.open( "about:blank", "DisplayWindow", "resizable=yes,scrollbars=yes" );
			displayWin.document.write("<html><title>XML</title><body style=\"font:x-small 'Verdana';\"><nobr id=x>working...</nobr></body></html>\n");
		}
		else
  		displayWin.document.body.all("x").innerText = "working...";

		displayWin.document.title = title;

		displayWin.focus();
    displayWin.document.body.all("x").innerText = menutxt;
  }*/
	if( isDOM && menutxt && menutxt != '' )
  {
		AdjustPositioningVariables( document.images['topleft'] )
		document.write( menutxt );
    AdjustAndMakeVisible()
  }
}

function WriteSubMenuText( menu )
{
	if( menu != '' && menu != 'ESCnone' && (isIE4 || isNS4) )
		document.write( "<table width=\"100%\" cellpadding=\"10\" cellspacing=\"5\" border=\"0\">" +
                    "<tr><td valign=\"top\" class=\"smalllinks\" colspan=\"2\" align=\"left\">" + 
										 menu + 
										"<\/td><\/tr></table>" );
}

function AdjustAndMakeVisible()
{

    var obj;

    WM_changeVisibility( "LinkBar", szVisible );

    for( i = 1; i <= totalmenus; i++ )
    {
      obj = WM_checkIn( "Link" + i );
      obj.style.visibility = 'visible';
      //WM_changeVisibility( "Link" + i, szVisible );
    }


}