
// CrossBrowserElement Object Constructor:

function CrossBrowserElement(eleId, width, height)
{
  // Properties:
  this.id = eleId;
  this.ele = null;
  this.x = 0;
  this.y = 0;
  this.width = 0;
  this.height = 0;
  this.clipping = false;
  this.xMoving = false;
  this.yMoving = false;
  this.xTarget = 0;
  this.yTarget = 0;
  this.clipSpeed = 50;
  this.xSpeed = .5;
  this.ySpeed = .6;

  // Methods (high-level):
  this.moveTo = cbeMoveTo;
  this.moveToPos = cbeMoveToPos;
  this.moveBy = cbeMoveBy;
  this.slideTo = cbeSlideTo;
  this.slideToPos = cbeSlideToPos;
  this.slideToX = cbeSlideToX;
  this.slideToY = cbeSlideToY;
  this.getPos = cbeGetPos;

  // Methods (browser-specific):
  this.setLeft = domSetLeft;
  this.getLeft = domGetLeft;
  this.setTop = domSetTop;
  this.getTop = domGetTop;
  this.setZIndex = domSetZIndex;
  this.getZIndex = domGetZIndex;
  this.show = domShow;
  this.hide = domHide;
  this.isVisible = domIsVisible;

  // Assign browser-specifics:

  if (document.getElementById) {
    this.ele = document.getElementById(eleId);
    if (is.opera) {
      this.setLeft = opSetLeft;
      this.getLeft = opGetLeft;
      this.setTop = opSetTop;
      this.getTop = opGetTop;
      this.setWidth = opSetWidth;
      this.setHeight = opSetHeight;
      this.setClip = 
      this.getClip = 
      this.getClipTop = 
      this.getClipRight = 
      this.getClipBottom = 
      this.getClipLeft = 
      this.getClipArray = returnZero;
      this.getClipWidth = domGetWidth;
      this.getClipHeight = domGetHeight;
      this.show = opShow;
      this.setHtml = returnZero;
      this.setBgColor = opSetBgColor;
      this.setBgImage = returnZero;
      
    }
  }
  else if (is.ie4up) {
    this.ele = document.all[eleId];
  }
  else if (is.nav4up) {
    this.ele = document.layers[eleId];
    this.setLeft = nnSetLeft;
    this.getLeft = nnGetLeft;
    this.setTop = nnSetTop;
    this.getTop = nnGetTop;
    this.setZIndex = nnSetZIndex;
    this.getZIndex = nnGetZIndex;
    this.show = nnShow;
    this.hide = nnHide;
    this.isVisible = nnIsVisible;
  }
  else {
    alert("This javascript will not run on your browser!");
    return;
  }
  if (!this.ele) {
    alert(eleId + " does not exist");
    return;
  }

  if (arguments.length > 1) {
    this.setSize(width, height);
    this.setClip(0, width , height , 0);
    this.moveTo(-width, -height);
    this.hide();
  }
}

//-----------------------------------------------------------------------------
// CrossBrowserElement Method Definitions:

//-----------------------------------------------------------------------------
// Move element to x,y position.

function cbeMoveTo(newX, newY)
{
  this.setLeft(newX);
  this.setTop(newY);
}

//-----------------------------------------------------------------------------
// Move element to logical position.

function cbeMoveToPos(pos, margin, outside)
{
  this.getPos(pos, margin, outside);
  this.setLeft(this.x);
  this.setTop(this.y);
}

//-----------------------------------------------------------------------------
// Get coordinates of logical position and assign to this.x and this.y

function cbeGetPos(pos, margin, outside)
{
  var x = this.getLeft();
  var y = this.getTop();
  var w = this.getClipWidth();
  var h = this.getClipHeight();
  var cw = getClientWidth();
  var ch = getClientHeight();
  var left = getScrollX();
  var top = getScrollY();
  var right = left + cw;
  var bottom = top + ch;
  var cenLeft = left + Math.floor(cw/2) - Math.floor(w/2);
  var cenTop = top + Math.floor(ch/2) - Math.floor(h/2);
  
  if (arguments.length > 1) {
    if (outside)
      margin = -margin;
    left += margin;
    top += margin;
    right -= margin;
    bottom -= margin;
  }

  switch (pos.toLowerCase()) {
    case 'center':
      x = cenLeft;
      y = cenTop;
      break;
    case 'centerH':
      x = cenLeft;
      break;
    case 'centerV':
      y = cenTop;
      break;  
    case 'n':
      if (outside) y = top - h;
      else y = top;
      break;
    case 'ne':
      if (outside) { x = right; y = top - h; }
      else { x = right - w; y = top; }
      break;
    case 'e':
      if (outside) x = right;
      else x = right - w;
      break;
    case 'se':
      if (outside) { x = right; y = bottom; }
      else { x = right - w; y = bottom - h }
      break;
    case 's':
      if (outside) y = top - h;
      else y = bottom - h;
      break;
    case 'sw':
      if (outside) { x = left - w; y = bottom; }
      else { x = left; y = bottom - h; }
      break;
    case 'w':
      if (outside) x = left - w;
      else x = left;
      break;
    case 'nw':
      if (outside) { x = left - w; y = top - h; }
      else { x = left; y = top; }
      break;
    default:
      alert("invalid 'pos' argument in getPos()");
  }
  this.x = x;
  this.y = y;
}

//-----------------------------------------------------------------------------
// Move element with respect to current position.

function cbeMoveBy(dX, dY)
{
  if (dX)
    this.setLeft(this.getLeft() + dX);
  if (dY)
    this.setTop(this.getTop() + dY);
}

//-----------------------------------------------------------------------------
// Set element's x position.

function domSetLeft(newX)
{
  this.ele.style.left = newX + "px";
}

function nnSetLeft(newX)
{
  this.ele.left = newX;
}

function opSetLeft(newX)
{
  this.ele.style.pixelLeft = newX;
}

//-----------------------------------------------------------------------------
// Set element's y position.

function domSetTop(newY)
{
  this.ele.style.top = newY + "px";
}

function nnSetTop(newY)
{
  this.ele.top = newY;
}

function opSetTop(newY)
{
  this.ele.style.pixelTop = newY;
}

//-----------------------------------------------------------------------------
// Get element's current x position.

function domGetLeft()
{
  return parseInt(this.ele.style.left);
}

function nnGetLeft()
{
  return this.ele.left;
}

function opGetLeft()
{
  return this.ele.style.pixelLeft;
}

//-----------------------------------------------------------------------------
// Get element's current y position.

function domGetTop()
{
  return parseInt(this.ele.style.top);
}

function nnGetTop()
{
  return this.ele.top;
}

function opGetTop()
{
  return this.ele.style.pixelTop;
}

//-----------------------------------------------------------------------------
// Set the element's z index.

function domSetZIndex(newZ)
{
  this.ele.style.zIndex = newZ;
}

function nnSetZIndex(newZ)
{
  this.ele.zIndex = newZ;
}

//-----------------------------------------------------------------------------
// Get the element's z index.

function domGetZIndex()
{
  return this.ele.style.zIndex;
}

function nnGetZIndex()
{
  return this.ele.zIndex;
}


function domShow()
{
  this.ele.style.visibility = 'inherit';
}

function nnShow()
{
  this.ele.visibility = 'inherit';
}

function opShow()
{
  this.ele.style.visibility = 'visible';
}

//-----------------------------------------------------------------------------
// Hide the element.

function domHide()
{
  this.ele.style.visibility = 'hidden';
}

function nnHide()
{
  this.ele.visibility = 'hide';
}

//-----------------------------------------------------------------------------
// Return true if the element is visible (or vis is inherited), else false.

function domIsVisible()
{
  return (
    this.ele.style.visibility == 'visible'
    || this.ele.style.visibility == 'inherit'
    || this.ele.style.visibility == ''
  );
}

function nnIsVisible()
{
  return (
    this.ele.visibility == 'show'
    || this.ele.visibility == 'inherit'
    || this.ele.visibility == ''
  );
}

//-----------------------------------------------------------------------------
// Slide element to x,y position.

function cbeSlideTo(newXTarget, newYTarget)
{
  if ( newXTarget != null)
    this.slideToX(newXTarget);
  if ( newYTarget != null)
    this.slideToY(newYTarget);
}

//-----------------------------------------------------------------------------
// Slide element to logical position.

function cbeSlideToPos(pos, margin, outside)
{
  this.getPos(pos, margin, outside);
  this.slideToX(this.x);
  this.slideToY(this.y);
}

//-----------------------------------------------------------------------------
// Slide element to x position.
// assumes id == object variable name

function cbeSlideToX(newXTarget, iterating)
{
  var delta, currentX;

  if (!this.xMoving) {
    this.xTarget = newXTarget;
  }
  else if (!iterating) {
    this.xTarget = newXTarget;
    return;
  }
  currentX = this.getLeft();
  this.xMoving = true;
  if (this.xSpeed < 1) {
    delta = this.xSpeed * Math.abs(Math.abs(currentX) - Math.abs(this.xTarget));
    if (delta < 1) delta = 1;
  }
  else
    delta = this.xSpeed;
  if (currentX < this.xTarget) {
    if (currentX + delta <= this.xTarget)
      this.setLeft(currentX + delta);
    else
      this.setLeft(this.xTarget);
  }
  else if (currentX > this.xTarget) {
    if (currentX - delta >= this.xTarget)
      this.setLeft(currentX - delta);
    else
      this.setLeft(this.xTarget);
  }
  else {
    this.xMoving = false;
    return;
  }
  setTimeout(this.id+".slideToX("+this.xTarget+","+true+")",25);
}

//-----------------------------------------------------------------------------
// Slide element to y position.
// assumes id == object variable name

function cbeSlideToY(newYTarget, iterating)
{
  var delta, currentY;

  if (!this.yMoving) {
    this.yTarget = newYTarget;
  }
  else if (!iterating) {
    this.yTarget = newYTarget;
    return;
  }
  currentY = this.getTop();
  this.yMoving = true;
  if (this.ySpeed < 1) {
    delta = this.ySpeed * Math.abs(Math.abs(currentY) - Math.abs(this.yTarget));
    if (delta < 1) delta = 1;
  }
  else
    delta = this.ySpeed;
  if (currentY < this.yTarget) {
    if (currentY + delta <= this.yTarget)
      this.setTop(currentY + delta);
    else
      this.setTop(this.yTarget);
  }
  else if (currentY > this.yTarget) {
    if (currentY - delta >= this.yTarget)
      this.setTop(currentY - delta);
    else
      this.setTop(this.yTarget);
  }
  else {
    this.yMoving = false;
    return;
  }
  setTimeout(this.id+".slideToY("+this.yTarget+","+true+")",25);
}

//-----------------------------------------------------------------------------
//

function returnZero()
{
  return 0;
}

//-----------------------------------------------------------------------------
// Get client area width.

function getClientWidth()
{
  var w = 0;
  if (is.nav4up) {
    w = window.innerWidth;
    if (document.height > window.innerHeight) // has vert scrollbar
      w -= 16;
  }
  else if (is.ie4up) {
    w = document.body.clientWidth;
  }
  else if (is.opera) {
    w = window.innerWidth;
  }
  return w;
}

//-----------------------------------------------------------------------------
// Get client area height.

function getClientHeight()
{
  var h = 0;
  if (is.nav4up) {
    h = window.innerHeight;
    if (document.width > window.innerWidth) // has horz scrollbar
      h -= 16;
  }
  else if (is.ie4up) {
    h = document.body.clientHeight;
  }
  else if (is.opera) {
    h = window.innerHeight;
  }
  return h;
}

//-----------------------------------------------------------------------------
// Get x scroll position.
// The number of pixels the document has scrolled horizontally.

function getScrollX()
{
  var offset;
  if (is.nav4up || is.opera) {
    offset = window.pageXOffset;
  }
  else if (is.ie4up) {
    offset = document.body.scrollLeft;
  }
  return offset;
}

//-----------------------------------------------------------------------------
// Get y scroll position.
// The number of pixels the document has scrolled vertically.

function getScrollY()
{
  var offset;
  if (is.nav4up || is.opera) {
    offset = window.pageYOffset;
  }
  else if (is.ie4up) {
    offset = document.body.scrollTop;
  }
  return offset;
}

//-----------------------------------------------------------------------------
// Get a reference to an Element object
// This is a cross-browser version of getElementById().

function getElementRef(eleId)
{
  var ele;

  if (document.getElementById)
    ele = document.getElementById(eleId);
  else if (is.ie4up)
    ele = document.all[eleId];
  else if (is.nav4up)
    ele = document.layers[eleId];

  return ele;
}

//-----------------------------------------------------------------------------
// ClientSnifferJr Object Constructor.

function ClientSnifferJr()
{
  this.ua = navigator.userAgent.toLowerCase();
  this.major = parseInt(navigator.appVersion);
  this.minor = parseFloat(navigator.appVersion);
  this.nav   = (
    (this.ua.indexOf('mozilla')!=-1)
    && ((this.ua.indexOf('spoofer')==-1)
    && (this.ua.indexOf('compatible') == -1))
  );
  this.nav4  = (this.nav && (this.major == 4));
  this.nav4up= (this.nav && (this.major >= 4));
  this.nav5up= (this.nav && (this.major >= 5));
  this.gecko = (this.ua.indexOf('gecko') != -1); 
  this.ie    = (this.ua.indexOf("msie") != -1);
  this.ie3   = (this.ie && (this.major == 2));
  this.ie4   = (
    this.ie && (this.major == 4)
    && (this.ua.indexOf("msie 5.0")==-1)
  );
  this.ie4up = (this.ie  && (this.major >= 4));
  this.ie5up = (this.ie && !this.ie3 && !this.ie4);
  this.opera = (this.ua.indexOf("opera") != -1);
  this.hotjava = (this.ua.indexOf("hotjava") != -1); 
  this.webtv = (this.ua.indexOf("webtv") != -1);
  this.aol   = (this.ua.indexOf("aol") != -1); 
}

var is = new ClientSnifferJr();


//-----------------------------------------------------------------------------
// End cbe.js
