// demonstration cross-browser compatibility API
// only tested for Netscape 6 and IE5.5

var useID = 0, useLayers = 0, useAll = 0;

if (document.getElementById) useID = 1;
if (document.layers) useLayers = 1;
if (document.all) useAll = 1;

var MSIE = (useID && useAll);
var NS   = (useID && (! useAll) );

function getObj(obj) {
  // cross platform tool for accessing the object style
  var myObj;
  if (useID) myObj = document.getElementById(obj).style;
  else if (useAll) myObj = document.all[obj].style;
  else if (useLayers) myObj = document.layers[obj];
  return myObj;
}

function getObjCore(obj) {
  // same as getObj() except it lets you access the core object
  var myObj;
  if (useID) myObj = document.getElementById(obj);
  else if (useAll) myObj = document.all[obj];
  else if (useLayers) myObj = document.layers[obj];
  return myObj;
}

function setBgColor(obj, color) 
{
  // set the background color for the specified object
  var myObj = getObj(obj);
  myObj.backgroundColor = color;
}

function moveObj(obj, x, y)
{
  // move the specified object to the specified x,y coordinates
  var myObj = getObj(obj);
  
  if (document.moveTo) {
    myObj.moveTo(x,y);
  } else {
    myObj.left = x;
    myObj.top = y;
  }
}

function slideObj(obj, newX, newY)
{
  // move the object to the new coordinates, one XY pixel at a time
  // this only works on slow browsers due to offscreen buffering of
  // the moving image. The more portable way to do this is with the
  // setInterval() function which lets you specify millisecond delays
  // between steps of the slide event.
  var x = getX(obj), y = getY(obj), deltaX, deltaY;
  while (x != newX && y != newY) {
    if (x < newX) deltaX = 1;
    if (x > newX) deltaX = -1;
    if (y < newY) deltaY = 1;
    if (y > newY) deltaY = -1;
    moveObj(obj, x + deltaX, y + deltaY); 
    x += deltaX;
    y += deltaY;
  }
}

function nudgeObj(obj, x, y)
{
  // move the object (x,y) away from where it is currently
  var myObj = getObj(obj);
  
  if (myObj.moveBy) {
    myObj.moveBy(x, y);
  } else if (MSIE) {
    myObj.pixelLeft += x;
    myObj.pixelTop  += y;
  } else {
    myObj.left = parseInt(myObj.left) + x;
    myObj.top = parseInt(myObj.top) + y;
  }
}

function showObj(obj)
{
  // turn on visibility for the object
  var myObj = getObj(obj);
  
  myObj.visibility = "visible";
}

function hideObj(obj)
{
  // turn off visibility, hiding the object
  var myObj = getObj(obj);
  
  myObj.visibility = "hidden";
}

function getX(obj)
{
  // return the y coordinate of the object
  var myObj = getObj(obj);

  if (MSIE) {
    x = myObj.pixelLeft;
  } else {
    x = myObj.left;
  }
  return(parseInt(x));  
}

function getY(obj)
{
  // return the y coordinate of the object
  var myObj = getObj(obj);

  if (MSIE) {
    y = myObj.pixelTop;
  } else {
    y = myObj.top;
  }
  return(parseInt(y));  
}

function windowWidth()
{
  // return the width of the browser window
  if (MSIE) {
    width = document.body.clientWidth;
  } else {
    width = window.innerWidth;
  }
  return(parseInt(width));
}

function windowHeight()
{
  // return the width of the browser window
  if (MSIE) {
    height = document.body.clientHeight;
  } else {
    height = window.innerHeight;
  }
  return(parseInt(height));
}

function screenWidth()
{
  // return the width of the users screen
  return(parseInt(window.screen.width));
}

function screenHeight()
{
  // return the height of the users screen
  return(parseInt(window.screen.height));
}

function objHeight(obj)
{
  // return the height of the specified object 
  var myObj = getObjCore(obj);
  
  if (myObj.offsetHeight) {
    ht = myObj.offsetHeight;
  } else {
    ht = myObj.clip.height;
  }
  return(parseInt(ht));
}

function objWidth(obj)
{
  // return the height of the specified object 
  var myObj = getObjCore(obj);
  
  if (myObj.offsetWidth) {
    wd = myObj.offsetWidth;
  } else {
    wd = myObj.clip.width;
  }
  return(parseInt(wd));
}

function centerObj(obj)
{
  // center the object in the window (horizontally only)
  var y = getY(obj), width = windowWidth(), owidth = objWidth(obj);
  var newX = Math.floor((width - owidth) / 2);
  moveObj(obj, newX, y);
}

function narrowobj(obj)
{
  var myObj = getObj(obj);
  myObj.width = parseInt(myObj.width) - 10;
}

function widenobj(obj)
{
  var myObj = getObj(obj);
  myObj.width = parseInt(myObj.width) + 10;
}