function initTicker(id, text, speed) {new Ticker(id, text, speed);}

function Ticker(parentid, text, speed) {
	this.text = text;
	if(speed)
	    this.speed = speed;
	else this.speed = 1;
	this.paused = false;
	
	this.element = document.getElementById(parentid);
	if(this.element) {
	    this.element.style.position = 'relative';
	    this.element.style.width = '100%';
	    this.element.style.overflow = 'hidden';
	    this.element.obj = this;
	    
	    this.element.onmouseover = function() {
			this.obj.pause();
	    }
	    this.element.onmouseout = function() {
			this.obj.resume();
	    }
    	
    	this.tickerText = new TickerText(text);
    	this.tickerText.element.style.left = this.element.offsetWidth + 'px';
    	this.element.appendChild(this.tickerText.element);
    	
    	var _self = this;
        setInterval(function(){_self.scroll()}, 35);
	}
}
Ticker.prototype.scroll = function() {
	if(!this.paused) {
		var posX = this.tickerText.getPosition();
		if(posX <= (this.tickerText.getWidth() * -1))
			this.tickerText.setPosition(this.element.offsetWidth);
		else this.tickerText.setPosition(posX-(this.speed));
    }
}
Ticker.prototype.pause = function() {
	this.paused = true;
}

Ticker.prototype.resume = function() {
	this.paused = false;
}

function TickerText (text) {
	this.element = document.createElement('span');
	this.element.style.whiteSpace = 'nowrap';
	this.element.style.left = '';
	this.element.style.top = '';
	this.element.style.visibility = 'visible';
	this.element.style.position = 'relative';
	this.element.innerHTML = text;
	document.documentElement.appendChild(this.element);
}
TickerText.prototype.getWidth = function() {
    return this.element.offsetWidth;
}

TickerText.prototype.getPosition = function() {
    return parseInt(this.element.style.left);
}

TickerText.prototype.setPosition = function(posX) {
    this.element.style.left = posX + 'px';
}