// This is a hacked up version of:
// http://www.codestyle.org/javascript/dom/css/visibility-HorizontalMenus.shtml
// Copyright (c) 2001-2003, Philip Shaw
// This hack is by K. Chayka, at:
// http://accessat.c-net.us/articles/menu/h_drop-down-menu.html
// If you take the code, please give credit where it is due.  thanks!

//  customize these variables as needed
var mCount = 7;           // number of menu groups
var mTix   = "";          // main group link tabindex value (numeric, blank=none)
var sTix   = "";          // sub-menu link item tabindex value (numeric, blank=none)
var lSep   = " &#8226; "  // link separator (space-bullet-space) for legacy browsers
var sInd   = "&nbsp;<span><img src=\"darrow.gif\" height=\"9\" width=\"9\" alt=\"\"><\/span>"
                           // sub-menu indicator (small down arrow image)
                           // might also try &#9660; or &#8595; instead of img
var dbug = false;         // set to true to dump the generated code

//  variables below do not need customizing
var mOpen = null;         // currently open menu
var mClose = null;        // menu to close
var stdDOM = document.getElementById;
var dom = "";
var mStr = "";
var menu = new makeArray(mCount);

function makeArray(n) {
  this.size = n;
  for(i=1; i<=n; i++){
    this[i] = 0;
  }
  return(this);
}

// Top-level menu group/category constructor:
function menuGroup(n,groupName,groupURL,groupTitle,groupAkey) {
// I personally like the idea of the submenu indicator, but the Unicode characters 
// that would give desireable results are not supported in the standard Mac (Classic)
// fonts.  A small image might be substituted, but that is not scalable and doesn't
// look as good, IMO.  Uncomment the 'if' statement if you'd like to experiment with it.
  this.size       = n;             // number of submenu links
  this.groupName  = groupName;     // button 'label'
//  if (stdDOM && (n > 0)) { this.groupName += sInd; }  // submenu indicator
  this.groupURL   = groupURL;      // button URL
  this.groupTitle = groupTitle;    // title attribute
  this.groupAkey  = groupAkey;     // accesskey value
  this.item       = new makeArray(n);
}

// Submenu list item constructor:
function menuItem(itemName,itemURL,itemTitle) {
  this.itemName  = itemName;       // link label
  this.itemURL   = itemURL;        // link url
  this.itemTitle = itemTitle;      // title attribute
}

// ********** All the menu building starts here
// group[#] = new menuGroup(# submenu links, group label, URL, title, accesskey);
// group[#].submenuLink[#] = new menuItem(link label, URL, title);

// First menu
  menu[1] = new menuGroup(0,"Home","index.htm","Home","1"); // no submenu for this group
//////////////////////////////////////////////////////////////////////////////////////////////////////////
  // Second menu
  menu[2] = new menuGroup(6,"Optics","#","Go to the Optics page","2");
  menu[2].item[1] = new menuItem("Small Beam Collimators","small_beam_collimators.htm","Small Beam Collimators");
  menu[2].item[2] = new menuItem("Thales Polymer Optics","thales_polymer_optics.htm","Thales Polymer Optics");
//  menu[2].item[3] = new menuItem("Optical Systems","optical_systems.htm","Optical Systems","");
//  menu[2].item[4] = new menuItem("Coatings","coatings.htm","Coatings");
  menu[2].item[3] = new menuItem("Telecentric &amp; CCD Lenses","telecentric_CCD_lenses.htm","Telecentric &amp; CCD Lenses");
  menu[2].item[4] = new menuItem("Moulded Aspheric Lenses","moulded_aspheric_lenses.htm","Moulded Aspheric Lenses");
  menu[2].item[5] = new menuItem("Graded Index Lenses","graded_index_lenses.htm","Graded Index Lenses");
  menu[2].item[6] = new menuItem("Micro Optics","micro_optics.htm","Micro Optics");
//////////////////////////////////////////////////////////////////////////////////////////////////////////
  // Third menu
  menu[3] = new menuGroup(7,"Lasers","#","Go to the Laser page","3");
  menu[3].item[1] = new menuItem("Low Power CO2 Lasers","low_power_CO2_lasers.htm","Low Power CO2 Lasers");
  menu[3].item[2] = new menuItem("Fibre Lasers & High Power Pump Modules","fibre_lasers.htm","Fibre Lasers & High Power Pump Modules");
  menu[3].item[3] = new menuItem("ASE White Light Test Source","ase_white_light_test_source.htm","ASE White Light Test Source");
  menu[3].item[4] = new menuItem("High Power Laser diodes","high_power_laser_diodes.htm","High Power Laser diodes");
  menu[3].item[5] = new menuItem("SLED Light Source","sled.htm","SLED Light Source");
  menu[3].item[6] = new menuItem("DPSS Lasers","dpss_lasers.htm","DPSS Lasers");
  menu[3].item[7] = new menuItem("Laser Drivers","laser_drivers.htm","Laser Drivers");
//////////////////////////////////////////////////////////////////////////////////////////////////////////
  // Fourth menu
  menu[4] = new menuGroup(7,"Electro Optics","#","Go to the Electro Optics page","4");  
  // no titles or accesskey
//  menu[4].item[1] = new menuItem("Silicon Photodiodes","silicon_photodiodes.htm","");
  menu[4].item[1] = new menuItem("Opto-Hybrid Detectors &amp; Silicon Photodiodes","photodiodes_opto-Hybrid_detectors.htm","Opto-Hybrid Detectors &amp; Silicon Photodiodes");
  menu[4].item[2] = new menuItem("Acousto Optic Modulators","ao_modulators.htm","Acousto Optic Modulators");
  menu[4].item[3] = new menuItem("Acousto Optic Tunable Filters","ao_tunable_filters.htm","Acousto Optic Tunable Filters");
  menu[4].item[4] = new menuItem("Acousto Optic Deflectors","ao_deflectors.htm","Acousto Optic Deflectors");
  menu[4].item[5] = new menuItem("Dynamic Gain Flattening Filter","dynamic_gain_flattening_filter.htm","Dynamic Gain Flattening Filter");
  menu[4].item[6] = new menuItem("Reflectometer & Lossmeter","reflectometer_lossmeter.htm","Reflectometer & Lossmeter");
  menu[4].item[7] = new menuItem("Passive Components","passive_components.htm","Passive Components");
//////////////////////////////////////////////////////////////////////////////////////////////////////////  
  // Fifth menu
  menu[5] = new menuGroup(1,"Cryogenic Coolers","#","Go to the Fibre Optics page","5");  
  // no titles or accesskey
  menu[5].item[1] = new menuItem("Cryogenic Coolers","cryogenic_coolers.htm","Cryogenic Coolers");
//  menu[5].item[2] = new menuItem("Fibre Optic Collimators","fibre_optic_collimators.htm","Fibre Optic Collimators");
//  menu[5].item[3] = new menuItem("Moulded Aspheric Lenses","moulded_aspheric_lenses.htm","Moulded Aspheric Lenes");
//  menu[5].item[5] = new menuItem("Programable add/drops & VOAs","programable_add-drops_&_VOAs.htm","Programable add/drops & VOAs");
//  menu[5].item[6] = new menuItem("VOA Collimator","voa_collimator.htm","VOA Collimator");
//////////////////////////////////////////////////////////////////////////////////////////////////////////
  // Sixth menu
  menu[6] = new menuGroup(9,"Spectrometers","#","Go to the Spectrometers page","6");
  // no titles or accesskey
  menu[6].item[1] = new menuItem("Cooled CCD Spectrometer UV/VIS NIR","cooled_CCD_spectrometer_UV-VIS_NIR.htm","Cooled CCD Spectrometer UV/VIS NIR");
  menu[6].item[2] = new menuItem("Un-Cooled CCD Spectrometer","un-cooled_CCD_spectrometer.htm","UnCooled CCD Spectrometer");
  menu[6].item[3] = new menuItem("OEM Spectrometer","oem_spectrometer.htm","OEM Spectrometer");
  menu[6].item[4] = new menuItem("High Resolution Spectrometer","high_resolution_spectrometer.htm","High Resolution Spectrometer");
  menu[6].item[5] = new menuItem("IR Spectrometer","ir_spectrometer.htm","IR Spectrometer");
  menu[6].item[6] = new menuItem("2-D Spectrometer","2-D_spectrometer.htm","2-D Spectrometer");
  menu[6].item[7] = new menuItem("PbS IR Spectrometer","pbS_IR_spectrometer.htm","PbS IR Spectrometer");
  menu[6].item[8] = new menuItem("Laser for Raman Spectroscopy ","raman_spectroscopy.htm","Laser for Raman Spectroscopy");
  menu[6].item[9] = new menuItem("Spectrometer Accessories","spectrometer_accessories.htm","Spectrometer Accessories");
//////////////////////////////////////////////////////////////////////////////////////////////////////////
  // Seventh menu
  menu[7] = new menuGroup(4,"Contact","contact_us.htm","Contact Us","7");  
  // no titles or accesskey
  menu[7].item[1] = new menuItem("Enquiries Form","contact_us.htm","Contact Us");
  menu[7].item[2] = new menuItem("Supplier Links","supplier_links.htm","Supplier Links");
  menu[7].item[3] = new menuItem("Company Info","company_info.htm","Company Info");
  menu[7].item[4] = new menuItem("Join the Team","join_the_team.htm","Join the Team");

  // For W3C-compliant browsers, make divs for each group and lists for the drop-down menus.
  // For legacy browsers, include just the main links (delimited with lSep).

  for(i=1; i<=mCount; i++) {
    if (stdDOM) {
       mStr += "<div class=\"menugroup\" id=\"group" + i + "\">";  // start menu group container
    }
    mStr += "<a href=\"" + menu[i].groupURL + "\"";  // the main link for this group
    if (mTix) {                 // include tabindex if defined
      mStr += " tabindex=\"" + mTix + "\"";
    }
    if (menu[i].groupAkey) {    // include accesskey if defined
      mStr += " accesskey=\"" + menu[i].groupAkey + "\"";
    }
    if (menu[i].groupTitle) {   // include title attribute if defined
      mStr += "\n title=\"" + menu[i].groupTitle + "\"";
    }
    if (stdDOM) {              // extra goodies for W3C-compliant browsers
      mStr += " class=\"grouplink\"";
      if (menu[i].size > 0) {   // skip if no submenu
        mStr += "\n onmouseover=\"menuOver('menu" + i + "'); return true;\"";
        mStr += " onmouseout=\"menuOut('menu" + i + "'); return true;\"";
      }
    }
    mStr += ">" + menu[i].groupName + "<\/a>";
    if (stdDOM) {              // add the drop-down links for W3C-compliant browsers
      if (menu[i].size > 0) {  // skip if no submenu
        mStr += "\n<ul class=\"menu\" id=\"menu" + i + "\">\n";
        for(j=1; j<=menu[i].size; j++) {
          mStr += "<li><a href=\"" + menu[i].item[j].itemURL + "\"";
          if (sTix) {          // include tabindex if defined
            mStr += " tabindex=\"" + sTix + "\"";
          }
          if (menu[i].item[j].itemTitle) {  // include title attribute if defined
            mStr += "\n title=\"" + menu[i].item[j].itemTitle + "\"";
          }
          mStr += "\n onmouseover=\"stayOpen('menu" + i + "'); return true;\"";
          mStr += " onmouseout=\"menuOut('menu" + i + "'); return true;\">";
          mStr += menu[i].item[j].itemName;
          mStr += "<\/a><\/li>\n";
        }
        mStr +="<\/ul>";
      }
      mStr += "<\/div>\n";      // end menu group
    } else {
      if (i<mCount) {mStr += lSep + "\n";}      // for legacy browsers, add link separator
    }
  }
// *************** End menu building

if (dbug) {debugWindow(mStr);}  // see the generated code in a pop-up window

function debugWindow (val) { 
  var newWin = window.open("","dBug");
  newWin.document.write(val);
  newWin.document.close();
}

// *************** Functions called by mouseover/mouseout start here
// Mouseover a menu
function menuOver(m){
  if (!stdDOM) {return;}
  dom = document.getElementById(m);
  if (dom != null) {
    if (mOpen == dom) {       // already open
      clearTimeout(mClose);   // don't close
    } else {
      if (mOpen != null) {    // another is open
        clearTimeout(mClose);
        hideNow();            // close it now
      }
    }
  mOpen = dom;                // set new open menu
  mOpen.style.visibility = "visible";    // show it
}
}
// Keep menu open
function stayOpen(m){
  // If menuOver has not been called or the menu is hidden, do nothing
  if ((mOpen == null) || ((mOpen.style) && (mOpen.style.visibility) && (mOpen.style.visibility == "hidden"))) return;
  else menuOver(m);
}
// Close menu after timeout
function menuOut(m){
  dom = document.getElementById(m);
  if ((stdDOM) && (dom != null)) {
    mOpen = dom;	// get current open menu
    mClose = window.setTimeout("hideNow();",400);  // auto-close after 400ms
  }
}
// Close previous menu now
function hideNow(){
  if ((mOpen.style) && (mOpen.style.visibility)) {
    mOpen.style.visibility = "hidden";
  }
}

// the end -->