$(document).ready(function() { 
	
	selecteurs();
	labelForm("#champNewsletter");
	labelForm("#re");
	labelForm("#loginProfil");
	labelForm("#passProfil");
	navigationsec();
	habillageTableau();
	didYouKnow();
	tabRub();
	showPrint();
});

	function resizeImgActu(){
		articles = $('.article');
		$.each(articles,function(i,article){
			$article = $(article);
			$pic = $article.find('.pic');
			$height = $article.find('.artContent').height();
			if($pic.height() > $height){
				$pic.height($article.find('.artContent').height());
				$article.find('.pic').css('overflow','hidden');
			}
		});
	}
	
	function tabRub(){
		var tabs = $('.tab');
		if(tabs.length >0){
			tabs.filter(':not(:first)').hide(); 
			
			var menus = $('#content_A a,#navSavoir a');
			menus.click(function(e){
				e.preventDefault();
				menus.parent('li').removeClass('current');
				$(this).parent('li').addClass('current');
				var lien = this.href.split('#');
				tabs.hide();
				tabs.filter('#'+lien[1]).show();
			});
			
			current = menus.parent('li').filter('.current'); 

			if(current.length == 0){
				current = menus[0];
			}else{
				current = current.find('a');
			}
		    $(current).trigger('click');
		}
	}
	
	function didYouKnow(){
		var didYouKnow = $('#didyouknow');
		if(didYouKnow){
			var listeP = didYouKnow.find('p');
			listeP.hide();
		   
			listeP.filter(':first').show();
			var $i =0;
			var $max = listeP.length;
			$('#dykprev').click(function(e){
				e.preventDefault();
				$i--;
				if($i<0){
					$i=$max-1;
				}
				listeP.hide();
				$(listeP[$i]).show();
			})
			$('#dyknext').click(function(e){
				e.preventDefault();
				$i++;
				if($i>=$max){
					$i=0
				}
				listeP.hide();
				$(listeP[$i]).show();
				
			})
		}
	}
	
	function coinArrondi(){
	// Images avec arrondis
		var $leftImg = $('.leftRnd');
		var $rightImg = $('.rightRnd');
		$leftImg.prepend('<b class="tl">&nbsp;</b><b class="bl">&nbsp;</b>')
		$rightImg.prepend('<b class="tr">&nbsp;</b><b class="br">&nbsp;</b>')
    }
	
//**  Selecteurs
	
	function selecteurs(){
		$('.pop').hide();
		// Passage en premier plan en roll
		$('.selector').hover(function(){
			$(this).css('z-index', '1000');
		}, function() {
			$(this).css('z-index', 'auto');
		});
		
		// Ouverture
		$('.opener').toggle(function(){
			$(this).css('z-index',6);
			$(this).next('.pop').show();
			return false;
		},
		function(){
			$(this).next('.pop').hide();
			$(this).css('z-index',4); 
			return false;
		});
		
		// Fermeture
		$('.selector').mouseleave(function() {
			$(this).find('.pop').hide();
			$(this).find('.opener').css('z-index',4); 
		});
	}
    
	function labelForm(champ){
	//** Affichage label formulaire newlstter home
	
		var $champ = $(champ);
		var $chLabel = $champ.find('label');
		var $chText = $champ.find('input');


		if ($chText.val() != "") {
			$chLabel.hide();
		};
		$chText.keypress(function() {
			$chLabel.hide();
		});

		$chText.focus(function() {
			if ($(this).val() == "") {
				$chLabel.fadeTo("fast", 0.3);
			} else {
				$chLabel.hide();
			}
		});

		$chText.blur(function() {
			if ($(this).val() == "") {
				$chLabel.fadeTo("fast", 1);
			} else {
				$chLabel.hide();
			}
		});   
	}
    
	function navigationsec(){
	// ** Navigation pages secondaires
		$('#navTyp .n2').hide();
		$('#navTyp .n1 li').hover(function() {
			$(this).find('.n2').show();
		}, function() {
			$(this).find('.n2').hide();
		});

		$('.n2').mouseleave(function() {
			$(this).hide();
		});
	}

   function habillageTableau(){
	// 	** Tableau zébré
		$('.wsg table:not(".tablecommissions") tr:odd').addClass('odd');
	}
	
	function showPrint() {
		var content = '';
		$('#t1').after(content);
	}
        

$(window).load(function(){
	resizeImgActu();
	coinArrondi();
});

