// onload_defaut.js
// simon - egzakt.com
// 2008-05-01
function document_ready_deroulant() {
	
	$('div.zone_deroulante').not('.garder_ouvert').hide();
	
	$('h2 a.lien_deroulant, h1 a.lien_deroulant').click(function() {
		if (!$(this).hasClass("selected")) {
			$('h2 a.lien_deroulant').each(function(i){
				$(this).parent().nextAll('div:first').slideUp();
				$(this).removeClass('selected');
			});
			
			$(this).parent().nextAll('div:first').slideToggle();
			$(this).toggleClass('selected');
		} else {
			$(this).parent().nextAll('div:first').slideUp();
			$(this).removeClass('selected');
		}
		return false;
	});

	// Tableaux
	$(".fcktexte table").attr("cellSpacing","2").attr("border","0");
	var tr = 1;
	$(".fcktexte table tbody").each(function() {
		tr = 1;
		$(this).children("tr").not(".header").each(function() {
			if ((tr % 2) == 0)
				$(this).addClass("paire");
			tr++;
		});
	});
	$(".fcktexte table tbody tr:first-child td, .fcktexte table tbody tr:first-child th").addClass("premier_ligne");
	$(".fcktexte table tbody tr td:first-child, .fcktexte table tbody tr th:first-child").addClass("premier_colonne");


	//Listes
	$(".fcktexte ul li:first-child").addClass("premier");
	
	// Liens : si externe, ouvrir en nouvelle fenetre
	$('.fcktexte a').each(function () {
		if ($(this).attr('href').match(/groupesce.com/) == null) {
			if ($(this).attr('target') == null)
				$(this).attr('target','_blank');
		}
	});
	
	// Imprimer
	$('#outils a.imprimer').click(function () {
		window.print();
		return false;
	});

	// Proteger les adresses courriels
	// geo_decode() dans fonctions.js
	$('a').not("[@href='']").each(function()  {
		geo_decode(this);
	});
}



/**
 * FONCTION geo_decode
 * Modification de http://www.alistapart.com/articles/gracefulemailobfuscation
 *
 * @package		egzakt
 * @author		Simon
 * @param		anchor		string (lien courriel)
 * @return		-			bool
 * @version		SVN: $Id: fonctions.js 3335 2008-01-21 00:00:00Z Simon $
 */
function geo_decode(anchor,domaine) {
	var href = $(anchor).attr('href');
	var nlettre = 1;
	var adresse = "";
	if (!domaine)
		domaine = 'qim'+'t'+'l'+'.'+'qc'+'.'+'ca';

// Simplifier pour le client : 1 seule facon : courriel
	var code = href.replace(/.*contact\/(courriel|email)\/([a-z0-9._%-]+)/i, '$2');
// 	if (langue == "fr")
// 		var code = href.replace(/.*contact\/courriel\/([a-z0-9._%-]+)/i, '$1');
// 	else
// 		var code = href.replace(/.*contact\/email\/([a-z0-9._%-]+)/i, '$1');

	
	if (href != code) {
		var code_params = new Array();
		if ((code == "info") || (code == "webmestre")) {
			code_params[0] = code;
		} else {
			code_params = code.split('-');
			for (i=0;i<(code_params.length-1);i++) {
				adresse += code_params[i].substring(0,nlettre);
			}
		}
		adresse += code_params.pop()+'@'+domaine;
		$(anchor).attr('href','mail'+'to'+':'+adresse);
		$(anchor).html(adresse);
	}
}