/* RENSEIGNER ICI LA RUBRIQUE (CF PHP) */
rubrique = 'CRYPTEDLINK';

function hexdec (hex_string) {
	hex_string = (hex_string+'').replace(/[^a-f0-9]/gi, '');
	return parseInt(hex_string, 16);
}

function chr(AsciiNum) {
	return String.fromCharCode(AsciiNum);
}

function hex2bin(hex) {
	var r = '';
	var a=0;
	for (a=0; a<hex.length; a=a+2) {
		r = r + chr(hexdec(hex.slice(a,a+2)));
	}
	return r;
}

$(document).ready(function() {
	var classList, deb, lnk, cryptedLink, classes, obj, blank, id;
	$("span[class*=" + rubrique + "]").each(function() {
		classList = $(this).attr('class').split(/\s+/);
		obj = $(this);
		lnk = "";
		classes = "";
		blank = 0;
		$.each( classList, function(index, item) {
			deb = item.indexOf(rubrique);
			if(deb > -1) {
				deb += rubrique.length;
				cryptedLink = item.substr(deb,item.length);
				lnk = "<a href=\"" + hex2bin(cryptedLink) + "\"";
			}
			else {
				if(item == "blank") blank = 1;
				else classes += ((classes.length) ? " " : "") + item;
			}
		});
		if(lnk.length) {
			if(classes.length) lnk += " class=\"" + classes + "\"";
			if(blank) lnk += " target=\"_blank\"";
			id = jQuery.trim(obj.attr("id"));
			if((id != "") && (id != "undefined")) {
				lnk += " id=\"" + obj.attr("id") + "\"";
			}
			lnk += ">" + obj.html() + "</a>";
			obj.html(lnk);
			obj.removeAttr("class");
			obj.removeAttr("id");
		}
	});
}); 

