window.addEvent('domready', function() {
	
	var status = {
		'true': 'open',
		'false': 'close'
	};


	//create our Accordion instance
	var myAccordion = new Accordion($('accordion'), 'div.toggler', 'div.element', {
	    display: accordionDisplayElement,
		opacity: false,
		onActive: function(toggler, element){
			toggler.setStyle('color', '#6BB6ED');
		},
		onBackground: function(toggler, element){
			toggler.setStyle('color', '#fff');
		}
	});
	
    // Let's define some variables first
	var wrapper = $('wrap'); // The outer wrapper
	var wrapper2 = $('wrap2'); // The outer wrapper
	var carousel = $('carousel'); // The inner wrapper
	var carousel2 = $('carousel2'); // The inner wrapper
	var items = $$('#carousel li'); // The different elements, this is an array
	var items2 = $$('#carousel2 li'); // The different elements, this is an array
	var item_width = 129; // The full width of a single item (incl. borders, padding, etc ... if there is any)
	var item_width2 = 151; // The full width of a single item (incl. borders, padding, etc ... if there is any)
	var max_margin = items.length * item_width - item_width;
	var max_margin2 = items2.length * item_width2 - item_width2;
	
	// Set up the animation
	var animation = new Fx.Tween(carousel, {duration: 500});
	var animation2 = new Fx.Tween(carousel2, {duration: 500});
	
	// The function to browse forward
	function next_item(pos){
		if(pos == -max_margin){
			animation.start('left', 0);
		} else { 
			var newposition = pos - item_width;
			animation.start('left', newposition);
		}
	}
	
	function next_item2(pos){
		if(pos == -max_margin2){
			animation2.start('left', 0);
		} else { 
			var newposition2 = pos - item_width2;
			animation2.start('left', newposition2);
		}
	}
	
	// The function to browse backward
	function previous_item(pos){
		if(pos == 0){
			animation.start('left', -max_margin);
		} else { 
			var newposition = pos + item_width;
			animation.start('left', newposition);
		}
	}
	
	function previous_item2(pos){
		if(pos == 0){
			animation2.start('left', -max_margin2);
		} else { 
			var newposition2 = pos + item_width2;
			animation2.start('left', newposition2);
		}
	}
	
	
	// Set up the 'next' and 'previous' buttons
	$('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);
	});	
	
	


});

