// Filtering something
function filtering() {
  $('#product-hub .options h3').each(function() {
    var $heading = $(this),
        $options = $heading.siblings('ul'),
        containerWidth = $heading.parent().outerWidth(),
        emWidth = $heading.children('em').width(),
        optionsWidth = $options.outerWidth();

    $options.hide().css('left','0');

    if(containerWidth >= optionsWidth) {
      $options.width(containerWidth);
    }
  });
  $('#product-hub .options h3').click(function() {
    if($(this).parent().prevAll().length !== 0) {
      $(this).parent().toggleClass('selected');
    }
    $(this).siblings('ul').slideToggle();
  });

  $('.filter-items .filter input:checked').closest('li').addClass('selected').children('ul').show();
  $('.filter-items .filter .forms ul input:checked').closest('ul').show().parent().addClass('selected');
  $('.filter-items .filter label').click(function() {
    var $filterLabel = $(this),
        $labelParent = $filterLabel.parent(),
        $labelFormParent = $filterLabel.parents('.forms');
    if(!$labelParent.hasClass('selected')) {
      $labelParent.siblings('.selected').removeClass('selected');
      $labelFormParent.find('input:checked').removeAttr('checked');
      $labelParent.addClass('selected');
      $filterLabel.children('input').attr('checked','checked');

      if($labelParent.parent().hasClass('forms')) {
        if($labelFormParent.find('ul').length) {
          $labelFormParent.find('ul:visible .selected').removeClass('selected');
          $labelFormParent.find('ul:visible').slideUp(250);
          $filterLabel.siblings('ul').slideDown(250);
        }
      }
    }
  });
}
