var dpSlider = new Class({
	active: 0,
	getOptions: function(){
		return {
			'element': null,
			'slideClass': 'slide',
			'width': 900,
			'speed': 4000,
			'go_delay': 8000,
			'slides': 0,
			'next': null,
			'previous': null
		}
	},
	initialize: function(options){
		this.setOptions(this.getOptions(), options);

		if (this.options.element == null) {
			alert('No element selected!');
		} else {
			window.addEvent('domready', function(){
				this.el = $(this.options.element);
				this.options.slides = this.el.getElements('.slide').length;
				this.el.setStyle('width', this.options.width*this.options.slides);
				this.createRotation();

				if (this.options.previous !== null){
					$(this.options.previous).addEvent('click', function(){
						this.previous();
					}.bind(this));
				}

				if (this.options.next !== null){
					$(this.options.next).addEvent('click', function(){
						this.next();
					}.bind(this));
				}
			}.bind(this));
		}
	},
	createRotation: function(){
		this.rotate();
		this.timer = this.rotate.periodical(this.options.speed, this);
	},
	clearRotation: function(){
		clearTimeout(this.delayer);
		clearInterval(this.timer);
	},
	rotate: function(){
		var margin = parseInt(this.el.getStyle('margin-left').replace(/px/, ''));
		if (margin == this.options.width*(this.options.slides-1)*-1) {
			this.active = 1;
			margin = 0;
		} else {
			margin = this.options.width*this.active*-1;
			this.active++;
		}
		this.el.tween('margin-left', margin);
	},
	go: function(key){
		this.clearRotation();
		this.active = key-1;
		margin = this.options.width*this.active*-1;
		this.el.tween('margin-left', margin);
		this.active++;
		this.delayer = (function(){this.createRotation()}.bind(this)).delay(this.options.go_delay);
	},
	next: function(){
		if (this.active < this.options.slides) {
			this.go(++this.active);
		} else {
			this.go(1);
		}
	},
	previous: function(){
		if (this.active > 1) {
			this.go(--this.active);
		} else {
			this.go(this.options.slides);
		}
	}
}).implement(new Options);
