function Marquee() {
  this.initialize.apply(this, arguments);
}
Marquee.prototype = {
  initialize: function() {
    this.isScrolling = false;
    this.elm = document.getElementById(arguments[0]);
    this.parentElm = this.elm.parentNode;
    
    var opt = arguments[1] || [];
    
    this.scrollDelay = opt.scrollDelay || 30;
    this.scrollSpeed = opt.scrollSpeed || 2;
    this.isPause = (typeof(opt.isPause) != 'undefined') ? opt.isPause : false;
    if (this.isPause) {
      var th = this;
      this.parentElm.onmouseover = function(){ th.stop(); };
      this.parentElm.onmouseout = function(){ th.start(); };
    }
    
    this.initPosition();
    
    this.isChange = (typeof(opt.isChange) != 'undefined') ? opt.isChange : false;
    if (this.isChange) {
      this.contents = arguments[2] || [];
      this.contentsLength = this.contents.length;
      this.currentIndex = 0;
      if (this.elm.tagName.toLowerCase() == 'a') {
        this.isLink = true;
        this.links = arguments[3] || [];
      } else {
        this.isLink = false;
      }
      this.updateContents();
    } else {
      this.endLeft = parseInt(this.elm.offsetWidth) * (-1);
    }
    
    this.start();
  },
  
  initPosition: function() {
    this.startLeft = this.parentElm.offsetWidth;
    this.elm.style.left = this.startLeft + "px";
  },
  
  start: function() {
    if (!this.isScrolling) {
      this.timerID = (function(thisObj) {
        return setInterval(function() { thisObj.scroll(); },thisObj.scrollDelay);
      })(this);
      this.isScrolling = true;
    }
  },
  
  scroll: function() {
    var currentLeft = parseInt(this.elm.style.left);
    if (currentLeft <= this.endLeft) {
      if (this.isChange) 
        this.update();
      currentLeft = this.startLeft;
    }
    this.elm.style.left = currentLeft - this.scrollSpeed + "px";
  },
  
  stop: function() {
    if (this.isScrolling) {
      clearInterval(this.timerID);
      this.isScrolling = false;
    }
  },
  
  update: function() {
    this.stop();
    
    this.currentIndex++;
    if (this.currentIndex >= this.contentsLength) this.currentIndex = 0;
    this.initPosition();
    this.updateContents();
    
    this.start();
  },
  
  updateContents: function(){
    this.elm.innerHTML = this.contents[this.currentIndex];
    if (this.isLink && this.links[this.currentIndex]) {
      this.elm.href = this.links[this.currentIndex];
      this.elm.title = this.contents[this.currentIndex];
      this.elm.target = "_blank";
    } else {
      this.elm.href = "javascript:void(0);";
      this.elm.target = "";
    }
    this.endLeft = parseInt(this.elm.offsetWidth) * (-1);
  }
};

/* ファイルコード化形式を変えるためのコメント*/

