$(function() {
	$.preloadCssImages();
	initSlideShow();
	initText();
	
	if(location.hash == "#petition") {
		tb_show("","fr/petition/?keepThis=true&TB_iframe=true&height=400&width=500",""); 
	}
});

function initSlideShow() {
	var pauseSlideshow = 5000;
	var fadeSlideshow = 1000;
		
	$('#content_photo_slideshow').Slides({images : photos, pause : pauseSlideshow, fade : fadeSlideshow});
}


// Variables globales pour l'initialisation du texte
var transitionText;
var hiddenContent;

// Fonction qui initialise la zone texte qui a des portions de texte cachées
function initText() {
	hiddenContent = true;
	var contentToShow = location.hash;
	contentToShow = parseInt(contentToShow.replace(/#/g,''));
	transitionText = false;

	// On affiche la portion de texte cachée au départ en fonction de l'anchor(location.hash) demandé dans l'URL
	if(!isNaN(contentToShow)) {
		var hiddenContentArray = $("#content_text").find("div.div_contenu_cache");
		$(hiddenContentArray[contentToShow - 1]).slideToggle('slow',function() {
			hiddenContent = false;																				
		});
	}
	
	// Mouseover sur les titres (h2) des portions de texte cachées
	$('#content_text h3.h3_contenu_cache').mouseover(function() {
		$(this).addClass('h3_contenu_cache_roll');
		$(this).css({'cursor' : 'pointer'});
	// Mouseout sur les titres (h2) des portions de texte cachées
	}).mouseout(function() {
		$(this).removeClass('h3_contenu_cache_roll');		
	// Mouseup sur les titres (h2) des portions de texte cachées
	}).mouseup(function() {
		if(!transitionText) {
			var contentToShow = this;
			var contentToShowDisplay = $(this).next().css('display');
			
			// Si le contenu cliqué n'est pas déjà affiché
			if(contentToShowDisplay != 'block') {
				transitionText = true;
				// Si tous les contenus sont cachés
				if(hiddenContent) {
					$(contentToShow).next().slideToggle('slow',function() {
						transitionText = false;
						hiddenContent = false;													
					});
				// Sinon il y a déjà un contenu affiché
				} else {
					$('#content_text div.div_contenu_cache:visible').slideToggle('slow',function() {
						transitionText = false;
						$(contentToShow).next().slideToggle('slow');
					});
				}
			}
		}
	});
}