//Add the window event to create the class
window.addEvent("domready", function() {

	new EventView("EventViewWrapper", {
		item: {
			klass: "EventViewScroll"
		}
	});
});	
  
var EventView = new Class({
	options: {
		interval: 6000,	//Set the interval (ms)
		item: {
			klass: "item"
		}
	},

	//Create class instance
	//container = the first argument in "new EventView" call in "window.addEvent("domready"..."
	initialize: function(container, options) {
		this.setOptions(options);
		this.container = $(container);
		
		this.scrollPos = 0;
		this.scrollHt = $('EventViewScroll').getStyle('height');
		this.viewHt = $('HomePageEvents').getStyle('height');

		this.timer = $clear(this.timer);
		this.timer = this._scrollList.periodical(this.options.interval, this);

		$('EventViewWrapper').addEvent('mouseleave', function(e){
//			e.stop();
			//Advance on mouse leave
			this._scrollList();
			//Start timer on mouse leave
			this.timer = $clear(this.timer);
			this.timer = this._scrollList.periodical(this.options.interval, this);
		}.bind(this));

		$('EventViewWrapper').addEvent('mouseenter', function(e){
//			e.stop();
			//Stop timer on mouse enter
			this.timer = $clear(this.timer);
		}.bind(this));
	},

	_scrollList: function(curItem) {
//		var lastPos = this.scrollPos;
		this.scrollPos -= (400 - 40) / 2;
//		$('EventViewScroll').fade('out');
		$('EventViewScroll').setStyle('margin-top', this.scrollPos);
//		$('EventViewScroll').tween('margin-top', [lastPos, this.scrollPos]);
	
		//Scrolled to end? Then back to beginning
		if(this.scrollPos <= -parseInt(this.scrollHt)){
			this.scrollPos = parseInt(0);
			$('EventViewScroll').setStyle('margin-top', this.scrollPos);
		}

//		$('EventViewScroll').fade('in');
	}	//END: _scrollList
});
EventView.implement(new Events); // Implements addEvent(type, fn), fireEvent(type, [args], delay) and removeEvent(type, fn)
EventView.implement(new Options);// Implements setOptions(defaults, options)
