$(document).ready(function(){
	// hide while we reconstruct - should prevent flickering
	$('#subnav').hide();
	// turn <a> tags into h3s from top level pages that have children
	$('#subnav>li:has(ul)>a').each(function() {
		$(this).replaceWith('<h3>' + $(this).html() + '</h3>');
	})
	// next level - <a> tags into h4s that will be folded up
	$('#subnav>li>ul>li:has(ul)>a').each(function() {
		$(this).replaceWith('<h4 class="fold">' + $(this).html() + '</h4>');
	}) 
	// subsequent levels into h4s that will not be folded
	$('#subnav>li>ul>li>ul li:has(ul)>a').each(function() {
		$(this).replaceWith('<h4>' + $(this).html() + '</h4>');
	})	
	// give arrow bullets to lists more than 2 levels deep
	$('#subnav>li>ul>li:has(ul)').addClass('expand-up');
	// hide lists more than 2 levels deep
	$('#subnav>li>ul>li>ul').hide();
	// reveal the current page section
	$('#subnav li.current_page_parent').parents().show();
	$('#subnav>li>ul>li.current_page_parent>ul').show().parent().toggleClass('expand-down');
	// apply fold-in and fold-out functionality at the right depth
	$('#subnav>li>ul>li>.fold').click(function() {
		$(this).parent().toggleClass('expand-down');
		$(this).parent().find('ul:first').slideToggle('fast');
	})
	// show
	$('#subnav').show();
});
function popup(mylink)
{
	if (! window.focus)return true;
	var href;
	if (typeof(mylink) == 'string')
	   href=mylink;
	else
	   href=mylink.href;
	window.open(href, '_blank', 'width=500,height=300,scrollbars=yes');
	return false;
}
