<!DOCTYPE html>
<html>
  <head>
    <meta charset='utf-8'>
    <meta http-equiv="X-UA-Compatible" content="chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link href='https://fonts.googleapis.com/css?family=Architects+Daughter' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" type="text/css" href="<%=path_to_root%>/sexy_assets/architect/stylesheets/stylesheet.css" media="screen" />
    <link rel="stylesheet" type="text/css" href="<%=path_to_root%>/sexy_assets/architect/stylesheets/pygment_trac.css" media="screen" />
    <link rel="stylesheet" type="text/css" href="<%=path_to_root%>/sexy_assets/architect/stylesheets/print.css" media="print" />
    <script type="text/javascript" src="<%=path_to_root%>/sexy_assets/marked.js"></script>
    <!--[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">
      $(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 class="inner">
        <h1>Viewing <%=path[path.length-1].basename %></h1>
        <h2><% path.forEach(function(seg){ %>
                <a href="<%=seg.path %>"><%=seg.basename %></a>
                /
              <% }) %></h2>
        <!-- <a href="https://github.com/pansafe/express-sexy-static" class="button"><small>View project on</small>GitHub</a> -->
      </div>
    </header>

    <div id="content-wrapper">
      <div class="inner clearfix">
        <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>

        <aside id="sidebar">
          <a href="?download=zip" class="button">
            <small>Download</small>
            .zip file
          </a>
          <a href="?download=tgz" class="button">
            <small>Download</small>
            .tar.gz file
          </a>

          <p class="repo-owner">this directory shown via <a href="http://sexystatic.micy.in/">SexyStatic</a>.</p>

          <p>Theme ported from <a href="pages.github.com">GitHub Pages</a> using the Architect theme by <a href="http://twitter.com/jasonlong">Jason Long</a>.</p>
        </aside>
      </div>
    </div>

  
  </body>
</html>