$(function() {

  $('ul#nav ul').hide();
  $('ul#nav li:has(ul)').each(function(i) {
    $(this).children('ul').slideUp(400);
  });
  $('a.current').parent().parents('ul').show();
  $('a.current').parent().children('ul:eq(0)').show();

  $('li.p1:has(ul)').click(function(event) {
	if(event.target.tagName != 'LI')
		var target = $(event.target).parent().get(0);
	else target = event.target;
    if (this == target) {
      current = this;
      $('ul#nav li:has(ul)').each(function(i) {
        if (this != current) { $(this).children('ul').slideUp(400); }
      });
      $(this).children('ul:eq(0)').slideToggle(400);
    }
  });
 $('li.p2:has(ul)').click(function(event) {
	if(event.target.tagName != 'LI')
		var target = $(event.target).parent().get(0);
	else target = event.target;
    if (this == target) {
      current = this;
      $('li.p2:has(ul)').each(function(i) {
        if (this != current) { $(this).children('ul').slideUp(400); }
      });
      $('li.p3:has(ul)').each(function(i) {
        if (this != current) { $(this).children('ul').slideUp(400); }
      });
      $(this).children('ul:eq(0)').slideToggle(400);
    }
  });

  $('li.p3:has(ul)').click(function(event) {
	if(event.target.tagName != 'LI')
		var target = $(event.target).parent().get(0);
	else target = event.target;
    if (this == target) {
      current = this;
      $('li.p3:has(ul)').each(function(i) {
        if (this != current) { $(this).children('ul').slideUp(400); }
      });
      $(this).children('ul:eq(0)').slideToggle(400);
    }
  });


 });