#line 4452 "/home/travis/build/felix-lang/felix/src/packages/flx_web.fdoc"
  include "./toc_menu-interface";
  
  fun setup (config_data:string) = {
    eprintln$ "Setup toc_menu v1.1 " + config_data;
    return 0;
  }
  
  var menu_js = """
  <script type="text/javascript">
  
    function mexpand(id)
    {
      var n = document.getElementById(id).style;
      n.display = "block";
    }
  
    function mcollapse(id)
    {
      var n = document.getElementById(id).style;
      n.display = "none";
    }
  
    var counter_max = 0;
    function mshow(id,loc)
    {
      var i;
      for(i=1; i<=counter_max; ++i)
        mcollapse("menu"+String(i));
      mexpand(id);
      window.location.replace(loc);
    }
  </script>
  """;
  
  var menu_style = """
  <style>
  div.m {
      margin: 0px;
      padding:0px;
      border-width:2px;
      border-color: green;
  }
  
  div.m1 {
      background-color: #86E870;
      border-style:outset;
      border-color:#ccc;
      border-width:2px 0;
      font-size:90%;
      padding: 1px 0 2px 10px;
  }
  
  div.m2 {
      background-color: #70C070;
      padding-left:15px;
      padding-top:2px;
      border-style:outset;
      border-color:green;
      border-width:0 0 1px 0;
      font-size:80%;
  }
  
  div.m1:hover, div.m2:hover {
      background-color: white;
  }
  
  #leftmargintoc a {
      text-decoration: none;
      color: #404040;
  }
  
  
  </style>
  """;
  
  fun escape_sp(h: string) => map (fun (c: char) => if c == ' ' then '_'.char else c) h;
  
  
  object toc_menu (h:list[int * string * string]) implements toc_menu_interface =
  {
    method fun whatami () => "toc_menu maker";
    method fun get_style () => menu_style;
    method fun get_js() => menu_js;
    method fun make_menu() =
    {
      // LEFT MARGIN
      var leftcontent ='  <!--Left Margin Toc-->\n';
        leftcontent +='  <div id="leftmargintoc">\n';
  
        // Contents body
          leftcontent+='    <!--Left Margin Toc Main Contents-->\n';
  
          proc head1(level:int, text:string, link:string) {
            leftcontent+= """      <div class=m1 onclick="mshow('menu"""+ counter.str+"""','"""+link+"""')"> """;
            leftcontent+= '''<a href="'''+escape_sp(link)+'''">''';
            leftcontent+= text + "</a></div>\n";
            leftcontent+= """      <div class=sm id=menu"""+counter.str+""">\n""";
          }
          proc foot1() { leftcontent+="      </div>\n"; }
          proc break1(level:int, text:string,link:string) {foot1(); ++counter; head1(level,text,link); }
  
          var counter = 0;
          iter proc (level:int,text:string, link:string)
            {
              //println$ i,s;
              if level == 1 do // first level meny entry
                if counter == 0 do ++counter; head1 (level, text, link);
                else break1 (level,text,link);
                done
              elif level == 2 do // second level menu entry
                leftcontent+="      <div class=m2>";
                leftcontent+='''<a href="'''+escape_sp(link)+'''">'''+text+'''</a></div>\n''';
              done
            }
            h
          ;
          if counter >= 1 do  foot1; done;
          leftcontent+="    <script>counter_max="+counter.str+";</script>\n";
  
        leftcontent+='  </div>\n'; // leftmargintoc end
        leftcontent+='  <!--End Left Margin Toc-->\n';
      return leftcontent;
    }
  
  }
  
  export fun setup of (string) as "toc_menu_setup";
  export fun toc_menu of (list[int * string * string]) as "toc_menu";