/*
	replacetitles.js	Version 1.1 6-May-2007
	----------------------------------------
	Copyright (c) 2007 Conrad Consulting, Inc.
	Author: Charles J. Conrad

	Description:
	Replaces content titles (h1 tags with class 'title*') with images
	
	h1 tag id is image filename.
	No replacement occurs if id is missing.
	Replacement images are assumed to be stored in directory defined by variable ipath.
	
	image src is set to ipath + id
		Note: xhtml does not allow '/' in an id name, even though browsers may support it.
	image class is set to h1 class
	image id is set to h1 id

	Usage:
	include as external script
	activated by onload event

	Acknowledgements:
	prior image replacement advocates

	replacetitles.js is free software; you can redistribute it and/or
	modify it under the terms of the GNU Lesser General Public
	License as published by the Free Software Foundation; either
	version 2.1 of the License, or (at your option) any later version.

	replacetitles.js is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
	Lesser General Public License for more details.

	You should have received a copy of the GNU Lesser General Public
	License along with this library; if not, write to the Free Software
	Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

/* image path defined here */
var ipath = 'images/titles/';

function _replaceTitle(node)
{
	if (node.id)
	{
			var image = document.createElement('img');
			image.className=node.className;
			image.id  = node.id;
			image.src = ipath + node.id;
			image.alt = node.firstChild.nodeValue;
			node.replaceChild(image,node.firstChild);
	}
}

function replaceTitles()
{
/* Check for DOM support */
    if (!(document && document.implementation && document.implementation.hasFeature))
    	return;

/* Check for image support */
	if (!document.images)
		return;

	var pattern = /(^|\s)title/;
	var titles = document.getElementsByTagName('h1');
	for (var i=0; i < titles.length; i++)
		if (pattern.test(titles[i].className)) 
			_replaceTitle(titles[i]);
}

if (window.addEventListener)
	window.addEventListener("load", replaceTitles, false);
else if (window.attachEvent)
	window.attachEvent("onload", replaceTitles);
else if (document.getElementById)
	window.onload=replaceTitles;

