////

//// support code for MIT Staff Site

////



///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////

//

// Dreamweaver functions

//

function MM_preloadImages() { //v3.0

  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();

    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)

    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}

}

function MM_swapImgRestore() { //v3.0

  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;

}

function MM_findObj(n, d) { //v4.01

  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {

    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}

  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];

  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);

  if(!x && d.getElementById) x=d.getElementById(n); return x;

}

function MM_swapImage() { //v3.0

  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)

   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}

}

function MM_showHideLayers() { //v6.0

  var i,p,v,obj,args=MM_showHideLayers.arguments;

  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];

    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }

    obj.visibility=v; }

}





///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////

//

// function checks if PNGs need to be fixed, and if so,

// calls correctPNG()

// (see pngfix.js)

//

function fixPNG() {

  if (typeof needtofixpng != 'undefined' && needtofixpng)

    correctPNG();

}





///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////

//

// preload mouseover images

//

function preloadMouseovers() {

  MM_preloadImages('img/nav/gettingaround_ro.gif','img/nav/business_ro.gif','img/nav/create_ro.gif','img/nav/career_ro.gif','img/nav/benefits_ro.gif','img/nav/connect_ro.gif','img/nav/inclusive_ro.gif');

}





///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////

//

// functions to swap and restore Go button

// replace "_off" with "_on.gif" and vice versa

// HTML: <input type="image" src="img/go_off.gif" onmouseover="swapGo(this)" onmouseout="swapGoRestore(this)" />

//

function swapGo(buttonobj) {



  buttonobj.oSrc = buttonobj.src;      // stash original src

  buttonobj.src = buttonobj.src.replace(/_off/,"_on");

}

function swapGoRestore(buttonobj) {

  buttonobj.src = buttonobj.oSrc;      // restore src from saved location

}





///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////

//

// code to open/close menus

//

// how it works:

//  When the mouse passes over one of the nav links, it calls

//   startmenu() to open the corresponding menu and close any others

//   that might be open. It also swaps the nav image.

//  When the mouse leaves a menu, it starts a delayed close by calling endmenu().

//

//



//// globals



// variable records which menu is currently open

var open_menu = "";    // name of open menu (the layer id is derived from this)

// menus enabled flag

var menus_enabled = true;

// menu that will not be opened because it is the current section (HR NEO quirk)

var menu_forbidden = '';



// timer for delayed hide

var timerid = null;



//// functions



// show menu, hiding any previously open

//

function startMenu(menuname) {

  if (timerid != null) {        // cancel any delayed hides

    clearTimeout (timerid);

    timerid = null;

  }



  if (menuname == menu_forbidden) // prevent disabled menu from opening

    menuname = "";



  if (open_menu == menuname)  // return if this menu already open

    return;



  // close old menu

  if (open_menu != "") {

    // swap back original nav image

    var oldimgid = "imgn1_"+open_menu;      // get image id

    var oldimgobj = MM_findObj(oldimgid);  // find object

    if (oldimgobj) {

      oldimgobj.src = oldimgobj.oSrc;      // restore src from saved location

    }

    if (menus_enabled) {

      // hide the old menu

      var oldmenuid = "divmenu_"+open_menu;     // get menu id

      MM_showHideLayers(oldmenuid,'','hide');  // hide menu

    }

  }



  // open new menu

  if (menuname != "") {

    // swap in new nav image

    var newimgid = "imgn1_"+menuname;         // get image id

    var newimgobj = MM_findObj(newimgid);  // find object

    if (newimgobj) {

      newimgobj.oSrc = newimgobj.src;      // stash original src

      newimgobj.src = newimgobj.src.replace(/_off/,"_ro");

    }

    if (menus_enabled) {

      // show the new menu

      var newmenuid = "divmenu_"+menuname;         // get menu id

      MM_showHideLayers(newmenuid,'','show');  // show menu

    }

  }



  // record the open menu

  open_menu = menuname;

}



// start delayed main nav image restoration and pop-up menu hiding

//

function endMenu() {

  timerid = setTimeout("doDelayedHideMenu()", 50); // last arg is delay in milliseconds

}



// perform delayed menu hiding

//

function doDelayedHideMenu() {

  startMenu("");

}



///

/// SETUP FUNCTION - call after loading the main nav to load the 'on' image for the current section

/// and to block display of that menu

///

function primarynavSetup() {



  // get section name from subroutine

  var section = getSection();



  if (section == 'gettingaround' || section == 'business' || section == 'create' || section == 'career' || section == 'benefits' || section == 'connect' || section == 'inclusive') {

    // change nav image to "on" state

    var imgobj = MM_findObj("imgn1_"+section);  // find object

    if (imgobj) {

      imgobj.src = imgobj.src.replace(/_off/,"_on"); // change to on image

    }

    // prevent current section's menu from being shown

    //

    menu_forbidden = section;

  }

}

//

// get current section from class of body tag

//

function getSection() {

  // section class names

  var sectionnames = Array('gettingaround','business','create','career','benefits','connect', 'inclusive');

  var section = '';



  // get BODY node

  var nodes = document.getElementsByTagName("BODY");

  if (nodes) {

    // iterate through list of nodes (of course, there should only be one BODY!)

    for(var i = 0; i < nodes.length; i++) {

      var bodyobj = nodes.item(i);

      if (typeof bodyobj.className != 'undefined') {

        // iterate through list of class names

        for (var j = 0; j < sectionnames.length; j++) {

          var classregexp = new RegExp(sectionnames[j],"i");

          if (classregexp.test(bodyobj.className)) {

            section = sectionnames[j];

            break;

          }

        }

      }

    }

  }

  return section;

}

///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////

//

// Secondary navigation page highlight

//

function highlightSecondaryNav() {

  // extract html filename from URL

  var pieces = document.URL.split("/");

  var filename = pieces[pieces.length-1];

  // find secondary nav

  var ulobj = MM_findObj("leftnav");

  // look for li elements

  for (var i = 0; i < ulobj.childNodes.length; i++) {

    if (ulobj.childNodes[i].nodeName == "LI") { // don't check nodeType because IE doesn't like that...

      // found li

      var liobj = ulobj.childNodes[i];

      // look for li elements

      for (var j = 0; j < liobj.childNodes.length; j++) {

        if (liobj.childNodes[j].nodeName == "A") {

          // found a

          var aobj = liobj.childNodes[j];

          // extract href filename

          pieces = aobj.pathname.split("/");

          // check against current filename

          if (filename == pieces[pieces.length-1]) {

            // if link matches this file, set li tag classname to "current" and exit

            liobj.className = "current";

            return;

          }

        }

      }

    }

  }

}

///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////

//

// Random photos NO announcement

//

var photodir = "img/photos/";

var randphotos = new Array();

randphotos[randphotos.length] = "group01.jpg";

randphotos[randphotos.length] = "group02.jpg";

randphotos[randphotos.length] = "group03.jpg";

randphotos[randphotos.length] = "group04.jpg";

randphotos[randphotos.length] = "group05.jpg";

randphotos[randphotos.length] = "group06.jpg";

randphotos[randphotos.length] = "group07.jpg";

randphotos[randphotos.length] = "group08.jpg";

randphotos[randphotos.length] = "group09.jpg";

// (add new photos here)

function writeRandomPhoto() {

  var nphoto = Math.floor(Math.random()*randphotos.length);

  document.writeln("<div id='divphoto'><img src='"+photodir+randphotos[nphoto]+"' alt='' /></div>");

}


// Random photos WITH announcement

//

var photodirA = "img/photos/";

var randphotosA = new Array();

randphotosA[randphotosA.length] = "group00a.jpg";

randphotosA[randphotosA.length] = "group00b.jpg";

randphotosA[randphotosA.length] = "group00c.jpg";

randphotosA[randphotosA.length] = "group00d.jpg";

randphotosA[randphotosA.length] = "group00e.jpg";

randphotosA[randphotosA.length] = "group00f.jpg";

randphotosA[randphotosA.length] = "group00g.jpg";

// (add new photos here)

function writeRandomPhotoA() {

  var nphoto = Math.floor(Math.random()*randphotosA.length);

  document.writeln("<div id='divphoto'><img src='"+photodirA+randphotosA[nphoto]+"' alt='' /></div>");

}

