/*
'---------------------------------------------------------------------------------------------
' JS(LayerFunctions.js)                                                                  01/03
'
' Developers : Brian Garber
' Area       : Navagation
'
' This page contains all the JavaScript functions that are used for roll over affects.
'---------------------------------------------------------------------------------------------
' Revisions  :
'---------------------------------------------------------------------------------------------
*/

  //Declare the constants used for browser checks in code.
  var IS_NS4   = (document.layers) ? true : false;
  var IS_IE    = (document.all) ? true : false;
  var IS_NS6   = (!document.all && document.getElementById) ? true : false;

//--------------------------------------------------------------------------------------------
// Layer utilities.
//--------------------------------------------------------------------------------------------
//Function gets the layer for the passed name.
function fcnGetLayer(a_strLayerName)
{
  if (IS_NS4)
    return fcnFindLayer(a_strLayerName, document);

  if (IS_NS6)
    return document.getElementById(a_strLayerName);

  if (IS_IE)
    return eval('document.all.' + a_strLayerName);

  return null;
}

//Function finds the layer from the document object model.
function fcnFindLayer(a_strLayerName, a_objDocument)
{
  var intCount;
  var objLayer;

  for (intCount = 0; intCount < a_objDocument.layers.length; intCount++)
  {
    objLayer = a_objDocument.layers[intCount];
    if (objLayer.name == a_strLayerName)
      return objLayer;
    if (objLayer.document.layers.length > 0)
    {
      objLayer = fcnFindLayer(a_strLayerName, objLayer.document);
      if (objLayer != null)
        return objLayer;
    }
  }
  return null;
}

//--------------------------------------------------------------------------------------------
// Layer visibility.
//--------------------------------------------------------------------------------------------
//This function hides the layer.
function fcnHideLayer(a_objLayer)
{
  if (IS_NS4)
    a_objLayer.visibility = "hide";

  if (IS_IE || IS_NS6)
    a_objLayer.style.visibility = "hidden";
}

//This function displays the layer.
function fcnShowLayer(a_objLayer)
{
  if (IS_NS4)
    a_objLayer.visibility = "show";

  if (IS_IE || IS_NS6)
    a_objLayer.style.visibility = "visible";
}

//This function shows the layer visiblity then sets the display to show the layer.
function fcnDisplayLayer(a_objLayer)
{
  fcnShowLayer(a_objLayer);

  if (IS_NS4)
    a_objLayer.display = "";

  if (IS_IE || IS_NS6)
    a_objLayer.style.display = "";
}

//This function hides the layer visiblity then sets the display to none.
function fcnRemoveLayer(a_objLayer)
{
  fcnHideLayer(a_objLayer);

  if (IS_NS4)
    a_objLayer.display = "none";

  if (IS_IE || IS_NS6)
    a_objLayer.style.display = "none";
}

//--------------------------------------------------------------------------------------------
// Layer positioning.
//--------------------------------------------------------------------------------------------
//Function moves a layer to the passed coordinates.
function fcnMoveLayerTo(a_objlayer, a_intXAxis, a_intYAxis)
{
  if (IS_NS4)
    a_objlayer.moveTo(a_intXAxis, a_intYAxis);

  if (IS_IE || IS_NS6)
  {
    a_objlayer.style.left = a_intXAxis;
    a_objlayer.style.top = a_intYAxis;
  }
}

//Function moves layer and then displays the layer.
function fcnMoveToShow(a_strLayerName, a_intXAxis, a_intYAxis)
{
  fcnMoveLayerTo(fcnGetLayer(a_strLayerName), a_intXAxis, a_intYAxis);
  fcnShowLayer(fcnGetLayer(a_strLayerName));
}

//Function moves layer and then hides the layer.
function fcnMoveToHide(a_strLayerName, a_intXAxis, a_intYAxis)
{
  fcnMoveLayerTo(fcnGetLayer(a_strLayerName), a_intXAxis, a_intYAxis);
  fcnHideLayer(fcnGetLayer(a_strLayerName));
}

//Function moves the passed layer to new coordinates.
function fcnMoveLayerBy(a_objLayer, a_intXPixels, a_intYPixels)
{
  var intXSpot;
  var intYSpot;

  if (IS_NS4)
    a_objLayer.moveBy(a_intXPixels, a_intYPixels);

  if (IS_NS6)
  {
    intXSpot = parseInt(a_objLayer.style.left);
    intYSpot = parseInt(a_objLayer.style.top);

    intXSpot += a_intXPixels;
    intYSpot += a_intYPixels;

    a_objLayer.style.left = intXSpot;
    a_objLayer.style.top  = intYSpot;
  }

  if (IS_IE)
  {
    a_objLayer.style.pixelLeft += a_intXPixels;
    a_objLayer.style.pixelTop  += a_intYPixels;
  }
}

//Function gets the left side coordinate of the passed layer.
function fcnGetLeft(a_objLayer)
{
  if (IS_NS4)
    return(a_objLayer.left);

  if (IS_NS6)
    return(parseInt(a_objLayer.style.left));

  if (IS_IE)
    return(a_objLayer.style.pixelLeft);

  return(-1);
}

//Function gets the top side coordinate of the passed layer.
function fcnGetTop(a_objLayer)
{
  if (IS_NS4)
    return(a_objLayer.top);

  if (IS_NS6)
    return(parseInt(a_objLayer.style.top));

  if (IS_IE)
    return(a_objLayer.style.pixelTop);

  return(-1);
}

//--------------------------------------------------------------------------------------------
// Gathering Image coordinates.
//--------------------------------------------------------------------------------------------
//Obtain X coordinate of imageName.
function fcnFindX(a_strImageName)
{
  var objImage;
  var intCount;
  var intTotal;

  objImage = document.images[a_strImageName]
  if (IS_NS4)
  {
    //Test for image in document object.
    if (document.images[a_strImageName])
    {
      return eval(objImage).x
    }
    //Fix for Netscape 4 div bug - find image in document.layers object instead (will NOT work for nested divs).
    else
    {
      for (intCount = 0; intCount < document.layers.length; intCount++)
      {
        if (document.layers[intCount].document.images[a_strImageName])
        {
          intTotal = document.layers[intCount].left + document.layers[intCount].document.images[a_strImageName].x;
          return intTotal;
        }
      }
    }
  }
  else
  {
    return fcnGetXPosition(objImage);
  }
}

//Get X Coordinate by a different mean.
function fcnGetXPosition(a_objImage)
{
  var intXPosition;
  var objTemp;

  intXPosition = eval(a_objImage).offsetLeft;
  objTemp = eval(a_objImage).offsetParent;

  while (objTemp != null)
  {
    intXPosition += objTemp.offsetLeft;
    objTemp = objTemp.offsetParent;
  }
  return intXPosition;
}

//Obtain Y coordinate of imageName.
function fcnFindY(a_strImageName)
{
  var objImage;
  var intCount;
  var intTotal;

  objImage = document.images[a_strImageName];
  if (IS_NS4)
  {
     //Test for image in document object.
    if (document.images[a_strImageName])
    {
      return eval(objImage).y;
    }
    //Fix for Netscape 4 div bug - find image in document.layers object instead (will NOT work for nested divs).
    else
    {
      for (intCount = 0; intCount < document.layers.length; intCount++)
      {
        if (document.layers[intCount].document.images[a_strImageName])
        {
          intTotal = document.layers[intCount].top + document.layers[intCount].document.images[a_strImageName].y;
          return intTotal;
        }
      }
    }
  }
  else
  {
    return fcnGetWindowWidth(objImage);
  }
}

//Get Y Coordinate by a different mean.
function fcnGetWindowWidth(a_objImage)
{
  var intYPosition;
  var objTemp;

  intYPosition = eval(a_objImage).offsetTop;
  objTemp = eval(a_objImage).offsetParent;
  while (objTemp != null)
  {
    intYPosition += objTemp.offsetTop;
    objTemp = objTemp.offsetParent;
  }
  return intYPosition;
}

