function RDGscroller_item(id, speed) {
	this.scroller_id = id;
	this.speed = speed; // scale of 1-10
	this.distance = 1;
	this.timeoutTime = null;
	this.tim = null;
	this.divWidth = null;
	this.parentWidth = null;
	this.canvas = null;
	this.messages = new Array();;
	this.scrollerElement = null;
	this.messageElement = null;
	this.messageIndex = -1;
	this.self = null;
//	alert("hello");

	this.doNothing = function() {
		var tmp = "";
	};
	
	this.clickScroller = function() {
		clearTimeout(this.tim);
		document.location.href=this.messages[this.messageIndex]["url"];
	};
	
	this.moveScroller = function() {  
		var self = this;
		clearTimeout(this.tim);
		if(parseInt(this.messageElement.style.left) > (-1*this.divWidth)) {
			this.messageElement.style.left = (parseInt(this.messageElement.style.left) - this.distance)+"px";
			this.tim = setTimeout(function() { RDGscroller.moveScroller(self); }, this.timeoutTime);
		} else {
			this.startScroller();
		}
	};
	
	this.init = function() {
		this.scrollerElement = document.getElementById(this.scroller_id);
		for(var i in this.scrollerElement.childNodes) {
			if(this.scrollerElement.childNodes[i].nodeType==1) {
				switch(this.scrollerElement.childNodes[i].nodeName.toLowerCase()) {
					case "p": this.canvas = this.scrollerElement.childNodes[i]; break;
					case "ul": 
						for(var j in this.scrollerElement.childNodes[i].childNodes) {
							if(this.scrollerElement.childNodes[i].childNodes[j].nodeType==1) {
								this.messages.push({"url":this.scrollerElement.childNodes[i].childNodes[j].getAttribute("title"),"message":this.scrollerElement.childNodes[i].childNodes[j].firstChild.nodeValue});
							}
						}
						break;
				}
			}
		}
		if(this.messages.length > 0) {
			this.timeoutTime = 150-(self.speed*5);
			this.startScroller();
		}
	};
	
	this.startScroller = function() {
		var self = this;
		clearTimeout(this.tim);
		
		while(this.canvas.hasChildNodes()) this.canvas.removeChild(this.canvas.firstChild);
		
		this.messageIndex++;
		if(this.messageIndex >= this.messages.length) this.messageIndex = 0;  
		
		this.canvas.appendChild(html_tags["span"](
			{"onclick":(this.messages[this.messageIndex]["url"]?function() {RDGscroller.clickScroller(self);}:this.doNothing),"class":(this.messages[this.messageIndex]["url"]?"clickable":"nonclickable")},
			this.messages[this.messageIndex]["message"]));
		
		this.messageElement = this.canvas.firstChild;
		this.divWidth = this.messageElement.offsetWidth;
		this.parentWidth = this.canvas.offsetWidth;
		
		this.messageElement.style.left = this.parentWidth+"px";
		this.messageElement.style.visibility = "visible";
		this.moveScroller();
	};
}

var RDGscroller = new function() {
	this.scrollerItems = new Array();
	
	this.moveScroller = function(obj) {
		obj.moveScroller();
	};
	
	this.clickScroller = function(obj) {
		obj.clickScroller();
	};
	
	this.create = function(id, speed) {
		RDGscroller.scrollerItems.push(new RDGscroller_item(id, speed));
	};

	this.init = function() {
		var self = RDGscroller;
		for (var i in self.scrollerItems) {
			if(i >= 0) 
				self.scrollerItems[i].init();
		}
	};
}
RDGonloader.add("RDGscroller.init()");
