//////////////////////////////////////////////////////////////////////////////
//
//  API - managing layers under various browsers
//
//////////////////////////////////////////////////////////////////////////////
//
//  getObj(param);
//  getWindowObj(param);
//  getWindowHeight(obj);
//  getWindowWidth(obj);
//  getObjectLeft(obj);
//  getObjectTop(obj);
//  getObjectHeight();
//  getObjectWidth();
//  moveObjectTo(obj,x,y);
//  moveObjectBy(obj,x,y);
//  setBGColor(obj, color);
//  centerObject(obj);
//  showObject(obj);
//  hideObject(obj);
//
//////////////////////////////////////////////////////////////////////////////


var isIE     = false;
var isNS     = false;
var isW3C    = false;

var noCSS    = true;

var collObj  = "";
var styleObj = "";


//////////////////////////////////////////////////////////////////////////////

function initAPI() {
  if (document.documentElement) {
    isW3C    = true;
    noCSS    = false;
    collObj  = "getElementById('";
    styleObj = "').style";
  }
  else if (document.layers) {
    isNS     = true;
    noCSS    = false;
    collObj  = "layers.";
    styleObj = "";
  }
  else if (document.all) {
    isIE     = true;
    noCSS    = false;
    collObj  = "all.";
    styleObj = ".style";
  }
}


//////////////////////////////////////////////////////////////////////////////

function getObj(param) {
  var Object;
  if (typeof param == "string") {
    Object = eval ("window.document." + collObj + param + styleObj);
  }    
  else  {
    Object = param;
  }
  return Object;
}


//////////////////////////////////////////////////////////////////////////////

function getWindowObj(param) {
  var Object;
  if (typeof param == "string") {
    Object = eval ("document." + collObj + param);
  }   
  else {
    Object = param;
  }
  return Object;
}


//////////////////////////////////////////////////////////////////////////////

function getWindowHeight(obj) {
  var Object = getWindowObj(obj);
  if (isW3C) {
    return Object.clientHeight;
  }   
  else if (isNS) {   
    return Object.clip.height;
  } 
  else if (isIE) {
    return Object.clientHeight;
  }
}


//////////////////////////////////////////////////////////////////////////////

function getWindowWidth(obj) {
  var Object = getWindowObj(obj);
  if (isW3C) {
    return Object.clientWidth;
  }   
  else if (isNS) {   
    return Object.clip.width;
  } 
  else if (isIE) {
    return Object.clientWidth;
  }
}


//////////////////////////////////////////////////////////////////////////////

function getObjectLeft(obj) {
  var Object = getObj(obj);
  if (isW3C) {
    return Object.pixelLeft;
  }   
  else if (isNS) {   
    return Object.left;
  } 
  else if (isIE) {
    return Object.pixelLeft;
  }
}


//////////////////////////////////////////////////////////////////////////////

function getObjectTop(obj) {
  var Object = getObj(obj);
  if (isW3C) {
    return Object.pixelTop;
  }   
  else if (isNS) {   
    return Object.top;
  } 
  else if (isIE) {
    return Object.pixelTop;
  }
}


//////////////////////////////////////////////////////////////////////////////

function getObjectWidth() {
  if (isW3C) {
    return document.body.clientWidth;
  }   
  else if (isNS) {   
     return window.innerWidth;
  } 
  else if (isIE) {
    return document.body.clientWidth;
  }
}


//////////////////////////////////////////////////////////////////////////////

function getObjectHeight() {
  if (isW3C) {
    return document.body.clientHeight;
  }   
  else if (isNS) {   
    return window.innerHeight;
  } 
  else if (isIE) {
    return document.body.clientHeight;
  }
}


//////////////////////////////////////////////////////////////////////////////

function moveObjectTo(obj,x,y) {
  var Object = getObj(obj);
  if (x < 0) x = getObjectWidth() + x;
  if (y < 0) y = getObjectHeight() + y;
  if (isW3C) {
    Object.pixelLeft = x;
    Object.pixelTop  = y;
  }   
  else if (isNS) {   
    Object.moveTo(x,y);
  } 
  else if (isIE) {
    Object.pixelLeft = x;
    Object.pixelTop  = y;
  }   
}


//////////////////////////////////////////////////////////////////////////////

function moveObjectBy(obj,x,y) {
  var Object = getObj(obj);
  if (isW3C) {
    Object.pixelLeft += x;
    Object.pixelTop  += y;
  }   
  else if (isNS) {   
    Object.moveBy(x,y);
  } 
  else if (isIE) {
    Object.pixelLeft += x;
    Object.pixelTop  += y;
  }    
}


//////////////////////////////////////////////////////////////////////////////

function setBGColor(obj,color) {
  var Object = getObj(obj);
  if (isW3C) {
    Object.backgroundColor = color;
  }   
  else if (isNS) {   
    Object.bgColor         = color;
  } 
  else if (isIE) {
    Object.backgroundColor = color;
  }  
}


//////////////////////////////////////////////////////////////////////////////

function centerObject(obj) {
  var x = Math.round(getObjectWidth()/2  - getWidth(obj)/2);
  var y = Math.round(getObjectHeight()/2 - getHeight(obj)/2);
  moveObjectTo(obj,x,y);
}


//////////////////////////////////////////////////////////////////////////////

function showObject(obj) {			
  var Object = getObj(obj);
  if (Object) {
    if (isW3C) {
      return Object.visibility = "visible";
    }   
    else if (isNS) {   
      return Object.visibility = "show";
    } 
    else if (isIE) {
      return Object.visibility = "visible";
    } 
  }
}


//////////////////////////////////////////////////////////////////////////////

function hideObject(obj) {			
  var Object = getObj(obj);
  if (Object) {
    if (isW3C) {
      return Object.visibility = "hidden";
    }   
    else if (isNS) {   
      return Object.visibility = "hide";
    } 
    else if (isIE) {
      return Object.visibility = "hidden";
    } 
  }
}


//////////////////////////////////////////////////////////////////////////////

initAPI();

//////////////////////////////////////////////////////////////////////////////
