<!DOCTYPE html>
<html lang="en">
<head>
  <title>TOPISTO</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

  <link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet" type="text/css">
  <link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet" type="text/css">
  <link href="https://fonts.googleapis.com/css?family=Bangers" rel="stylesheet" type="text/css">

  <link href="css/topisto.css" rel="stylesheet" type="text/css">
  <link href="css/fonts.css" rel="stylesheet" type="text/css">

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

  <script src="js/console.js" defer></script>
  <script src="js/lastblock.js" defer></script>

  <!--
    -- From https://highlightjs.org
    -->
  <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/styles/atom-one-dark.min.css">
  <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/highlight.min.js"></script>
  <script>hljs.initHighlightingOnLoad();</script>
  
  <script>

    $(document).ready(function(){
      $('#myNavbar').on('show.bs.collapse', function () {
        $('#logo_topisto').css({'height' : '30px','width' : '30px'});
        $('#titre_topisto').css({'font-size' : '30px'});
      });
      $('#myNavbar').on('hidden.bs.collapse', function () {
        $('#logo_topisto').css({'height' : '72px','width' : '72px'});
        $('#titre_topisto').css({'font-size' : '60px'});
      });

      // Add smooth scrolling to all links in navbar + footer link
      $(".navbar a, footer a[href='#myPage']").on('click', function(event) {
        // Make sure this.hash has a value before overriding default behavior
        if (this.hash !== "") {
          // Prevent default anchor click behavior
          event.preventDefault();

          // Store hash
          var hash = this.hash;

          // Using jQuery's animate() method to add smooth page scroll
          // The optional number (900) specifies the number of milliseconds it takes to scroll to the specified area
          $('html, body').animate({
            scrollTop: $(hash).offset().top
          }, 900, function(){
            // Add hash (#) to URL when done scrolling (default click behavior)
            window.location.hash = hash;
          });
        } // End if
      });
  
      $(window).scroll(function() {
        $(".slideanim").each(function(){
          var pos = $(this).offset().top;
          var winTop = $(window).scrollTop();
          if (pos < winTop + 600) {
            blockchainExplorer.ajouterPreviousBlock();
            $(this).addClass("slide");
          }
        });
      });
    });

  </script>

</head>
<body id="myPage" data-spy="scroll" data-target=".navbar" data-offset="60">

<nav class="navbar navbar-default navbar-fixed-top">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>                        
      </button>
      <a class="navbar-brand" href="index.php">
        <img id="logo_topisto" src="images/topisto_vert.png" style="border-radius:6px;display:inline-block;height:72px;;box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19)">
        <span id="titre_topisto" style="vertical-align:text-bottom;display:inline-block;color:black;font-family: Bangers, sans-serif;font-size: 60px;text-shadow: 2px 2px #ffffff">TOPISTO</span>
      </a>
    </div>
    <div class="collapse navbar-collapse" id="myNavbar">
      <ul class="nav navbar-nav navbar-right">
        <li><a href="about.php">About</a></li>
        <li><a href="index.php">Explorer</a></li>
        <li><a href="#blog">Blog</a></li>
      </ul>
    </div>
  </div>
</nav>

<div id="blog" class="container-fluid bg-white" style="padding-top:50px;align:right">
  <div class="row">
    <div class="col-sm-12 text-right">&nbsp;</div>
  </div>
</div>

<?php
$odd_even = 0;
$liste    = '';
foreach (glob("articles/20*/header.html") as $filename) {
  $article = basename(dirname($filename));
  $odd_even = 1 - $odd_even;
  $header = file_get_contents($filename);
  if ($odd_even == 0) $header = str_replace('bg-grey','bg-grey-odd',$header);
  else $header = str_replace('bg-grey','bg-grey-even',$header);

  $header = str_replace('ARTICLE',$article,$header);

  if (!file_exists('articles/'.$article.'/content.html'))
  {
    $header = str_replace('####BUTTON####','',$header);
  } else {
    echo '<script>';
    echo '$(document).ready(function(){';
    echo '  $("#'.$article.'_button").on("click", function(event) {';
    echo '    window.location="page.php?id='.$article.'"';
    echo '  })';
    echo '})';
    echo '</script>';
    $header = str_replace('####BUTTON####','<button id="'.$article.'_button" class="btn btn-default btn-lg float-left">See more</button>',$header);
  }

  $liste = $header.PHP_EOL.$liste;
}
echo $liste;
?>

<footer class="container-fluid bg-grey text-center">
  <a href="#myPage" title="To Top">
    <span class="glyphicon glyphicon-chevron-up"></span>
  </a>
</footer>
</body>
</html>
