<?php
   @include_once("functions.php");
   $config = getConfig();
?>
<!DOCTYPE html>
<html xmlns:fb="http://ogp.me/ns/fb#">
<head>
   <meta http-equiv="Content-type" content="text/html; charset=utf-8">
   <title><?php echo $config['galleryName'];?> | photo</title>
   <link rel="stylesheet" href="basic.css" type="text/css" />
   <link rel="stylesheet" href="showimage.css" type="text/css" />
   <script type="text/javascript" src="jquery.js"></script>
</head>
<body>

<!-- Facebook stuff
<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    FB.init({appId: 'insert_app_id_here', 
             status: true, 
             cookie: true,
 	     xfbml: true,
 	     channelUrl: 'http://<?php echo $_SERVER["SERVER_NAME"]; ?>/channel.html'});
  };

  (function() {
    var e = document.createElement('script'); e.async = true;
    e.src = 'https://connect.facebook.net/en_US/all.js';
    document.getElementById('fb-root').appendChild(e);
  }());

   function createFbmlNode(url) {
      var like = document.createElement("fb:like");
      like.setAttribute('href', url);
      like.setAttribute('send', false);
      like.setAttribute('width', 450);
      like.setAttribute('show_faces', false);
      like.setAttribute('colorscheme', 'dark');
      like.setAttribute('font', 'trebuchet ms');

      var container = document.getElementById('fblikecontainer');
      while (container.hasChildNodes()) {
       container.removeChild(container.lastChild);
      }
      container.appendChild(like);

      if (typeof FB !== 'undefined') {
         FB.XFBML.parse(); 
      }
   }
</script>
-->

   <div id="page">
      <div id="container">
<?php
if (!isset($_GET['album']) || $_GET['album'] == "") {
   die('ERROR: must specify album location');
}
if (!isset($_GET['image']) || $_GET['image'] == "") {
   die('ERROR: must specify image filename');
}
$albumDir = $_GET['album'];
$imageFile = $_GET['image'];
$imagePath = 'albums/' . $albumDir . '/small/small_' . $imageFile;
if (!file_exists($imagePath)) {
   die('ERROR: image ' . $imagePath . ' does not exist');
}
$jsonPath = 'albums/' . $albumDir . '/album.json';
if (!file_exists($jsonPath)) {
   die('ERROR: missing configuration file ' . $jsonPath);
}
$jsonFile = fopen($jsonPath, 'r');
$jsonStr = fread($jsonFile, filesize($jsonPath));
fclose($jsonFile);
$jsonDecoded = json_decode($jsonStr, true);
$albumName = $jsonDecoded['title'];
$albumMonth = $jsonDecoded['month'];
$albumYear = $jsonDecoded['year'];
?>
         <h1><a href=showalbum.php?album=<?php echo $albumDir . '>' . $albumName;?></a></h1>
         <h2><?php echo $albumMonth . ' ' . $albumYear; ?></h2>
         <div id="gallery" class="content">
<?php
   echo '   <img id="mainImage" src="' . $imagePath . '"/>';
   echo '   <div id="captionArea">' . $jsonDecoded['captions'][$imageFile];
   echo '      <div id="miscButtons">';
   /*
   echo '         <div class="fb-like" data-href="//' . $_SERVER["SERVER_NAME"] . dirname($_SERVER['PHP_SELF']) . '/showimage.php?album=' .         $albumDir . '&image=' . $imageFile . '" data-send="false" data-width="450" data-show-faces="false" data-colorscheme="dark"' .
                       ' data-font="trebuchet ms"></div>';
   */
   echo '         <div id="downloadLink"><a href="albums/' . $albumDir . '/' . $imageFile . '">Download</a></div>';
?>
               </div>
            </div>
         </div>
      </div>
   </div>		
   <div id="footer"><a href="http://raspberryalbums.sf.net">Raspberry Albums</a></div>
</body>
</html>
