var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;

function nav_open()
{  nav_canceltimer();
   nav_close();
   ddmenuitem = $(this).find('ul').css('visibility', 'visible');
	 //ddmenuitem.bind('mouseover', function() { $(this).parent().find('a:first').css('color', '#0773b4'); })
	 //ddmenuitem.bind('mouseout', function() { $(this).parent().find('a:first').css('color', '#bfbfbf'); })	
}

function nav_close() {  
	if(ddmenuitem) { 
		ddmenuitem.css('visibility', 'hidden');
	}
}

function nav_timer()
{  closetimer = window.setTimeout(nav_close, timeout);}

function nav_canceltimer()
{  if(closetimer)
   {  window.clearTimeout(closetimer);
      closetimer = null;}}

$(window).load(function() {  
  //$('#search #query').focus(function() { $('#query').val('') });
	$('#nav > li').bind('mouseover', nav_open)
  $('#nav > li').bind('mouseout',  nav_timer)

	if ($('body').attr('id').length > 0) {
		var linkname = $('body').attr('id') + '_link';
		$('#nav #' + linkname + ' a:first').css('color', '#0773b4');
	}

});

document.onclick = nav_close;
