// JavaScript Document


var obj = null;

function checkHover() {
   if (obj) {
      obj.find('ul').fadeOut('fast');
   } //if
} //checkHover

$(document).ready(function(){
	
	(function(){for(var l=document.links,h=window.location.hostname,i=0,a;a=l[i];i++){if(a.hostname!=h){a.target='_blank';}}})();
	
	$('a[href*=#top]').click(function(){
			$('html, body').animate({scrollTop:0}, 'normal');
		});

	
	
	$('#menu > div').hover(function() {
      if (obj && obj.find('ul').css("display") == "block") {
         obj.find('ul').fadeOut('fast');
         obj = null;
      } //if
    $(this).find('ul').fadeIn('fast');
   }, function() {
      obj = $(this);
      setTimeout(
         "checkHover()",
         400);
   });
		
	
	var fichier = document.location.href;
	fichier = fichier.substring( fichier.lastIndexOf( "/" )+1 , fichier.length );
	
	$('.nav2').html($('.active').next('ul').html());
	$('.nav3').html($('.active').next('ul').html());
	$('.nav3').prepend('<li>&Agrave; lire aussi : </li>');
	
	$('.nav2 li').each(function (i) {
		//window.alert($(this).find('h2 a').attr('href'));
        if ($(this).find('a').attr('href') == fichier)
		{
			
			$(this).css('display','none');	
		}
      });
	
	$('.nav3 li').each(function (i) {
		//window.alert($(this).find('h2 a').attr('href'));
        if ($(this).find('a').attr('href') == fichier)
		{
			
			$(this).css('display','none');	
		}
      });
	
	//window.alert($('.active').next('ul').html());
	
	
	//window.alert($('.nav2').find('h2 a').attr('href'));
	//window.alert(fichier);
	
	$(".overAlpha").mouseover(function(){
		$(this).fadeTo(0, .5);
	});
	
	$(".overAlpha").mouseout(function(){
		$(this).fadeTo(0, 1);
		
	});
	
	 
	
	window.onresize = resize;
	window.onload = resize;
	
});

function resize(){
	var plop = $(window).height()-40;
	var headerheight = $("#header").height();
	var contenuheight = $("#contenu").height();
	var footerheight = $("#footer").height();
	var cleanerheight = $("#cleaner").height();
	var somme = headerheight + contenuheight + footerheight + cleanerheight;
	
	//window.alert("header:"+headerheight+" + contenu:"+contenuheight+" = somme:"+somme+"");
	if (somme < plop) {
		$("#conteneur").css("height",plop+"px");
		
		var ecart = plop - somme;
		$("#footer").css("marginTop",ecart+"px");
	}
	
	else {
		$("#conteneur").css("height",somme+"px");	
		$("#footer").css("marginTop","auto");
	}
};
