// global variables
// Horizontal menu variables
var hsmenu01 = new Array("Looking");
var hsmenu02 = new Array("Corporate Sponsorship", "Individual Donations", "Special Event Sponsorship", "Friendship Donations");
var hsmenu03 = new Array("Off Stage", "Backstage", "On Stage");
var hsmenu04 = new Array();

var hslink01 = new Array("Looking");
var hslink02 = new Array("SupportUsCorporate", "SupportUsIndividual", "SupportUsSpecialEvent", "SupportUsFriendship");
var hslink03 = new Array("OffStage", "Backstage", "OnStage");
var hslink04 = new Array();

var hsmenuArray = new Array(hsmenu01, hsmenu02, hsmenu03, hsmenu04);
var hslinkArray = new Array(hslink01, hslink02, hslink03, hslink04);

// Vertical menu variables
var buttonLabel = new Array("Home", "About Us", "Biographies", "Mandate and Values");
var buttonSource = new Array("index", "", "Biographies", "");

var vmenu01 = new Array();
var vmenu02 = new Array("Mission Statement", "Profile", "Our Conception", "Background");
var vmenu03 = new Array("Board of Directors", "Operating Officers", "Talented Members");
var vmenu04 = new Array("Mandate", "Values");

var vlink01 = new Array();
var vlink02 = new Array("MissionStatement", "Profile", "OurConception", "Background");
var vlink03 = new Array("BoardOfDirectors", "Officers", "General");
var vlink04 = new Array("Mandate", "Values");

var menuArray = new Array(vmenu01, vmenu02, vmenu03, vmenu04);
var linkArray = new Array(vlink01, vlink02, vlink03, vlink04);

var bodyWidth=800;
var headerHeight=178;
var buttonWidth=200;
var buttonHeight=30;
var timeoutLimit=1500;

var flyout;
var mousex;
var mousey;
var menuOn = false;
var windowWidth = 0;
var windowHeight = 0;
var topEdgeOffset = 0;
var topEdgeHMenuOffset = 0;
var leftEdgeOffset = 0;
var leftEdgeHMenuOffset = 0;

var isIE = false;
var isFF = false;

function establishBrowser() {  //***** determines type of browser, windowWidth, windowHeight and calculates the topEdgeOffset for buttons
//  document.write(navigator.appName.indexOf("Netscape")+" "+navigator.appName.indexOf("Internet Explorer"));

  if (navigator.appName.indexOf("Internet Explorer") >= 0) {
    isIE = true;
    isFF = false;
    windowWidth = document.body.offsetWidth;
    windowHeight = document.body.offsetsHight;
    topEdgeOffset = headerHeight+12;
    topEdgeHMenuOffset = -2;
    leftEdgeOffset = (windowWidth - bodyWidth) / 2;
    leftEdgeHMenuOffset = leftEdgeOffset-2;
  } else {
    isFF = true;
    isIE = false;
    windowWidth = window.innerWidth;
    windowHeight = window.innerHeight;
    topEdgeOffset = headerHeight+4;
    topEdgeHMenuOffset = 0;
    leftEdgeOffset = (windowWidth - bodyWidth) / 2;
    leftEdgeHMenuOffset = leftEdgeOffset+0;
  }

} //+++++ establishBrowser

function initMouseEvents(e) {  //***** update the current mouse position
  document.onMousemove = getMouseXY; // update(event) implied on NS, update(null) implied on IE
  getMouseXY(e); // NS is passing (event), while IE is passing (null)
} //+++++ initMouseEvents

function getMouseXY(e) { //***** gets the coordinates of the mouse.  Works on IE6, FF, Moz, Opera7
  if (!e) e = window.event; // works on IE, but not NS (we rely on NS passing us the event)

  if (e) { 
    if (e.pageX || e.pageY) { // this doesn't work on IE6!! (works on FF, Moz, Opera7)
      mousex = e.pageX;
      mousey = e.pageY;
    } else if (e.clientX || e.clientY) { // works on IE6,FF,Moz,Opera7
      mousex = e.clientX + document.body.scrollLeft;
      mousey = e.clientY + document.body.scrollTop;
    } 
  }
} //+++++ getMouseXY

function getQueryStringParameter( paramName ) { //***** gets the value of 'paramName' defined in the URL
  qryString = window.location.search.substring(1);
  items = qryString.split("&");

  for ( i = 0; i < items.length; i++ ) {
    aItem = items[i].split("=");
    if ( aItem[0] == paramName ) {
      return aItem[1];
    }
  }

  return null;
} //+++++ getQueryStringParameter

function goToAnchor() { //***** jumps to the prodCatagory anchor tag
  anchor=getQueryStringParameter("prodCatagory");

  if (anchor == null) {
    anchor = "topOfPage";
  }

  temp="#"+anchor;
  window.location.href=temp;
} //+++++ goToAnchor

function hideSubmenu(mNum, timeOff) {  //***** hides flyout menu for button number 'mNum'
  divTag=top.document.getElementById("flyOutMenu");
  flyout = setTimeout('divTag.innerHTML=""',timeOff);
  divTag.style.width="0";
  divTag.style.height="0";
/*  divTag.zIndex="0";
*/  menuOn = false;
} //+++++ hideSubmenu

function showHSubmenu(hmNum, hmPosition) {  //***** display flyout menu for button number'vmNum'
//  alert("x="+mousex+" y="+mousey);
//  document.write(leftEdgeOffset);
//  document.write(windowWidth+" "+windowHeight+"<br></br>");
//  document.write(navigator.appName.indexOf("Netscape")+" "+navigator.appName.indexOf("Internet Explorer"));
  establishBrowser();
//  var menuYPos= 	(hmNum * (buttonHeight)) + topEdgeOffset + "px";  //(mousey).toString(10)+"px";
  var menuYPos=		8 + topEdgeOffset + topEdgeHMenuOffset + "px"
//  var menuXPos=		buttonWidth + 1 + leftEdgeOffset-20 + "px";  //(mousex).toString(10)+"px";
  var menuXPos=		hmPosition + leftEdgeHMenuOffset +2 + "px";
//  var menuWidth=	hmWidth;
  var menuHeight=	buttonHeight * hsmenuArray.length + "px";
  var topIndex=		"1000";
//alert("x="+menuXPos+"; y="+menuYPos+"; Width="+menuWidth+"; Height="+menuHeight);
  var hMenuLabel = new Array();
  var hMenuLink = new Array();

  var tempString = window.location.href;


  clearTimeout(flyout);
  menuOn = true;

  hMenuLabel = hsmenuArray[hmNum-1];
  hMenuLink = hslinkArray[hmNum-1];

  divTag=top.document.getElementById("flyOutMenu");
  menu = "<table class=hsubmenu onMouseout='hideSubmenu(\"" + hmNum + "\", timeoutLimit);' onBlur='hideSubmenu(\"" + hmNum + "\", timeoutLimit);' onMouseover='clearTimeout(flyout); menuOn=true;'>";

  for (var x = 0; x < hMenuLabel.length; x++) {
    menu +="<tr class=hsubmenu><td class=hsubmenu width=100%>";
    if (isIE) { // if IE browser
      menu +="  <a class=hsubmenuIE"
    } else {  
      menu +="  <a class=hsubmenuFF"
    } // if IE

    if (hmNum == 2) { // if the submenu belongs to Support Us
      menu +=" href='" + hMenuLink[x] + ".html";
    } else { 
      if (tempString.indexOf(hmenuSource[hmNum-1] + ".html",0) != -1) { // if launching from current page
        menu +=" href='#" + hMenuLink[x];
      } else {
        menu +=" href='" + hmenuSource[hmNum-1] + ".html?prodCatagory=" + hMenuLink[x];
      } // if launching from current page
    }
    menu +="' onMouseover='' onMouseout='' onClick='hideSubmenu(\"" + (x+1) + "\", 0);'>" + hMenuLabel[x] + "</a>";

//    menu +="  <a class=hsubmenu href='javascript: var anon;' onMouseover='showHSubmenu(\""+ hmNum +"\");' onMouseout='' onClick='getLink(\"" + hMenuLink[x] + "\");'>" + hMenuLabel[x] + "</a>";
    menu +="</td></tr>";
  } // for x

  menu +="</table>";

  	
  divTag.style.position= "absolute";
  divTag.style.top= menuYPos;
  divTag.style.left= menuXPos;
//  divTag.style.width= menuWidth;
  divTag.style.height= menuHeight;
  divTag.style.zIndex= topIndex;

  divTag.innerHTML = menu;

} //+++++ showHSubmenu

function showVSubmenu(vmNum) {  //***** display flyout menu for button number'vmNum'
//  alert("x="+mousex+" y="+mousey);
//  document.write(leftEdgeOffset);
//  document.write(windowWidth+" "+windowHeight+"<br></br>");
//  document.write(navigator.appName.indexOf("Netscape")+" "+navigator.appName.indexOf("Internet Explorer"));
  establishBrowser();

  var menuYPos = 	(vmNum * (buttonHeight)) + topEdgeOffset + "px";  //(mousey).toString(10)+"px";
  var menuXPos =	leftEdgeOffset + buttonWidth - 0 + "px";  //(mousex).toString(10)+"px";
  var menuWidth =	"250px";
  var menuHeight =	buttonHeight * menuArray.length + "px";
  var topIndex =	"1000";

  var vMenuLabel = new Array();
  var vMenuLink = new Array();

  var tempString = window.location.href;


  clearTimeout(flyout);
  menuOn = true;

  vMenuLabel = menuArray[vmNum-1];
  vMenuLink = linkArray[vmNum-1];

  divTag=top.document.getElementById("flyOutMenu");
  menu = "<table class=submenu onMouseout='hideSubmenu(\"" + vmNum + "\", timeoutLimit);' onBlur='hideSubmenu(\"" + vmNum + "\", timeoutLimit);' onMouseover='clearTimeout(flyout); menuOn=true;'>";

  for (var x = 0; x < vMenuLabel.length; x++) {
    menu +="<tr class=submenu><td class=submenu width=100%>";
    if (isIE) { // if IE browser
      menu +="  <a class=submenuIE"
    } else {  
      menu +="  <a class=submenuFF"
    } // if IE

    if (vmNum == 2 || vmNum == 4) { // if the submenu belongs to About Us
      menu +=" href='" + vMenuLink[x] + ".html";
    } else { 
      if (tempString.indexOf(buttonSource[vmNum-1] + ".html",0) != -1) { // if launching from current page
        menu +=" href='#" + vMenuLink[x];
      } else {
        menu +=" href='" + buttonSource[vmNum-1] + ".html?prodCatagory=" + vMenuLink[x];
      } // if launching from current page
    }
    menu +="' onMouseover='' onMouseout='' onClick='hideSubmenu(\"" + (x+1) + "\", 0);'>" + vMenuLabel[x] + "</a>";

//    menu +="  <a class=submenu href='javascript: var anon;' onMouseover='showVSubmenu(\""+ vmNum +"\");' onMouseout='' onClick='getLink(\"" + vMenuLink[x] + "\");'>" + vMenuLabel[x] + "</a>";
    menu +="</td></tr>";
  } // for x

  menu +="</table>";

  divTag.style.position= "absolute";
  divTag.style.top= menuYPos;
  divTag.style.left= menuXPos;
  divTag.style.width= menuWidth;
  divTag.style.height= menuHeight;
  divTag.style.zIndex= topIndex;

  divTag.innerHTML = menu;

} //+++++ showVSubmenu

function getButtons() { //***** displays toplevel menu buttons
  var numOfButtons = buttonLabel.length;

  clearTimeout(flyout);

  string="        <table class=buttons>";
  for (var x=0; x < numOfButtons; x++) {
    string+="          <tr class=buttons>";
    string+="            <td class=buttons>";
    if (isIE) { // if IE browser
      string+="              <a class=sidebarIE ";
      if (buttonSource[x]=="") {
        string+="";
      } else {
        string+="href='"+buttonSource[x]+".html'";
      }
      string+=" onMouseover='clearTimeout(flyout); showVSubmenu(\""+ (x+1) +"\");' onFocus='clearTimeout(flyout); showVSubmenu(\""+ (x+1) +"\");' onMouseout='hideSubmenu(\"" + (x+1) + "\", 0);' onBlur='hideSubmenu(\"" + (x+1) + "\", 0);'>"+buttonLabel[x]+"</a>";
    } else {
      string+="              <a class=sidebarFF ";
      if (buttonSource[x]=="") {
        string+="";
      } else {
        string+="href='"+buttonSource[x]+".html'";
      }
      string+=" onMouseover='clearTimeout(flyout); showVSubmenu(\""+ (x+1) +"\");' onFocus='clearTimeout(flyout); showVSubmenu(\""+ (x+1) +"\");' onMouseout='hideSubmenu(\"" + (x+1) + "\", 0);' onBlur='hideSubmenu(\"" + (x+1) + "\", 0);'>"+buttonLabel[x]+"</a>";
    } // if IE
    string+="            </td>";
    string+="          </tr>";
  } // for x
  string+="        </table>";
  string+="&nbsp;";

  objDiv = document.getElementById("buttons");
  if (objDiv) {
    objDiv.innerHTML = string;
  } else {
    objDiv.innerHTML = "Buttons could not be created";
  } // if objDiv
} //+++++ getButtons
