// Carousel Class
var lusan_carousel = new Class({
    Implements: [Events, Options],

    options: {
	// Der zurückButton        
	leftButton: 'additionalimages_prev',
	// Der VorButton
	rightButton: 'additionalimages_next',
	// Breite der CarouselElemente
	itemWidth: 67,
	// Selektor für die Subelemente
	subItems: 'li',
	// Onclick Funktion
	clickFunction:$empty
    },
    
    initialize: function(wrapper, carousel, options){
	this.setOptions(options);
	this.leftButton = $(this.options.leftButton);
        this.rightButton = $(this.options.rightButton);
	if (!wrapper || !carousel){alert('wrapper oder carousel nicht gefunden'); return false;}        
	this.wrapper = wrapper;
        this.carousel = carousel;
	this.tweener = new Fx.Tween(carousel, {duration:500});	
	this.carouselWidth = 0;
	this.currentPosition = 0;	
	carousel.getElements(this.options.subItems).each(function(item){
		item.addEvent('click',this.options.clickFunction);
		this.carouselWidth+=this.options.itemWidth;	
	}.bind(this));
	this.leftButton.addEvent('click',function(){this.moveNext();}.bind(this)).setStyle('cursor','pointer');
        this.rightButton.addEvent('click',function(){this.movePrevious();}.bind(this)).setStyle('cursor','pointer');
    },
    moveNext:function(){
	var newposition =  this.currentPosition+this.options.itemWidth;		
	if (newposition < 1){
		this.tweener.start('left',this.currentPosition, newposition);
		this.currentPosition = newposition;
	}

	},
    movePrevious: function(){
	var newposition =  this.currentPosition-this.options.itemWidth;		
	if (Math.abs(newposition)<= (this.carouselWidth-this.wrapper.getStyle('width').toInt())){
		this.tweener.start('left',this.currentPosition, newposition);
		this.currentPosition = newposition;
	}

	}
});

