/*
	PureDOM explorer
	written by Christian Heilmann (http://icant.co.uk)
	Please refer to the pde homepage for updates: http://www.onlinetools.org/tools/puredom/
	Free for non-commercial use. Changes welcome, but no distribution without 
	the consent of the author.
*/
function pde_init(navID)
{
	/* CSS class names, change if needed */
	var mp='pde_nav';
	var hp='pde_hide';
	var sp='pde_show';
	var pp='pde_parent';
	var pa='pde_active';
	var pi='pde_init';
	var cu='current';
	
	var d,uls,i;
	if(!document.getElementById && !document.createTextNode){return;}

	/* navigation ID, change if needed */
	d=document.getElementById(navID);

	if (!d){return;}
	pde_removeclass(d,pi);
	pde_addclass(d,mp)
	uls=d.getElementsByTagName('div');
	for (i=0;i<uls.length;i++)
	{
		pde_removeclass(uls[i],pi);
		pde_addclass(uls[i], pde_checkcurrent(uls[i]) ? sp : hp);
		pde_addclass(uls[i].parentNode.firstChild,pp);
		uls[i].parentNode.firstChild.onclick = function()
		{
			if(this.href.length > 0)
			{
				location.href = this.href;
			}
			
			pde_swapclass(this,pp,pa);
			ul = this.parentNode.getElementsByTagName('div')[0];
			pde_swapclass(ul,hp,sp);
			swapInverse(ul,sp,hp,pa,pp);
			return false;
		}
	}
	function swapInverse(o,c1,c2,c3,c4)
	{
		path = [];
		
		// Walk the DOM path of the given node and mark all encountered nodes
		i = 0;
		for (p = o; p != null && p.id != "nav"; p = p.parentNode)
		{
			if (p.nodeName.toLowerCase() == "div")
			{
				path[i++] = p;
				pde_addclass(p, "INSELECTEDPATH");
			}
		}
		
		// Set all nodes not in the path
		if (p != null)
		{
			uls = p.getElementsByTagName('div');
			for (i = 0; i < uls.length; i++)
			{
				ul = uls[i];
				if (!pde_check(ul, "INSELECTEDPATH"))
				{
					pde_removeclass(ul, c1);
					pde_addclass(ul, c2);
					
					if (pde_check(ul.parentNode.firstChild, c3))
						pde_swapclass(ul.parentNode.firstChild, c3, c4);
				}
			}
		}
		
		// Remove marker class again
		i = path.length;
		while (i-- > 0)
			pde_removeclass(path[i],"INSELECTEDPATH");
	}
	
	function pde_checkcurrent(o)
	{
		if (pde_check(o.parentNode,cu))
			return true;
			
		for (var i=0;i<o.getElementsByTagName('span').length;i++)
			if (pde_check(o.getElementsByTagName('span')[i],cu))
				return true;
			
		return false;
	}
	function pde_swapclass(o,c1,c2)
	{
		var cn=o.className;
		o.className = !pde_check(o,c1) ? cn.replace(c2,c1) : cn.replace(c1,c2);
	}
	function pde_addclass(o,c)
	{
		if (!pde_check(o,c))
			o.className+=o.className==''?c:' '+c;
	}
	function pde_removeclass(o,c)
	{
		if (pde_check(o,c))
			pde_swapclass(o,c,'');
	}
	function pde_check(o,c)
	{
	 	return new RegExp('\\b'+c+'\\b').test(o.className);
	}
}

