$(function() { 
	
	$("a.spip_out").attr("target", "_blank");
	
	$("#documents_portfolio a").fancybox();

	$(".texte_article a").each(function() {
		var url = $(this).attr('href');
		if (url != undefined) {
			var extension = url.substr(url.length-3, url.length);
			if(extension == "pdf") { $(this).attr("target", "_blank"); }
		}
	});
	
	if($("#documents_portfolio_diapo").length > 0) {
		$('#documents_portfolio_diapo').innerfade({ timeout: 3000, speed: "slow", type: 'random', containerheight: $('#documents_portfolio_diapo').css("height") });
	}
	
	$('#pied_footer li:last a, #pied_footer_ps li:last a').css('border', 'none');
	$('.page_sommaire #menu_principal li:first').addClass('menu_active_oui');
	
	var rand = Math.floor(Math.random() * 8);
	rand = (rand%8) * 4;
	
	var mood = $('#diaporama ul').moodular({
		direction: 'top',
		dispTimeout: 3000,
		speed: 500,
		callbacks: [makeLegend],
		startOn: rand,
		api: true
	});
	
	$('#diaporama_controls_top').bind('click', function () { mood.prev(); return false; });
	$('#diaporama_controls_bottom').bind('click', function () { mood.next(); return false; });
	
	if (mood) makeLegend(mood);
	
	$('#quizz').css('cursor', 'pointer').bind('click', function () {
		window.location = $('a', $(this)).attr('href');
	});
	
	$("#acces_prive a").addClass('iframe').fancybox({
		width: '90%',
		height : '90%'
	});
	
});

function makeLegend(mood) {
	$('#diaporama_legend').html($('> li:first > div', mood.e).html());
}

