
// ----------------------------------------------------------------------------
// Try and do something to prevent IE memory leaks. Could also do with calling
// "purge(obj)" before any & all calls to obj.remove() or .removeChild(obj)
// ----------------------------------------------------------------------------
// Purge function from: http://javascript.crockford.com/memory/leak.html
// ----------------------------------------------------------------------------

Event.observe(window, 'unload', function(e) {
	purge(document.body);
});

function purge(obj) {
	// Cycle through attributes of DOM object
	// and nullify any event handlers we find.
	var attr = obj.attributes;
	if (attr) {
		var len = attr.length;
		for (var i=0; i<len; i+=1) {
			var n = attr[i].name;
			if (typeof obj[n] === 'function') {
				obj[n] = null;
			}
		}
	}
	// Recurse through children of this object.
	var children = obj.childNodes;
	if (children) {
		var len = children.length;
		for (var i=0; i<len; i+=1) {
			purge(obj.childNodes[i]);
		}
	}
}
