<?php $_helper = Mage::helper('catalog/category');?>      
<?php $_categories = $_helper->getStoreCategories();?>

<!-- BEGIN SIDE-NAV-CATEGORY -->  
<div class="side-nav-categories">
<div class="block-title">
<?php echo $this->__('Categories');?>
</div><!--block-title-->
<?php if (count($_categories) > 0):  ?>
<!-- BEGIN BOX-CATEGORY -->  
<div class="box-content box-category">
<ul>

<?php 
$i=0;
foreach($_categories as $_category): ?>
<li >
  <?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?>
        <?php $_subcategories = $_category->getChildrenCategories() ?>

        <?php if($this->getCurrentCategory()->getId()==$_category->getId()) { ?>
                <a class="active" href="<?php echo $_helper->getCategoryUrl($_category) ?>"><?php echo $_category->getName() ?></a>
                <?php if (count($_subcategories) > 0): ?><span class="subDropdown minus"></span> <?php endif; ?>
        <?php } else { ?>
                <a href="<?php echo $_helper->getCategoryUrl($_category) ?>"><?php echo $_category->getName() ?></a>
                <?php if (count($_subcategories) > 0): ?><span class="subDropdown plus"></span> <?php endif; ?>
        <?php } ?> <!-- root -->

        <?php if (count($_subcategories) > 0): ?>

           <ul class="level0_<?php echo $_category->getId();?>" 
              <?php if($this->getCurrentCategory()->getId()==$_category->getId()){?>
              style="display:block"
              <?php } else {?>
              style="display:none"
              <?php } ?>>
            <?php foreach($_subcategories as $_subcategory): 
$_secondLevelCat = Mage::getModel('catalog/category')->load($_subcategory->getId());
                                if (!$_secondLevelCat->getData("include_in_menu")) continue;
?>
              <li class="level1">

                <?php $_category1 = Mage::getModel('catalog/category')->load($_subcategory->getId())?>
                <?php $_subcategories_l1 = $_category1->getChildrenCategories() ?>

                <a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>" >                              
                    <?php echo $_subcategory->getName() ?>                                            
                </a>

                <?php if (count($_subcategories_l1) > 0): ?>
                    <?php if($this->getCurrentCategory()->getId()==$_category->getId()){?>
                       <span class="subDropdown plus"></span>
                    <?php } else { ?>
                       <span class="subDropdown minus"></span>
                    <?php } ?>
                <?php endif; ?>

                <?php if (count($_subcategories_l1) > 0) { ?>
                   <ul class="level1">
                      <?php foreach($_subcategories_l1 as $_subcategories_l1_l1){ 
$_thirdLevelCat = Mage::getModel('catalog/category')->load($_subcategories_l1_l1->getId());
                                          if (!$_thirdLevelCat->getData("include_in_menu")) continue;
?>
                         <li class="level2">
                            <a href="<?php echo $_helper->getCategoryUrl($_subcategories_l1_l1) ?>" >                                      
                               <?php echo $_subcategories_l1_l1->getName() ?> 
                            </a>  
                         </li> <!--level2-->
                      <?php } ?><!--end for-each -->   
                   </ul> <!--level1-->
                <?php } ?> 

              </li><!--level1-->
            <?php endforeach; ?>
         </ul><!--level0-->

      <?php endif; ?>  <!--(count($_subcategories) > 0)-->
</li><!--level 0-->
<?php 
endforeach; ?>
</ul>
</div><!--box-content box-category-->
<?php endif; ?>
</div><!--side-nav-categories-->