(function($) {

  $.fn.navMenu = function(element, options){

  $("#nav ul").hide();
  
  $("#nav li:has(ul)").each(function() {
      $(this).find('li').each(function(){  
        $(this).slideUp(400);
      });
  });
  
  
  $("#nav a.p1").click(function(event){
    var current = this;
    var doGray = false;
    
    //Kijken of het element subItems heeft
    if ($(this).siblings("ul").length >0){
      doGray = true;
    }
        
    //Alle fonts op none bold, en grijs als er children zijn
    $("#nav a").each(function() {
      if (this != current){
        $(this).css("font-weight","");
        if (doGray){
          if (this.className == 'p1') {
            $(this).css("color","#888");
          }
        }else{
          $(this).css("color","#000");
        }  
      }else{
        $(this).css({"font-weight": "bolder","color": "black"});
      }
    });
    
    $("#nav li:has(ul)").each(function() {
      if (this != current.parentNode){
        $(this).children(":not(a)").each(function(){  
          $(this).slideUp(400);
        });
      }
    });
    $("ul:first", $(current).parent()).slideDown(400);
  });
      
 
  $("#nav a.p2").click(function(event){
    var current = this;
    $(this).css("font-weight","bolder");
    
    $("#nav a.p2").each(function() {
      if (this != current){
        $(this).css("font-weight","");
      }
    });
    
    $("#nav a.p3").each(function() {
      if (this != current){
        $(this).css("font-weight","");
      }
    });
    
    $("#nav li.p2:has(ul)").each(function() {
      if (this != current.parentNode){
        $(this).children(":not(a)").each(function(){  
          $(this).slideUp(400);
        });
      }
    });
    $("ul:first", $(current).parent()).slideDown(400);
  });

  $("#nav a.p3").click(function(event){
    var current = this;
    $(this).css("font-weight","bolder");
    
    $("#nav a.p3").each(function() {
      if (this != current){
        $(this).css("font-weight","");
      }
    });
    
    $("#nav li.p3:has(ul)").each(function() {
      if (this != current.parentNode){
        $(this).children(":not(a)").each(function(){  
          $(this).slideUp(400);
        });
      }
    });
    $("ul:first", $(current).parent()).slideDown(400);
  });   

}
})(jQuery);


