<!DOCTYPE html>
<html>
  <head>
    <meta charset='utf-8'>
    <meta http-equiv="X-UA-Compatible" content="chrome=1">
    <link href='https://fonts.googleapis.com/css?family=Chivo:900' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" type="text/css" href="<%=path_to_root%>/sexy_assets/tactile/stylesheets/stylesheet.css" media="screen" />
    <link rel="stylesheet" type="text/css" href="<%=path_to_root%>/sexy_assets/tactile/stylesheets/pygment_trac.css" media="screen" />
    <link rel="stylesheet" type="text/css" href="<%=path_to_root%>/sexy_assets/tactile/stylesheets/print.css" media="print" />
    <!--[if lt IE 9]>
    <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <title>Viewing <%=path[path.length-1].basename %></title>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script type="text/javascript" src="<%=path_to_root%>/sexy_assets/marked.js"></script>
    <script type="text/javascript">
      $(document).ready(function () {
        $('[data-action]').click(function(e){
          var $btn=$(this).parent();
          if($btn.next().hasClass('block')){
            $btn.next().remove();
            return false;
          }
          $('.block').remove();
          
          switch(this.dataset.action){
            case 'source':
              $.ajax({
                url:this.href,
                dataType:'text',
                success:function(data){
                  $('<pre class="block"><a href="#" class="close" onclick="$(this).parent().remove();return false;">x</a><code></code></pre>')
                  .insertAfter($btn).find('code').text(data);
                }
              });
              return false;
            case 'markdown':
              $.ajax({
                url:this.href,
                dataType:'text',
                success:function(data){
                  $('<blockquote class="block"><a href="#" class="close" onclick="$(this).parent().remove();return false;">x</a>'+marked(data)+'</blockquote>')
                  .insertAfter($btn);
                }
              });
              return false;
            case 'iframe':
              var block=$('<blockquote class="block"><a href="#" class="close" onclick="$(this).parent().remove();return false;">x</a><iframe style="width:100%;height:100%;" src="'+this.href+'"></iframe></blockquote>')
              .insertAfter($btn);
              setTimeout(function(){
                block.height($(block).width());
              },100);
              return false;
            case 'image':
              var block=$('<blockquote class="block"><a href="#" class="close" onclick="$(this).parent().remove();return false;">x</a><img style="max-width:90%" src="'+this.href+'"/></blockquote>')
              .insertAfter($btn);
              return false;
          }
        });
      });
    </script>
    <style type="text/css">
      .block{
        position: relative;
      }
      .block>.close{
        position: absolute;
        right: 10px;
        top: 10px;
      }
    </style>
  </head>

  <body>
    <div id="container">
      <div class="inner">

        <header>
          <h1>Viewing <%=path[path.length-1].basename %></h1>
          <h2><% path.forEach(function(seg){ %>
                <a href="<%=seg.path %>"><%=seg.basename %></a>
                /
              <% }) %></h2>
        </header>

        <section id="downloads" class="clearfix">
          <a href="?download=zip" id="download-zip" class="button"><span>Download .zip</span></a>
          <a href="?download=tgz" id="download-tar-gz" class="button"><span>Download .tar.gz</span></a>
          <!-- <a href="https://github.com/pansafe/express-sexy-static" id="view-on-github" class="button"><span>View on GitHub</span></a> -->
        </section>

        <hr>

        <section id="main_content">
          <h1>Viewing <%=path[path.length-1].basename %></h1>
          <script>
            $.ajax({
              url: 'README.md',
              dataType: 'text',
              async: false,
              success: function(data){
                document.write('<h2>README.md</h2>');
                document.write(marked(data));
              }
            });
          </script>

        <ul>
          <li>
            <a href="<%=path_to_root%>/">[root]</a>
          </li>
          <li>
            <a href="..">..</a>
          </li>
          <% items.forEach(function(item){ %>
            <li>
              <a href="<%=encodeURIComponent(item.basename) + (item.type=='directory'?'/':'') %>"><%-item.icon%><%=item.basename%></a>
              <% if(item.type=='text'||item.type=='html') {%>
                <a href="<%=encodeURIComponent(item.basename)%>" data-action="source"><em>source</em></a>
              <% } %>
              <% if(item.type=='html') {%>
                <a href="<%=encodeURIComponent(item.basename)%>" data-action="iframe"><em>preview</em></a>
              <% } %>
              <% if(item.type=='image') {%>
                <a href="<%=encodeURIComponent(item.basename)%>" data-action="image"><em>preview</em></a>
              <% } %>
              <% if(item.type=='markdown') {%>
                <a href="<%=encodeURIComponent(item.basename)%>" data-action="markdown"><em>preview</em></a>
              <% } %>
            </li>
          <% }) %>
        </ul>
        </section>

        <footer>
          this directory shown via <a href="http://sexystatic.micy.in/">SexyStatic</a><br>
          Theme ported from <a href="http://pages.github.com">GitHub Pages</a>. Tactile theme by <a href="http://twitter.com/jasonlong">Jason Long</a>.
        </footer>

        
      </div>
    </div>
  </body>
</html>