/**********************************************************************
 * For LaTeX formula                                                  *
 *********************************************************************/

// Create a namespace to hold variables and functions
mathtex = new Object();

// Change this to use your server
mathtex.imgSrc = "http://www.forkosh.dreamhost.com/mathtex.cgi?";

// Transform the whole document: add src to each img with
// alt text starting with "mathtex:", unless img already has a src.
mathtex.init = function()
{
	if( !document.getElementsByTagName )
		return;

	var objs = document.getElementsByTagName("img");
	var len  = objs.length;

	for( i=0; i<len; i++ )
	{
		var img = objs[i];

		if( img.alt.substring(0,6) == 'latex:' && !img.src )
		{
			var tex_src = img.alt.substring(6);
			img.src = mathtex.imgSrc + encodeURIComponent(tex_src);

			// Append TEX to the class of the IMG.
			img.className +=' tex';
		}
	}

	mathtex.hideElementById("mathtex.error");
}

// Utility function
mathtex.hideElementById = function( id )
{
	var obj = document.getElementById(id);

	if( obj )
		obj.style.display = 'none';
}

// resolve a cross-browser issue (see CBS events)
mathtex.addEvent = function( obj, evType, fn, useCapture )
{
	if( obj.addEventListener )
	{
		//For Mozilla.
		obj.addEventListener(evType, fn, useCapture);
		return true;
	}
	else if (obj.attachEvent)
	{
		//For Internet Explorer.
		var r = obj.attachEvent("on"+evType, fn);
		return r;
	}
}

// Initialize after entire document is loaded
mathtex.addEvent(window, 'load', mathtex.init, false);

