﻿/* code pour jQuery */
$(document).ready(function() {

	// préchargement image "hover" sur l'étoile "signer"
	var image1 = new Image();
	image1.src = 'css/css-img/star_sign_hover.png';
	var image2 = new Image();
	image2.src = 'css/css-img/star_sign_big_hover.png';

	$('.next').show();
	$('.flot_graph').show();
	$('.acc_closed').hide();

	// tip : choisissez une sous-section
	$('#minimenu a, .next a').click(function (event) {
		$('p.tip').animate({opacity: 'hide'}, 2500);
	});

	// afficher/masquer les sous-sections
	// initialisation
	var hashMenu = location.hash.substring(1); // ex. si URL se termine par "#02", retourne "02"
	if (!location.hash) {hashMenu = '01';} // si pas de hash, on affiche la première sous-section; sinon, celle du hash
	$('#minimenu li#menu' + hashMenu + ' a').addClass('active');
	$('div.accordeon').hide();
	$('#bloc_' + hashMenu).show().addClass('active');

	// fonctionnement du menu pour les sous-sections
	$('#minimenu li[id^=menu] a').click(function (event) {
		var clickNumber = $(this).parent().attr('id').slice(4);
		if (!($(this).hasClass('active'))) {
			$('#minimenu li a').removeClass('active');
			$(this).addClass('active');
			$('div.accordeon.active').removeClass('active').animate({height: 'hide', opacity: 'hide'}, 1000, function() {
				$('#bloc_' + clickNumber).animate({height: 'show', opacity: 'show'}, 1000).addClass('active');});
		}
		$(this).blur();
		event.preventDefault();
		window.location.hash = clickNumber;
	});

	// ouverture de la table des signatures (sur la page signer)
	$('#noms').hide();
	$('#sigs span').show();
	$('#nb_sign a').click(function(event) {
		$('#noms').show();
		$(this).blur();
	});
	$('#sigs span a').click(function() {
		$('#noms').hide();
		$(this).blur();
	});

	// "crypter" les adresses e-mail
	// Pour tous les liens commençant par "mailto" ou les span ayant une class "wmail"
	// remplace "[arobase]" par "@" et "[point]" par "."
	$('a[href^="mailto"], span.wmail').each(function (i) {
			//Remplacment du texte dans l'élément
			var temp = $(this).html();
			temp = temp.replace("[arobase]","@");
			temp = temp.replace("[point]",".");
			$(this).html(temp);
			//Si il y a un attribut "href", on remplace le texte dans l'attribut
			if($(this).attr("href")){
					var temphref = $(this).attr("href");
					temphref = temphref.replace("[arobase]","@");
					temphref = temphref.replace("[point]",".");
					$(this).attr("href",temphref);
			}
	})

}); // fin jQuery
