jQuery.fn.jqueryNav = function(options){
  
  var animationSpeed = 500;
  
  children = "> li > a";
  if(options) {
    if(children.children) children = options.children;
  }
  
  //close all child uls
  jQuery(this).find("> li > ul").css({height:"0px"});
  
  //build nav for each item
  jQuery(this).each(function(i, e){
    
    var items = jQuery(e).find(children);
    if(items.length < 1) return;
    
    
    var currentItem;
    
    items.click(function(){
      
      var a = jQuery(this);
      var ul = a.parent().find("> ul").stop();
      var originalHeight = ul.innerHeight();
      ul.css({height:"auto"});
      
      if(currentItem){
        var oldUL = currentItem.parent().find("> ul").stop()
      }
        
      if(currentItem){
        oldUL.animate({height:"0"}, animationSpeed);
        currentItem.removeClass("open");
        //if we click the same one again close
        if(currentItem.get(0) == this) {
          currentItem = null;
          return false;
        }
      }
      
      currentItem = a;
      a.addClass("open");
      
      var targetHeight = ul.innerHeight();
      ul.css({height:originalHeight+"px"});
      
      ul.animate({height:targetHeight+"px"}, animationSpeed, function(){
        jQuery(this).css({height:"auto"});
      });
      
      return false;
      
    });
      
  });
}