var headline_count;
var headline_interval;
var current_headline = 0;
var old_headline = 0;

$(document).ready( function () {

// AFFICHAGE / MASQUAGE DES SOUS-MENUS DE GAUCHE
	$(".niveau-1 ul.niveau-2").hide();
	$(".niveau-1 li.affiche_niveau-2 > a").click( function () {
		if ($(this).next("ul.niveau-2:visible").length != 0) {
			$(this).next("ul.niveau-2").slideUp("normal");
		}
		else {
			$(".niveau-1 ul.niveau-2").slideUp("normal");
			$(this).next("ul.niveau-2").slideDown("normal");
		}
		return false;
	});


// AFFICHAGE / MASQUAGE DE L'EDITO
	$("a.lire_edito").click(function(){
		if ($("div#edito_bottom").is(":hidden")) {
		$("div#edito_bottom").slideDown("slow");
		} else {
		$("div#edito_bottom").slideUp("slow");
		}
		return false;
	});

// AFFICHAGE / MASQUAGE DES INTERVENTIONS SUR LE FORUM
	$(".forum-nv1 ul.forum-nv2").hide();
	$(".forum-nv1 li.forum-affiche-nv2 > a").click( function () {
		if ($(this).next("ul.forum-nv2:visible").length != 0) {
			$(this).next("ul.forum-nv2").slideUp("normal");
		}
		else {
			$(".forum-nv1 ul.forum-nv2").slideUp("normal");
			$(this).next("ul.forum-nv2").slideDown("normal");
		}
		return false;
	});


// FILTRER LE CONTENU PAR MOT-CLE CATEGORIE
	$("#filtre_categorie > a").click( function () {
		$("#filtre_categorie > a").removeClass("categorie_selected");
		if ($(this).attr("id") == 'A') {
			$(this).addClass("categorie_selected");
			$("p.post").hide();
			$("p.A").fadeIn("slow");
		}
		if ($(this).attr("id") == 'B') {
			$(this).addClass("categorie_selected");
			$("p.post").hide();
			$("p.B").fadeIn("slow");
		}
		if ($(this).attr("id") == 'C') {
			$(this).addClass("categorie_selected");
			$("p.post").hide();
			$("p.C").fadeIn("slow");
		}
		if ($(this).attr("id") == 'CONTRACTUELS') {
			$(this).addClass("categorie_selected");
			$("p.post").hide();
			$("p.CONTRACTUELS").fadeIn("slow");
		}
		if ($(this).attr("id") == 'tout') {
			$(this).addClass("categorie_selected");
			$("p.post").fadeIn("slow");
		}
		return false;
	});


// RORATION DES FLASHS INFO EN PAGE D'ACCUEIL
	headline_count = $("div.headline").size();
	$("div.headline:eq("+current_headline+")").css('top', '5px');

	headline_interval = setInterval(headline_rotate,5000);
	$('#scrollup').hover(function() {
		clearInterval(headline_interval);
	}, function() {
		headline_interval = setInterval(headline_rotate,5000);
		headline_rotate();
	});
	

// OUVERTURE D'UNE THICKBOX LORS D'UN CLIC SUR "ADHESIONS"
	$(".adherer").click( function () {
		tb_show('', 'squelettes/formulaires/form_adhesion.html?TB_iframe=true&height=520&width=460', 'false');
		return false;
	});

	
// OUVERTURE D'UNE THICKBOX LORS D'UN CLIC SUR "NOUS ECRIRE"
	$(".nous_ecrire").click( function () {
		tb_show('', 'squelettes/formulaires/form_ecrire.html?TB_iframe=true&height=500&width=460', 'false');
		return false;
	});
	
	
// REDIRECTION VERS UN SITE INTERNET EN CAS DE SELECTION DANS LA LISTE
	$('.liste_sites').change(function(){
		lien();
		return false;
	});
	
// OUVERTURE D'UNE NOUVELLE FENETRE LORS DE L'OUVERTURE D'UN DOCUMENT
	$("a.nouvelle_fenetre").click(function(){
	  window.open(this.href);
	  return false;
	});
	
} ) ;



// FONCTION DE ROTATION DES FLASHS INFO DE LA PAGE D'ACCUEIL
function headline_rotate() {
	current_headline = (old_headline + 1) % headline_count;

	$("div.headline:eq(" + old_headline + ")")
	.animate({top: -205},"slow", function() {
		$(this).css('top', '210px');
	});

	$("div.headline:eq(" + current_headline + ")")
		.animate({top: 5},"slow"); 
		old_headline = current_headline;
}


// FONCTION PERMETTANT LA REDIRECTION VERS UNE URL SELECTIONNEE DANS LA LISTE
function lien() {
	i = document.sites_locaux.liste_sites.selectedIndex;
	if (i == 0) return;
	url = document.sites_locaux.liste_sites.options[i].value;
	parent.location.href = url;
}



// VARIABLE ET FONCTION DE MODIFICATION DE LA TAILLE DU TEXTE
var taille_texte;
taille_texte = 10;
function changerTaille(modif) {
	taille_texte = taille_texte + modif;
	document.getElementById("ventre").style.fontSize = taille_texte + "pt";
}
