$(function() {
	/*function resize_container(){
		var w = $(this).parent().width()-20;
		$(this).width(w);
	}	
	
	function set_width(){
		var width = $(this).width();
		$(this).width(width+1);
	}
	
	$('.section').children().each(set_width)
	$('.container').each(resize_container)*/
	
	//Met le style current sur le lien quand on est dans les sous-menus
	$('#navigation .container').hover(function(){
		$(this).prev().addClass('current');
	},function(){
		$(this).prev().removeClass('current');
		if($(this).parent().hasClass('selected')){
			$(this).prev().addClass('current');
		}
		
	});
	
	
	
	$('#navigation_bottom .container').hover(function(){
		$(this).parent().prev().addClass('current');
	},function(){
		$(this).parent().prev().removeClass('current');
		if($(this).parent().parent().hasClass('selected')){
			$(this).parent().prev().addClass('current');
		}
		
	});
	
	
	
	
	$('.navigation .head').click( function() { return false; });
	$('.navigation .section > .container').css('opacity', 0.9);	
	
	var current = $('.navigation a').not('.head').filter(function() { return location.href.indexOf(this.href) != -1; });
	
	if (current.size()) {
		current.addClass('current');
		current.parents('div.section, div.subSection').addClass('selected');
		current.parents('div.section').children('.head').addClass('current');
	}
	
	var open_timers = new Array();
	var close_timers = new Array();
	
	function open(e) {
		$(e).addClass('over');		
		$('> .container', e).slideDown(300);
	}	
		
	function close(e) {
		$('> .container', e).slideUp(300, function() {
			$(e).removeClass('over');	
		});	
	}	
	
	
	//Placer les containers justes et leur donne la largeur juste
	function placement(){
		$('#navigation_bottom .section .cache_container').each(function(){
			var top = $(this).children().height();
			var width = $(this).parent().width();
			
			$(this).css('top', -top);
			$(this).height(top);
			$(this).children().css('margin-top', top);
			$(this).width(width);
			$(this).children().width(width-20);
			
			
		});
	}
	placement();
	
	
	function open_bottom(e,o) {
		$(e).addClass('over');
		$(o).parent().css('visibility','visible');
		$(o).animate({
			marginTop:0
		});
	}	
		
	function close_bottom(e,o) {
		
		$(o).animate({
			marginTop:$(o).height()
		},function(){
			$(o).parent().css('visibility','hidden');
		});
		
	}		
	
	$('#navigation.navigation .section').hover(
		function() {
			var e = this;
			clearTimeout(close_timers[$(e).attr('id')]);
			open_timers[$(e).attr('id')] = setTimeout(function() { open(e); }, 200);			
		},
		function() {
			var e = this;
			
			clearTimeout(open_timers[$(e).attr('id')]);
			close_timers[$(e).attr('id')] = setTimeout(function() { close(e); }, 100);
		}
	);
	
	$('#navigation_bottom .section').hover(
		function() {
			var e = this;
			var o = $(e).children().next().children();
			
			clearTimeout(close_timers[$(e).attr('id')]);
			open_timers[$(e).attr('id')] = setTimeout(function() { open_bottom(e,o); }, 200);			
		},
		function() {
			var e = this;
			var o = $(e).children().next().children();
			clearTimeout(open_timers[$(e).attr('id')]);
			close_timers[$(e).attr('id')] = setTimeout(function() { close_bottom(e,o); }, 100);
		}
	);
	
	//met le lien current pour le sous menu
	$('#navigation_bottom .selected').children().addClass('current');
});
