// Clear the element
function carousel(e_items)
{
	// Variable Setup
	var o_items = e_items;
	var o_menu = $$("a.introLink");				
	var i_position = 0;
	var i_currentItem = 1;
	
	// Tween instance setup
	var o_tween = new Fx.Tween(o_items);
	var i_interval = 5000;
	
	// Periodical Tween
	var timedCarousel = function(){
		if(i_currentItem < 3) i_currentItem++;
		else i_currentItem = 1;
		
		activeMenu(o_menu, i_currentItem);			
		
		// Determine position, based on the currentItem
		i_position = -((i_currentItem * 244) - 244); 
		o_tween.start('margin-left', i_position);
	};
	// Periodical function from mootools
	timedCarousel.periodical(i_interval);
	
	// Loop through carousel links
	o_menu.each(function(el){		
		el.addEvent("click", function(){			
			// Fetch currently selected item(this is located in each link's href)
			i_currentItem = (el.get('href'));		
			// Determine position, based on the currentItem
			i_position = -((i_currentItem * 244) - 244); 
			// Start tween
			o_tween.start('margin-left', i_position);

			activeMenu(o_menu, i_currentItem);
			
			// Cancel default href action
			return false;
		});
	});
}

// Clean menu styles and style the active one
function activeMenu(o_menu, i_currentItem)
{
	o_menu.each(function(elem){			
		if(elem.get('href') == i_currentItem) elem.getParent().setStyle('background-color', '#0096d7');
		else elem.getParent().setStyle('background-color', '#6DB7D6');
	});	
}