// JavaScript Document

	window.addEvent('domready', function() { 
			
		// CAROUSEL 
		// --------------------------------------------------------------------------------------------------------
		
		// 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 nav_items = $$('#carousel_nav li'); // The different elements, this is an array
				
		if ($chk(carousel) && $chk(wrapper)) {
		
			var itemwidth = parseInt(wrapper.getStyle('width')); // The full width of a single item
			var maxmargin = items.length * itemwidth - itemwidth;
		
			// Set up the animation
			var animation = new Fx.Tween(carousel, {duration: 500});
			
			// The function to browse forward
			function next_item(pos){
				if(pos == -maxmargin){
					animation.start('left', 0);
				} else { 
					var newposition = pos - itemwidth;
					animation.start('left', newposition);
				}
			}
			
			// The function to browse backward
			function previous_item(pos){
				if(pos == 0){
					animation.start('left', -maxmargin);
				} else {
					var newposition = pos + itemwidth;
					animation.start('left', newposition);
				}
			}
		
			// The function to browse to any
			function select_item(pos, itemno){
				var newposition = (itemno*itemwidth-itemwidth)+pos;
				animation.start('left', pos-newposition);
			}
			
			// Set up the 'next' and 'previous' buttons
			
			if ($chk($('next')) && $chk($('previous'))) {
				$('next').addEvent('click', function(){
					var position = parseInt(carousel.getStyle('left'));
					next_item(position);
					return false;
				});
				$('previous').addEvent('click', function(){
					var position = parseInt(carousel.getStyle('left'));
					previous_item(position);
					return false;
				});
			}
			
			$$('#carousel_nav li').addEvent('click', function(){
				return false;
			});								
			
			$$('#carousel_nav li.available').addEvent('click', function(){
				var item_number = $$('#carousel_nav li').indexOf(this) + 1;
				$('this_item').removeProperty('id');
				this.setProperty('id', 'this_item');
				if (item_number) { 
					var position = parseInt(item_number)*itemwidth-itemwidth;
					select_item(position, item_number);
				}
				return false;
			});
			
			$('carousel_nav').getFirst().setProperty('id', 'this_item');	
		}
	}); 
	
	// Setup Flash
	AC_FL_RunContent = 0;