// UTILITY FUNCTIONS, ALSO USED IN EXTERNAL FILES
//------------------------------------------------------------------------------

var EventCache = function()	// fix for IE memory leak problem with event handling; relies on 'array.push' being enabled
{
	var listEvents = [];
	return {
			listEvents : listEvents,

			add : function(node, sEventName, fHandler, bCapture)
				{
				listEvents.push(arguments);
				},

			flush : function()
			{
				var i, item;
				for(i = listEvents.length - 1; i >= 0; i = i - 1)
				{
					item = listEvents[i];

					if(item[0].removeEventListener)
						{
						item[0].removeEventListener(item[1], item[2], item[3]);
						};

					/* From this point on we need the event names to be prefixed with 'on" */
					if(item[1].substring(0, 2) != "on")
						{
						item[1] = "on" + item[1];
						};

					if(item[0].detachEvent)
						{
						item[0].detachEvent(item[1], item[2]);
						};

					item[0][item[1]] = null;
				};
			}
		};
}();

function addEvent(obj, type, fn) // - requires above EventCache var
{
	if(obj.addEventListener)
		{obj.addEventListener(type, fn, false);}
	else
	{
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
	EventCache.add(obj, type, fn);
}

function removeEvent(obj, type, fn)
{
	if (obj.detachEvent)
		{
		obj.detachEvent("on"+type, fn );
		obj[type+fn] = null;
		}
	else
		{obj.removeEventListener( type, fn, false );}
}

function addClass()					// adding a class; needs a .newClass property added by the calling function
{
	if(this.className)
		{
		currentClass = this.className;
		}
	else
		{currentClass = ''}
	this.className = (currentClass + ' ' + this.newClass);
}

function removeClass()
{
	var str = this.className;
	str = str.replace(this.newClass,'');
	this.className = str;
}