window.addEvent('domready', function() { 

	// Let's define some variables first
	var wrapper = $('quotebox'); // The outer wrapper
	var carousel = $('carousel'); // The inner wrapper
	var items = $$('#carousel li'); // The different elements, this is an array
	var item_width = 400; // The full width of a single item (incl. borders, padding, etc ... if there is any)
	var max_margin = items.length * item_width - item_width;
	
	// Set up the animation
	var animation = new Fx.Tween(carousel, {duration: 700});
	var returnanim = new Fx.Tween(carousel, {duration: 0});
	
	// The function to browse forward
	function next_item(pos){
		if(pos == -max_margin){
			returnanim.start('left', 0);
		} else { 
			var newposition = pos - item_width;
			animation.start('left', newposition);
		}
	}
	
	var repeat = function() {
		var position = parseInt(carousel.getStyle('left'));
		next_item(position);
	};
	
	repeat.periodical(5000);


});
