
/*
	FIR = "Fahrner Image Replacement".
	
	Die Texte bestimmter IDs sollen ersetzten werden durch die entsprechenden
	Buchstabengrafiken. Wenn der Browser das Script nicht versteht, ausführen
	kann oder der User JavaScript ausgestellt hat oder, oder... passiert nichts
	und die Tags bleiben in der vorherigen Form erhalten.

	Script gefunden bei quirksmode.org, thanks!
	Erweitert von mir! edv-service-tb.de
*/

function init()
{
	/*
		We also have to see if the browser supports images. If it doesn't our
		script shouldn't run, since it would create all kinds of odd effects.

		Therefore we generate an image and set its src. This is a classic pre-
		loading trick: the browser now fetches the image. This is the only
		support detection we need. If this test image loads succesfully, the
		browser supports images. I assume that a browser that doesn't support
		images doesn't download them, either.

		So we activate the main image replacement routine only when this image
		has been loaded, ie. after its load event has taken place.

		A browser problem here. If you return to this page by using the Back
		button, Explorer on Windows does not fire the onload event of cached
		images. Therefore we have to make sure that it fetches a new image
		every time by adding a suffix that contains the current time in
		milliseconds.

		I don't like this feature of the script, it causes unnecessary HTTP
		requests, but at the moment I don't see a way around it.

	*/

	var test = new Image();
	var tmp = new Date();
	var suffix = tmp.getTime();
	test.src = '../images/headlines/fir_test.gif?'+suffix;
		/*
		so war das Original von quirksmode.org:
		
		test.onload = imageReplacement; 

		Das hat ber nicht so richtig klasse geklappt, also deswegen diese Form:
		*/
	go = imageReplacement();
}

function imageReplacement()
	/*
		Once the test image has been loaded, it's safe to do wholesale image
		replacement. The function imageReplacement is called. It's an
		intermediate function to allow you to define several areas of the
		document where images should be replaced. This example script
		just replaces h3s.

		However, if you'd also like to replace, say, all links in div id="nav",
		do
		function imageReplacement()
		{
			replaceThem(document.getElementsByTagName('h3'));
			replaceThem(document.getElementById('nav').getElementsByTagName('a'));
		}

		Die Idee ist also, alle /z.B.) <hr> Elemente zu suchen und mit einem
		*.gif Image zu ersetzen, dass den equivalenten Namen der ID des Tags hat
		z.B.:
		
		<hr ID="fir_doedel>So und so</h3>
		
		soll mit fir_doedel.gif ersetzt werden.

	*/
{
	replaceThem(document.getElementsByTagName('h1'));
}

function replaceThem(x)

	/*
		The function replaceThem() handles the actual image replacement. It is
		handed an array which it searches for elements with an id. If it finds
		one, the script replaces the element's firstChild (the text node
		containing the text) for an image with a name that's similar to the id.

		To be on the safe side I also set the alt attribute. Theoretically it's
		unnecessary, since images will shown only when the browser supports
		images, but better safe than sorry.
	*/

{
	var replace = document.createElement('img');
	for (var i=0;i<x.length;i++)
	{
		if (x[i].id)
		{

			var y = replace.cloneNode(true);
			y.src = '../images/headlines/' + x[i].id + '.gif';
			y.alt = x[i].firstChild.nodeValue;
			x[i].replaceChild(y,x[i].firstChild);
		}
	}
}
