var Slider = new Activa.Class({
	fx: null,
	container: null,
	slider: null,
	direction: null,
	options: {
	}, 
	
	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.fx.options.onComplete = function() {
			this.fx.options.transition = Fx.Transitions.Sine.easeOut;
			var move = 50;
			this.calcDuration(move*2);
			if ( this.direction == 'left' ) {
				this.fx.start(this.getMove(move), 0);	
			} else if ( this.direction == 'right' ) {
				this.fx.start(this.getMove(-move), 0);
			}
			this.fx.options.transition = Fx.Transitions.Sine.easeInOut;
		}.bind(this);
	},
	setOptions: function setOptions(options) {
		options = options || {};
		for ( var k in this.options ) {
			this.options[k] = (k in options) ? options[k] : this.options[k];
		}
	},
	start: function start(pos) {
		if ( pos == 'left' ) {
			this.direction = 'left';
			this.calcDuration(this.container.scrollLeft, true);
			move = this.getScroll();
			this.fx.start(move, 0);
		} else {
			this.direction = 'right';
			this.calcDuration(this.container.scrollLeft);
			this.fx.start(0, 0);
		}
	},
	stop: function stop() {
		this.fx.stop();
		this.direction = null;
	},
	getMove: function(jump) {
		var cur = this.container.scrollLeft;
		var move = cur + jump;
		if ( move < 0 ) {
			return 0;
		} else if ( move >= this.getScroll() ) {
			return this.getScroll();
		} else {
			return move;
		}
	},
	calcDuration: function calcDuration(int, left) {
		if ( !left ) {
			left = false;
		}
		if ( int == 0 ) {
			int = this.getScroll();
		} else if ( left ) {
			int = this.getScroll() - int
		}
		//console.log(this.getScroll(), int, this.container.scrollLeft);
		var move = int * 5;
		if ( move < 400 ) {
			move = 500;
		}
		this.fx.options.duration = move;
	},
	getScroll: function() {
		return this.container.scrollWidth - this.container.offsetWidth;
	}
});
