/* x1.js
 * version 1.01
 * basic cross-browser dhtml library
 * Copyright (c) 2002 Michael Foster (mike@cross-browser.com)
 * This library is distributed under the terms of the
 * GNU Lesser General Public License (gnu.org).
*/

/* This version uses browser detection. Version 2+ uses object detection. */

//// Core

function xClientSniffer()
{
  this.ua = navigator.userAgent.toLowerCase();
  this.major = parseInt(navigator.appVersion);
  // Opera
  this.opera = this.ua.indexOf('opera') != -1;
  if (this.opera) return;
  // MSIE
  this.ie = this.ua.indexOf('msie') != -1;
  if (this.ie) this.domBrowser = this.ie;
  if (this.ie)
  	return;
  // Gecko, NN, and NS
  this.gecko = this.ua.indexOf('gecko') != -1;
  this.nav = (this.ua.indexOf('mozilla') != -1
    && this.ua.indexOf('spoofer') == -1
    && this.ua.indexOf('compatible') == -1);
  this.nav4 = this.nav && this.major == 4;
  // Konqueror and AOL
  this.konq = this.ua.indexOf('konqueror') != -1;
  if (this.konq) this.gecko = true;
  this.aol = this.ua.indexOf('aol') != -1;
  if (this.aol) this.ie = true;
  this.domBrowser = (this.nav || this.ie) && !this.nav4  
}

window.is = new xClientSniffer();


function xGetElementById(sId) {
  var ele = null;
  if (document.getElementById) ele = document.getElementById(sId);
  else if (document.all) ele = document.all[sId];
  else if (document.layers) ele = nnGetElementById(sId);
  return ele;
}

function xGet(sId) {
	return xGetElementById(sId);
}

function nnGetElementById(sId, oParent) {
  var i, layer, found=null;
  if (!oParent) oParent = window;
  for (i = 0; i < oParent.document.layers.length; i++) {
    layer = oParent.document.layers[i];
    if (layer.id == sId) return layer;
    if (layer.document.layers.length) found = nnGetElementById(sId,layer);
    if (found) return found;
  }
  return null;
}

//// Appearance

function xShow(sId) {
  var ele = xGetElementById(sId);
  if (is.domBrowser)
 	  ele.style.visibility = "visible";
  if (is.ie && ele.style.position == "relative")
	  ele.style.display = 'inline';
  if (is.nav4)
  	ele.visibility = 'show';
  if (is.opera)
 	  ele.style.visibility = "visible";
}

function xHide(sId) {
  var ele = xGetElementById(sId);
  if (is.domBrowser)
 	  ele.style.visibility = "hidden";
  if (is.ie && ele.style.position == "relative")
  	  ele.style.display = 'none';
  if (is.nav4)
  	ele.visibility = 'hide';
  if (is.opera)
 	  ele.style.visibility = "hidden";
}

function xBackground(sId, sBgColor, sBgImage) {
  var bg = "", ele = xGetElementById(sId);
  if (is.nav4) {
    if (arguments.length > 1) ele.bgColor = sBgColor;
    if (arguments.length == 3) ele.background.src = sBgImage;
    bg = ele.bgColor;
  }
  else {
    if (arguments.length > 1)
      ele.style.backgroundColor = sBgColor;
    if (arguments.length == 3)
      ele.style.backgroundImage = "url(" + sBgImage + ")";
    bg = ele.style.backgroundColor;
  }
  return bg;
}

//// Position

function xMoveTo(sId, iX, iY) {
  xLeft(sId, iX);
  xTop(sId, iY);
}

function xMoveBy(sId, iDx, iDy) {
  xLeft(sId, iDx+xLeft(sId));
  xTop(sId, iDy+xTop(sId));
}

function xLeft(sId, iLeft) {
  var x=0, ele=xGetElementById(sId);
  if (is.ie) {
    if (arguments.length==2) ele.style.pixelLeft = iLeft;
    x = ele.style.pixelLeft;
  }
  else if (is.nav4) {
    if (arguments.length==2) ele.left = iLeft;
    x = ele.left;
  }
  else {
    if (arguments.length==2) ele.style.left = iLeft + "px";
    x = parseInt(ele.style.left);
  }
  return x;
}

function xTop(sId, iTop) {
  var y=0, ele=xGetElementById(sId);
  if (is.ie) {
    if (arguments.length==2) ele.style.pixelTop = iTop;
    y = ele.style.pixelTop;
  }
  else if (is.nav4) {
    if (arguments.length==2) ele.top = iTop;
    y = ele.top;
  }
  else {
    if (arguments.length==2) ele.style.top = iTop + "px";
    y = parseInt(ele.style.top);
  }
  return y;
}

//// Size

function xResizeTo(sId, uW, uH) {
  xWidth(sId, uW);
  xHeight(sId, uH);
  xClip(0, uW, uH, 0);
}

function xWidth(sId, uW) {
  var w=0, ele=xGetElementById(sId);
  if (is.ie) {
    if (arguments.length==2) ele.style.pixelWidth = uW;
    w = ele.style.pixelWidth;
  }
  else if (is.nav4) {
    w = ele.clip.width;
  }
  else {
    if (arguments.length==2) ele.style.width = uW + "px";
    w = parseInt(ele.style.width);
  }
  return w;
}

function xHeight(sId, uH) {
  var h=0, ele=xGetElementById(sId);
  if (is.ie) {
    if (arguments.length==2) ele.style.pixelHeight = uH;
    h = ele.style.pixelHeight;
  }
  else if (is.nav4) {
    h = ele.clip.height;
  }
  else {
    if (arguments.length==2) ele.style.height = uH + "px";
    h = parseInt(ele.style.height);
  }
  return h;
}

function xClip(iTop, iRight, iBottom, iLeft) {
  var ele=xGetElementById(sId);
  if (is.nav4) {
    ele.clip.top = iTop;
    ele.clip.right = iRight;
    ele.clip.bottom = iBottom;
    ele.clip.left = iLeft;
  }
  else {
    ele.style.clip =
      "rect("
      + iTop + "px "
      + iRight + "px "
      + iBottom + "px "
      + iLeft + "px" + ")";
  }
}

//// Window Functions

function xClientWidth() {
  var w = 0;
  if (is.nav) {
    w = window.innerWidth;
    if (document.height > window.innerHeight) w -= 16;
  }
  else if (is.ie) w = document.body.clientWidth;
  else if (is.opera) w = window.innerWidth;
  return w;
}

function xClientHeight() {
  var h = 0;
  if (is.nav) {
    h = window.innerHeight;
    if (document.width > window.innerWidth) h -= 16;
  }
  else if (is.ie) h = document.body.clientHeight;
  else if (is.opera) h = window.innerHeight;
  return h;
}

function xScrollLeft() {
  var offset=0;
  if (is.nav || is.opera) offset = window.pageXOffset;
  else if (is.ie) offset = document.body.scrollLeft;
  return offset;
}

function xScrollTop() {
  var offset=0;
  if (is.nav || is.opera) offset = window.pageYOffset;
  else if (is.ie) offset = document.body.scrollTop;
  return offset;
}

// end x1.js
