/**
 * Adds and removes classes to a list of links to allow keyboard accessibility
 *
 * @param string dropDownId
 * @param string hoverClass
 * @param int mouseOffDelay
 */
function dropdown(dropdownId, hoverClass, mouseOffDelay) {
	if ( dropdown = document.getElementById( dropdownId ) )
	{
		var listItems = dropdown.getElementsByTagName( 'li' );
		
		for ( var i = 0; i < listItems.length; i++ ) 
		{
			if ( typeof(listItems[i]) != 'undefined' )
			{
				listItems[i].onmouseover = function() {
					this.className = addClass( this );
				}
				listItems[i].onmouseout = function() {
					var that = this;
					setTimeout( function() { that.className = removeClass( that ); }, mouseOffDelay );
					this.className = that.className;
				}
				
				var anchor = listItems[i].getElementsByTagName( 'a' );
				anchor = anchor[0];
				if( typeof( anchor ) != 'undefined' )
				{
					anchor.onfocus = function() { tabOn( this.parentNode ); }
					anchor.onblur = function() { tabOff( this.parentNode ); }
				}
			}
		}
	}
	
	function tabOn( li )
	{
		if ( li.nodeName == 'LI')
		{
			li.className = addClass( li );
			tabOn( li.parentNode.parentNode );
		}
	}
	
	function tabOff( li )
	{
		if ( li.nodeName == 'LI' )
		{
			li.className = removeClass( li );
			tabOff( li.parentNode.parentNode );
		}
	}
	
	function addClass( li )
	{
		$(li).siblings('li').removeClass('hover');
		return li.className + ' ' + hoverClass;
	}
	
	function removeClass( li )
	{
		return li.className.replace( ' ' + hoverClass, "" );
	}
}
function buildNav(){
	//fix height popular links
	$('#topmenu').children('li').each(function(){
		if( $(this).children('ul.submenu').html() )
		{
			var height = 0;
			var heightPop = 0;
			if( currentBrowser == 'IE6' )
			{
				$(this).addClass('hover');
				height = $(this).children('ul.submenu').height() + 10;
				heightPop = $(this).children('ul.popularlinks').height() + 10;
			}
			else if( currentBrowser == 'IE7' )
			{
				height = $(this).children('ul.submenu').height() + 14;
				heightPop = $(this).children('ul.popularlinks').height() + 14;
			}
			else if( currentBrowser == 'IE8' )
			{
				height = $(this).children('ul.submenu').height() + 14;
				heightPop = $(this).children('ul.popularlinks').height() + 14;
			}
			else
			{
				height = $(this).children('ul.submenu').height() + 14;
				heightPop = $(this).children('ul.popularlinks').height() + 14;
			}
			
			if ( height > heightPop )
			{
				$(this).children('ul.popularlinks').height( height );
			}
			else
			{
				$(this).children('ul.popularlinks').height( heightPop + 14 );
				$(this).children('ul.submenu').height( heightPop );
			}
			if( currentBrowser == 'IE6')
			{
				$(this).removeClass('hover');
			}
		}
	});
	
	$('#topmenu li.level1').mouseover(function(){
		$(this).siblings('li').removeClass('hover');
	});
	$('#topmenu li.level1').focus(function(){
		$(this).siblings('li').removeClass('hover');
	});
	
}
