<?php
/*
 * Copyright 2015 osclass-pro.com
 *
 * You shall not distribute this theme and any its files (except third-party libraries) to third parties.
 * Rental, leasing, sale and any other form of distribution are not allowed and are strictly forbidden.
 */
?>
<?php
    function drawSubcategory($category) {
        if ( osc_count_subcategories2() > 0 ) {
            osc_category_move_to_children();
            ?>
            <ul>
                <?php while ( osc_has_categories() ) { ?>
                    <li><a class="category cat_<?php echo osc_category_id(); ?>" href="<?php echo osc_search_category_url(); ?>"><?php echo osc_category_name(); ?></a> <span>(<?php echo osc_category_total_items(); ?>)</span><?php drawSubcategory(osc_category()); ?></li>
                <?php } ?>
            </ul>
        <?php
            osc_category_move_to_parent();
        }
    }
    $total_categories   = osc_count_categories();
    $col1_max_cat       = ceil($total_categories/4);
    $col2_max_cat       = ceil(($total_categories-$col1_max_cat)/3);
    $col3_max_cat       = ceil(($total_categories-($col1_max_cat+$col2_max_cat))/2);
	$col4_max_cat      = $total_categories-($col1_max_cat+$col2_max_cat+$col3_max_cat);
?>
<div class="categories <?php echo 'c' . $total_categories; ?>">
    <?php osc_goto_first_category(); ?>
    <?php
        $i      = 1;
        $x      = 1;
        $col    = 1;
        if(osc_count_categories () > 0) {
            echo '<div class="col c1">';
        }
    ?>
    <?php while ( osc_has_categories() ) { ?>
        <div class="category">
		     <a class="category cat_<?php echo osc_category_id(); ?>" href="<?php echo osc_search_category_url(); ?>"><div class="focus pic"><img src="<?php echo osc_current_web_theme_url('images/') . osc_category_id() .'.png' ?>" /></div></a> 
            <h1><strong><a class="category cat_<?php echo osc_category_id(); ?>" href="<?php echo osc_search_category_url(); ?>"><?php echo osc_category_name(); ?> </a></strong></h1>
            
        </div>
        <?php
            if (($col==1 && $i==$col1_max_cat) || ($col==2 && $i==$col2_max_cat) || ($col==3 && $i==$col3_max_cat) || ($col==4 && $i==$col4_max_cat)) {
                $i = 1;
                $col++;
                echo '</div>';
                if($x < $total_categories) {
                    echo '<div class="col c'.$col.'">';
                }
            } else {
                $i++;
            }
            $x++;
        ?>
    <?php } ?>
</div>

