function getChildrenByTagName ( $obj, $tag )
{
	try
	{
		var $found = new Array();
		for( var $c = 0; $c < $obj.childNodes.length; $c++ ) {
			$cn = $obj.childNodes[ $c ];
			if( $cn.nodeName.toLowerCase() == $tag.toLowerCase() )
			{
				$found[ $found.length ] = $cn;
			}
		}
		return $found;
	}
	catch( e )
	{
		return null;
	}
}

function hasClassName( $obj, $name )
{
	try
	{
		if ( $obj.className.indexOf( $name ) > -1 )
		{

			return true;
		}
		return false;
	}
	catch( e )
	{
		return null;
	}
}

function showSubMenu()
{
	try
	{
		var $topUl = this.parentNode;
		var $siblingLis = getChildrenByTagName( $topUl, 'li' );
		for( var $l = 0; $l < $siblingLis.length; $l++ )
		{
			var $ln = $siblingLis[ $l ];
			if( $ln != this && ( $lnChildUl = $ln.getElementsByTagName( 'ul' )[ 0 ] ) )
			{
				$lnChildUl.style.display = 'none';
			}
			if( $ln != this && ( $lnChildDiv = $ln.getElementsByTagName( 'div' )[ 0 ] ) )
			{
				$lnChildDiv.style.display = 'none';
			}
		}
		if( $childUl = this.getElementsByTagName( 'ul' )[ 0 ] )
		{
			$childUl.style.display = 'block';
		}
		if( $lnChildDiv = this.getElementsByTagName( 'div' )[ 0 ] )
		{
			$lnChildDiv.style.display = 'block';
		}
		$topUl.style.background = '#4b4b4b url(/img/bg-nav-main-over.gif)';
		return true;
	}
	catch( e )
	{
		return false;
	}
}

function hideSubMenu()
{
	try
	{
		var $topUl = this.parentNode;
		var $siblingLis = getChildrenByTagName( $topUl, 'li' );
		for( var $l = 0; $l < $siblingLis.length; $l++ )
		{
			var $ln = $siblingLis[ $l ];
			if( $lnChildUl = $ln.getElementsByTagName( 'ul' )[ 0 ] )
			{
				$lnChildUl.style.display = $ln.id == 'selected' ? 'block' : 'none';
			}
			if( $lnChildDiv = $ln.getElementsByTagName( 'div' )[ 0 ] )
			{
				$lnChildDiv.style.display = $ln.id == 'selected' ? 'block' : 'none';
			}	
		}
		$topUl.style.background = hasClassName( $topUl, 'home' ) ? '#4b4b4b url(/img/bg-nav-main.gif)' : '#4b4b4b url(/img/bg-nav-main-over.gif)';
		return true;
	}
	catch( e )
	{
		return false;
	}
}

function toggleNewsItem( obj, dontAnimate )
{
	var container = obj.parentNode.parentNode;
	var childDivs = getChildrenByTagName(container, 'div');
	var title = childDivs[0]; 
	var contentContainer = childDivs[1];
	var toggle = childDivs[2];
	var content = getChildrenByTagName(contentContainer, 'div')[0];
	if( contentContainer.isAnimating ) return false;
	if( !contentContainer.isVisible || contentContainer.isVisible == null )
	{
		title.firstChild.className = 'expanded';
		toggle.className = 'contract';
		toggle.firstChild.firstChild.innerHTML = 'inklappen';
		if( dontAnimate )
		{
			contentContainer.style.display = 'block';
			contentContainer.isAnimating = false;
			contentContainer.isVisible = true;
		}
		else
		{
			contentContainer.isAnimating = true;
			new Effect.SlideDown(
				contentContainer, 
				{ 
					duration: .75, 
					from: 0.0, 
					to: 1.0, 
					restoreAfterFinish: false,
					afterFinish: function()
					{
						contentContainer.isAnimating = false;
						contentContainer.isVisible = true;
					}
				}
			);
		}
	}
	else
	{
		toggle.className = 'expand';
		toggle.firstChild.firstChild.innerHTML = 'uitklappen';
		if( dontAnimate )
		{
			contentContainer.style.display = 'none';
			contentContainer.isAnimating = false;
			contentContainer.isVisible = false;
			title.firstChild.className = '';
		}
		else
		{
			contentContainer.isAnimating = true;
			new Effect.SlideUp(
				contentContainer, 
				{ 
					duration: .75, 
					from: 0.0, 
					to: 1.0, 
					restoreAfterFinish: true,
					afterFinish: function()
					{
						contentContainer.isAnimating = false;
						contentContainer.isVisible = false;
						title.firstChild.className = '';
					}
				}
			);
		}
	}
	return false;
}

function replaceHeadings()
{
	try
	{
		h1 = document.getElementsByTagName( 'h1' )[ 0 ];
		if( h1.innerHTML )
		{
			var h1image = 'h1-' +  h1.innerHTML.toLowerCase() + '.gif';
			h1image = h1image.replace( /[ \/]/g, '-' );
			h1.style.backgroundImage = 'url(/img/headings/' + h1image + ')';
			h1.style.textIndent = '-9999px';
		}
		return true;
	}
	catch( e )
	{
		return false;
	}
}

function attachEventHandlers()
{
	try
	{
		var $topUl = document.getElementById( 'nav' );
		var $siblingLis = getChildrenByTagName( $topUl, 'li' );
		for( var $l = 0; $l < $siblingLis.length; $l++ )
		{
			var $ln = $siblingLis[ $l ];
			$ln.onmouseover = showSubMenu;
			$ln.onmouseout = hideSubMenu;
		}
	}
	catch( e )
	{
		return false;
	}
}