var tabLinks, tabs, curTab, nextTab = 0;

function switchTabs(){
	// Masque les tabulations qui ne sont pas actives
	var hash = window.location.hash;
	var href = window.location.href;
	if( window.location.hash=='' ){
		currentElem = $('#content-tabs-header ul li.current').attr('id').substr(3);
		hash = '#'+ currentElem;

		href += hash;
	}
	
	tabLinks.each(
		function(){
			if( $(this).attr('href')==hash ){
				$(this).parent('li').addClass( 'current' );
			}
			else{
				$(this).parent('li').removeClass( 'current' );
			}
		});
	curTab = nextTab = 0;
	
	tabs.each(
		function(){
			if( '#' + $(this).attr('id')==hash ){
				nextTab = $(this);
			}else{
				if( $(this).hasClass('open-tab') )
					curTab = $(this);
				else {
					$(this).removeClass('open-tab');
					$(this).addClass('close-tab');
				}
			}
		});
	
	if( curTab ){
		curTab.fadeOut(function(){
			$(this).removeClass('open-tab');
			$(this).addClass('close-tab');
			nextTab.removeClass('close-tab');
			nextTab.addClass('open-tab');
			nextTab.fadeIn();
			curTab.removeAttr( 'style' );
		});
		
	}else{
		if( nextTab )
			nextTab.addClass('open-tab');
	}
	
}
function activeTabs(){
	
	tabLinks.each(
		function(){
			$(this).click(
				function(){
					window.location.href = $(this).attr('href');
					switchTabs();
					return false;
				});
		});
}

$(document).ready(function(){
	tabLinks = $('#content-tabs-header a');
	tabs = $('#content-body div.content-tab');
	switchTabs();
	activeTabs();
});

