<div id="expandedSidebar" style="overflow:hidden; padding:0; margin:0">
 <div id="menu" style="overflow:hidden; padding:0; margin:0">
  <?php if (!empty($conf['logo']['image']) || !Util::getFormData('mozbar')): ?>
  <span style="float:left"><?php if (!$is_mozbar) echo Horde::link('#', _("Collapse Sidebar"), '', '', 'toggleMenuFrame(); return false;', _("Collapse Sidebar")) . Horde::img('hide_panel.png') . '</a>' ?></span>
  <span style="float:left"<?php if (empty($conf['logo']['image'])) echo ' id="themelogo"' ?>>
  <?php
  if (!empty($conf['logo']['image'])) {
      if (!empty($conf['logo']['link'])) {
          echo Horde::link($conf['logo']['link'], null, null, '_top');
      }
      echo Horde::img($conf['logo']['image'], '', '', '');
      if (!empty($conf['logo']['link'])) {
          echo '</a>';
      }
  } else {
      echo '&nbsp;';
  }
  ?>
  </span>
  <span style="float:left;" id="logopad">&nbsp;</span>
  <div class="clear">&nbsp;</div>
  <?php endif; ?>
 </div>
 <div id="sidebarPanel">
  <?php $tree->renderTree() ?>
 </div>
</div>

<div id="hiddenSidebar">
 <div id="menu">
  <?php echo Horde::link('#', _("Expand Sidebar"), '', '', 'toggleMenuFrame(); return false;', _("Expand Sidebar")) . Horde::img('show_panel.png') . '</a>' ?>
 </div>
</div>

<script language="Javascript" type="text/javascript">

var rtl = <?php echo $rtl ? 'true' : 'false' ?>;
var expandedSidebar = new Horde_Hideable('expandedSidebar');
var hiddenSidebar = new Horde_Hideable('hiddenSidebar');
hiddenSidebar.hide();

function toggleMenuFrame()
{
    if (parent && parent.document.getElementById('hf')) {
        if (expandedSidebar.shown()) {
            parent.document.getElementById('hf').cols = rtl ? '*,20' : '20,*';
            expandedSidebar.hide();
            hiddenSidebar.show();
        } else {
            parent.document.getElementById('hf').cols = (rtl ? '*,' : '') + <?php echo (isset($prefs) ? $prefs->getValue('sidebar_width') : 150) ?> + (rtl ? '' : ',*');
            hiddenSidebar.hide();
            expandedSidebar.show();
        }
    }
}
</script>

<script language="Javascript1.5" type="text/javascript">
var MenuUpdateHandler = {
    onLoad: function(result)
    {
        // Run the javascript we got back.
        eval(result);
    }
};

function update()
{
    var client = new HTTPClient();
    client.init("<?php echo Horde::applicationUrl('services/portal/sidebar.php?httpclient=1', true) ?>");

    try {
        client.asyncGET(MenuUpdateHandler);
    } catch (e) {
        // Don't do anything on errors; probably a transient failure,
        // and we'll try again after the next interval.
    }
}

<?php if ($prefs->getValue('menu_refresh_time')): ?>
// Update the menu if set in user prefs.
<?php if ($GLOBALS['browser']->hasFeature('xmlhttpreq')): ?>
window.setInterval('update();', <?php echo $prefs->getValue('menu_refresh_time') ?> * 1000);
<?php else: ?>
window.setTimeout('window.location.reload(true);', <?php echo $prefs->getValue('menu_refresh_time') ?> * 1000);
<?php endif; endif; ?>

</script>

<?php if (isset($GLOBALS['notification'])) $GLOBALS['notification']->notify(array('listeners' => array('javascript'))) ?>

</body>
</html>
