<?php
//ini_set('display_errors','1');
$GALLERIES_DIR = '/home/antsa/public_html/photos/';
$GALLERIES_URL = 'http://elite.oldskool.fi/~antsa/photos/';

$photos_arr = array();
//galleriat
$galleries_arr = array();
if($handle = opendir($GALLERIES_DIR)){
  while (false !== ($file = readdir($handle))){
    if($file != '.' && $file != '..' && $file != '.svn') $galleries_arr[] = $file;
  }
}
if(!isset($_GET['gallery'])) $_GET['gallery'] = $galleries_arr[0];
$gallery_dir = $GALLERIES_DIR.$_GET['gallery'].'/';
$gallery_url = $GALLERIES_URL.$_GET['gallery'].'/';

//kuvat talteen
if($handle = opendir($gallery_dir)){
  while (false !== ($file = readdir($handle))){
    if(substr($file, -3) == 'jpg') $photos_arr[] = $file;
  }
}

//kuvatekstit
$captions_arr = array();
$handle = @fopen($gallery_dir.'captions.txt', 'r');
if($handle){
  while(!feof($handle)) {
    $buffer = fgets($handle, 4096);
    $strings = explode('|',$buffer);
    $captions_arr[$strings[0]] = $strings[1];
    //$captions_arr[$strings[0]] = array('name'=> $strings[1],'caption'=>$strings[2]);
  }
  fclose($handle);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
  <title>Anssi Toivakka Portfolio <?php echo date('Y'); ?></title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <link rel="stylesheet" type="text/css" href="styles/main.css" />
  <link rel="stylesheet" type="text/css" href="js/galleryview-2.1.1/galleryview.css" />
  <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
  <script type="text/javascript" src="js/jquery.easing.1.3.js"></script>
  <script type="text/javascript" src="js/galleryview-2.1.1/jquery.galleryview-2.1.1.js"></script>
  <script type="text/javascript" src="js/galleryview-2.1.1/jquery.timers-1.2.js"></script>
  <!-- InstanceBeginEditable name="head" -->
  <script type="text/javascript">
    $(document).ready(function(){
      $('#gallery').galleryView({
        panel_width: 1200,
	panel_height: 500,
        gallery_width: 1200,
        gallery_height: 900,
        frame_width: 75,
        frame_height: 75,
        overlay_height: 50,
        pause_on_hover: true,
        nav_theme: 'light'
      });
    });
  </script>
  </head>
  <body>
    <div id="container">
      <div id="header">Anssi Toivakka - Portfolio</div>
      <div id="gallery_container">
        <ul id="gallery">
        <?php
          $view = '';
          foreach($photos_arr as $photo){
            //echo '<li><img src="'.$gallery_url.$photo.'" alt="" /></li>';
            $view .= '<li>'."\n";
            $view .= '<img src="'.$gallery_url.$photo.'" alt="'.@$captions_arr[$photo]['name'].'" title="'.@$captions_arr[$photo]['name'].'" />'."\n";
            $view .= '<div class="panel-overlay">'."\n";
            //$view .= '<h3>'.@$captions_arr[$photo]['name'].'</h3>'."\n";
            $view .= '<span>'.@$captions_arr[$photo].'&nbsp;&nbsp;&nbsp;&nbsp;</span>';
            $view .= '<a href="'.$gallery_url.$photo.'" target="_blank">Full size</a>'."\n";
            $view .= '</div>'."\n";
            $view .= '</li>'."\n";
          }
          echo $view;
        ?>
        </ul><div style="clear: both; font-size: 10px">&copy; Anssi Toivakka</div>
      </div>
      <div id="footer">
        <div id="bio_container">
          Links - Bio<br/>
  <div>
    <ul>
      <li>
        <a target="_blank" href="http://www.facebook.com/anssi.toivakka">
          Facebook
        </a>
      </li>

       <li>
        <a target="_blank" href="http://www.dingle.fi/">
          Work
	</a>
	</li>
      <li>
        <a target="_blank" href="http://www.flickr.com/photos/antsaphoto/">
          Flickr
        </a>
      </li>

      </li>

      <li>
        <a target="_blank" href="http://www.last.fm/user/Antsa">
          Music
        </a>      
      </li>  

      <li>
        <a target="_blank" href="mailto:atoivakka@gmail.com">
          Gmail
        </a>

      </li>
    </ul>
  </div>
     </div>
        <div id="gallery_links">
          <ul>
          <?php
            foreach($galleries_arr as $gallery){
              $class = '';
              if($_GET['gallery'] == $gallery) $class = 'selected';
              echo '<li><a href="index.php?gallery='.$gallery.'" class="'.$class.'">'.$gallery.'</a></li>';
            }
          ?>
          </ul>
        </div>
      </div>
    </div>
  </body>
</html>

