/* --------------------------------- */
/* Created:      2000-10-21          */
/* Issued:       2001-01-11          */
/* Modified:     2001-07-14          */
/* Copyright (c) 2001-2002 by        */
/* Philip Shaw, all rights reserved. */
/* --------------------------------- */

///////////////////////////////////////
// Successfully debugged for:        //
//   Mozilla                         //
//     M15                           //
//   Netscape                        //
//     3, 4.5, 6.0                   //
//   Internet Explorer               //
//     4.0 5.0, 5.5                  //
//   Opera                           //
//     3.62, 4.0, 5.0, 5.11. 6.0     //
///////////////////////////////////////

// See also:
// visibility-HorizontalMenuWriter.js

// Declare the number of menus
// N.B. Add menu IDs and adjust
// widths of divs in stylesheet:
// visibility-HorizontalMenus.css
///////////////////////////////////////

// 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);
}

// 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(0,'Home','index.htm');

// Second menu
///////////////////////////////////////
menu[2] = new menuObject(7,'About','about.htm');
menu[2].Bullet[1] = new bulletObject('Aims & Purposes','aimsandpurposes.htm');
menu[2].Bullet[2] = new bulletObject('Contact Details','contactdetails.htm');
menu[2].Bullet[3] = new bulletObject('Meet the Team','meettheteam.htm');
menu[2].Bullet[4] = new bulletObject('Situations Vacant', 'situationsvacant.htm');
menu[2].Bullet[5] = new bulletObject('Bournemouth YMCA History','bournemouthymcahistory.htm');
menu[2].Bullet[6] = new bulletObject('YMCA History','ymcahistory.htm');
menu[2].Bullet[7] = new bulletObject('Did You Know?', 'didyouknow.htm');

// Third menu
///////////////////////////////////////
menu[3] = new menuObject(6,'Accommodation','accommodation.htm');
menu[3].Bullet[1] = new bulletObject('Housing','housing.htm');
menu[3].Bullet[2] = new bulletObject('Hostel','hostel.htm');
menu[3].Bullet[3] = new bulletObject('Flats','flats.htm');
menu[3].Bullet[4] = new bulletObject('Move-On','moveon.htm');
menu[3].Bullet[5] = new bulletObject('Room Hire','roomhire.htm');
menu[3].Bullet[6] = new bulletObject('Sandyholme','sandyholme.htm');

// Fourth menu
///////////////////////////////////////
menu[4] = new menuObject(4,'Young People','youngpeople.htm');
menu[4].Bullet[1] = new bulletObject('Schools Work','schoolswork.htm');
menu[4].Bullet[2] = new bulletObject('Nursery','nursery.htm');
menu[4].Bullet[3] = new bulletObject('Fusion Youth Centre','fusionyouthcentre.htm');
menu[4].Bullet[4] = new bulletObject('Pokesdown Youth Club','pokesdownyouthclub.htm');

// Fifth menu
///////////////////////////////////////
menu[5] = new menuObject(3,'Health & Fitness','healthandfitness.htm');
menu[5].Bullet[1] = new bulletObject('Lifewise Fitness Centre','lifewisefitnesscentre.htm');
menu[5].Bullet[2] = new bulletObject('Membership & Fees','membershipandfees.htm');
menu[5].Bullet[3] = new bulletObject('Sports Hall','sportshall.htm');

// Sixth menu
///////////////////////////////////////
menu[6] = new menuObject(2,'Media','media.htm');
menu[6].Bullet[1] = new bulletObject('Hope FM','hopefm.htm');
menu[6].Bullet[2] = new bulletObject('Hands on Media','handsonmedia.htm');

// Sixth menu
///////////////////////////////////////
menu[7] = new menuObject(4,'Can you Help?','canyouhelp.htm');
menu[7].Bullet[1] = new bulletObject('Funding','funding.htm');
menu[7].Bullet[2] = new bulletObject('Volunteering','volunteering.htm');
menu[7].Bullet[3] = new bulletObject('Full Membership','fullmembership.htm');
menu[7].Bullet[4] = new bulletObject('Road Show','roadshow.htm');

// Compile the static menu headings:
///////////////////////////////////////
menutxt += '<div id="LinkBar">\n';
  for(i=1;i<=totalmenus;i++){
    menutxt += '\t<div id="Link' + i + '"';
    // Only compile the event handlers if able to handle them
    if(document.getElementById){// DOM1 compliant   
      menutxt += ' onmouseover="menuOver(\'Menu' + i + '\', \'Link' + i + '\'); return true;"';
      menutxt += ' onmouseout="menuOut(\'Menu' + i + '\'); return true;"';
    }
	 
	 //if(menu[i].Bullet.size == 0)
	 //{
    	menutxt += '><a href="' + menu[i].MenuURL + '"';
	 	menutxt += '>' + menu[i].MenuTitle + '</a>';
	 //}
	 //else
	 //{
	 //	menutxt += ' style="cursor: default;">' + menu[i].MenuTitle;
	 //}
	 
    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++)
  {
  	 // Only create the drop down menu if there are items for it
  	 if(menu[i].size > 0)
	 {
    menutxt += '<div id="Menu' + i + '"';
	 menutxt += ' onmouseover="stayOpen(\'Menu' + i + '\'); return true;"';
    menutxt += ' onmouseout="menuOut(\'Menu' + i + '\'); return true;">';

    // Build the bullet list
    for(j=1;j<=menu[i].size;j++){
      menutxt += '<div class="LinkSurround"><a href="' + menu[i].Bullet[j].BulletURL + '">';
      menutxt += menu[i].Bullet[j].BulletTitle;
      menutxt += '<\/a></div>';
    }
    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, LinkID){
  // 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))
	 {
	 	var MyLinkMenu = document.getElementById(LinkID);
		if (MyLinkMenu != null)
		 	LiveMenu.style.left = MyLinkMenu.offsetLeft + "px";
			
      LiveMenu.style.visibility = 'visible';
    }
  }
  else
  {
  	  // If another menu is open...
     if(LiveMenu!=null){
        // Do not wait, shut it now
        clearTimeout(Timeout_ID);
        hideNow();
	  }
  }
}

// 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';
  }
}
