var menutxt = "";

menutxt += "@0 home.htm Home";
menutxt += "@0 history.htm History of the Society";
menutxt += "@1 history_early_years.htm The Early Years";
menutxt += "@1 history_first_century.htm The First 100 Years";
menutxt += "@1 history_centenary.htm Centenary Celebrations";
menutxt += "@0 committee.htm The Committee";
menutxt += "@0 patron.htm Our Patron";
menutxt += "@1 roy_hudd.htm Roy Hudd Drops In";
menutxt += "@0 previous_productions.htm Previous Productions";
menutxt += "@1 previous_1903_to_1950.htm 1903 to 1950";
menutxt += "@1 previous_1951_to_2000.htm 1951 to 2000";
menutxt += "@1 previous_2001_to_2005.htm 2001 to 2005";
menutxt += "@2 2001_pirates_of_penzance.htm The Pirates of<BR>Penzance";
menutxt += "@2 2001_south_pacific.htm South Pacific";
menutxt += "@2 2002_card.htm The Card";
menutxt += "@2 2002_gigi.htm Gigi";
menutxt += "@2 2003_hms_pinafore.htm HMS Pinafore";
menutxt += "@2 2003_crazy_for_you.htm Crazy For You";
menutxt += "@2 2004_mikado.htm The Mikado";
menutxt += "@2 2004_best_little_whorehouse.htm The Best Little<BR>Whorehouse in Texas";
menutxt += "@2 2005_kiss_me_kate.htm Kiss Me Kate";
menutxt += "@2 2005_a_funny_thing_happened.htm A Funny Thing<BR>Happened on the Way<BR>to the Forum";
menutxt += "@1 previous_2006_to_2010.htm 2006 to 2010";
menutxt += "@2 2006_rodgers_and_hart.htm Rodgers & Hart";
menutxt += "@2 2006_yeomen_of_the_guard.htm The Yeomen of the<BR>Guard";
menutxt += "@2 2007_annie_get_your_gun.htm Annie Get Your Gun";
menutxt += "@2 2008_iolanthe.htm Iolanthe";
menutxt += "@2 2008_42nd_street.htm 42nd Street";
menutxt += "@2 2008_merry_widow.htm The Merry Widow";
menutxt += "@2 2009_mame.htm Mame";
menutxt += "@2 2009_thoroughly_modern_millie.htm Thoroughly Modern<BR>Millie";
menutxt += "@2 2009_pirates_of_penzance.htm The Pirates of<BR>Penzance";
menutxt += "@2 2010_bitter_sweet.htm Bitter Sweet";
menutxt += "@2 2010_carousel.htm Carousel";
menutxt += "@0 recent_productions.htm Recent Productions";
menutxt += "@1 2011_beauty_and_the_beast.htm Disney's Beauty and<BR>The Beast";
menutxt += "@1 2011_strictly_musicals.htm Strictly Musicals!";
menutxt += "@1 2011_patience.htm Patience";
menutxt += "@0 future_productions.htm Future Productions";
menutxt += "@1 2012_follies.htm Follies";
menutxt += "@1 2012_half_a_sixpence.htm Half a Sixpence";
menutxt += "@1 2013_hot_mikado.htm Hot Mikado";
menutxt += "@1 2013_fiddler_on_the_roof.htm Fiddler On The Roof";
menutxt += "@0 join.htm Join the Society";
menutxt += "@0 friends.htm Become a Friend";
menutxt += "@0 fivehundred_club.htm The 500 Club";
menutxt += "@0 alan_holt_award.htm Alan Holt Award";
menutxt += "@0 links.htm Links";
menutxt += "@0 members.php Members' Page";
menutxt += "@1 rehearsals.php Rehearsal Schedule";
menutxt += "@1 directors.php Directors' Notes";
menutxt += "@1 downloads.php Downloads";
menutxt += "@1 fee_structure.php Fee Structure";
menutxt += "@1 social_events.php Social Events";
menutxt += "@1 newswatch.php News Watch";

var menu = menutxt.split("@");

var docurl = document.URL.replace(/\\/g, "/");
var referer = docurl.split("/");
var reqpage = referer[referer.length - 1].split("#")[0];

var lev = new Array(200), url = new Array(200), link = new Array(200), pclass = new Array(200), vis = new Array(200);
var mask, n, i, r, j, reqn, reqlev;

mask = /(\d) ([\w\.]*) (.*)/;
n = 0;
while (menu[n + 1])
{
  n++;
  lev[n] = menu[n].match(mask)[1];
  url[n] = menu[n].match(mask)[2];
  link[n] = menu[n].match(mask)[3];
  link[n] = link[n].replace(/<BR>/, "<br />");
  pclass[n] = '<p class="leftnav">';
  if (lev[n] > 0)
  {
    pclass[n] = pclass[n].replace(/leftnav/, "leftnav-");
    for (i = 1; i <= lev[n]; i++)
    {
      pclass[n] = pclass[n].replace(/-/, "-sub");
    }
  }
  vis[n] = false;
  if (url[n] == reqpage)
  {
    reqn = n;
    reqlev = lev[n];
  }
}

// embolden the selected menu item, and the start of each collapsible menu segment in which the selected element sits, back to the start of the menu
r = reqlev;
for (i = reqn; i >= 1; i--)
{
  if ((url[i] == reqpage) || (lev[i] < r))
  {
    pclass[i] = pclass[i].replace(/">/, '-on">');
    r = lev[i];
  }
}

// make visible each preceding menu item in the local group at the level of the selected item, as well as all menu items at progressively lower levels back to the start of the menu
r = reqlev;
for (i = reqn; i >= 1; i--)
{
  if ((r - lev[i] == 0) || (r - lev[i] == 1))
  {
    vis[i] = true;
    r = lev[i];
  }
}

// if the selected element is the start of a collapsible segment, display all elements of the segment at a level one higher than the selected element, but ignoring collapsible segments at higher levels
j = reqn + 1;
while (lev[j] > reqlev)
{
  if (lev[j] - reqlev == 1)
  {
    vis[j] = true;
  }
  j++;
}

// from the end of the collapsible segment (or the selected element if it doesn't start a collapsible segment), display all elements at a progressively lower level, to the end of the menu
r = reqlev;
for (i = j; i <= n; i++)
{
  if (r - lev[i] >= 0)
  {
    vis[i] = true;
    r = lev[i];
  }
}

for (i = 1; i <= n; i++)
{
  if (vis[i])
  {
    document.write (pclass[i] + '<a href="' + url[i] + '">' + link[i] + '</a></p>');
  }
}

