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

	// Let's define some variables first
	var wrapper = $('wrap'); // The outer wrapper
	var carousel = $('carousel'); // The inner wrapper
//	var items = $$('#carousel li'); // The different elements, this is an array
	var items = document.getElementsByTagName('li'); // provisum mod

	var item_width = 890; // The full width of a single item (incl. borders, padding, etc ... if there is any)
	var maxmargin = items.length * item_width - item_width;
	
	// Set up the animation
	var animation = new Fx.Tween(carousel, {duration: 800});
	

	// The function to browse forward
	function next_item(pos){
		if(pos == -maxmargin){
			animation.start('left', 0);
		} else { 
			var newposition = pos - item_width;
			animation.start('left', newposition);
		}
	}
	
	// The function to browse backward
	function previous_item(pos){
		if(pos == 0){
			animation.start('left', -maxmargin);
		} else { 
			var newposition = pos + item_width;
			animation.start('left', newposition);
		}
	}
	
	// Set up the 'next' and 'previous' buttons
	
	$('startover').addEvent('click', function(){
		var position = parseInt(carousel.getStyle('left'));
		next_item(position);
	});
	
	$('next').addEvent('click', function(){
		var position = parseInt(carousel.getStyle('left'));
		next_item(position);
	});
	
	
	$('previous').addEvent('click', function(){
		var position = parseInt(carousel.getStyle('left'));
		previous_item(position);
	});

//var repeat = function() {
//var position = parseInt(carousel.getStyle('left'));
//next_item(position);
//};
//repeat.periodical(15000);

}); 



