// set up the menu structure
// each line creates a menu item out of 3 pieces of information, in this format:
//
//     name|url|type|
//
// the vertical lines ("pipes") separate the data, and it is important that each line END with one
// name = the text to display as the name of the link
// url = the link (absolute or relative) to go to (can be full urls, like http://www.aft.org)
// type = complete, parent or child
// a "complete" type is just a link (it does not create a submenu)
// a "parent" type creates a submenu made up of all following "children"
// a "child" type lives on a submenu created by the previous "parent"
// this will only create one level of submenus
//
// IMPORTANT: quotation marks in the text MUST be either
//    1) replaced with the HTML entity &quot;
//    2) escaped with a backslash: \"

var menuStructure = "";
menuStructure += "Home|index.html|complete|";
menuStructure += "About UA|about.html|complete|";
menuStructure += "What Is Collective Bargaining?|colbar.html|complete|";
menuStructure += "How and Why to Join UA|join.html|complete|";
menuStructure += "Get Involved!|getinvolved.html|complete|";
menuStructure += "Recent News|news.html|complete|";
menuStructure += "Officers, Representatives & Delegates|representatives.html|complete|";
menuStructure += "UA Committees|committees.html|complete|";
menuStructure += "Constitution and Charter|conandcharter.html|parent|";
menuStructure += "UA Constitution|constitution.html|child|";
menuStructure += "UA Charter|charter.html|child|";
menuStructure += "Contracts and Contract Tips|conandtipshomepage.html|parent|";
menuStructure += "Current Contracts|currentcontracts.html|child|";
menuStructure += "Contract Tips|contracttips.html|child|";
menuStructure += "Contract Archives|contractarchives.html|child|";
menuStructure += "Contract Questions and Grievances|conquestiongrievancehomepage.html|parent|";
menuStructure += "Do you have a complaint or grievance?|complaintgrievance.html|child|";
menuStructure += "UA Contract Information|contractinfo.html|child|";
menuStructure += "Salary Data|salary.html|complete|";
menuStructure += "Student Awards|backusbraceawardshomepage.html|parent|";
menuStructure += "Backus Award|backus.html|child|";
menuStructure += "Brace Award|brace.html|child|";
menuStructure += "UA Press Releases|pressreleases.html|complete|";
menuStructure += "UA Reports and Resolutions|reportshomepage.html|parent|";
menuStructure += "President's Updates|presidentsupdates.html|child|";
menuStructure += "CAC Reports|cacreports.html|child|";
menuStructure += "Messages to Members|messagemembers.html|child|";
menuStructure += "Other UA Reports|otheruareports.html|child|";
menuStructure += "UA Resolutions|resolutions.html|child|";
menuStructure += "UA Links|links.html|complete|";
menuStructure += "Contact Us|contact.html|complete|";
menuStructure += "Site Map|sitemap.html|complete|";

//////////////////////////////////////////////
//
// scripts which create menu DHTML
//
//////////////////////////////////////////////


// this removes the final pipe character, to help with splitting
menuStructure = menuStructure.substr(0,menuStructure.length-1);

// split the string into an array
struct = menuStructure.split('|');

// start html,level (at parent level), and n (count of parents with children)
var menuHtml = '<ul>';
var level = 'parent';
var n = 0;

for (i=0; i<(struct.length-2); i+=3) {

  name = struct[i];
  url = struct[i+1];
  type = struct[i+2];

  if (type == 'complete') {

    // close out any previous list of children
    if (level == 'child') {
      menuHtml += '</ul>';
      menuHtml += '<div class="submenuhide" id="submenuhide'+n+'" onmouseover="hidemenus();"></div>';
      level = 'parent';
    }

    // add the html for a complete item
    menuHtml += '<li><a href="'+url+'" onmouseover="hidemenus();">'+name+'</a></li>';

  }

  if (type == 'parent') {

    // close out any previous list of children
    if (level == 'child') {
      menuHtml += '</ul>';
      menuHtml += '<div class="submenuhide" id="submenuhide'+n+'" onmouseover="hidemenus();"></div>';
      level = 'parent';
    }

    // increase n (count of parents with children)
    n++;

    // add the html for the item itself
    menuHtml += '<li><a href="'+url+'" onmouseover="dropmenu('+n+');">'+name+'</a>';

    // start the submenu, and change level to child
    menuHtml += '<ul class="submenu" id="menudrop'+n+'">';
    level = 'child';

  }

  if (type == 'child') {
    menuHtml += '<li><a href="'+url+'">'+name+'</a></li>';
  }

}

// close the ul
menuHtml += '</ul>';

//////////////////////////////////////////////
//
// scripts for making the menu DHTML function
//
//////////////////////////////////////////////

var n = 5 // total number of submenus

function dropmenu(x) {
  for (i=1;i<=n;i++) {
    if (i==x) {
      showDropDown(i);
    } else {
      hideDropDown(i);
    }
  }
}
function hidemenus() {
  for (i=1;i<=n;i++) {
    hideDropDown(i);
  }
}
function showDropDown(x) {
    var dropid = 'menudrop' + String(x);
    var drophideid = 'submenuhide' + String(x);
    document.getElementById(dropid).style.visibility = 'visible';
    document.getElementById(drophideid).style.visibility = 'visible';
}
function hideDropDown(x) {
    var dropid = 'menudrop' + String(x);
    var drophideid = 'submenuhide' + String(x);
    document.getElementById(dropid).style.visibility = 'hidden';
    document.getElementById(drophideid).style.visibility = 'hidden';
}

////////////////////////////////////////
//
// javascript for hiding mailto links
//
////////////////////////////////////////

function makeLink() {
  args = makeLink.arguments;
  displayname = '';

  // check to see if there is 'text:' for link
  if (args[0].substr(0,5) == 'text:') {
    displayname = args[0].substr(5);
    newargs = new Array;
    for (i=1;i<args.length;i++) {
      newargs[i-1] = args[i];
    }
    args = newargs;
  }

  // put together the email address
  if (args.length == 1) {
    email = args[0] + '@uvm.edu';
  } else {
    if ((args.length == 2) && (args[1] == 'ua')) {
      email = args[0] + '@unitedacademics.org';
    } else {
      domain = '';
      for (i=1;i<args.length;i++) {
        domain += args[i]+'.';
      }
      domain = domain.substr(0,domain.length-1);
      email = args[0] + '@' + domain;
    }
  }

  if (!displayname) { displayname = email; }
  document.write('<a href="mailto:'+email+'">'+displayname+'</a>');
}
