var OM_mooScroller = new Class({
	Implements: [Options, Events],
	options: {
		controlPrev: 'controlPrev',
		controlNext: 'controlNext',
		scroller: 'scroller_wrapper',
		transition: Fx.Transitions.Quad.easeInOut,
		duration: 500
	},
	initialize: function(options){
		this.currentScroll = 1;
		this.setOptions(options);
		window.addEvent('domready', this.domReady.bind(this));
	},
	domReady: function(){
		this.scroller = $(this.options.scroller);
		if($defined(this.scroller)){
			this.controlPrev = $(this.options.controlPrev);
			this.controlNext = $(this.options.controlNext);
			this.scrollItems = this.scroller.getElements('div.scroll').length;
			this.scrollHandler = new Fx.Scroll(this.scroller,{
				link: 'chain',
				transition: this.options.transition,
				duration: this.options.duration
			});
			
			if($defined(this.controlPrev)){
				this.controlPrev.addEvent('click', this.scrollPrev.bind(this));
			}
			if($defined(this.controlNext)){
				this.controlNext.addEvent('click', this.scrollNext.bind(this));
			}
		};
	},
	scrollPrev: function(event){
		event.stop()
		if(this.currentScroll>1){
			this.scrollHandler.toElement('nouveaute'+(this.currentScroll - 2));
			this.currentScroll = (this.currentScroll - 2);
		}
		else{
			this.scrollHandler.toElement('nouveaute'+this.scrollItems);
			this.currentScroll = this.scrollItems;
		};
	},
	scrollNext: function(event){
		event.stop();
		if(this.currentScroll<(this.scrollItems-1)){
			this.scrollHandler.toElement('nouveaute'+(this.currentScroll + 2));
			this.currentScroll = (this.currentScroll + 2);
		}
		else{
			this.scrollHandler.toElement('nouveaute1');
			this.currentScroll = 1;
		};
	}
});
