// --------------------------------------------------
// Image Preloader  v1.0.1
// documentation: http://www.dithered.com/javascript/image_preloader/
// license: http://creativecommons.org/licenses/by/1.0/
// code by Chris Nott (chris[at]dithered[dot]com)
function preloadImages() {
	if (document.images) {
		for (var i = 0; i < preloadImages.arguments.length; i++) {
				(new Image()).src = preloadImages.arguments[i];
		}
	}
}
// Preload any images not already loaded
preloadImages(
'/img/rule/pick.gif',
'/img/rule/pickhere.gif',
'/img/col/topbg.png',
'/img/nav/bghere.png',
'/img/nav/bghomeoff.png',
'/img/nav/bghomeon.png',
'/img/nav/bg.png'
);

// --------------------------------------------------
// IMAGE REPLACEMENT
// see http://www.quirksmode.org/dom/fir.html
function init()
{
	var test = new Image();
	var tmp = new Date();
	var suffix = tmp.getTime();
	test.src = '/img/rule/pick.gif?'+suffix;
	test.onload = imageReplacement;
}

function imageReplacement()
{
	replaceThem(document.getElementsByTagName('h4'));
}

function replaceThem(x)
{
	var replace = document.createElement('img');
	for (var i=0;i<x.length;i++)
	{
		if (x[i].id)
		{
			var y = replace.cloneNode(true);
			y.src = '/img/rule/' + x[i].id + '.gif';
			y.alt = x[i].firstChild.nodeValue;
			x[i].replaceChild(y,x[i].firstChild);
		}
	}
}

// window.onunload = function () {

	// execute unload routine of page, if present

	// if (self.exit)
		// exit();
// }

window.onload = function () {

	/* Initialise scripts on content pages in all browsers */
	
	if (self.init)
		init();
}