/* Category Browse dropdown function for any dropdown */
$(document).ready(function(){
  /* side navigation (left browse) */
  /* collapse non-selected categories */
  $('.CatLvl01_Title').each(function(){
    /* if the height determines 2 line wrap was made, reduce top &amp; bottom padding */
    if ($(this).height() == 32){
      $(this).addClass('DblLine');
    }

    if (!$(this).hasClass('selectedCat')) {
      $(this).find('.CatLvl01_arrow').toggleClass('pointRight');
    }
    else {
      $(this).next('.CatLvl02').slideToggle('1');
      $(this).find('.CatLvl01_arrow').toggleClass('pointDown');
    }
  });

  /* toggle expansion on click; only one expanded at a time */
  $('.CatLvl01_Title').click(function(){
    if (!$(this).hasClass('selectedCat')) {
      /* reset the previously selected category */
      $('.selectedCat').find('.CatLvl01_arrow').toggleClass('pointDown pointRight');
      $('.selectedCat').next('.CatLvl02').slideToggle('slow');
      $('.selectedCat').toggleClass('selectedCat');
    }

    /* update the currently selected category */
    $(this).toggleClass('selectedCat');

    /* toggle arrow direction of clicked title and expand sub list */
    $(this).find('.CatLvl01_arrow').toggleClass('pointDown pointRight');
    $(this).next('.CatLvl02').slideToggle('slow');
  });
});
