<?php if ($categories) { ?>
<div class="oc-category hidden-xs col-sm-12">
<div class="list-group">
	<?php
	$child2_id = isset($parts[2]) ? $parts[2] : 0;

	foreach ($categories as $category) {
		$class = ($category['category_id'] == $category_id) ? 'active open' : '';
		$child_handler = '';

		if (isset($category['children']) && $category['children']) {
			$class .= ' has-child';
			$child_handler = '<i class="category-child-handler"></i>';
		}

		?><a href="<?php echo $category['href']; ?>" class="list-group-item lvl1 <?php echo $class; ?>"><span><?php echo $category['name']; ?></span><?php echo $child_handler; ?></a><?php

		if (isset($category['children']) && $category['children']) {
			?><div class="category-children"><?php
			foreach ($category['children'] as $child) {
				$class = ($child['category_id'] == $child_id) ? 'active open' : '';
				$child_handler2 = '';

				if (isset($child['children']) && $child['children']) {
					$class .= ' has-child';
					$child_handler2 = '<i class="category-child-handler"></i>';
				}

				?><a href="<?php echo $child['href']; ?>" class="list-group-item lvl2 <?php echo $class; ?>"><span><?php echo $child['name']; ?></span><?php echo $child_handler2; ?></a><?php

				if (isset($child['children']) && $child['children']) {
					?><div class="category-children"><?php
					foreach ($child['children'] as $child2) {
						$class = ($child2['category_id'] == $child2_id) ? 'active' : '';

						?><a href="<?php echo $child2['href']; ?>" class="list-group-item lvl3 <?php echo $class; ?>"><span><?php echo $child2['name']; ?></span></a><?php
					}
					?></div><?php
				}
			}
			?></div><?php
		}
	}
	?>
</div>
</div>

<script>
$('.oc-category').off('.categoryChildHandler').on('click.categoryChildHandler', '.category-child-handler', function(e){
	e.preventDefault();
	$(this).parent().toggleClass('open').blur();
	return false;
});
</script>
<?php } ?>
