function com_stewartspeak_replacement() {
/*
	Dynamic Heading Generator
    By Stewart Rosenberger
    http://www.stewartspeak.com/headings/

	This script searches through a web page for specific or general elements
	and replaces them with dynamically generated images, in conjunction with
	a server-side script.
*/

var chemin="http://www.lobodis.com/escale-equitable";

// Appel des différentes fonctions de remplacement.
replaceSelector(".darkbrown",					chemin+"/scripts/replacement/heading_darkbrown.php",	true);
replaceSelector(".menu li.lier a",				chemin+"/scripts/replacement/heading_darkbrown.php",	true);
replaceSelector(".menu li.nonlier",				chemin+"/scripts/replacement/heading_darkbrown.php",	true);
replaceSelector(".darkcream",					chemin+"/scripts/replacement/heading_darkcream.php",	true);
replaceSelector(".encart h2",					chemin+"/scripts/replacement/heading_darkcream.php",	true);
replaceSelector(".lightbrown",					chemin+"/scripts/replacement/heading_lightbrown.php",	true);
replaceSelector(".lightcream",					chemin+"/scripts/replacement/heading_lightcream.php",	true);
replaceSelector("#txthome > h2",				chemin+"/scripts/replacement/heading_lightcream.php",	true);
replaceSelector("#txthome .bloc_liste h2 a",	chemin+"/scripts/replacement/heading_lightcream.php",	true);
replaceSelector("#txthome .bloc_liste h2.vide",	chemin+"/scripts/replacement/heading_lightcream.php",	true);
replaceSelector("#txthome #txthomeg h2",		chemin+"/scripts/replacement/heading_lightcream.php",	true);
replaceSelector("#txthome #txthomed h2",		chemin+"/scripts/replacement/heading_lightcream.php",	true);

var testURL = chemin+"/img/css/test.png" ;

var doNotPrintImages = false;
var printerCSS = chemin+"/css/replacement-print.css";

var hideFlicker = false;
var hideFlickerCSS = chemin+"/replacement-screen.css";
var hideFlickerTimeout = 1000;




/* ---------------------------------------------------------------------------
    For basic usage, you should not need to edit anything below this comment.
    If you need to further customize this script's abilities, make sure
	you're familiar with Javascript. And grab a soda or something.
*/

var items;
var imageLoaded = false;
var documentLoaded = false;

function replaceSelector(selector,url,wordwrap)
{
	if(typeof items == "undefined")
		items = new Array();

	items[items.length] = {selector: selector, url: url, wordwrap: wordwrap};
}

if(hideFlicker)
{		
	document.write('<link id="hide-flicker" rel="stylesheet" media="screen" href="' + hideFlickerCSS + '" />');		
	window.flickerCheck = function()
	{
		if(!imageLoaded)
			setStyleSheetState('hide-flicker',false);
	};
	setTimeout('window.flickerCheck();',hideFlickerTimeout)
}

if(doNotPrintImages)
	document.write('<link id="print-text" rel="stylesheet" media="print" href="' + printerCSS + '" />');

var test = new Image();
test.onload = function() { imageLoaded = true; if(documentLoaded) replacement(); };
test.src = testURL + "?date=" + (new Date()).getTime();

addLoadHandler(function(){ documentLoaded = true; if(imageLoaded) replacement(); });


function documentLoad()
{
	documentLoaded = true;
	if(imageLoaded)
		replacement();
}

function replacement()
{
	for(var i=0;i<items.length;i++)
	{
		var elements = $$(items[i].selector);
		if(elements.length > 0) for(var j=0;j<elements.length;j++)
		{
			if(!elements[j])
				continue ;
		
			var text = extractText(elements[j]);
    		while(elements[j].hasChildNodes())
				elements[j].removeChild(elements[j].firstChild);

			var tokens = items[i].wordwrap ? text.split(' ') : [text] ;
			for(var k=0;k<tokens.length;k++)
			{
				var url = items[i].url + "?text="+escape(tokens[k]+' ')+"&selector="+escape(items[i].selector);
				var image = document.createElement("img");
				image.className = "replacement";
				image.alt = tokens[k] ;
				image.src = url;
				elements[j].appendChild(image);
			}

			if(doNotPrintImages)
			{
				var span = document.createElement("span");
				span.style.display = 'none';
				span.className = "print-text";
				span.appendChild(document.createTextNode(text));
				elements[j].appendChild(span);
			}
		}
	}

	if(hideFlicker)
		setStyleSheetState('hide-flicker',false);
}

function addLoadHandler(handler)
{
	if(window.addEventListener)
	{
		window.addEventListener("load",handler,false);
	}
	else if(window.attachEvent)
	{
		window.attachEvent("onload",handler);
	}
	else if(window.onload)
	{
		var oldHandler = window.onload;
		window.onload = function piggyback()
		{
			oldHandler();
			handler();
		};
	}
	else
	{
		window.onload = handler;
	}
}

function setStyleSheetState(id,enabled) 
{
	var sheet = document.getElementById(id);
	if(sheet)
		sheet.disabled = (!enabled);
}

function extractText(element)
{
	if(typeof element == "string")
		return element;
	else if(typeof element == "undefined")
		return element;
	else if(element.innerText)
		return element.innerText;

	var text = "";
	var kids = element.childNodes;
	for(var i=0;i<kids.length;i++)
	{
		if(kids[i].nodeType == 1)
		text += extractText(kids[i]);
		else if(kids[i].nodeType == 3)
		text += kids[i].nodeValue;
	}

	return text;
}

}// end of scope, execute code
if(document.createElement && document.getElementsByTagName && !navigator.userAgent.match(/opera\/?6/i))
	com_stewartspeak_replacement();

function addLoadHandler(handler)
{
	if(window.addEventListener)
	{
		window.addEventListener("load",handler,false);
	}
	else if(window.attachEvent)
	{
		window.attachEvent("onload",handler);
	}
	else if(window.onload)
	{
		var oldHandler = window.onload;
		window.onload = function piggyback()
		{
			oldHandler();
			handler();
		};
	}
	else
	{
		window.onload = handler;
	}
}