$(document).ready(function() {
$("#leftmenu #menu ul").hide();
$("#leftmenu #menu li:has(ul)").each(function() {
$(this).children().slideUp(400);
});
$("li.p1:has(ul)").click(function(event){
if (this == event.target) {
var current = this;
$("#leftmenu #menu li:has(ul)").each(function() {
if (this != current) $(this).children().slideUp(400);
});
$("ul:first", $(this)).slideToggle(400);
}
});

$("li.p2:has(ul)").click(function(event){
if (this == event.target) {
var current = this;
$("li.p2:has(ul)").each(function() {
if (this != current) $(this).children().slideUp(400);
});
$("li.p3:has(ul)").each(function() {
if (this != current) $(this).children().slideUp(400);
});
$("ul:first", $(this)).slideToggle(400);
}
});

$("li.p3:has(ul)").click(function(event){
if (this == event.target) {
var current = this;
$("li.p3:has(ul)").each(function() {
if (this != current) $(this).children().slideUp(400);
});
$("ul:first", $(this)).slideToggle(400);
}
});
$('#leftmenu #menu li.active').children('ul').css("display","block");
$('#leftmenu #menu li.active').parent('ul').css("display","block"); 
$('#leftmenu #menu li.active2').parent('ul').css("display","block");
$('#leftmenu #menu li.active3').parent('ul').parent('li').parent('ul').css("display","block");
$('#leftmenu #menu li.active3').parent('ul').css("display","block");
});

