<!DOCTYPE html>
<html>

  <head>
    <meta charset='utf-8' />
    <meta http-equiv="X-UA-Compatible" content="chrome=1" />
    <meta name="description" content="Viewing <%=path[path.length-1].basename %>" />

    <link rel="stylesheet" type="text/css" media="screen" href="<%=path_to_root%>/sexy_assets/slate/stylesheets/stylesheet.css">

    <title>Viewing <%=path[path.length-1].basename %></title>
    <link rel="stylesheet" href="<%=path_to_root%>/sexy_assets/icomoon.css"/>

    <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>

    <!-- HEADER -->
    <div id="header_wrap" class="outer">
        <header class="inner">
          <!-- <a id="forkme_banner" href="https://github.com/pansafe/express-sexy-static">View on GitHub</a> -->

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

            <section id="downloads">
              <a class="zip_download_link" href="?download=zip">Download as a .zip file</a>
              <a class="tar_download_link" href="?download=tgz">Download as a tar.gz file</a>
            </section>
        </header>
    </div>

    <!-- MAIN CONTENT -->
    <div id="main_content_wrap" class="outer">
      <section id="main_content" class="inner">
        <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>
    </div>

    <!-- FOOTER  -->
    <div id="footer_wrap" class="outer">
      <footer class="inner">
        <p class="copyright">this directory shown via <a href="http://sexystatic.micy.in/">SexyStatic</a></p>
        <p>Theme ported from <a href="http://pages.github.com">GitHub Pages</a>'s Slate</p>
      </footer>
    </div>

    

  </body>
</html>
