// *****************************************************************************
//
// Filename: nav.js
// Description: Library of javascript functions for navigation, specifically for
//  Duke Annual Review 2001-2002 web site.
//
// Note: The naming convention used for image names and Image objects is for the
// filenames to end in "on", "off", or "over". The name/id of the scriptable
// html element must be the same as the Image object variable name.
//
// *****************************************************************************


// True if this is this a newer browser (not Netscape Navigator 4.x), else false.
var isNewerBrowser = newerBrowser();
// Becomes true when the School Reports sub nav is displayed.
var srSubNavIsDisplayed = false;
// Becomes true when the Year In Review sub nav is displayed.
var yirSubNavIsDisplayed = false;
// Number of images in Headway School Reports sub nav
var SCHOOL_REPORTS_SUBNAV_LENGTH = 9;
// Number of images in Headway Year In Review sub nav
var YIR_SUBNAV_LENGTH = 11;
// Check for Mac IE browser.
var isMacIE = checkIsMacIE();
// Are we on the home page?
var onHomePage = false;

//
// Image state pseudo-constants.
//
var ON = "on";
var OFF = "off";
var OVER = "over";
var MAIN = "main";

var headlineStoryTag = new Array(
  "&nbsp;&nbsp;&nbsp;\"The Next Big Idea\" (New York Times)",
  "&nbsp;&nbsp;&nbsp;\"America's Best\" (Time Magazine)",
  "&nbsp;&nbsp;&nbsp;\"Hot Type\" (Chronicle of Higher Education)",
  "&nbsp;&nbsp;&nbsp;\"New Lease On Life\" (60 Minutes)",
  "&nbsp;&nbsp;&nbsp;\"Achievers\" (People)",
  "&nbsp;&nbsp;&nbsp;Rhodes Scholars Record (News &amp; Observer)");
  
var headlineStoryImage = new Array(
  "nn4TextImg1",
  "nn4TextImg2",
  "nn4TextImg3",
  "nn4TextImg4",
  "nn4TextImg5",
  "nn4TextImg6");


//
// In newer browsers, this code places into the document the images we need for 
// the School Reports and Year In Review buttons sub nav popup.
//
if (isNewerBrowser) {
  var srwrapper_starttag = '<div class="srsubnavwrapper" id="sr_wrapper" name="sr_wrapper">';
  var s0 = '<div class="srsubnav0" id="sr_sub0" name="sr_sub0">' +
    '<img src="./images/srconnector.gif" class="srconnector" id="sr0" name="sr0" border="0"></div>';
  var s1 = '<div class="srsubnav1" id="sr_sub1" name="sr_sub1">' +
    '<a href="./hw3_artsci_highlights.html" onmouseover="schoolReportsSubNavRollOver(document.images[' + "'sr1'" + '].name);" ' +
    'onmouseout="schoolReportsSubNavRollOut(document.images[' + "'sr1'" + '].name);">' +
    '<img src="./images/sr1off.gif" id="sr1" name="sr1" border="0"></a></div>';
  var s2 = '<div class="srsubnav2" id="sr_sub2" name="sr_sub2">' +
    '<a href="./hw3_eng_highlights.html" onmouseover="schoolReportsSubNavRollOver(document.images[' + "'sr2'" + '].name);" ' +
    'onmouseout="schoolReportsSubNavRollOut(document.images[' + "'sr2'" + '].name);">' +
    '<img src="./images/sr2off.gif" id="sr2" name="sr2" border="0"></a></div>';
  var s3 = '<div class="srsubnav3" id="sr_sub3" name="sr_sub3">' +
    '<a href="./hw3_divinity_highlights.html" onmouseover="schoolReportsSubNavRollOver(document.images[' + "'sr3'" + '].name);" ' +
    'onmouseout="schoolReportsSubNavRollOut(document.images[' + "'sr3'" + '].name);">' +
    '<img src="./images/sr3off.gif" id="sr3" name="sr3" border="0"></a></div>';
  var s4 = '<div class="srsubnav4" id="sr_sub4" name="sr_sub4">' +
    '<a href="./hw3_bus_highlights.html" onmouseover="schoolReportsSubNavRollOver(document.images[' + "'sr4'" + '].name);" ' +
    'onmouseout="schoolReportsSubNavRollOut(document.images[' + "'sr4'" + '].name);">' +
    '<img src="./images/sr4off.gif" id="sr4" name="sr4" border="0"></a></div>';
  var s5 = '<div class="srsubnav5" id="sr_sub5" name="sr_sub5">' +
    '<a href="./hw3_grad_highlights.html" onmouseover="schoolReportsSubNavRollOver(document.images[' + "'sr5'" + '].name);" ' +
    'onmouseout="schoolReportsSubNavRollOut(document.images[' + "'sr5'" + '].name);">' +
    '<img src="./images/sr5off.gif" id="sr5" name="sr5" border="0"></a></div>';
  var s6 = '<div class="srsubnav6" id="sr_sub6" name="sr_sub6">' +
    '<a href="./hw3_env_highlights.html" onmouseover="schoolReportsSubNavRollOver(document.images[' + "'sr6'" + '].name);" ' +
    'onmouseout="schoolReportsSubNavRollOut(document.images[' + "'sr6'" + '].name);">' +
    '<img src="./images/sr6off.gif" id="sr6" name="sr6" border="0"></a></div>';
  var s7 = '<div class="srsubnav7" id="sr_sub7" name="sr_sub7">' +
    '<a href="./hw3_med_highlights.html" onmouseover="schoolReportsSubNavRollOver(document.images[' + "'sr7'" + '].name);" ' +
    'onmouseout="schoolReportsSubNavRollOut(document.images[' + "'sr7'" + '].name);">' +
    '<img src="./images/sr7off.gif" id="sr7" name="sr7" border="0"></a></div>';  
  var s8 = '<div class="srsubnav8" id="sr_sub8" name="sr_sub8">' +
    '<a href="./hw3_law_highlights.html" onmouseover="schoolReportsSubNavRollOver(document.images[' + "'sr8'" + '].name);" ' +
    'onmouseout="schoolReportsSubNavRollOut(document.images[' + "'sr8'" + '].name);">' +
    '<img src="./images/sr8off.gif" id="sr8" name="sr8" border="0"></a></div>';
  var s9 = '<div class="srsubnav9" id="sr_sub9" name="sr_sub9">' +
    '<a href="./hw3_nursing_highlights.html" onmouseover="schoolReportsSubNavRollOver(document.images[' + "'sr9'" + '].name);" ' +
    'onmouseout="schoolReportsSubNavRollOut(document.images[' + "'sr9'" + '].name);">' +
    '<img src="./images/sr9off.gif" id="sr9" name="sr9" border="0"></a></div>';
  var srwrapper_endtag = '</div>';
  
    
  var yirwrapper_starttag = '<div class="yirsubnavwrapper" id="yir_wrapper" name="yir_wrapper">';
  var yir0 = '<div class="yirsubnav0" id="yir_sub0" name="yir_sub0">' +
    '<img src="./images/srconnector.gif" id="yir0" name="yir0" border="0"></div>';
  var yir1 = '<div class="yirsubnav1" id="yir_sub1" name="yir_sub1">' +
    '<a href="hw2_yih.html" onmouseover="schoolReportsSubNavRollOver(document.images[' + "'yir1'" + '].name);" ' +
    'onmouseout="schoolReportsSubNavRollOut(document.images[' + "'yir1'" + '].name);">' +
    '<img src="./images/yir1off.gif" id="yir1" name="yir1" border="0"></a></div>';
  var yir2 = '<div class="yirsubnav2" id="yir_sub2" name="yir_sub2">' +
    '<a href="hw2_911.html" onmouseover="schoolReportsSubNavRollOver(document.images[' + "'yir2'" + '].name);" ' +
    'onmouseout="schoolReportsSubNavRollOut(document.images[' + "'yir2'" + '].name);">' +
    '<img src="./images/yir2off.gif" id="yir2" name="yir2" border="0"></a></div>';
  var yir3 = '<div class="yirsubnav3" id="yir_sub3" name="yir_sub3">' +
    '<a href="hw2_campaign.html" onmouseover="schoolReportsSubNavRollOver(document.images[' + "'yir3'" + '].name);" ' +
    'onmouseout="schoolReportsSubNavRollOut(document.images[' + "'yir3'" + '].name);">' +
    '<img src="./images/yir3off.gif" id="yir3" name="yir3" border="0"></a></div>';
  var yir4 = '<div class="yirsubnav4" id="yir_sub4" name="yir_sub4">' +
    '<a href="hw2_construct.html" onmouseover="schoolReportsSubNavRollOver(document.images[' + "'yir4'" + '].name);" ' +
    'onmouseout="schoolReportsSubNavRollOut(document.images[' + "'yir4'" + '].name);">' +
    '<img src="./images/yir4off.gif" id="yir4" name="yir4" border="0"></a></div>';
  var yir5 = '<div class="yirsubnav5" id="yir_sub5" name="yir_sub5">' +
    '<a href="hw2_faculty.html" onmouseover="schoolReportsSubNavRollOver(document.images[' + "'yir5'" + '].name);" ' +
    'onmouseout="schoolReportsSubNavRollOut(document.images[' + "'yir5'" + '].name);">' +
    '<img src="./images/yir5off.gif" id="yir5" name="yir5" border="0"></a></div>';
  var yir6 = '<div class="yirsubnav6" id="yir_sub6" name="yir_sub6">' +
    '<a href="hw2_research.html" onmouseover="schoolReportsSubNavRollOver(document.images[' + "'yir6'" + '].name);" ' +
    'onmouseout="schoolReportsSubNavRollOut(document.images[' + "'yir6'" + '].name);">' +
    '<img src="./images/yir6off.gif" id="yir6" name="yir6" border="0"></a></div>';
  var yir7 = '<div class="yirsubnav7" id="yir_sub7" name="yir_sub7">' +
    '<a href="hw2_undergrad.html" onmouseover="schoolReportsSubNavRollOver(document.images[' + "'yir7'" + '].name);" ' +
    'onmouseout="schoolReportsSubNavRollOut(document.images[' + "'yir7'" + '].name);">' +
    '<img src="./images/yir7off.gif" id="yir7" name="yir7" border="0"></a></div>';
  var yir8 = '<div class="yirsubnav8" id="yir_sub8" name="yir_sub8">' +
    '<a href="hw2_athletics.html" onmouseover="schoolReportsSubNavRollOver(document.images[' + "'yir8'" + '].name);" ' +
    'onmouseout="schoolReportsSubNavRollOut(document.images[' + "'yir8'" + '].name);">' +
    '<img src="./images/yir8off.gif" id="yir8" name="yir8" border="0"></a></div>';
  var yir9 = '<div class="yirsubnav9" id="yir_sub9" name="yir_sub9">' +
    '<a href="hw2_comm.html" onmouseover="schoolReportsSubNavRollOver(document.images[' + "'yir9'" + '].name);" ' +
    'onmouseout="schoolReportsSubNavRollOut(document.images[' + "'yir9'" + '].name);">' +
    '<img src="./images/yir9off.gif" id="yir9" name="yir9" border="0"></a></div>';
  var yir10 = '<div class="yirsubnav10" id="yir_sub10" name="yir_sub10">' +
    '<a href="hw2_apptsyir.html" onmouseover="schoolReportsSubNavRollOver(document.images[' + "'yir10'" + '].name);" ' +
    'onmouseout="schoolReportsSubNavRollOut(document.images[' + "'yir10'" + '].name);">' +
    '<img src="./images/yir10off.gif" id="yir10" name="yir10" border="0"></a></div>';
  var yir11 = '<div class="yirsubnav11" id="yir_sub11" name="yir_sub11">' +
    '<a href="hw2_leaders1.html" onmouseover="schoolReportsSubNavRollOver(document.images[' + "'yir11'" + '].name);" ' +
    'onmouseout="schoolReportsSubNavRollOut(document.images[' + "'yir11'" + '].name);">' +
    '<img src="./images/yir11off.gif" id="yir11" name="yir11" border="0"></a></div>';
  var yirwrapper_endtag = '</div>';
  

  //
  // Write the images to the document.
  //
  document.write(srwrapper_starttag);
  document.write(s0);
  document.write(s1);
  document.write(s2);
  document.write(s3);
  document.write(s4);
  document.write(s5);
  document.write(s6);
  document.write(s7);
  document.write(s8);
  document.write(s9);
  document.write(srwrapper_endtag);
  
  document.write(yirwrapper_starttag);
  document.write(yir0);
  document.write(yir1);
  document.write(yir2);
  document.write(yir3);
  document.write(yir4);
  document.write(yir5);
  document.write(yir6);
  document.write(yir7);
  document.write(yir8);
  document.write(yir9);
  document.write(yir10);
  document.write(yir11);
  document.write(yirwrapper_endtag);
}


/**
 * Popup window for credits/contacts.
 */
function creditsPopup() {
  popupWindow = window.open("./credits.html", "credits", 
    "location=no,width=640,height=280");
} 

/**
 * Check if the user agent is IE for Mac. We're having a problem with this
 * browser, so we need to troubleshoot and possible write some workaround code.
 */
function checkIsMacIE() {
  var ua = navigator.userAgent;
  var ret = false;
  if (ua.indexOf("MSIE ") != -1 && ua.indexOf("Mac") != -1) {
    ret = true;
  }
  return ret;
}


/**
 * Change an image to a specific display state.
 *
 * @param imgName Name property of the image to change.
 * @param displayState State to change the image to.
 */
function imgChange(imgName, displayState) {
  document.images[imgName].src = eval(imgName + displayState + ".src");
}


/**
 * Returns the html element name for the circle image corresponding to a
 * headline. 
 *
 * @param imgName HTML element name of the image that triggered the event.
 */
function getCircleImgName(imgName) {
  return new String(imgName + "circle");
}


/**
 * Returns the number contained in the imgName argument. Assumes the number is
 * last character in the string. For example, we expect something like "hl5", in
 * which case we return 5.
 *
 * @param imgName HTML element name of the image that triggered the event.
 * @return The number contained in the imgName parameter.
 */
function getImgNum(imgName) {
  var headline = new String(imgName);
  return headline.charAt(headline.length - 1);
}


/**
 * Triggered by a mouseover on a headline menu button. If the moused over 
 * headline button is not the active headline, we change the button to
 * it's corresponding "over" image. If no headlines have been activated yet,
 * we also change the main image and the corresponding headline circle image.
 *
 * @param imgName HTML element name of the image that triggered the event.
 */
function headlineRollOver(imgName) {
  //
  // If imgName is not in the active state, change it to its over display
  // state.
  //
  if (imgName != activeHeadlineName) {
    imgChange(imgName, OVER);
  }
  
  // Always change the main image on mouseover.
  document.images["hlmain"].src = eval(imgName + "main.src");
  
  // If we're on the home page, turn the corresponding circle image on.
  if (!headlineIsActive && !headwayIsActive) {
    imgChange(getCircleImgName(imgName), ON);
  }
  
  //
  // If any sub navs are displayed, hide them.
  //
  hideAllSubNavs();
}


/**
 * Triggered by a mouseout event on a headline menu button. This method
 * changes the calling headline menu button image back to it's corresponding
 * "off" image and the corresponding headline circle image to "off", unless
 * the calling menu button is the active headline.
 *
 * @param imgName HTML element name of the image that triggered the event.
 */
function headlineRollOut(imgName) {
  //
  // If imgName is not the active headline, change it back to its off display
  // state.
  //
  if (imgName != activeHeadlineName) {   
    imgChange(imgName, OFF);
  }
  
  //
  // If we're on a headlines page, change the main image back to the one that
  // corresponds with the story. Otherwise, change it back to the default image
  // and turn the circle off.
  //
  if (!headlineIsActive && !headwayIsActive) {
    // We're on the home page.  
    document.images["hlmain"].src = hlmain.src;
    imgChange(getCircleImgName(imgName), OFF);
  } else if (headlineIsActive) {
    if (document.URL.indexOf("headline2_time1") != -1) {
      document.images["hlmain"].src = "./images/hl2/krzyzewski_main_on.jpg"
    } else if (document.URL.indexOf("headline2_time2") != -1) {
      document.images["hlmain"].src = "./images/hl2/hauerwas_main_on.jpg"
    } else {
      document.images["hlmain"].src = eval(activeHeadlineName + "main.src");
    } 
  } else if (headwayIsActive) {
      document.images["hlmain"].src = hlmain.src;
  }
}


/**
 * Triggered by a mouseover on a headway nav menu image.
 *
 * @param imgName HTML element name of the image that triggered the event. 
 */
function headwayRollOver(imgName) {
  //
  // If the image isn't currently active, change it to its over state.
  //
  if (imgName != activeHeadwayName) {
    imgChange(imgName, OVER);
  }
  
  if (isNewerBrowser) {
    // Get the image number.
    var imgNum = getImgNum(imgName);
        
    //
    // If necessary, show the sub nav. Else, hide any displayed sub navs.
    //
    if (hasSubNav(imgNum)) {
      if (imgNum == 3) {
        showSchoolReportsSubNav();
        hideYIRSubNav();
      } else if (imgNum == 2) {
        showYIRSubNav();
        hideSchoolReportsSubNav();
      }
    } else {
      hideSchoolReportsSubNav();
      hideYIRSubNav();
    }
  }
}


/**
 * Triggered by a mouseout event on a headway nav menu image.
 *
 * @param imgName HTML element name of the image that triggered the event.
 */
function headwayRollOut(imgName) {
  //
  // If imgName is not the active headline, change it back to its off display
  // state.
  //
  if (imgName != activeHeadwayName) {
    imgChange(imgName, OFF);
  }
}


/**
 * Returns true if the image has an associated sub nav menu, otherwise false.
 *
 * @param imgNum Headway menu image number.
 */
function hasSubNav(imgNum) {
  if(imgNum == 3 || imgNum == 2) {
    return true;
  }
  return false;
}


/**
 * Displays the sub nav menu for the School Reports headway button.
 */
function showSchoolReportsSubNav() {
  //
  // If we're on a headway page, the menu appears higher in order to be next
  // to the button that triggers it.
  //
  if (headwayIsActive) {
    if (document.all) {
      document.all('sr_wrapper').style.top = "281px";
      document.all('sr_wrapper').style.visibility = "visible";
    } else if (document.getElementById) {
      document.getElementById('sr_wrapper').style.top = "281px";
      document.getElementById('sr_wrapper').style.visibility = "visible";
    }    
  }
  
  //
  // Show connector line and all images in the sub nav.
  //
  for (var i = 0; i <= SCHOOL_REPORTS_SUBNAV_LENGTH; i++) {
    var divName = new String("sr_sub" + i);
    document.getElementById(divName).style.visibility = "visible";
  }
  
  // Sub nav is now displayed.
  srSubNavIsDisplayed = true;
}


/**
 * Displays the sub nav menu for the Year In Review headway button.
 */
function showYIRSubNav() {
  //
  // If we're on a headway page, the menu appears higher in order to be next
  // to the button that triggers it.
  //
  if (headwayIsActive) {
    if (document.all) {
      document.all('yir_wrapper').style.top = "243px";
      document.all('yir_wrapper').style.visibility = "visible";
    } else if (document.getElementById) {
      document.getElementById('yir_wrapper').style.top = "243px";
      document.getElementById('yir_wrapper').style.visibility = "visible";
    }
        
  }
  
  //
  // Show connector line and all images in the sub nav.
  //
  for (var i = 0; i <= YIR_SUBNAV_LENGTH; i++) {
    var divName = new String("yir_sub" + i);
    document.getElementById(divName).style.visibility = "visible";
    //alert(document.getElementById(divName).style.visibility);
  }
  
  // Sub nav is now displayed.
  yirSubNavIsDisplayed = true;
}


/**
 * Hides the sub nav menu for the School Reports headway button.
 */
function hideSchoolReportsSubNav() {
  //
  // Hide connector line and all images in the sub nav.
  //  
  for (var i = 0; i <= SCHOOL_REPORTS_SUBNAV_LENGTH; i++) {
    var divName = new String("sr_sub" + i);
    document.getElementById(divName).style.visibility = "hidden";
  }
  
  srSubNavIsDisplayed = false;
}


/**
 * Hides the sub nav menu for the Year In Review headway button.
 */
function hideYIRSubNav() {
  //
  // Hide connector line and all images in the sub nav.
  //  
  for (var i = 0; i <= YIR_SUBNAV_LENGTH; i++) {
    var divName = new String("yir_sub" + i);
    document.getElementById(divName).style.visibility = "hidden";
  }
  
  yirSubNavIsDisplayed = false;
}


/**
 * Meant to hide all sub navs when the document body is clicked.
 */
function hideAllSubNavs() {
  if (srSubNavIsDisplayed) {
    hideSchoolReportsSubNav();
  } else if (yirSubNavIsDisplayed) {
    hideYIRSubNav();
  } 
}


/**
 * Triggered by a mouseover event in the School Reports sub nav menu.
 *
 * @param imgName HTML element name of the image that triggered the event. 
 */
function schoolReportsSubNavRollOver(imgName) {
  imgChange(imgName, OVER);
}


/**
 * Triggered by a mouseout event in the School Reports sub nav menu.
 *
 * @param imgName HTML element name of the image that triggered the event. 
 */
function schoolReportsSubNavRollOut(imgName) {
  imgChange(imgName, OFF);
}


/**
 * Detects the browser type. If it's Netscape Navigator 4.x we return false. For
 * everything else we return true.
 */
function newerBrowser() {
  if (document.layers) {
    return false;
  } else {
    return true;
  }
}

function hlcirclehwOver(imgName) {
  // Change to "on" orange circle.
  imgChange(imgName, ON);
  // Get the number of the image.
  var imgNum = imgName.charAt(2);
  
  var txt = "";
  switch (imgNum) {
    case '1':
      txt = headlineStoryTag[0];
      break;
    case '2':
      txt = headlineStoryTag[1];
      break;
    case '3':
      txt = headlineStoryTag[2];
      break;
    case '4':
      txt = headlineStoryTag[3];
      break;
    case '5':
      txt = headlineStoryTag[4];
      break;
    case '6':
      txt = headlineStoryTag[5];
      break;
    default:
      txt = "Error";
      break;
  }
  
  changeHeadlineStoryText(txt, imgNum);  
}


function hlcirclehwOut(imgName) {
  imgChange(imgName, OFF);
  if (document.layers) {
    document.images["headlineStoryTagImg"].src = "./images/1pxwhite.gif";
  } else {
    changeHeadlineStoryText("");
  }
}

/**
 * Changes the headline story text to the passed-in string or image, depending on the browser.
 */
function changeHeadlineStoryText(txt, imgNum) {
  if (document.getElementById) {
    document.getElementById('headlineStoryTagText').innerHTML = txt;
  } else if (document.all) {
    document.all.headlineStoryTagText.innerHTML = txt;
  } else if (document.layers) {
    document.images["headlineStoryTagImg"].src = eval(headlineStoryImage[imgNum - 1] + ".src");
  }
}


/* ***********************************************************
Example 4-3 (DHTMLapi.js)
"Dynamic HTML:The Definitive Reference"
2nd Edition
by Danny Goodman
Published by O'Reilly & Associates  ISBN 1-56592-494-0
http://www.oreilly.com
Copyright 2002 Danny Goodman.  All Rights Reserved.
************************************************************ */
// DHTMLapi.js custom API for cross-platform
// object positioning by Danny Goodman (http://www.dannyg.com).
// Release 2.0. Supports NN4, IE, and W3C DOMs.

// Global variables
var isCSS, isW3C, isIE4, isNN4;

// initialize upon load to let all browsers establish content objects
function initDHTMLAPI() {
    if (document.images) {
        isCSS = (document.body && document.body.style) ? true : false;
        isW3C = (isCSS && document.getElementById) ? true : false;
        isIE4 = (isCSS && document.all) ? true : false;
        isNN4 = (document.layers) ? true : false;
        isIE6CSS = (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false;
    }
}

// set event handler to initialize API
window.onload = initDHTMLAPI;

// Seek nested NN4 layer from string name
function seekLayer(doc, name) {
    var theObj;
    for (var i = 0; i < doc.layers.length; i++) {
        if (doc.layers[i].name == name) {
            theObj = doc.layers[i];
            break;
        }
        // dive into nested layers if necessary
        if (doc.layers[i].document.layers.length > 0) {
            theObj = seekLayer(document.layers[i].document, name);
        }
    }
    return theObj;
}

// Convert object name string or object reference
// into a valid element object reference
function getRawObject(obj) {
    var theObj;
    if (typeof obj == "string") {
        if (isW3C) {
            theObj = document.getElementById(obj);
        } else if (isIE4) {
            theObj = document.all(obj);
        } else if (isNN4) {
            theObj = seekLayer(document, obj);
        }
    } else {
        // pass through object reference
        theObj = obj;
    }
    return theObj;
}

// Convert object name string or object reference
// into a valid style (or NN4 layer) reference
function getObject(obj) {
    var theObj = getRawObject(obj);
    if (theObj && isCSS) {
        theObj = theObj.style;
    }
    return theObj;
}

// Position an object at a specific pixel coordinate
function shiftTo(obj, x, y) {
    var theObj = getObject(obj);
    if (theObj) {
        if (isCSS) {
            // equalize incorrect numeric value type
            var units = (typeof theObj.left == "string") ? "px" : 0 
            theObj.left = x + units;
            theObj.top = y + units;
        } else if (isNN4) {
            theObj.moveTo(x,y)
        }
    }
}

// Move an object by x and/or y pixels
function shiftBy(obj, deltaX, deltaY) {
    var theObj = getObject(obj);
    if (theObj) {
        if (isCSS) {
            // equalize incorrect numeric value type
            var units = (typeof theObj.left == "string") ? "px" : 0 
            theObj.left = getObjectLeft(obj) + deltaX + units;
            theObj.top = getObjectTop(obj) + deltaY + units;
        } else if (isNN4) {
            theObj.moveBy(deltaX, deltaY);
        }
    }
}

// Set the z-order of an object
function setZIndex(obj, zOrder) {
    var theObj = getObject(obj);
    if (theObj) {
        theObj.zIndex = zOrder;
    }
}

// Set the background color of an object
function setBGColor(obj, color) {
    var theObj = getObject(obj);
    if (theObj) {
        if (isNN4) {
            theObj.bgColor = color;
        } else if (isCSS) {
            theObj.backgroundColor = color;
        }
    }
}

// Set the visibility of an object to visible
function show(obj) {
    var theObj = getObject(obj);
    if (theObj) {
        theObj.visibility = "visible";
    }
}

// Set the visibility of an object to hidden
function hide(obj) {
    var theObj = getObject(obj);
    if (theObj) {
        theObj.visibility = "hidden";
    }
}

// Retrieve the x coordinate of a positionable object
function getObjectLeft(obj)  {
    var elem = getRawObject(obj);
    var result = 0;
    if (document.defaultView) {
        var style = document.defaultView;
        var cssDecl = style.getComputedStyle(elem, "");
        result = cssDecl.getPropertyValue("left");
    } else if (elem.currentStyle) {
        result = elem.currentStyle.left;
    } else if (elem.style) {
        result = elem.style.left;
    } else if (isNN4) {
        result = elem.left;
    }
    return parseInt(result);
}

// Retrieve the y coordinate of a positionable object
function getObjectTop(obj)  {
    var elem = getRawObject(obj);
    var result = 0;
    if (document.defaultView) {
        var style = document.defaultView;
        var cssDecl = style.getComputedStyle(elem, "");
        result = cssDecl.getPropertyValue("top");
    } else if (elem.currentStyle) {
        result = elem.currentStyle.top;
    } else if (elem.style) {
        result = elem.style.top;
    } else if (isNN4) {
        result = elem.top;
    }
    return parseInt(result);
}

// Retrieve the rendered width of an element
function getObjectWidth(obj)  {
    var elem = getRawObject(obj);
    var result = 0;
    if (elem.offsetWidth) {
        result = elem.offsetWidth;
    } else if (elem.clip && elem.clip.width) {
        result = elem.clip.width;
    } else if (elem.style && elem.style.pixelWidth) {
        result = elem.style.pixelWidth;
    }
    return parseInt(result);
}

// Retrieve the rendered height of an element
function getObjectHeight(obj)  {
    var elem = getRawObject(obj);
    var result = 0;
    if (elem.offsetHeight) {
        result = elem.offsetHeight;
    } else if (elem.clip && elem.clip.height) {
        result = elem.clip.height;
    } else if (elem.style && elem.style.pixelHeight) {
        result = elem.style.pixelHeight;
    }
    return parseInt(result);
}


// Return the available content width space in browser window
function getInsideWindowWidth() {
    if (window.innerWidth) {
        return window.innerWidth;
    } else if (isIE6CSS) {
        // measure the html element's clientWidth
        return document.body.parentElement.clientWidth
    } else if (document.body && document.body.clientWidth) {
        return document.body.clientWidth;
    }
    return 0;
}
// Return the available content height space in browser window
function getInsideWindowHeight() {
    if (window.innerHeight) {
        return window.innerHeight;
    } else if (isIE6CSS) {
        // measure the html element's clientHeight
        return document.body.parentElement.clientHeight
    } else if (document.body && document.body.clientHeight) {
        return document.body.clientHeight;
    }
    return 0;
}
