var Carousel = Class.create();
Carousel.prototype = {
    initialize: function(key) {
		this.element = $(key);
		this.width = this.element.getWidth();
		this.list = this.element.getElementsByClassName('carousel-items')[0];
		this.items = this.list.getElementsByTagName('li');
		this.numItems = this.items.length;
		this.currentItem = 0;
	},
	
	next: function() {
		if (this.currentItem < this.numItems-1) {
			++this.currentItem;
			this.animate();
		}
	},
	
	prev: function() {
		if (this.currentItem > 0) {
			--this.currentItem;
			this.animate();
		}
	},
	
	goto: function(index) {
		if (index >= 0 && index < this.numItems) {
			this.currentItem = index;
			this.animate();
		}
	},
	
	animate: function() {
		new Effect.Morph(this.list, {style: 'left: -' + (this.width * this.currentItem) + 'px', duration: 1});
	}
}