jQuery('document').ready(function() {

	jQuery('ul#menu-header li:first-child').addClass('first');
	jQuery('ul#menu-header li:last-child').addClass('last');
	
	
	jQuery('#menu-header').superfish({
		autoArrows : false,
		dropShadows : false
	}); 
	jQuery('#slider_formation').coolSlider();
	
	//Cufon.replace('.cufon', { fontFamily : 'Helvetica Neue', hover : true });
	//Cufon.replace('#content h3', { fontFamily : 'Helvetica Neue', hover : true });
	//Cufon.replace('.cufon2', { fontFamily : 'Helvetica Neue Condensed' });
	//Cufon.replace('.items li', { fontFamily : 'Helvetica Neue Condensed' });
	//Cufon.replace('.menu-item', { fontFamily : 'Helvetica Neue Condensed' });
	
	jQuery('.empty_focus').focusin(function() {
		jQuery(this).val('');
	});
	
	jQuery('#linkami').click(function() {
		jQuery('#envoyer_ami').slideToggle();
	});
	
	
	jQuery('.emptyfocus').focusin(function() {
		jQuery(this).val('');
	});
	
});


////////////////////////////////////////
//COOLSLIDER
////////////////////////////////////////
(function($){
	$.fn.coolSlider = function() {
		
		var base = this;
		var $parent = jQuery(this);
		var $liste = $parent.find('ul'); //items container
		var $nextbtn = $parent.find('#nav_form_left');
		var $prevbtn = $parent.find('#nav_form_right');
		var listId = $liste.attr('id'); //id of the items container
		var nbItems = jQuery('#'+listId+' li').length; //nombre d'items dans le slider
		var itemWidth = jQuery('#'+listId+' li').outerWidth(true); //item width

		
		//calculate container width depending of the number of items
		var containerWidth= nbItems*itemWidth;

		//set container width
		$liste.width(containerWidth);
		
		//INIT
		if(getIndex()==0) {
			$prevbtn.hide();
		}
		
		//return the container left position
		function getPos() {
			if($liste.html() != null)
			{
				var position=$liste.position();
				return position.left;
			}
		}
		
		//return the current position of the slider
		function getIndex() {
			var pos=getPos();
			var index = pos/itemWidth;
			return index;
		}
		
		//click on "next" button
		$nextbtn.click( function() {
			var curIndex = getIndex();
			
			if(nbItems+curIndex==4) {
					$nextbtn.hide();
				}
				
				
			$liste.animate({ left : '-='+itemWidth },
			500,
			function () {
				var curIndex = getIndex();

				if(curIndex<0) {
					if(!$prevbtn.is(":visible")) $prevbtn.fadeIn();
				}
			}
		);
			
			return false;
		});
		
		//click on "previous" button
		$prevbtn.click( function() {
			
			var curIndex = getIndex();
			//if the slider is at the first position, hide the previous button
			if(curIndex==-1) {
				$prevbtn.hide();
			}
				
			$liste.animate({ left : '+='+itemWidth },
			500,
			function () {
				var curIndex = getIndex();

				if(nbItems+curIndex>2) {
					if(!$nextbtn.is(":visible")) $nextbtn.fadeIn();
				}
			}
		);
			
			return false;
		});
		
		$liste.find('li').each(function(i){
			var link=jQuery(this,i).find('a').attr('href')||'';
			if(link!=='') {
				jQuery(this,i).hover(function() {
					jQuery(this,i).css('cursor', 'pointer');
				}, function() {
					jQuery(this,i).css('cursor', 'default');
				});
				jQuery(this,i).click(function() {
					jQuery.scrollTo("#header",800);
					document.location.href= link;
				});
			}
		});
		
		
	}
})(jQuery);
////////////////////////////////////////
//END OF COOLSLIDER
////////////////////////////////////////

