// Show page
$(document).ready(function() {
//   $('.page-content').animate({"height": "toggle"}, { duration: 1000 });
});

// Show menu
$(document).ready(function() {
	//expand the next div after the current table
	$('ul.submenu').hide();
	$('h3.menu-title').click(function() {
		$('ul.submenu').not(this).slideUp('fast');
		if($(this).next('ul.submenu').css('display') == "none"){
			$(this).next('ul.submenu').slideToggle('fast');
		}
	});
});

// Show nouvelles
//$(document).ready(function() {
//	$('div.nouvelles').hide();
//	$('div.nouvelles:first').show();
//	$('h5.titre-nouvelles').click(function() {
//		$(this).next('div.nouvelles').slideToggle('fast').siblings('div.nouvelles').slideUp('fast');
//	});
//});

// Show emplois
$(document).ready(function() {
	$('div.emplois').hide();
	// $('div.emplois:first').show();
	$('div.titre-emplois').click(function() {
		$(this).next('div.emplois').slideToggle('fast').siblings('div.emplois').slideUp('fast');
	});
});

jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel();
});

// Ajax page 
$(document).ready(function() {
	
	$('#menu-ajax a').click(function(){
		var toLoad = $(this).attr('href');
		var height = $('.texte-ajax').height();
		$('.texte-ajax').fadeOut('normal',loadContent);
		//loadContent();
    
		$(this).addClass("selected").parents('li').siblings().children().removeClass("selected");
		function loadContent() {
			$('.texte-ajax').load(toLoad + ' .texte', function () {
					cufonRefresh();
				$('.texte-ajax').fadeIn('normal', function(){
					activateFlash();
					hideBloc();
				});
			});
		}
		function cufonRefresh() {
			Cufon.refresh('h1')
		}
		return false;
	});
	
	
});







// Ajax inside page 
$(document).ready(function() {
	//insidePage();
});

function insidePage(){
//alert('insidePage')
//alert($('.listing a').size());
	// $('.listing a').click(function(){
	// 	//alert('click');
	// 	var toLoad = $(this).attr('href');
	// 	var height = $('.texte-ajax').height();
	// 	//$('.texte-ajax').fadeOut('normal', loadContent);
	// 	loadContent()
	// 	function loadContent() {
	// 		fixHeight(height);
	// 		$('.texte-ajax').load(toLoad + ' .texte', showNewContent(), cufonRefresh);
	// 	}
	// 	function showNewContent() {
	// 		setTimeout("activateFlash();", 50);
	// 		//setTimeout("$('.texte-ajax').fadeIn('normal', fixHeight);", 300);
	// 	}
	// 	function cufonRefresh() {
	// 		Cufon.refresh('h1');
	// 	}
	// 	return false;
	// });
}

function fixHeight(h){
	//insidePage();
	//hideBloc();
	//activateFlash();
	//alert('Before -> texte = ' + $('.texte-ajax').height() + ', fix = ' + $('#heightFix').height());
	//$('.page').append('<div>'+ 'Before -> texte = ' + $('.texte-ajax').height() + ', fix = ' + $('#heightFix').height() + '</div>');
	if (h != undefined){
		$('#heightFix').height(h);
	} else {
		$('#heightFix').height($('.texte-ajax').height() + 200);
	}
	//alert('After -> texte = ' + $('.texte-ajax').height() + ', fix = ' + $('#heightFix').height());
	//$('.page').append('<div>'+ 'After -> texte = ' + $('.texte-ajax').height() + ', fix = ' + $('#heightFix').height() + '</div>');
}

// Show hide
$(document).ready(function() {
	hideBloc();
});

function hideBloc(){
	$('.bloc').hide();
	$('.bloc:first').show();
	$('.show-hide li').click(function() {
		$('.show-hide li').removeClass('selected');
		var toLoad = $(this).attr('id');
		$(this).addClass('selected');
		$('.'+toLoad).siblings('.bloc').hide();
		$('.'+toLoad).fadeIn('slow');
	});
	fixHeight()
}






