$(document).ready(function() {

	$('#content').hide();
	$('#content div').hide();
	
	openDiv();
	
	$('#prenom').click(function() { closeDiv(); });
	$('#nom').click(function() { closeDiv(); });

});


function openDiv() {

	$('#menu a').click(function() {
	
		// Div  ouvrir
		var linkID = $(this).attr('id');
		var divID = linkID.replace('link', '');
		
		if($('#'+linkID).hasClass('active')) {
			$('#'+linkID).click(function() { return false; });
		} else {
		
		// Ouverture
		if($('#content').hasClass('open')) {
			$('#menu').fadeOut(500);
			$('.showed').fadeOut(500, function() {
				
				$('#'+divID).fadeIn(1000);
				$('#menu').fadeIn(500);
				$('.showed').removeClass('showed');
				$('#'+divID).addClass('showed');
				$('.active').removeClass('active');
				$('#'+linkID).addClass('active');
			
			});
			
		} else {
		
			// Ouverture complte
			$('#content').addClass('open');
			
			$('#menu').fadeOut(500);

			$('#prenom').animate({ marginLeft: '-250px' }, 1000, function(){
			
				$(this).addClass('door');
			
			});
			
			$('#nom').animate({ marginRight: '-250px' }, 1000, function(){
							
				$(this).addClass('door');
							
				$('#'+divID).show();
				$('#'+divID).addClass('showed');
				$('#content').fadeIn(1000);
				$('#menu').fadeIn(500);
				$('.active').removeClass('active');
				$('#'+linkID).addClass('active');
				
			
			});
			
		}
		}
	
	});

}


function closeDiv() {

	if($('#prenom').hasClass('door')){
	
		$('.open').removeClass('open');
		$('.door').removeClass('door');
		$('.active').removeClass('active');
		
		$('#menu').fadeOut(500);
		$('.showed').fadeOut(500);
		
		$('.showed').removeClass('showed');	
		
		$('#content').fadeOut(500, function(){
			$('#prenom').animate({ marginLeft: '0px' }, 1000);
			$('#nom').animate({ marginRight: '0px' }, 1000, function(){
				$('#menu').fadeIn(500);
			});
		});
		
	} else {
	
		return false;
		
	}
	
}
