
var Scroller = Class.create();

Scroller.prototype = {
	
	initialize: function(containerId, direction)
	{
		
		this.container = $(containerId);
		this.direction = direction;
		this.go = false;
		this.interval = 225;
		
		if (!this.container)
			return false;
		
		this.container.style.position = 'relative';
		this.container.style.overflow = 'hidden';
		this.container.style.whiteSpace = 'nowrap';
		
		Event.observe(window, 'load', this.setup.bindAsEventListener(this));
		
	},
	
	setup: function()
	{
		var tempHTML = this.container.innerHTML;
		
		this.group1 = document.createElement('div');
		this.group1.innerHTML = tempHTML;
		this.group1.style.position = 'absolute';
		
		
		this.container.innerHTML = '';
		this.container.appendChild(this.group1);
		if (this.direction == 'vert')
			this.offset = this.group1.offsetHeight;
		else
			this.offset = this.group1.offsetWidth;
		
		this.group2 = document.createElement('div');
		this.group2.innerHTML = tempHTML;
		this.group2.style.position = 'absolute';
		
		if (this.direction == 'vert')
			this.group2.style.top = this.offset + 2+ 'px';
		else
			this.group2.style.left = this.offset + 2+ 'px';
		
		this.container.appendChild(this.group2);
		
		
		this.start();
	},
	
	start: function()
	{
		this.go = true;
		setTimeout(this.scroll.bindAsEventListener(this), this.interval);
	},
	
	stop: function()
	{
		this.go = false;
	},
	
	scroll: function()
	{	
		if (!this.go)
			return;
		
		if (this.direction == 'vert') {
			this.group1.style.top = this.group1.style.top.replace('px', '') - 2 + 'px';
			this.group2.style.top = this.group2.style.top.replace('px', '') - 2 + 'px';
			
			if (this.group1.offsetTop <= 0) {
				this.group2.style.top = this.offset + 2 + 'px';
				
				var temp = this.group1;
				this.group1 = this.group2;
				this.group2 = temp;
				//reset
			}
		} else {
			this.group1.style.left = this.group1.style.left.replace('px', '') - 2 + 'px';
			this.group2.style.left = this.group2.style.left.replace('px', '') - 2 + 'px';
			
			if (this.group1.offsetLeft <= 0) {
				this.group2.style.left = this.offset + 2 + 'px';
				
				var temp = this.group1;
				this.group1 = this.group2;
				this.group2 = temp;
				//reset
			}
		}
		
		setTimeout(this.scroll.bindAsEventListener(this), this.interval);
	}
	
};







