var SlideScroll = new Activa.Class({
	fx: null,
	container: null,
	slider: null,
	number: 0,
	current: 1,
	current_element: null,
	previous_element: null,
	timer: null,
	
	options: {
		link_prefix: null,
		link_on_class: null,
		fps: 50,
		duration: 800,
		width: 1000,
		//transition: Fx.Transitions.Sine.easeOut
		//transition: Fx.Transitions.Bounce.easeOut
		transition: Fx.Transitions.Circ.easeOut,
		auto_scroll: true,
		auto_scroll_duration: 5,
		number: 1
	}, 
	
	init: function init(container, slider, options) {
		this.container = did(container);
		this.slider = did(slider);
		this.setOptions(options);
		
		this.fx = new Fx.Scroll(this.container, this.options);
		//this.number = this.container.getElementsByTagName('img').length;
		this.number = this.options.number;
		
		// Set the width of the Slider
		this.slider.style.width = parseInt(this.number) * parseInt(this.options.width)+'px'
	},
	setOptions: function setOptions(options) {
		options = options || {};
		for ( var k in this.options ) {
			this.options[k] = (k in options) ? options[k] : this.options[k];
			if ( k == 'auto_scroll_duration' ) {
				this.options[k] = this.options[k] * 1000;
			}
		}
	},
	goTo: function goTo(pos) {
		if ( this.options.auto_scroll ) {
			clearTimeout(this.timer);
		}
		
		if ( this.options.link_prefix ) {
			if ( this.current_element ) {
				this.previous_element = this.current_element;
			}
			this.current_element = did(this.options.link_prefix+pos);
		}
		
		Activa.DOM.addClass(this.current_element, this.options.link_on_class);
        Activa.DOM.removeClass(this.previous_element, this.options.link_on_class);
        
		this.fx.start(parseInt(this.options.width) * (parseInt(pos)-1), 0);
		this.current = parseInt(pos);
		
		if ( this.options.auto_scroll ) {
			this.timer = setTimeout(function() {
				this.next();
			}.bind(this), this.options.auto_scroll_duration);
		}
	},
	next: function next() {
		this.goTo(this.current==this.number ? 1 : this.current+1);
	}
});