window.addEvent('domready', function () {
	
		var duration = 1000,
		
			links = $$('div.tabs a'),
			
			tab = new Carousel({
				container: 'slide',
				scroll: 1,
				circular: true,
				current: 0,
				/* mode: 'horizontal', */
				onChange: function (index) {
					links.each(function (el, off) {
					el[off == index ? 'addClass' : 'removeClass']('selected')
					})
				},
				fx: {
					transition: Fx.Transitions.Quart.easeOut,
					duration: 800
				}
			}),
			
			pe = new PeriodicalExecuter(function () {
		
				// tab.move((tab.first() + 1) % 5) // FS mod 5 entfernt da Probleme mit mehr als 5 Items dazu führt, dass er die letzten überspringt
				tab.move((tab.first() + 1))
			}, duration / 1000 + 5);
			
			[links.shift(), links.pop()].map(function (el, index) {
			
				el.addEvent('click', function (e) {
				
					e.stop();
					pe.stop();
					
					tab.move(tab.first() + (index == 0 ? -1 : 1) * tab.options.scroll);
					
					(function () { pe.registerCallback() }).delay(2 * duration)
				})
			});
		
		links.each(function (el, index) {
		
			el.addEvent('click', function (e) {
				
				e.stop();
				pe.stop();
				
				tab.move(index);
				(function () { pe.registerCallback() }).delay(2 * duration)
			})
		})
	});

