// JavaScript Document
var RollingContent = null;

var RollingContent = Class.create({
	initialize: function(elm, options) {
		
		this.container = $(elm);
		
		this.options = Object.extend({
			Direction: 'left',
			step: 1,
			delay: 100,
			stopOnOver: true
		}, options || {});

		if (this.options.stopOnOver) {
			Event.observe(this.container, 'mouseover', this.stop.bindAsEventListener(this));
			Event.observe(this.container, 'mouseout', this.start.bindAsEventListener(this));
		}

		this.start();
	},
	start:function() {
		if (!this.timer) {
			if (this.options.Direction=='left') {
				this.timer = setInterval(this.left.bind(this), this.options.delay);
			} else if (this.options.Direction=='right') {
				
			} else if (this.options.Direction=='up') {
				this.timer = setInterval(this.up.bind(this), this.options.delay);
			} else if (this.options.Direction=='down') {
					
			}
		}
	},
	left: function() {
		this.container.scrollLeft += this.options.step;
		if (this.container.scrollLeft>Element.childElements(this.container).first().getWidth()) {
			this.container.appendChild(Element.childElements(this.container).first().cloneNode(true));
			Element.childElements(this.container).first().remove();
			this.container.scrollLeft = 0;
		}
	},
	right: function() {

	},
	up: function() {
		this.container.scrollTop += this.options.step;
		if (this.container.scrollTop>Element.childElements(this.container).first().getHeight()) {
			this.container.appendChild(Element.childElements(this.container).first().cloneNode(true));
			Element.childElements(this.container).first().remove();
			this.container.scrollTop = 0;
		}
	},
	down: function() {
		
	},
	stop: function() {
		clearInterval(this.timer);
		this.timer = null;
	}
});