////

//// support code for Human Resources New Employee Orientation 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('/welcome/img/nav/mit_ro.gif','/welcome/img/nav/checklists_ro.gif','/welcome/img/nav/benefits_ro.gif','/welcome/img/topbar/go_on.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 == 'mit' || section == 'checklists' || section == 'benefits') {

    // 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

// returns 'mit', 'checklists', 'benefits', or ''

//

function getSection() {

  // section class names

  var sectionnames = Array('mit','checklists','benefits');

  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;

}



///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////

//

// Random photos for banner (interior pages)

//

var photodir = "/welcome/img/banner/";

var randphotos = new Array();

randphotos[randphotos.length] = "photo01.jpg";

randphotos[randphotos.length] = "photo04.jpg";

randphotos[randphotos.length] = "photo05.jpg";

randphotos[randphotos.length] = "photo06.jpg";

randphotos[randphotos.length] = "photo07.jpg";

randphotos[randphotos.length] = "photo08.jpg";

randphotos[randphotos.length] = "photo09.jpg";

randphotos[randphotos.length] = "photo10.jpg";

randphotos[randphotos.length] = "photo11.jpg";

randphotos[randphotos.length] = "photo12.jpg";

randphotos[randphotos.length] = "photo13.jpg";

randphotos[randphotos.length] = "photo14.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]+"' width='450' height='157' alt='' /></div>");

}





///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////

//

// 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("divsecondarynav");

  // 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;

          }

        }

      }

    }

  }

}





///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////

//

// Community bubble

//

// requires swfobject.js (version 2.1)

//

function makeBubble() {



  var params = {

                 play:    "true",

                 loop:    "false",

                 menu:    "false",

                 swLiveConnect: "false",

                 wmode:   "transparent",

                 quality: "high",

                 align:   ""

               };

  var attributes = {};



  var flashvars = {

                    datafile:    "/welcome/img/flash/bubbledata.xml",

                    section:     getSection(),

                    debug:       (location.search == "?debug" ? "1" : "0"),

                    refreshdata: (location.search == "?refreshdata" ? "1" : "0"),

                    xyzzy:       0

                  };

  if (location.search != "?noflash") {

    swfobject.embedSWF("/welcome/img/flash/bubble.swf", "divbubble", "260", "300", "8.0.0", false, flashvars, params, attributes);

  }

}



///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////

//

// Multimedia button

//

// requires swfobject.js (version 2.1)

//

function makeMMButton() {



  var params = {

                 play:    "true",

                 loop:    "false",

                 menu:    "false",

                 swLiveConnect: "false",

                 wmode:   "transparent",

                 quality: "high",

                 align:   ""

               };

  var attributes = {};



  var flashvars = {

                    debug:          (location.search == "?debug" ? "1" : "0"),

                    clickcallback:  "openMultimedia",

                    xyzzy:          0

                  };



  if (swfobject.hasFlashPlayerVersion("8.0.0") && location.search != "?noflash") {

    swfobject.embedSWF("/welcome/img/flash/mmbutton.swf", "divmmbutton", "202", "118", "8.0.0", false, flashvars, params, attributes);

  }

  else {

    var pobj = MM_findObj("mmbuttonerror");

    if (pobj) {

      pobj.innerHTML = "You must <a href='http://www.macromedia.com/software/flash/about/' target='_blank'>update your Flash player</a> to view this presentation."+

			                 "<br />- or -<br /><a href='/welcome/slides/mit_benefits_quickstart.pdf' target='_blank'>View the PDF version of the presentation</a>";

    }

  }

}



//

// function called by multimedia button

//

function openMultimedia() {

	var url = "/welcome/slides/benefits/player.html";

  var width = 980;

  var height = 640;

  if (screen.width < 1000) {

    width *= 0.75;

    height *= 0.75;

	}

	var left = (screen.width - width)/2;

	var top = (screen.height - height)/2;



  var newwindow = window.open(url, 'mmpresentation', 'left='+left+',top='+top+',width='+width+',height='+height+',resizable=yes,scrollbars=no,toolbar=no,menubar=no,location=no,status=no');

  if (newwindow) {

    if (window.focus)

      newwindow.focus();

    return false;

  }

  //return true; // unsuccessful

	window.location = url;

}

