// scroll.js

var basetime = 20;
scroll_items = new Array();

function scrollBaseTime()
{
	$each(scroll_items, function(item){item.scroll();});
	window.setTimeout(scrollBaseTime, basetime);
}

window.addEvent('domready', function() {
	window.setTimeout(scrollBaseTime, basetime);
	
	$each($$('.scroll_v'), function(item){
			var scroll = new ScrollText({'container': item});
			scroll.start();
			scroll_items.include(scroll);
		});
	});

var ScrollText = new Class({
	Implements: Options,
	limit_y: 0,
	limit_x: 0,
	waitCount: 0,
	waitStart: 0,
	halted: false,
	options: {
		container: null,
		speed: 1,
		step: 2,
		stopOnMouseUp: true,
		pause: 100
	},
	initialize: function(options){
		this.setOptions(options);
		var sc=this.options.container.getScrollSize();
		var sz=this.options.container.getSize();
		this.limit_x=sc.x-sz.x;
		this.limit_y=sc.y-sz.y;
		if(this.options.stopOnMouseUp)
		{
			var self = this;
			this.options.container.addEvent('mouseover', function(){
				self.halted=true;
			});
			this.options.container.addEvent('mouseout', function(){
				self.halted=false;
			});
		}
	},
	start: function(){
		this.options.container.scrollTo(0,0);
		this.waitStart = this.options.pause;
	},
	scroll: function(){
		if(this.halted) return;
		if(this.waitStart > 0)
		{
			this.waitStart--;
			return;
		}
		var sc = this.options.container.getScroll();
		sc.y += this.options.step;
		if(sc.y >= this.limit_y)
		{
			if(--this.waitCount<=0)
			{
				this.start();
			}
		}
		else
		{
			this.waitCount = this.options.pause;
			this.options.container.scrollTo(0,sc.y);
		}
	}
});
	
	
