var HorizontalScroller = function(scrollEl, divEl, fullEl, prefix, newtext) {
 this.scrollEl = document.getElementById(scrollEl);
 this.divEl = document.getElementById(divEl);
 this.fullEl = $(fullEl);
 var that = this;
 this.divEl.onmouseover = function() { that.stop(); if(that.fullEl) that.fullEl.show(); };
 this.divEl.onmouseout = function() { that.runAgain(); if(that.fullEl) that.fullEl.hide();};
 this.prefix = prefix;
 this.updateHTML(newtext);
}

HorizontalScroller.prototype.updateHTML = function(newtext) {
 this.stop();
 var lwidth = this.divEl.offsetWidth;
 var ltext = (newtext === undefined ? this.scrollEl.innerHTML : newtext);
 if (ltext.match(/^\s*$/)) return;
 ltext = this.prefix + ltext;
 var ltext2 = ltext + ltext;
 this.scrollEl.innerHTML = ltext2;
 this.origwidth = this.scrollEl.offsetWidth / 2;
 var counter = 0;
 while(this.scrollEl.offsetWidth < lwidth + this.origwidth) {
	ltext2 += ltext;
	this.scrollEl.innerHTML = ltext2;
	if (++counter > 30) break;
 }
 this.scrollEl.style.left = Math.round(lwidth / 2);
 this.runAgain();
}

HorizontalScroller.prototype.runAgain = function() {
	if (!this.stopped) return;
	this.stopped = false;
	this.run();
}

HorizontalScroller.prototype.stop = function() {
	if (this.timer) window.clearTimeout(this.timer);
	this.timer = null;
	this.stopped = true;
}

HorizontalScroller.prototype.run = function() {
	if (this.stopped) return;
 var lnew = Math.round(parseInt(this.scrollEl.style.left) - 1);
 if (lnew <= -this.origwidth) {
  lnew = 0;  
 } 
 this.scrollEl.style.left = lnew+'px';
 var that = this;
 this.timer = window.setTimeout(function() {that.run()}, 50);
}

