function preloadImages() {
	document.preload = new Array();
	if (document.images) {
		for (var i = 0; i < preloadImages.arguments.length; i++) {
			document.preload[i] = new Image();
			document.preload[i].src = preloadImages.arguments[i];
		}
	}
}

var ext = '.png';

// used to test whether browser has images enabled
// basically, pick the smallest image your site uses, as it will be loaded twice: once for normal use, once for the test.
var testimg = '/_img/headings/h1/about_us.png';



function do_replace(hlev) {
	$('h'+hlev+'.replace_with').removeClass('replace_with').each(function() {
		$(this).replaceWith('<img class="replaced h'+hlev+'" src="/_img/headings/h'+hlev+'/' + $(this).attr('class') + ext + '" />');
	});		
}

$(document).ready(function() {
	// Only perform image replacement if user has images enabled
	$('<img src="' + testimg + '#' + Math.random() + '"/>').load(function() {
		for (var i = 1; i <= 6; i++) {
			do_replace(i);
		}				  
	});
});
