
	var targets 		= [];
	var handlers		= [];
	
	var closeAll = function(){
		for (var i = 0; i<targets.length; i++){
			targets[i].removeClassName('current');
			handlers[i].removeClassName('current');
		}
	};
	var setCurrentTab = function(index){
		targets[index].addClassName('current');
		handlers[index].addClassName('current');
	};
	
	var caroussel = function(){
		
		var prev = $('prev');
		var next = $('next');
		
		prev.setStyle({opacity: 0.5});
		
		var gap 			= 200;
		var currentPos 		= 0;
		var maxPos 			= parseInt($('caroussel').select('ul li').length * gap);
		var carousselElt 	= $('caroussel').down('ul');
		var isMoving 		= false;

		var go = function(direction){
   
			if(!isMoving){
			
				var dir = (direction == 'left') ? 1 : -1;
				var newGap = parseInt(dir * gap);
   
				if((currentPos >= newGap) && (currentPos < maxPos + newGap)){
					new Effect.Move(carousselElt, {
						x: newGap,
						mode: 'relative',
						duration : 0.2,
						beforeStart : function(){
							isMoving = true;
							prev.setStyle({opacity: 1});
							next.setStyle({opacity: 1});
						},
						afterFinish : function(){
							isMoving = false;
							currentPos -= newGap;
							if (currentPos == 0){prev.setStyle({opacity: 0.5});}
							if (currentPos == maxPos-gap){next.setStyle({opacity: 0.5});}
							console.log("0", currentPos, maxPos);
						}
					});
				}
   
			} // isMoving ?
		};
		
		prev.observe('click', function(){go('left')});
		next.observe('click', function(){go('right')});
	};
	
	var behaviors = function(){
		
		var handlersCollection 	= $$('#tabs li a');
		
		handlersCollection.each(function(handler, index){
			
			var id			= handler.readAttribute('href').split('#')[1];
			var target		= $(id);
			
			handler.writeAttribute('href', 'javascript:void(0);');
			
			targets[index]	= target;
			handlers[index]	= handler;
			
			handler.observe('click', function(){
				closeAll();
				setCurrentTab(index);
			});
			
		});
		
		$('formAnchor').writeAttribute('href', 'javascript:void(0);');
		$('formAnchor').observe('click', function(){
			new Effect.ScrollTo('form');
			new Effect.Pulsate('form', { pulses: 2, duration: 1 });
		});
		
		caroussel();
		
	};
	
	document.observe('dom:loaded', behaviors);