<?php
  /*
     *      Osclass – software for creating and publishing online classified
     *                           advertising platforms
     *
     *                        Copyright (C) 2012 OSCLASS
     *
     *       This program is free software: you can redistribute it and/or
     *     modify it under the terms of the GNU Affero General Public License
     *     as published by the Free Software Foundation, either version 3 of
     *            the License, or (at your option) any later version.
     *
     *     This program is distributed in the hope that it will be useful, but
     *         WITHOUT ANY WARRANTY; without even the implied warranty of
     *        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     *             GNU Affero General Public License for more details.
     *
     *      You should have received a copy of the GNU Affero General Public
     * License along with this program.  If not, see <http://www.gnu.org/licenses/>.
     */
?>
<?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();
?>
<div class="categories <?php echo 'c' . $total_categories; ?>">
    <?php osc_goto_first_category(); ?>

    <?php while ( osc_has_categories() ) { ?>
	    <div class="col c1">
	    <div class="box_category">
        <div class="category">
		<div class="cat-header">
		<div class="cat-icon">
 <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></div> 
            <div class="cat-title"><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> </div>
		     <?php if ( osc_count_subcategories() > 0 ) { ?>
                   <ul class="subcat_i">
                         
      <?php $num = 0; while ( osc_has_subcategories() && $num < 5) { ?>
                             <li class="subcat_i">
                             <a class="category <?php echo osc_category_slug() ; ?>" href="<?php echo osc_search_category_url() ; ?>"><?php echo osc_category_name() ; ?><span class="cat_i"><?php echo osc_category_total_items() ; ?></span></a> 
                             </li>
<?php $num++;} ?>
                                       


	 <?php View::newInstance()->_erase('subcategories') ; ?>
	 	<li class="subcat_i"><a class="category cat_last" href="<?php echo osc_search_category_url(); ?>"><span><?php _e('View all subcategories', 'next_revo'); ?></span></a> </li>
                   </ul>
                 <?php } ?>			

        </div></div>
       </div>

<?php } ?>

