var productNav = {
  init:function(){
   
    var items = $("#SideCategoryList .BlockContent > ul > li > a");
   
    $("#SideCategoryList .BlockContent > ul > li > ul").each(function(){
      var ul = $(this);
      if( ul.parent().find("> a").attr("class").indexOf("current") < 0) ul.css({height:"0px", overflow:"hidden"});
    });

    items.click(function(){
     
      var a = $(this);
     
      if(a.parent().find("> ul").length == 0) return true;
     
      if(productNav.currentItem && productNav.currentItem.get(0) == a.get(0)) return true;
     
      if(productNav.currentItem){
        productNav.currentItem.parent().find("> ul").stop().animate({height:"0"}, 600);
        productNav.currentItem.removeClass("open");
      }
     
      productNav.currentItem = a;
      a.addClass("open");
     
      var ul = a.parent().find("> ul").stop();
     
      var originalHeight = ul.height();
      ul.css({height:"auto"});
      var targetHeight = ul.height();
      ul.css({height:originalHeight+"px"});
     
      ul.animate({height:targetHeight+"px"}, 600);
     
      return false;
    });
   
  }
}

$(document).ready(function(){
  productNav.init();
});