var magicScroller = Class.create();
magicScroller.prototype = {
	initialize: function(containerId) {
		var options = Object.extend({
			scrollInterval : 3000,
			isScrollPaused : false,
			amountToScroll : 0,
			totalScroll : 0,
			isScrollPaused: false,
			scrollIntervalId: null,
			lastItem:0,
			items_num:0
		}, arguments[1] || {});
		this.options=options;
		this.firstTime=true;
		this.container=$($(containerId).getElementsByTagName('ul')[0]);
		this.items=this.container.getElementsByTagName('li');
		this.options.items_num=this.items.length;
		//console.log(this.items[this.options.lastItem]);
		
		//Logger.info($A(this.items).inspect());
		
		//Logger.info($(this.items[this.options.lastItem]).getHeight());
		
		var timeoutCallback = this.scroll.bind(this);

		if (this.container.getHeight()>this.container.parentNode.getHeight()) {
			Event.observe(this.container,'mouseover',this.pauseScroll.bind(this));
			Event.observe(this.container,'mouseout',this.resumeScroll.bind(this));
			
			window.setInterval(function() { timeoutCallback(); }, this.options.scrollInterval);
		}
	},
	scroll: function() {
		if(!this.options.isScrollPaused) {
			
			this.options.amountToScroll=$(this.items[this.options.lastItem]).getHeight();

			var context=this;

			new Effect.Move(this.container,{
				y:-this.options.amountToScroll,
				mode:'relative',
				duration:1,
				afterFinish:function() {
					//context.container.appendChild(context.items[context.options.lastItem]);
					//context.container.style.top="0px";
					
					context.container.appendChild(context.items[context.options.lastItem].cloneNode(true));
					context.options.lastItem++;
				}
			});
		}
	},
	pauseScroll:function() {
		Try.these(
			function() {console.log("pause")},
			function() {Logger.info("pause")}
		);
		this.options.isScrollPaused = true;
	},
	resumeScroll:function() {
		Try.these(
			function() {console.log("resume")},
			function() {Logger.info("resume")}
		);
		this.options.isScrollPaused = false;
		//this.options.scrollIntervalId=window.setInterval(function() { timeoutCallback(); }, this.options.scrollInterval);
	}
};