;(function($, undefined){
	$.fn.cycle.transitions.scrollLeft = function($cont, $slides, opts) {
		$cont.css('overflow','hidden');
		opts.before.push($.fn.cycle.commonReset);
		var w = $cont.width();
		opts.cssFirst.left = 0;
		opts.cssBefore.left = w;
		opts.cssBefore.top = 0;
		opts.animIn.left = 0;
		opts.animOut.left = 0-w;
	};
	
	
	/**
	 * Gestion des précisions pour les cases à cocher "autres"
	 */
	$.fn.ifrChampsPrecisions = function(){
		this.each(function(){
			var $this = $(this);
			var $autreCheckbox = $this.prev('.form-field').find('input[type="checkbox"]:last');
			
			$this.hide();
			
			$autreCheckbox.change( function(){
				if(this.checked){
					$this.slideDown('fast');
				} else {
					$this.slideUp('fast');
				}
			});
			$autreCheckbox.change();
		});
	};

	$(function(){
		/**
		 * Calage des marges du menu
		 */
		setTimeout(function(){
			var totalWidth = $('header .menu').width();
			var linksWidth = 0;
			var links = $('header .menu').children();
			var curW = 0;
			links.each(function(){
				curW = $(this).width();
				linksWidth += curW;
			});
			
			var margin = Math.floor( ( totalWidth - linksWidth ) / ( links.length - 1 ) );
			links.not( links.last() ).css('margin-right', margin + 'px' );
				//Sur IE9, 2 pixels font chier
			links.eq( links.length - 2 ).css('margin-right', (margin-2) + 'px' );
			links.last().css('margin-right', 0);
		}, 1000);
		
		
		
		
		$('.block-latest_news').children().helioEqualHeight();
		
		$('.full.class-references').ifrRef();
		
		$('#liste-raisons').accordion({ header: "h1", autoHeight:false });
		
		$( ".onglets-article" ).tabs();
		
		$( "#liste_glossaire" ).tabs();
		
		
		$('.form-formulaire_partenaire').find('.field-autre_domaine, .field-autre_motivation, .field-autre_type').ifrChampsPrecisions();
		
		
		//hauteur des flèches du menu de gauche
		var additionalCSS = {};
		$(".left_menu a.level1").each(function(){
			var $this = $(this);
			var h = $this.outerHeight(); 
			if( h > 21 )	//21 est la hauteur normale d'une ligne (en tout cas la hauteur définie via les bordures du :after)
			{
				additionalCSS['menu_hook' + h ] = '.left_menu ul li a.level1.menu_hook' + h + ':hover:after, '
										   + '.left_menu ul li a.level1.current.menu_hook' + h + ':after{ '
										   + 'border-top-width: ' + Math.floor(h/2) + 'px; '
										   + 'border-bottom-width: ' + Math.ceil(h/2) + 'px; '
										   + '}';
				$this.addClass( 'menu_hook' + h );
			}
		});
		
		if( additionalCSS )
		{
			var css = '<style type="text/css">';
			for( var i in additionalCSS )
			{
				css += additionalCSS[i];
			}
			css += '</style>';
			
			$('head').append( css );
		}
		
			
		
		//hack Séparateurs footer IE
		var $ie = $('.ie7, .ie8');
		if( $ie.length > 0 )
			$ie.find('footer .liens a').not(':last-child').after('|');
	});
})(window.jQuery);
