<?php
include_once("../scripts/config.php");
include_once("../scripts/album.php");
include_once("../scripts/thumbnail.php");

$width = 100;
$height = 75;

function image($album, $file) {
	global $album_root;
  echo $album_root . $album . "/" . $file;
}


if($album) {
	$a = new Album($album);

  if($image) {
		$photo = new Photo("", "");
    $prev = "";
    $next = "";
    
    foreach($a->photos as $p) {
			if($image == $p->file) {
				$photo = $p;
			}
      if($image == $last->file) {
				$next = $p;
				break;
      }
      $prev = $last;
      $last = $p;
    }
?>
<div class="gallery">
  <div class="headline"><?php echo $a->title; ?></div>
  <div class="center">Copyright <?php echo $a->copyright; ?></div>
  <div class="gallery_image">
    <img alt="<?php echo $photo->text ?>" src="<?php image($album, $photo->file); ?>"/>
  </div>
  <div class="description"><?php echo $photo->text; ?></div>
<?php if($prev) { ?>
  <div class="gallery_image">
    <a href="?page=photoview&amp;image=<?php echo $prev->file ?>&amp;album=<?php echo $album ?>" >
      <img alt="prev" src="<?php echo thumbnail($album, $prev->file, $width, $height); ?>"/>
    </a>
  </div>
<?php } else { ?>
  <div class="gallery_image">
    <img alt="stop" src="gfx/stop.jpg"/>
  </div>
<?php } ?>
  <div class="gallery_image">
    <a href="?page=photoview&amp;album=<?php echo $album ?>" >
      <img alt="home" src="gfx/home.jpg"/>
    </a>
  </div>
<?php if($next) { ?>
  <div class="gallery_image">
    <a href="?page=photoview&amp;image=<?php echo $next->file; ?>&amp;album=<?php echo $album ?>" >
      <img alt="next" src="<?php echo thumbnail($album, $next->file, $width, $height); ?>"/>
    </a>
  </div>
<?php } else { ?>
  <div class="gallery_image">
    <img alt="stop" src="gfx/stop.jpg"/>
  </div>
<?php } ?>
</div>
<?php
   } else {
     echo "<div class=\"headline\">" . $a->title . "</div>\n"; 
     echo "<div class=\"gallery\">\n";
     foreach($a->photos as $photo) {
?>
       <div class="gallery_image">
          <a href="?page=photoview&amp;image=<?php echo $photo->file ?>&amp;album=<?php echo $album ?>">
             <img alt="<?php echo $photo->file; ?>"
					        src="<?php echo thumbnail($album, $photo->file, 200, 150); ?>"/>
          </a>
       </div>
<?php
     }
     echo "</div>\n";
   }
}
?>