/* ALDaySlider (C) 2010 Adrian Levano. All rights reserved.

Version 1.0.1 (Mootools 1.11)
ALDaySlider is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/
var ALDaySlider = new Class( {
	options: {
            duration : 500,
            delay : 5000,
            container: null,
            wrapper:'.eldayslider_wrapper',
            inner:'.eldayslider_inner',
            items: '.eldayslider_content',
            columns: '.eldayslider_column',
            prevBtn :'.eldayslider_prev',
            nextBtn :'.eldayslider_next',
            transition: Fx.Transitions.Back.easeInOut
	},
	current:	0,
	container:	null,
	wrapper:	null,
	inner:		null,
	items:		null,
	columns:	null,
	prevBtn:	null,
	nextBtn:	null,
	scroll:		null,

	initialize : function(options) {
		this.setOptions(options);
		this.container = $(this.options.container);
		this.wrapper = this.container.getElement(this.options.wrapper);
		this.inner = this.container.getElement(this.options.inner);
		this.items = this.container.getElements(this.options.items);
		this.columns= this.container.getElements(this.options.columns);
		this.prevBtn = this.container.getElement(this.options.prevBtn);
		this.nextBtn = this.container.getElement(this.options.nextBtn);
		this.scroll = new Fx.Scroll(this.wrapper, {wait: false,duration: this.options.duration,wheelStops: false,transition:this.options.transition});	
	
		this.inner.setStyle('width', 999999);
		this.inner.setStyle('height', this.wrapper.getSize().size.y);
		
		
		if($defined(this.prevBtn)) {
			this.prevBtn.addEvent('click', function(e) {
				e = new Event(e).stop();
				this.prev();
			}.bind(this));
		}
		
		if($defined(this.nextBtn)) {
			this.nextBtn.addEvent('click', function(e) {
				e = new Event(e).stop();
				this.next();
			}.bind(this)); 
		}

		if($defined(this.columns)) {
			this.columns.each(function(item,index) { 
				new Scroller(item, {
					'area': 20
				}).start();
			}); 
		}
	
	},
	next : function() {		
		if (this.current < this.items.length - 1){ 
			this.current++;
			this.scroll.toElement(this.items[this.current]);
		}
	},
	prev : function() {
		if (this.current > 0){ 
			this.current--;
			this.scroll.toElement(this.items[this.current]);
		}
	}
});

ALDaySlider.implement(new Options);
