// Initialisation d'un objet ajax
function getXhr() {
	var xhr = null;
	if (window.XMLHttpRequest) // Firefox et autres
		xhr = new XMLHttpRequest();
	else if (window.ActiveXObject) { // Internet Explorer
		try {
			xhr = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
		}
	} else { // XMLHttpRequest non supporté par le navigateur
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
		xhr = false;
	}
	return xhr;
}

// Charge une chaine comme du xml
function xmlFromString(string) {
	// code for IE
	try // Internet Explorer
	{
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async = "false";
		xmlDoc.loadXML(string);
	} catch (e) {
		try // Firefox, Mozilla, Opera, etc.
		{
			parser = new DOMParser();
			xmlDoc = parser.parseFromString(string, "text/xml");
		} catch (e) {
			alert(e.message)
		}
	}
	return xmlDoc;
}

// Initialisation des variables
var feeds = new Array();
var current_page = 0;
var nbpages = 0;
var currentstring = '';
var tags = new Array();
var nb_recherche_en_cours = 0;
var currentplaying = '';
var currentplayingsite = '';
var xml = "<sites><site><num>1</num><name>Youtube.fr</name><classe>Youtube</classe><nb_pages>2</nb_pages><image></image><preg>^http://.*youtube\\.com/watch\\?.*v=([a-zA-Z0-9_]{1,15}).*$</preg></site><site><num>2</num><name>Dailymotion.fr</name><classe>Dailymotion</classe><nb_pages>7</nb_pages><image></image><preg>^http://www\\.dailymotion\\.com/.*video/([A-Za-z0-9]*).*$</preg></site><site><num>3</num><name>MySpace.com</name><classe>Myspace</classe><nb_pages>4</nb_pages><image></image><preg>^http://vids\\.myspace\\.com/index\\.cfm\\?.*videoid=([0-9]*).*$</preg></site><site><num>4</num><name>Metacafe.com</name><classe>Metacafe</classe><nb_pages>1</nb_pages><image></image><preg>^http://www\\.metacafe\\.com/watch/([0-9]*).*$</preg></site></sites>";
var sites = xmlFromString(xml).getElementsByTagName("site");

// Cherche la liste des sites
var xhr2 = getXhr();
xhr2.open("GET", "sites.xml?a=1",false);
xhr2.send(null);
sites = xhr2.responseXML.getElementsByTagName("site");

// Récupère un fichier xml et en extrait les vidéos
function parseXML(string) {
	tags = new Array();
	feeds = new Array();
	xmlDoc = xmlFromString(string);

	var videos = xmlDoc.getElementsByTagName("video");
	count = videos.length;
	for (i = 0; i < count; i++) {
		feeds[feeds.length] = videos[i];
	}

	var tagsxml = xmlDoc.getElementsByTagName("tag");
	count_tags = tagsxml.length;
	var is_present = false;
	for (i = 0; i < count_tags; i++) {
		tags[tags.length] = new Array();
		tags[tags.length - 1]["num"] = parseFloat(tagsxml[i]
				.getElementsByTagName("num")[0].firstChild.nodeValue);
		tags[tags.length - 1]["name"] = tagsxml[i].getElementsByTagName("name")[0].firstChild.nodeValue;
	}
	nbpages = Math.ceil(feeds.length / 16);
}

// Lance la page pour une nouvelle recherche
function lunch_search() {
	var string = document.getElementById('c').value;
	 //var xmlDoc = xmlFromString(xml);
	 //var sites = xmlDoc.getElementsByTagName("site");

	for (i = 0; i < sites.length; i++) {
		var regex = new RegExp(sites[i].getElementsByTagName("preg")[0].firstChild.nodeValue);
		if (regex.test(string)) {
			var OK = regex.exec(string);
			if (confirm("Voulez-vous télécharger la vidéo \""
					+ OK[1]
					+ "\" sur le site "
					+ sites[i].getElementsByTagName("name")[0].firstChild.nodeValue
					+ " ?")) {
				document.location.href = "/download-"
						+ sites[i].getElementsByTagName("num")[0].firstChild.nodeValue
						+ "-" + OK[1] + ".flv";
				document.getElementById('c').value = '';
				return;
			}
		}
	}
	document.location.href = '/recherche-video-' + urlencode(string) + '.html';
}

// Lance les différentes recherches
function send_search() {
	var ctt = document.getElementById('res');
	var string = document.getElementById('c').value;
	var titre = document.getElementById('titre');
	feeds = new Array();
	tags = new Array();

	currentstring = string;

	titre.innerHTML = 'DownMine : Vid&eacute;os &agrave; t&eacute;l&eacute;charger correspondant &agrave; la recherche : "' + string + '"';
	ctt.innerHTML = '<img class="waitgif" src="images/Reload.gif" alt="" />Recherche en cours... Veuillez patienter...';
	nb_recherche_en_cours = 0;

	// var xmlDoc = xmlFromString(xml);
	// var sites = xmlDoc.getElementsByTagName("site");

	for (i = 0; i < sites.length; i++) {
		for (k = 0; k < parseInt(sites[i].getElementsByTagName("nb_pages")[0].firstChild.nodeValue); k++) {
			make_search(
					parseInt(sites[i].getElementsByTagName("num")[0].firstChild.nodeValue),
					k, string);
		}
	}

	return false;
}

function sortPerso2(a, b) {
	return (a["num"] > b["num"]) ? -1 : 1;
}
function sortPerso3(a, b) {
	return (a["name"] < b["name"]) ? -1 : 1;
}

// Récupère le maximum d'un ensemble de tags
function GetMax(a) {
	var Max = a[0]["num"];
	if (isNaN(Max * 1) && !IsDate(Max))
		return '';
	for ( var i = 0; i < a.length; i++)
		if (a[i]["num"] * 1 > Max)
			Max = a[i]["num"];
	return Max;
}

// Récupère le minimum d'un ensemble de tags
function GetMin(a) {
	var Min = a[0]["num"];
	if (isNaN(Min * 1) && !IsDate(Min))
		return '';
	for ( var i = 0; i < a.length; i++)
		if (a[i]["num"] * 1 < Min)
			Min = a[i]["num"];
	return Min;
}

// Affiche le nuage de tags
function print_tags() {
	if (tags.length > 0) {
		var divtag = document.getElementById('tags');
		var newtags = new Array();

		for (i = 0; i < tags.length; i++) {
			for (j = 0; j < i; j++) {
				if (tags[i]["name"] == tags[j]["name"]) {
					tags[j]["num"] += tags[i]["num"];
					tags[i]["num"] = 0;
				}
			}
		}

		tags.sort(sortPerso2);
		for (i = 0; i < Math.min(tags.length, 20); i++) {
			newtags[newtags.length] = tags[i];
		}

		newtags.sort(sortPerso3);
		divtag.innerHTML = "";

		var min_size = 12;
		var max_size = 35;
		var couleurs = new Array('#07519A','#79C01A','#FBA327','#A72C2E','#DC5DA2');
		var i_color = 0;
		
		var min = GetMin(newtags);
		var max = Math.min(GetMax(newtags), 50);

		for (i = 0; i < newtags.length; i++) {
			if (newtags[i]["num"] > 0) {
				size = Math
						.floor(min_size
								+ ((Math.min(newtags[i]["num"], 50) - min) * ((max_size - min_size) / (max - min))));
				divtag.innerHTML += '<a href="/recherche-video-'
						+ urlencode(no_accent(newtags[i]["name"]))
						+ '.html" style="text-decoration:none;font-size:'
						+ size + 'px;white-space: nowrap;color:' + couleurs[i_color++ % couleurs.length] + ';font-weight: 600;" title="'
						+ newtags[i]["name"] + '">' + newtags[i]["name"]
						+ '</a> &nbsp;';
			}
		}
	}
}

// Supprime les accents d'une chaine
function no_accent(my_string) {
	return my_string.replace(/[ÈÉÊËèéêë]/g, "e").replace(/[ç]/g, "c").replace(
			/[àâä]/g, "a").replace(/[îï]/g, "i").replace(/[ôóö]/g, "o");
}

// Lance l'affichage des recherches
function print_search(page) {

	var html = '';
	county = feeds.length;
	document.getElementById('titre').innerHTML = 'Vid&eacute;os correspondant &agrave; la recherche "'
			+ currentstring
			+ '" - R&eacute;sultats '
			+ ((page * 16) + 1)
			+ ' à ' + Math.min((page * 16) + 16, county) + ' sur ' + county;
	var divres = document.getElementById("res");
	var printed = 0;
	for (i = 16 * page; i < Math.min(county, 16 * (page + 1)); i++) {
		html += '<script type="text/javascript"><![CDATA[load_image("' + feeds[i]
				.getElementsByTagName("image")[0].firstChild.nodeValue + '");//]]></script>';
		html += '<div class="resultat"><a href="/download-'
				+ feeds[i].getElementsByTagName("site")[0].firstChild.nodeValue
				+ '-'
				+ feeds[i].getElementsByTagName("link")[0].firstChild.nodeValue
				+ '.flv" class="iconedl"><img src="images/download.png" class="icone" alt="Télécharger la vidéo de ' + feeds[i].getElementsByTagName("sitename")[0].firstChild.nodeValue + '" /><span>Télécharger</span></a><a class="iconevoir" href="/showvideo-'
				+ feeds[i].getElementsByTagName("site")[0].firstChild.nodeValue
				+ '-'
				+ feeds[i].getElementsByTagName("link")[0].firstChild.nodeValue
				+ '.html" onclick="url(\''
				+ feeds[i].getElementsByTagName("link")[0].firstChild.nodeValue
				+ '\',\''
				+ feeds[i].getElementsByTagName("site")[0].firstChild.nodeValue
				+ '\');return false;"><img src="images/voir.png" class="icone" alt="Regarder la vidéo de ' + feeds[i].getElementsByTagName("sitename")[0].firstChild.nodeValue + '" /><span>Regarder</span></a><a class="iconeinfo" href="/"><img src="images/infos.png" class="icone" /><span>Durée : '
				+ feeds[i].getElementsByTagName("length")[0].firstChild.nodeValue
				+ '<br>Site : '
				+ feeds[i].getElementsByTagName("sitename")[0].firstChild.nodeValue
				+ '</span></a>';
		html += '<img src="'
				+ feeds[i].getElementsByTagName("image")[0].firstChild.nodeValue
				+ '" width="'
				+ feeds[i].getElementsByTagName("iwidth")[0].firstChild.nodeValue
				+ '" height="'
				+ feeds[i].getElementsByTagName("iheight")[0].firstChild.nodeValue
				+ '" class="thumbnail" alt="'
				+ feeds[i].getElementsByTagName("desc")[0].firstChild.nodeValue
				+ '" title="'
				+ feeds[i].getElementsByTagName("desc")[0].firstChild.nodeValue
				+ '" />';
		html += '<a href="javascript:url(\''
				+ feeds[i].getElementsByTagName("link")[0].firstChild.nodeValue
				+ '\',\''
				+ feeds[i].getElementsByTagName("site")[0].firstChild.nodeValue
				+ '\');">'
				+ feeds[i].getElementsByTagName("titre")[0].firstChild.nodeValue
				+ '</a>';
		html += '<p class="description">Post&eacute; le '
				+ feeds[i].getElementsByTagName("date")[0].firstChild.nodeValue
				+ ' par '
				+ feeds[i].getElementsByTagName("auteur")[0].firstChild.nodeValue
				+ '</p>';
		html += '</div>';
		printed = printed + 1;
	}
	printed = printed % 4;
	for (k = printed; (k > 0 && k < 4); k++) {
		html += '<div class="resultat">&nbsp;</div>';
	}
	current_page = page;
	build_pagination();
	print_tags();
	divres.className = 'res';
	divres.innerHTML = html;

	if (nb_recherche_en_cours == 0 && county == 0) {
		divres.innerHTML = 'Aucun résultat trouvé';
	}
}

// Affiche la pagination
function build_pagination() {
	var pagination = '';
	if (current_page != 0) {
		pagination += '<span onmouseout="change_class(this,\'bouton\');" onmouseover="change_class(this,\'boutonselected\');" onclick="print_search(0);" class="bouton"><<</span>';
		pagination += '<span onmouseout="change_class(this,\'bouton\');" onmouseover="change_class(this,\'boutonselected\');" onclick="print_search(' + (current_page - 1) + ');" class="bouton"><</span>';
	}

	for (i = Math.max((current_page - 1), 0); (i <= (Math.max(
			(current_page - 1), 0) + 3) && i < nbpages); i++) {
		if (i == current_page) {
			bouton = 'bouton underline';
			boutonselected = 'boutonselected underline';
		} else {
			bouton = 'bouton';
			boutonselected = 'boutonselected';
		}
		pagination += '<span onmouseout="change_class(this,' + bouton
				+ ');" onmouseover="change_class(this,' + boutonselected
				+ ');" onclick="print_search(' + i + ');" class="' + bouton
				+ '">' + (i + 1) + '</span>';
	}

	if (current_page < (nbpages - 1)) {
		pagination += '<span onmouseout="change_class(this,\'bouton\');" onmouseover="change_class(this,\'boutonselected\');" onclick="print_search(' + (current_page + 1) + ');" class="bouton">></span>';
	}
	if (pagination == '') {
		document.getElementById("pagination").innerHTML = '&nbsp;';
	} else {
		document.getElementById("pagination").innerHTML = pagination;
	}
}

function sortPerso(a, b) {
	return (parseFloat(a.getElementsByTagName("note")[0].firstChild.nodeValue) < parseFloat(b
			.getElementsByTagName("note")[0].firstChild.nodeValue)) ? -1 : 1;
}

// Recherche une page particulière pour un site
function make_search(site, page, string) {
	var xhr = getXhr();
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4 && xhr.status == 200) {
			nb_recherche_en_cours = nb_recherche_en_cours - 1;
			
			response = xhr.responseXML.documentElement;
			
			var videos = response.getElementsByTagName("video");
			count = videos.length;
			
			for (i = 0; i < count; i++) {
				feeds[feeds.length] = videos[i];
			}

			var tagsxml = response.getElementsByTagName("tag");
			count_tags = tagsxml.length;
			var is_present = false;
			for (i = 0; i < count_tags; i++) {
				tags[tags.length] = new Array();
				tags[tags.length - 1]["num"] = parseFloat(tagsxml[i]
						.getElementsByTagName("num")[0].firstChild.nodeValue);
				tags[tags.length - 1]["name"] = tagsxml[i]
						.getElementsByTagName("name")[0].firstChild.nodeValue;
			}
			nbpages = Math.ceil(feeds.length / 16);
			feeds.sort(sortPerso);
			print_search(0);
		} else if (xhr.readyState == 4) {
			nb_recherche_en_cours = nb_recherche_en_cours - 1;
			print_search(0);
		}
	}
	nb_recherche_en_cours = nb_recherche_en_cours + 1;
	xhr.open("GET", "get_search.php?s=" + site + "&p=" + page + "&c="
			+ urlencode(string) + "&xml=1&al=" + Math.random(), true);
	xhr.send(null);
}

// Change la classe css d'un objet
function change_class(id, classename) {
	id.className = classename;
}

// Permet de lancer la lecture d'une vidéo
function url(id, site) {
	var xhr = getXhr();
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4 && xhr.status == 200) {
			stop();
			document.getElementById("dlmini").style.visibility = 'visible';
			console.log(xhr.responseText +" retourné");
			document.monFlash.SetVariable("player:jsUrl", xhr.responseText);
			play();
		}
	}
	if (currentplaying != id) {
		currentplaying = id;
		currentplayingsite = site;

		partage(id, site);
		console.log("get_feed.php?s=" + site + "&v=" + id + "&al=" + Math.random() +" appelée");

		xhr.open("GET", "get_feed.php?s=" + site + "&v=" + id + "&al="
				+ Math.random(), true);
		xhr.send(null);
	}
}

function partage(id, site){
	var listepartage = document.getElementById("listepartage");
	var url = urlencode("http://www.downmine.fr/showvideo-"+site+"-"+id+".html");
	listepartage.innerHTML = '<li><a href="http://www.facebook.com/share.php?u='+url+'&amp;t=downmine" title="Facebook"><img src="http://www.journaldugeek.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li><li><a href="http://www.wikio.fr/vote?url='+url+'" title="Wikio FR"><img src="http://www.journaldugeek.com/wp-content/plugins/sociable/images/wikio.png" title="Wikio FR" alt="Wikio FR" class="sociable-hovers" /></a></li><li><a href="http://www.netvibes.com/share?title='+document.title+'&amp;url='+url+'" title="Netvibes"><img src="http://www.journaldugeek.com/wp-content/plugins/sociable/images/netvibes.png" title="Netvibes" alt="Netvibes" class="sociable-hovers" /></a></li><li><a href="http://digg.com/submit?phase=2&amp;url='+url+'&amp;title='+document.title+'" title="Digg"><img src="http://www.journaldugeek.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li><li><a href="http://twitter.com/home?status='+url+'" title="TwitThis"><img src="http://www.journaldugeek.com/wp-content/plugins/sociable/images/twitter.png" title="TwitThis" alt="TwitThis" class="sociable-hovers" /></a></li><li><a href="http://del.icio.us/post?url='+url+'&amp;title='+document.title+'" title="del.icio.us"><img src="http://www.journaldugeek.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li><li><a href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk='+url+'&amp;title='+document.title+'" title="Google"><img src="http://www.journaldugeek.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google" alt="Google" class="sociable-hovers" /></a></li><li><a href="http://www.myspace.com/Modules/PostTo/Pages/?u='+url+'&amp;t='+document.title+'" title="MySpace"><img src="http://www.journaldugeek.com/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" class="sociable-hovers" /></a></li><li><a href="http://www.scoopeo.com/scoop/new?newurl='+url+'%2F&amp;title='+document.title+'" title="Scoopeo"><img src="http://www.journaldugeek.com/wp-content/plugins/sociable/images/scoopeo.png" title="Scoopeo" alt="Scoopeo" class="sociable-hovers" /></a></li><li><a href="mailto:?subject='+document.title+'&amp;body='+url+'" title="Envoyer en mail à un ami"><img src="http://www.journaldugeek.com/wp-content/plugins/sociable/images/email_link.png" title="Envoyer en mail à un ami" alt="Envoyer en mail à un ami" class="sociable-hovers" /></a></li>';
}

// Permet de télécharger la vidéo en cours de lecture
function downloadcurrent() {
	document.location.href = "/download-" + currentplayingsite + "-"
			+ currentplaying + ".flv";
}

function play() {
	document.monFlash.SetVariable("player:jsPlay", "");
}

function pause() {
	document.monFlash.SetVariable("player:jsPause", "");
}

function stop() {
	document.monFlash.SetVariable("player:jsStop", "");
}

function startImage() {
	document.monFlash.SetVariable("player:jsStartImage", "rorobong.jpg");
}

function volume(value) {
	document.monFlash.SetVariable("player:jsVolume", value);
}

// Equivalent de urlencode
function urlencode(str) {
	// http://kevin.vanzonneveld.net
	// + original by: Philip Peterson
	// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// + input by: AJ
	// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// + improved by: Brett Zamir
	// % note: info on what encoding functions to use from:
	// http://xkr.us/articles/javascript/encode-compare/
	// * example 1: urlencode('Kevin van Zonneveld!');
	// * returns 1: 'Kevin+van+Zonneveld%21'
	// * example 2: urlencode('http://kevin.vanzonneveld.net/');
	// * returns 2: 'http%3A%2F%2Fkevin.vanzonneveld.net%2F'
	// * example 3:
	// urlencode('http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a');
	// * returns 3:
	// 'http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a'

	var histogram = {}, tmp_arr = [];
	var ret = str.toString();

	var replacer = function(search, replace, str) {	return(str.replace(new RegExp(search,"gi"),replace));};

	// The histogram is identical to the one in urldecode.
	histogram["'"] = '%27';
	histogram['\\('] = '%28';
	histogram['\\)'] = '%29';
	histogram['\\*'] = '%2A';
	histogram['~'] = '%7E';
	histogram['!'] = '%21';
	histogram['\\.'] = '%2E';
	histogram['%20'] = '+';

	// Begin with encodeURIComponent, which most resembles PHP's encoding
	// functions
	ret = encodeURIComponent(ret);

	for (search in histogram) {
		replace = histogram[search];
		ret = replacer(search, replace, ret); // Custom replace. No regexing
	}

	// Uppercase for full PHP compatibility
	return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) {
		return "%" + m2.toUpperCase();
	});

	return ret;
}

// Equivalent de htmlentities()
function htmlentities(string, quote_style) {
	// http://kevin.vanzonneveld.net
	// + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// + improved by: nobbler
	// + tweaked by: Jack
	// + bugfixed by: Onno Marsman
	// + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// - depends on: get_html_translation_table
	// * example 1: htmlentities('Kevin & van Zonneveld');
	// * returns 1: 'Kevin &amp; van Zonneveld'

	var histogram = {}, symbol = '', tmp_str = '', entity = '';
	tmp_str = string.toString();

	if (false === (histogram = get_html_translation_table('HTML_ENTITIES',
			quote_style))) {
		return false;
	}

	for (symbol in histogram) {
		entity = histogram[symbol];
		tmp_str = tmp_str.split(symbol).join(entity);
	}

	return tmp_str;
}

// Pour l'equivalent de url_encode()
function get_html_translation_table(table, quote_style) {
	// http://kevin.vanzonneveld.net
	// + original by: Philip Peterson
	// + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// + bugfixed by: noname
	// % note: It has been decided that we're not going to add global
	// % note: dependencies to php.js. Meaning the constants are not
	// % note: real constants, but strings instead. integers are also supported
	// if someone
	// % note: chooses to create the constants themselves.
	// % note: Table from http://www.the-art-of-web.com/html/character-codes/
	// * example 1: get_html_translation_table('HTML_SPECIALCHARS');
	// * returns 1: {'"': '&quot;', '&': '&amp;', '<': '&lt;', '>': '&gt;'}

	var entities = {}, histogram = {}, decimal = 0, symbol = '';
	var constMappingTable = {}, constMappingQuoteStyle = {};
	var useTable = {}, useQuoteStyle = {};

	useTable = (table ? table.toUpperCase() : 'HTML_SPECIALCHARS');
	useQuoteStyle = (quote_style ? quote_style.toUpperCase() : 'ENT_COMPAT');

	// Translate arguments
	constMappingTable[0] = 'HTML_SPECIALCHARS';
	constMappingTable[1] = 'HTML_ENTITIES';
	constMappingQuoteStyle[0] = 'ENT_NOQUOTES';
	constMappingQuoteStyle[2] = 'ENT_COMPAT';
	constMappingQuoteStyle[3] = 'ENT_QUOTES';

	// Map numbers to strings for compatibilty with PHP constants
	if (!isNaN(useTable)) {
		useTable = constMappingTable[useTable];
	}
	if (!isNaN(useQuoteStyle)) {
		useQuoteStyle = constMappingQuoteStyle[useQuoteStyle];
	}

	if (useQuoteStyle != 'ENT_NOQUOTES') {
		entities['34'] = '&quot;';
	}

	if (useQuoteStyle == 'ENT_QUOTES') {
		entities['39'] = '&#039;';
	}

	if (useTable == 'HTML_SPECIALCHARS') {
		// ascii decimals for better compatibility
		entities['38'] = '&amp;';
		entities['60'] = '&lt;';
		entities['62'] = '&gt;';
	} else if (useTable == 'HTML_ENTITIES') {
		// ascii decimals for better compatibility
		entities['38'] = '&amp;';
		entities['60'] = '&lt;';
		entities['62'] = '&gt;';
		entities['160'] = '&nbsp;';
		entities['161'] = '&iexcl;';
		entities['162'] = '&cent;';
		entities['163'] = '&pound;';
		entities['164'] = '&curren;';
		entities['165'] = '&yen;';
		entities['166'] = '&brvbar;';
		entities['167'] = '&sect;';
		entities['168'] = '&uml;';
		entities['169'] = '&copy;';
		entities['170'] = '&ordf;';
		entities['171'] = '&laquo;';
		entities['172'] = '&not;';
		entities['173'] = '&shy;';
		entities['174'] = '&reg;';
		entities['175'] = '&macr;';
		entities['176'] = '&deg;';
		entities['177'] = '&plusmn;';
		entities['178'] = '&sup2;';
		entities['179'] = '&sup3;';
		entities['180'] = '&acute;';
		entities['181'] = '&micro;';
		entities['182'] = '&para;';
		entities['183'] = '&middot;';
		entities['184'] = '&cedil;';
		entities['185'] = '&sup1;';
		entities['186'] = '&ordm;';
		entities['187'] = '&raquo;';
		entities['188'] = '&frac14;';
		entities['189'] = '&frac12;';
		entities['190'] = '&frac34;';
		entities['191'] = '&iquest;';
		entities['192'] = '&Agrave;';
		entities['193'] = '&Aacute;';
		entities['194'] = '&Acirc;';
		entities['195'] = '&Atilde;';
		entities['196'] = '&Auml;';
		entities['197'] = '&Aring;';
		entities['198'] = '&AElig;';
		entities['199'] = '&Ccedil;';
		entities['200'] = '&Egrave;';
		entities['201'] = '&Eacute;';
		entities['202'] = '&Ecirc;';
		entities['203'] = '&Euml;';
		entities['204'] = '&Igrave;';
		entities['205'] = '&Iacute;';
		entities['206'] = '&Icirc;';
		entities['207'] = '&Iuml;';
		entities['208'] = '&ETH;';
		entities['209'] = '&Ntilde;';
		entities['210'] = '&Ograve;';
		entities['211'] = '&Oacute;';
		entities['212'] = '&Ocirc;';
		entities['213'] = '&Otilde;';
		entities['214'] = '&Ouml;';
		entities['215'] = '&times;';
		entities['216'] = '&Oslash;';
		entities['217'] = '&Ugrave;';
		entities['218'] = '&Uacute;';
		entities['219'] = '&Ucirc;';
		entities['220'] = '&Uuml;';
		entities['221'] = '&Yacute;';
		entities['222'] = '&THORN;';
		entities['223'] = '&szlig;';
		entities['224'] = '&agrave;';
		entities['225'] = '&aacute;';
		entities['226'] = '&acirc;';
		entities['227'] = '&atilde;';
		entities['228'] = '&auml;';
		entities['229'] = '&aring;';
		entities['230'] = '&aelig;';
		entities['231'] = '&ccedil;';
		entities['232'] = '&egrave;';
		entities['233'] = '&eacute;';
		entities['234'] = '&ecirc;';
		entities['235'] = '&euml;';
		entities['236'] = '&igrave;';
		entities['237'] = '&iacute;';
		entities['238'] = '&icirc;';
		entities['239'] = '&iuml;';
		entities['240'] = '&eth;';
		entities['241'] = '&ntilde;';
		entities['242'] = '&ograve;';
		entities['243'] = '&oacute;';
		entities['244'] = '&ocirc;';
		entities['245'] = '&otilde;';
		entities['246'] = '&ouml;';
		entities['247'] = '&divide;';
		entities['248'] = '&oslash;';
		entities['249'] = '&ugrave;';
		entities['250'] = '&uacute;';
		entities['251'] = '&ucirc;';
		entities['252'] = '&uuml;';
		entities['253'] = '&yacute;';
		entities['254'] = '&thorn;';
		entities['255'] = '&yuml;';
	} else {
		throw Error("Table: " + useTable + ' not supported');
		return false;
	}

	// ascii decimals to real symbols
	for (decimal in entities) {
		symbol = String.fromCharCode(decimal)
		histogram[symbol] = entities[decimal];
	}

	return histogram;
}

$(function() {
	// Préchargement d'images
	function load_image(url) {
		$.("<img>").attr("src", url);
	}
	
	$("#rech").hover(
		function(){
			$(".intro").stop(true, true);
			$("#visiodiv").slideUp("normal");
			$("#telediv").slideUp("normal");
			$("#rechdiv").slideDown("normal");
		},
		function(){}
		);
	$("#visio").hover(
			function(){
				$(".intro").stop(true, true);
				$("#rechdiv").slideUp("normal");
				$("#telediv").slideUp("normal");
				$("#visiodiv").slideDown("normal");
			},
			function(){}
			);
	$("#tele").hover(
			function(){
				$(".intro").stop(true, true);
				$("#rechdiv").slideUp("normal");
				$("#visiodiv").slideUp("normal");
				$("#telediv").slideDown("normal");
			},
			function(){}
			);
});