/*************************************************************************
  This code is from Dynamic Web Coding at www.dyn-web.com
  Copyright 2003-4 by Sharon Paine
  See Terms of Use at www.dyn-web.com/bus/terms.html
  regarding conditions under which you may use this code.
  This notice must be retained in the code as is!
*************************************************************************/
bannerbox.holder = {};
function bannerbox(id,x,y,w,h) {
  var el = bannerbox.getElemRef(id);
  if (!el) return;  this.id = id;
  bannerbox.holder[this.id] = this; this.animString = "bannerbox.holder." + this.id;
  var px = window.opera? 0: "px";
        this.x = x || 0;
        if (x) el.style.left = this.x + px;
        this.y = y || 0;
        if (y) el.style.top = this.y + px;
        this.w = w || el.offsetWidth || 0;
        this.h = h || el.offsetHeight || 0;
        if (w) el.style.width = w + px;
        if (h) el.style.height = h + px;
}
bannerbox.getElemRef = function(id) {
  var el = document.getElementById? document.getElementById(id): null;
  return el;
}
bannerbox.getInstance = function(id) {
  var obj = bannerbox.holder[id];
  if (!obj) obj = new bannerbox(id);
  else if (!obj.el) obj.el = bannerbox.getElemRef(id);
  return obj;
}
bannerbox.prototype.shiftTo = function(x,y) {
  var el = this.el? this.el: bannerbox.getElemRef(this.id)? bannerbox.getElemRef(this.id): null;
  if (el) {
    if (x != null) el.style.left = (this.x = x) + "px";
    if (y != null) el.style.top = (this.y = y) + "px";
  }
}
bannerbox.prototype.shiftBy = function(x,y) { this.shiftTo(this.x+x, this.y+y); }
bannerbox.prototype.show = function() {
  var el = this.el? this.el: bannerbox.getElemRef(this.id)? bannerbox.getElemRef(this.id): null;
  if (el) el.style.visibility = "visible";
}
bannerbox.prototype.hide = function() {
  var el = this.el? this.el: bannerbox.getElemRef(this.id)? bannerbox.getElemRef(this.id): null;
  if (el) el.style.visibility = "hidden";
}
var Bezier = {
  B1: function (t) { return t*t*t },
  B2: function (t) { return 3*t*t*(1-t) },
  B3: function (t) { return 3*t*(1-t)*(1-t) },
  B4: function (t) { return (1-t)*(1-t)*(1-t) },
  getValue: function (percent,startVal,endVal,c1,c2) {
    return endVal * this.B1(percent) + c2 * this.B2(percent) + c1 * this.B3(percent) + startVal * this.B4(percent);
  }
}
Animation = {
  instances: [],
  add: function(fp) {
    this.instances[this.instances.length] = fp;
          if (this.instances.length == 1) this.timerID = window.setInterval("Animation.control()", 10);
  },
  remove: function(fp) {
    for (var i = 0; this.instances[i]; i++) {
                  if (fp == this.instances[i]) {
                          this.instances = this.instances.slice(0,i).concat( this.instances.slice(i+1) );
                          break;
                  }
          }
          if (this.instances.length == 0) {
                  window.clearInterval(this.timerID);        this.timerID = null;
          }
  },
  control: function() {
    for (var i = 0; this.instances[i]; i++) {
                  if (typeof this.instances[i] == "function" ) this.instances[i]();
      else eval(this.instances[i]);
    }
  }
}
bannerbox.prototype.slideTo = function (destX,destY,slideDur,acc,endFn) {
  if (!document.getElementById) return;
  this.slideDur = slideDur || .0001; var acc = -acc || 0;
  if (endFn) this.onSlideEnd = endFn;
         if (destX == null) this.destX = this.x;        else this.destX = destX;
  if (destY == null) this.destY = this.y; else this.destY = destY;
  this.startX = this.x; this.startY = this.y;
        this.st = new Date().getTime();
  this.xc1 = this.x + ( (1+acc) * (this.destX-this.x)/3 );
        this.xc2 = this.x + ( (2+acc) * (this.destX-this.x)/3 );
  this.yc1 = this.y + ( (1+acc) * (this.destY-this.y)/3 );
        this.yc2 = this.y + ( (2+acc) * (this.destY-this.y)/3 );
        this.sliding = true;
  this.onSlideStart();
  Animation.add(this.animString + ".doSlide()");
}
bannerbox.prototype.doSlide = function() {
        if (!this.sliding) return;
        var elapsed = new Date().getTime() - this.st;
        if (elapsed < this.slideDur) {
    var x = Bezier.getValue(elapsed/this.slideDur, this.startX, this.destX, this.xc1, this.xc2);
    var y = Bezier.getValue(elapsed/this.slideDur, this.startY, this.destY, this.yc1, this.yc2);
                this.shiftTo( Math.round(x) ,Math.round(y) );
                this.onSlide();
        } else {
    Animation.remove(this.animString + ".doSlide()");
                this.shiftTo(this.destX,this.destY);
                this.onSlide();
                this.sliding = false;
                this.onSlideEnd();
        }
}
bannerbox.prototype.slideBy = function(dx,dy,slideDur,acc,endFn) {
        var destX=this.x+dx; var destY=this.y+dy;
        this.slideTo(destX,destY,slideDur,acc,endFn);
}
bannerbox.prototype.onSlideStart = function () {}
bannerbox.prototype.onSlide = function () {}
bannerbox.prototype.onSlideEnd = function () { if (this.el) this.el = null; }
function Glide() {
  var winWd = getWinWidth();
  var glideLyr = new bannerbox("banner", 710, -300);
  glideLyr.show();
  glideLyr.slideTo(710, 440, 3000, -1.2);
}
function getWinWidth() {
        var winWd = 0;
        if (document.documentElement && document.documentElement.clientWidth)
                winWd = document.documentElement.clientWidth;
        else if (document.body && document.body.clientWidth)
                winWd = document.body.clientWidth;
        else if (document.body && document.body.offsetWidth)
                winWd = document.body.offsetWidth; // ns6
        else if (window.innerWidth) winWd = window.innerWidth-18;
        return winWd;
}
window.onload=Glide;
