$(document).ready(function() {
	/*****************************************
	* DESACTIVER LE LISERET AU CLICK SUR LES
	* LIENS
	****************************************/
	$('a').focus(function(){$(this).blur()});
	
	/*****************************************
	* REMPLACER LES BTNS "EN SAVOIR PLUS"
	****************************************/
	$('a.more').each(function() { 
		$(this).append('<img src="images/title/en-savoir-plus.png" alt="En savoir plus" title="En savoir plus" />');
	});
		
		
	/*****************************************
	* DEFINIR LES RUBRIQUES COURANTES
	****************************************/
	var url = $(location).attr('href').split(/\//);
	
	var prerub = url[url.length - 2];
	$('#menu a[href$="'+prerub+'"]').addClass('selected');
		
	var rub = url[url.length - 1];
	
	// cas de la redirection
	if (rub == 'espace-client-login') {
		rub = 'espace-client';
	}
	$('#diag-list a[href$="'+rub+'"]').addClass('selected');
	$('#menu a[href$="'+rub+'"]').addClass('selected');
		
		
	/*****************************************
	 * GERER LE HOVER SUR LES LIENS DIAGNOSTIC
	 ****************************************/
	function dequeue(){
		$(this).dequeue();
	};

	$('#main #col-left ul#diag-list li a[class!="selected"]').hover(
		function()
		{
			$(this).stop().animate( {
					backgroundPosition:"-1px -16px",
					color:"#fff"
				}, 'fast',
				dequeue);
		},
		function()
		{
			$(this).stop().animate( {
					backgroundPosition:"-152px -16px",
					color:"#000"
				}, 'fast', 
				dequeue
			);
		}
	);
		
	/*****************************************
	 * LANCER L'ANIMATION DES BANNIERES PUB
	 ****************************************/
	initAds();
	adverts_step(-1);
	
	var widthAds = 160;
	var paddingLeft = 15;
	var length;

	function initAds()
	{
		widthAds = 160;
		paddingLeft = 15;
		length = $('#bloc-ads a img').length;
		
		$('#bloc-ads a').attr('target', '_blank');
	}

	function adverts_step(index) {
	    
	     if(length > 0) {
	         
	    	 if( index > -1) {
	                $($('#bloc-ads img').get(index)).animate({
	                     'left': -(widthAds),
	                     'opacity': 0
	                },500,'linear',function() {
	                     $(this).css('left',widthAds);
	                });
	          }

	          if( index+1 >length-1) {
	                index2=0;
	          } else {
	                index2=index+1;
	          }

	          //$('#bloc-ads').height($('#bloc-ads img').height());
	          
	          $($('#bloc-ads img').get(index2)).css({
	                'left': widthAds,
	                'opacity': 0
	          }).animate({
	                'left': paddingLeft,
	                'opacity': 1
	          },500);

	          if(length > 1)
	          {
	              setTimeout(function() { adverts_step(index2); }, 6000);        	  
	          }

	     }
	}
})