function clipThis(element, top, right, bottom, left)
{
  if (browser == "NS4") {
    document.layers[element].clip.top = top;
    document.layers[element].clip.right = right;
    document.layers[element].clip.height = bottom - top;
    document.layers[element].clip.left = left;
  }

  if (browser == "IE" || browser == "NS6" || browser == "Opera") {
    document.getElementById(element).style.clip = 'rect(' + top + 'px, ' + right + 'px, ' + bottom + 'px, ' + left + 'px)';
  }
}

var sBrowser = "None";
var sVersion = "0";
browser = browserCheck();
os = osCheck();

function ticker() {
  this.ver = "1.00";

  this.type           = 1;
  this.itemwidth      = 150;
  this.width          = 300;
  this.height         = 150;
  this.scrollspeed    = 50;
  this.pausedelay     = 2000;
  this.spacing        = 5;
  this.pausemouseover = false;
  this.y_offset       = 8 + (sBrowser=="Safari" ? 300:0);
  this.x_offset       = 0;
  this.name           = 'ticker';
  this.aWidth         = new Array(100);
  this.aHeight        = new Array(100);
  this.currentspeed   = 50;
  this.curTopItem     = 1;
  this.numItems       = 0;
  this.active         = false;
  this.stop           = true;
  this.x              = 10;
  this.y              = 0;
  this.timeoutId      = 0;

  this.add = function()
  {
    var text = arguments[0];
    var itemwidth;

    if (this.type == 0) {
      itemwidth = this.width;
    } else {
      if (arguments.length == 2 && arguments[1] != '') {
        itemwidth = arguments[1];
      } else {
        itemwidth = this.itemwidth;
      }
    }

    this.numItems++;

    if (browser == "NS4") {
      document.writeln('<layer class="ticker" id="' + this.name + 'itm' + this.numItems + '" visibility="hide" width="' + itemwidth + '">');
      if (arguments.length >= 1) {
        document.writeln(text);
        document.writeln('</layer>');
      }
    }

    if (browser == "IE" || browser == "NS6" || browser == "Opera") {
      document.writeln('<div class="ticker" id="' + this.name + 'itm'
                                   + this.numItems + '" style="visibility:hidden;position:absolute;width:'
                                   + itemwidth     + 'px;z-index:3" onmouseover="'
                                   + this.name     + '.mouseover()"  onmouseout="'
                                   + this.name     + '.mouseout()">');

      if (arguments.length >= 1) {
        document.writeln(text);
        document.writeln('</div>');
      }
    }
  };

  this.display = function()
  {
    if (browser == "NS4") {
      document.write('<ilayer id="' + this.name + '" width="' + this.width + '" height="' + this.height + '">');
      document.write('</ilayer><br>');
    }

    if (browser == "IE" || browser == "NS6" || browser == "Opera") {
      document.write('<div id="' + this.name + '" style="position:absolute;width:1px;height:1px;"></div>');
      document.write('<div style="width:' + this.width + 'px;height:' + this.height + 'px;z-index:2" onmouseover="'
                             + this.name  + '.mouseover()" onmouseout="' + this.name   + '.mouseout()"></div>');
    }
    scrollActive = 1;
  };

  this.mouseover = function()
  {
    if (this.pausemouseover && this.active) {
      this.pause();
    }
  };

  this.mouseout = function()
  {
    if (this.pausemouseover && this.active) {
      this.timeoutId = setTimeout(this.name + '.resume()', 50);
    }
  };

  this.scroll = function()
  {
    var x = 0;
    var y = 0;
    var i;
    var name = this.name + 'itm';
    var cur_name = name + this.curTopItem;

    if (this.type == 0) {
      if (getOffsetY(cur_name) + this.getHeight(cur_name, this.curTopItem) < this.y) {
        setTop(cur_name, -800);

        if (this.curTopItem == this.numItems) {
          this.curTopItem = 1;
        } else {
          this.curTopItem++;
        }

        cur_name = name + this.curTopItem;
      }

      y = getOffsetY(cur_name) + this.y_offset;
      this.currentspeed = this.scrollspeed;

      for (i = this.curTopItem; i <= this.numItems; i++) {
        y = this.loopy(name + i, i, y);
      }

      for (i = 1; i < this.curTopItem; i++) {
        y = this.loopy(name + i, i, y);
      }
    } else {
      if (getOffsetX(cur_name) + this.getWidth(cur_name, this.curTopItem) < this.x) {
        getLeft(cur_name, -800);

        if (this.curTopItem == this.numItems) {
          this.curTopItem = 1;
        } else {
          this.curTopItem++;
        }

        cur_name = name + this.curTopItem;
      }

      x = getOffsetX(cur_name) + this.x_offset;
      this.currentspeed = this.scrollspeed;

      for (i = this.curTopItem; i <= this.numItems; i++) {
        x = this.loopx(name + i, i, x);
      }

      for (i = 1; i < this.curTopItem; i++) {
        x = this.loopx(name + i, i, x);
      }
    }

    if (!this.stop) {
      this.timeoutId = setTimeout(this.name + '.scroll()', this.currentspeed);
    }

    this.active = true;
  };

  this.loopx = function(cur_name, i, x)
  {
    if (x < this.width + this.x) {
      var item_x = getOffsetX(cur_name) + this.x_offset;

      var item_w = this.getWidth(cur_name, i);

      if (item_x == this.x + this.x_offset && this.pausedelay > this.scrollspeed) {
        this.currentspeed = this.pausedelay;
      }

      if (item_x > -800) {
        getLeft(cur_name, item_x - 1);
      } else {
        getLeft(cur_name, x);
      }

      if (item_x < this.x + this.x_offset || item_x + item_w > this.x + this.y_offset + this.width) {
        clipThis(cur_name, 0, Math.min(this.x + this.x_offset + this.width - x, item_w), this.height,
             Math.max(0, this.x + this.x_offset - x));
      }

      x += item_w + this.spacing;
      setVisible(cur_name, true);
    } else {
      getLeft(cur_name, -800);
    }

    return x;
  };

  this.loopy = function(cur_name, i, y)
  {
    if (y < this.height + this.y) {
      var item_y = getOffsetY(cur_name) + this.y_offset;

      var item_h = this.getHeight(cur_name, i);

      if (item_y == this.y + this.y_offset && this.pausedelay > this.scrollspeed) {
        this.currentspeed = this.pausedelay;
      }

      if (item_y > -800) {
        setTop(cur_name, item_y - 1);
      } else {
        setTop(cur_name, y);
      }

      if (item_y < this.y + this.y_offset || item_y + item_h > this.y + this.y_offset + this.height) {
        clipThis(cur_name,   Math.max(0, this.y + this.y_offset - item_y),
             this.width, Math.min(this.y + this.y_offset + this.height - item_y, item_h),
             0);
      }

      y += item_h + this.spacing;
      setVisible(cur_name, true);
    } else {
      setTop(cur_name, -800);
    }

    return y;
  };

  this.load = function()
  {
    if (os == "Mac" && browser == "IE") {
      this.y_offset = parseInt(document.body.topMargin);
      this.x_offset = parseInt(document.body.leftMargin);
    }

    this.y_offset = parseInt(this.y_offset*.9);

    var name = this.name + 'itm';
    var x;
    var w;

    this.x = getOffsetX(this.name);
    this.y = getOffsetY(this.name);

    this.curTopItem = 1;

    if (this.type == 0) {
      y = this.y - 1 + this.y_offset;

      for (var i = this.curTopItem; i <= this.numItems; i++) {
        setTop(name + i, y);

        getLeft(name + i, this.x + this.x_offset);
        h = getHeight(name + i);
        this.aHeight[i] = h;

        if (y < this.y + this.y_offset || y + h > this.y + this.y_offset + this.height) {
          clipThis(name + i,   Math.max(0, this.y + this.y_offset - y),
               this.width, Math.min(this.y + this.y_offset + this.height - y, h),
               0);
        }

        y += h + this.spacing;
        setVisible(name + i, true);
      }

      if (y < this.y + this.height) {
        // alert('Warning: The total height of the scroller items have to exceed the display height');
      }
    } else {
      x = this.x - 1 + this.x_offset;

      for (var i = this.curTopItem; i <= this.numItems; i++) {
        w = getWidth(name + i);

        this.aWidth[i] = w;
        setTop(name + i, this.y + this.y_offset);

        if (x < this.width + this.x) {
          getLeft(name + i, x);

          if (x < this.x + this.x_offset || x + w > this.x + this.x_offset + this.width) {
            clipThis(name + i, 0, Math.min(this.x + this.x_offset + this.width - x, w), this.height,
                 Math.max(0, this.x + this.x_offset - x));
          }

          x += w + this.spacing;
          setVisible(name + i, true);
        } else {
          getLeft(name + i, -800);
        }
      }

      if (x < this.x + this.width) {
        // alert('Warning: The total height of the scroller items have to exceed the display height');
      }
    }

    if (browser == "Opera" && version != 7) {
      return;
    }
  };

  this.start = function()
  {
    this.load();

    if (this.stop) {
      this.stop = false;

      this.currentspeed = this.scrollspeed;

      if (scrollActive != 0) {
        this.timeoutId = setTimeout(this.name + '.scroll()', this.pausedelay);
      }
    }
  };

  this.pause = function()
  {
    clearTimeout(this.timeoutId);

    this.stop = true;
  };

  this.resume = function()
  {
    if (this.stop) {
      clearTimeout(this.timeoutId);

      this.stop = false;
      this.currentspeed = this.scrollspeed;
      this.scroll();
    }
  };

  this.faster = function(value) { this.scrollspeed = Math.max(2, this.scrollspeed - parseInt(value)); } ;
  this.slower = function(value) { this.scrollspeed += parseInt(value); } ;
  this.getWidth = function(element, index)
  {
    if (browser == "NS4") {
      return (this.aWidth[index]);
    }

    if (browser == "IE") {
      return (document.all[element].offsetWidth);
    }

    if (browser == "NS6") {
      return document.getElementById(element).offsetWidth;
    }

    if (browser == "Opera") {
      if (version == 7) {
        return (document.getElementById(element).offsetWidth);
      } else {
        return (document.getElementById(element).style.pixelWidth);
      }
    }
  };

  this.getHeight = function(element, index)
  {
    if (browser == "NS4") {
      return (this.aHeight[index]);
    }

    if (browser == "IE") {
      return (document.all[element].offsetHeight);
    }

    if (browser == "NS6") {
      return document.getElementById(element).offsetHeight;
    }

    if (browser == "Opera") {
      if (version == 7) {
        return (document.getElementById(element).offsetHeight);
      } else {
        return (document.getElementById(element).style.pixelHeight);
      }
    }
  };
}