$(document).ready(function() 
{
	$(".second-level").each(function() 
	{
		// - find submenus, save original height and hide them
		$(this).attr('oh', $(this).get(0).offsetHeight);
		$(this).css('display', 'none');
		
		// - define event handler for menu item 
		var link = $(this).parents('li').children('a');
		
		link.click(function() 
		{
			var submenu = $(this).parents('li').children('ul');

			if (submenu.css('display') == 'none') // display submenu
			{	
				submenu.css('height', '0px');
				submenu.css('display', 'block');
				submenu.animate({height:submenu.attr('oh')}, 'slow');
			} else { // hide submenu
				submenu.animate({height : 0}, 'slow', function() { $(this).css('display', 'none'); });
			}
			return false;
		});
		
		if ($(this).hasClass('open')) link.trigger('click');
	});	
});

