$(function() {
	$('#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, div.container').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');	
		});	
	}		
	
	$('#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);
		}
	);
	
	//please login box
	$('a.showLoginBox').click(function() {
		$('#l_login').addClass('focus');
		$('#login input').addClass('focus').focus();
		return false;
	});
	
	//target blank for url outside domain
	$('a').filter(function() {
		return this.href.indexOf(window.location.hostname) == -1;
	}).attr('target', '_blank');
	
	//print stuffs
	$('a.letsPrint').click(function() {
		//hide other contents in annuaire mode to print only the required once
		if ($(this).attr('longdesc')) {
			$('div.printHider').not('#'+$(this).attr('longdesc')).hide();
		}
		window.print();
		if ($(this).attr('longdesc')) {
			$('.printHider').show();
		}
		return false;
	});	
});