<?php /* 

Add in your template
$store_cats = Mage::getModel('catalog/category')->getCategories(32); <- change category id to "2" if you want to list all categories. Otherwise you can use it to list child of certain category, in this example category with the id of 32.
*/
?>

<ul class="category-list">                                               
<?php
        $obj = new Mage_Catalog_Block_Navigation();
        $store_cats = Mage::getModel('catalog/category')->getCategories(32);
        $current_cat    = $obj->getCurrentCategory();
        $parent_id      = $current_cat->getParentId();
        $current_cat    = (is_object($current_cat) ? $current_cat->getName() : '');
        foreach ($store_cats as $cat) {
                $cat_id      = $cat->getId();

?>
        <li>
                <a <?php if ($cat->getName() == $current_cat) { ?>class="current"<?php } ?> href="<?php echo $obj->getCategoryUrl($cat) ?>"><?php echo $cat->getName() ?></a>

        <?php //Subcategories

                $count_children = $cat->getChildrenCount();
                if($count_children > 0) { //check if category has children ?>
                        <span class="open <?php if ($cat->getName() == $current_cat) { ?> minus <?php } ?>">Otvori</span>
                        <ul <?php if ($cat->getName() == $current_cat or $parent_id == $cat_id) { ?> class="open" <?php } ?>>

                        <?php //get children
                                
                                $children = Mage::getModel('catalog/category')->getCategories($cat_id);

                                foreach ($children as $subcat) {
                                        $subcat = Mage::getModel('catalog/category')->load($subcat->getId());
                                        $product_count = $subcat->getProductCount();

                                        if($product_count > 0){ //List only categories that have products in them ?>
                                        
                                                <li> 
                                                        <a <?php if ($subcat->getName() == $current_cat) { ?>class="current"<?php } ?> href="<?php echo $obj->getCategoryUrl($subcat) ?>">
                                                                <?php echo $subcat->getName() ?> (<?php echo $product_count ?>)
                                                        </a>
                                                </li> 
                                        <?php } ?>      
                                <?php } ?>
                        </ul>
        <?php } ?>

        </li>
<?php  } ?>
</ul>