﻿//ProgressText.js ver 1.0 (c)nuFuaue 2005 http://ga-bbs.hp.infoseek.co.jp/

var ProgressText = Class.create();
ProgressText.prototype = {
  initialize: function(element, before, after, text, maxCount, interval) {
    this.element = $(element);
    this.before = before;
    this.after = after;
    this.text = text;
    this.maxCount = maxCount;
    this.interval = interval;
  },

  start: function() {
    this.count = 0;
    this.changeText();
    this.intervalId = setInterval(this.changeText.bind(this), this.interval);
  },

  stop: function(text) {
    clearInterval(this.intervalId);
    this.intervalId = null;
    if (typeof(text) != 'undefined') this.element.innerHTML = text;
  },

  isMoving: function() {
    return (this.intervalId != null);
  },

  changeText: function() {
    var bufferArray = [this.before];
    for (i = 0; i < this.count; i++) {
      bufferArray.push(this.text);
    }
    bufferArray.push(this.after);
    this.element.innerHTML = bufferArray.join('');
    this.count++;
    if (this.count > this.maxCount) {
      this.count = 0;
    }
  }
}
