var idTimeOut = 0;

function cancelTimeOut()
{
	//Disable timeout if there is any
	if( idTimeOut > 0 )
	{
		clearTimeout( idTimeOut );
	}
}

function showSubMenu( hoverElement, sMenu )
{
	//sMenu = huren|leven|kopen|comwonen|mijncomwonen
	
	//First, disable currently shown submenu
	var allHTMLTags = document.getElementsByTagName( "*" );
	for( i = 0; i < allHTMLTags.length; i++ )
	{
		//Get all tags with the specified class name.
		if( allHTMLTags[i].className.substring( 0, 21 ) == 'subnavigation_section' )
		{
			if( allHTMLTags[i].id.substring( 0, 8 ) == 'subMenu_' )
			{
				allHTMLTags[i].style.display = 'none';
			}
		}
	}
	
	//Second, show submenu of hovered section
	var ulSubMenu = document.getElementById( 'subMenu_' + sMenu );
	if( ulSubMenu )
	{
		ulSubMenu.style.display = 'block';
		
		//Third, set background of hovered item
		resetSectionBackground();	//First remove all backgrounds for inactive sections
		if( sMenu == 'huren' ) { hoverElement.style.backgroundPosition = '0 -30px'; }
		if( sMenu == 'leven' ) { hoverElement.style.backgroundPosition = '0 -90px'; }
		if( sMenu == 'kopen' ) { hoverElement.style.backgroundPosition = '0 -60px'; }
		if( sMenu == 'comwonen' ) { hoverElement.style.backgroundPosition = '0 -120px'; }
		if( sMenu == 'mijncomwonen' ) { hoverElement.style.backgroundPosition = '0 -150px'; }
	}
}

function hideSubMenu()
{
	var allHTMLTags = document.getElementsByTagName( "*" );
	for( i = 0; i < allHTMLTags.length; i++ )
	{
		//Get all tags with the specified class name.
		if( allHTMLTags[i].className.substring( 0, 21 ) == 'subnavigation_section' )
		{
			if( allHTMLTags[i].id.substring( 0, 8 ) == 'subMenu_' )
			{
				allHTMLTags[i].style.display = 'none';
			}
		}
	}
	resetSectionBackground();
}

function resetSectionBackground()
{
	var allHTMLTags = document.getElementsByTagName( "*" );
	for( i = 0; i < allHTMLTags.length; i++ )
	{
		//Get all tags with the specified class name.
		if( allHTMLTags[i].className.substring( 0, 23 ) == 'navigation_section_item' &&
			allHTMLTags[i].className.substring( 0, 24 ) != 'navigation_section_item_' )
		{
			//Ignore active section
			if( allHTMLTags[i].className.substring( allHTMLTags[i].className.length - 6 ) != 'active' )
			{
				allHTMLTags[i].style.backgroundPosition = '0 0';
			}
		}
	}
}

function setHideTimeOut()
{
	idTimeOut = setTimeout ( 'hideSubMenu()', 2000 );
}