var num_scrolls = 0;
var scrolls = new Array();

function createScroll(div_id,time){
  scrolls[num_scrolls] = new Scroll(div_id,time,num_scrolls);
  return scrolls[num_scrolls++];
}

function Scroll(div_id,time,seq) {
  this._scroll_seq = seq;
  this._div_id = div_id;
  this._text_body = null;
  this._scroll_text = "";
  this._scroll_speed = parseInt(200/time);
  this._height = 0;
}

Scroll.prototype._scroll_seq;
Scroll.prototype._div_id;
Scroll.prototype._scroll_speed;
Scroll.prototype._scroll_text;
Scroll.prototype._text_body;
Scroll.prototype._height;

Scroll.prototype.add = function(text){
  this._scroll_text += text+"<br /> <br />";
}

Scroll.prototype.initialize = function() {
  this._text_body = document.getElementById(this._div_id);
  this._text_body.innerHTML = this._scroll_text;
  this._height = $(this._text_body).css('height');
  $(this._text_body).css({'margin-top':this._height,"height":"auto"});
  $(this._text_body).wrap("<div id='scroll_wrapper_"+this._scroll_seq+"'></div>");
  $("#scroll_wrapper_"+this._scroll_seq).css({'overflow':'hidden','margin':'0','padding':'0','height':this._height,'width':$(this._text_body).css('width')});
}

Scroll.prototype.startScroll = function() {
  this.initialize();
  setTimeout("scrolls["+this._scroll_seq+"].runScroll()", 0);
}

Scroll.prototype.runScroll = function() {
  var mTop = parseInt($(this._text_body).css("margin-top"));
  var comp = parseInt(this._text_body.scrollHeight)+mTop;
  if(comp<0){ mTop = parseInt(this._height);}
  mTop = (mTop-1)+"px";
  $(this._text_body).css({'margin-top':mTop});
  setTimeout("scrolls["+this._scroll_seq+"].runScroll()",parseInt(this._scroll_speed));
}