<?php $this->loadCss('/media/css/slide_menu.css'); ?>
<?php $this->loadJavascript('/media/js/slide_menu.js'); ?>

<?php
if ((!isset($id))) {
    $id = "";
}
?>

<?php
function openRecursively(&$array, $id) {
    if (array_key_exists($id, $array)) {
        $no = $array[$id];
       echo "justOpen('sub_menu_filho_" . $id . "');\n";
        if ($no['pai_id'] != '0') {
            openRecursively($array, $no['pai_id']);
        } else {
            return 0;
        }
    } else {
        return 0;
    }
}
?>

<?php if ($result) : ?>
<script>
var myDivs = new Array(<?php echo count($result); ?>);

<?php $i = 0; ?>
<?php foreach ($result as $key => $value) : ?>
myDivs[<?php echo $i; ?>] = "sub_menu_filho_<?php echo $key; ?>";
<?php $i++; ?>
<?php endforeach; ?>
</script>
<?php endif; ?>

<div id="catalogo_slide_menu">
    <?php if ($result) : ?>
    <?php
    $result_nivel1 = $result;
    $result_nivel2 = $result;
    $result_nivel3 = $result;
    $result_nivel4 = $result;
    ?>
    <?php foreach ($result_nivel1 as $item_nivel_1) : // nivel 1 1 1 1 1 1 1 1 1 1 1 ?>
        <?php if ($item_nivel_1['pai_id'] == $pai_id) : ?>
            <!-- inicio do div nivel 1 -->
            <div id="slide_menu_id_<?php echo $item_nivel_1['id']; ?>" class="slide_menu_nivel_1">
            <?php
            $class = "";
            if ($item_nivel_1['id'] <> $id) {
                $class = "title_nivel_1";
            } else {
                $class = "title_selected_nivel_1";
            }
            ?>
            <div class="<?php echo $class; ?>" onclick="openSubMenu('sub_menu_filho_<?php echo $item_nivel_1['id']; ?>', '', '<?php echo $item_nivel_1['id']; ?>', '/cms/view/id/');" onmouseover="this.className='title_hover_nivel_1';" onmouseout="this.className='<?php echo $class; ?>';"><span style="color:#ff6600;">&raquo;</span>&nbsp;<?php echo htmlentities($item_nivel_1['titulo']); ?>&nbsp;</div>
            <div id="sub_menu_filho_<?php echo $item_nivel_1['id']; ?>" class="slide_menu_nivel_2">
            <?php foreach ($result_nivel2 as $item_nivel_2) : // nivel 2 2 2 2 2 2 2 2 2 ?>
                <?php if ($item_nivel_2['pai_id'] == $item_nivel_1['id']) : ?>
                    <!-- inicio do div nivel 2 -->
                    <div id="slide_menu_id_<?php echo $item_nivel_2['id']; ?>">
                    <?php
                    $class = "";
                    if ($item_nivel_2['id'] <> $id) {
                        $class = "title_nivel_2";
                    } else {
                        $class = "title_selected_nivel_2";
                    }
                    ?>
                    <div class="<?php echo $class; ?>" onclick="openSubMenu('sub_menu_filho_<?php echo $item_nivel_2['id']; ?>', 'sub_menu_filho_<?php echo $item_nivel_1['id']; ?>', '<?php echo $item_nivel_2['id']; ?>', '/cms/view/id/');" onmouseover="this.className='title_hover_nivel_2';" onmouseout="this.className='<?php echo $class; ?>';">&bull;&nbsp;<?php echo htmlentities($item_nivel_2['titulo']); ?></div>
                    <div id="sub_menu_filho_<?php echo $item_nivel_2['id']; ?>" class="slide_menu_nivel_3">
                    <?php foreach ($result_nivel3 as $item_nivel_3) : // nivel 3 3 3 3 3 3 3 3 3 ?>
                        <?php if ($item_nivel_3['pai_id'] == $item_nivel_2['id']) : ?>
                            <!-- inicio do div nivel 3 -->
                            <div id="slide_menu_id_<?php echo $item_nivel_3['id']; ?>">
                            <?php
                            $class = "";
                            if ($item_nivel_3['id'] <> $id) {
                                $class = "title_nivel_3";
                            } else {
                                $class = "title_selected_nivel_3";
                            }
                            ?>
                            <div class="<?php echo $class; ?>" onclick="openSubMenu('sub_menu_filho_<?php echo $item_nivel_3['id']; ?>', 'sub_menu_filho_<?php echo $item_nivel_2['id']; ?>', '<?php echo $item_nivel_3['id']; ?>', '/cms/view/id/');" onmouseover="this.className='title_hover_nivel_3';" onmouseout="this.className='<?php echo $class; ?>';">&bull;&nbsp;<?php echo htmlentities($item_nivel_3['titulo']); ?></div>
                            <div id="sub_menu_filho_<?php echo $item_nivel_3['id']; ?>" class="slide_menu_nivel_4">
                            <?php foreach ($result_nivel4 as $item_nivel_4) : // nivel 4 4 4 4 4 4 4 4 4 ?>
                                <?php if ($item_nivel_4['pai_id'] == $item_nivel_3['id']) : ?>
                                    <!-- inicio do div nivel 4 -->
                                    <div id="slide_menu_id_<?php echo $item_nivel_4['id']; ?>">
                                    <?php
                                    $class = "";
                                    if ($item_nivel_4['id'] <> $id) {
                                        $class = "title_nivel_4";
                                    } else {
                                        $class = "title_selected_nivel_4";
                                    }
                                    ?>
                                    <div class="<?php echo $class; ?>" onclick="openSubMenu('sub_menu_filho_<?php echo $item_nivel_4['id']; ?>', '', '<?php echo $item_nivel_4['id']; ?>', '/cms/view/id/');" onmouseover="this.className='title_hover_nivel_4';" onmouseout="this.className='<?php echo $class; ?>';">&bull;&nbsp;<?php echo htmlentities($item_nivel_4['titulo']); ?></div>
                                    </div>
                                    <!-- fim do div nivel 4 -->
                                <?php endif; ?>
                            <?php endforeach; // nivel 4 4 4 4 4 4 4 4 4 ?>
                            </div>
                            </div>
                            <!-- fim do div nivel 3 -->
                        <?php endif; ?>
                    <?php endforeach; // nivel 3 3 3 3 3 3 3 3 3 ?>
                    </div>
                    </div>
                    <!-- fim do div nivel 2 -->
                <?php endif; ?>
            <?php endforeach; ?>
            </div>
            </div>
            <!-- fim do div nivel 1 -->
        <?php endif; ?>
    <?php endforeach; // nivel 1 1 1 1 1 1 1 1 1 1 1 1 ?>
    <?php endif; ?>
</div>



<?php
if ((isset($id)) && ($id)) {
   echo "<script>";
    openRecursively($result, $id);
   echo "</script>";
}
?>

