
/*
 * page just loaded? then call init ( ) to highlight the target entry.
 */
function init ( )
{
	hash = window.location.hash;
	if (hash == "") return; 
	div = document.getElementById(hash.substring(1));
	if (div == null) return;
	selectLater ( div );
}

var storedTargetDiv;

/*
 * called by init ( )
 */
function selectLater ( targetDiv )
{
	storedTargetDiv = targetDiv;
	if (targetDiv == null)
	{
		/*
		 * selection must go fast!
		 */
		selectNow ( );
	}
	else
	{
		/*
		 * selection is timed.
		 */		
		window.setTimeout("selectNow ( )", 500);
	}
}

/*
 * to be called if clicked on Keptn's Pic
 */
function unselect ( )
{
	storedTargetDiv = null;
	selectNow ( );
}

/*
 * to be called by onmousedown attribute
 */
function selectById ( id )
{
	select ( document.getElementById (id) );
}

/*
 * to be called on click on a permalink.
 */
function select ( targetDiv )
{	
	storedTargetDiv = targetDiv;
	selectNow ( );
	// alert (targetDiv);
	href = "#" + targetDiv.id;
	// window.location.href = "empty.txt";
	window.location.href = href;		
}

function selectNow ( )
{
	childNodes = document.getElementById("right").childNodes;
	for (i=0; i<childNodes.length; i++)
	{			
		div = childNodes[i];
		if (div.nodeName != "DIV") continue;			
		if (storedTargetDiv == null || div == storedTargetDiv)
		{
			/*
			 * target div found. select it.
			 * 
			 * note: if <h1> is first or second child element 
			 *       depents on the browser 
			 */
			h1 = div.childNodes[0];
			if (h1.nodeName != "H1")
			{
				h1 = div.childNodes[1];				
			}
			if (h1 == null) continue;
			div.style.border = "solid 1px black";
			h1.style.backgroundColor = "black";				
			// div.style.display = "block";								
		}
		else
		{
			/*
			 * other div found. unselect it.
			 * 
			 * note: if <h1> is first or second child element 
			 *       depents on the browser 
			 */
			h1 = div.childNodes[0];
			if (h1.nodeName != "H1")
			{
				h1 = div.childNodes[1];				
			}
			if (h1 == null) continue;
			div.style.border = "solid 1px #777777";
			h1.style.backgroundColor = "#777777";
			// div.style.display = "none";								
		}
	}
}
