<html>
<head>
<style type="text/css">
<!--
table      { border-collapse: collapse; border: 1px solid #C0C0C0; }
td         { border: 1px solid #C0C0C0;}
a:link     { color: black }
a:visited  { color: black }
a:hover    { color: gray  }
a:active   { color: black }

-->
</style>
<?php

$album = $_GET['album'];
$directory = "./$album";	
$id = $_GET['id'];
echo "<title>Fotoalbum $album</title>\n";
echo "</head>\n";
echo "<body>\n";

if(empty($album)){
	echo "Selecteer een album";
}
elseif(is_dir($directory)){
	if(!isset($id)){		
		$a_jpeg = array(); 
		if ($dir = @opendir("$directory")) {
		  while (($file = readdir($dir)) !== false) {
		   $filetype = substr($file,-3,3);
		   if ($filetype == "jpg" || $filetype == "JPG" ){
		   	$a_jpeg[] = $directory."/thumbs/".$file; 
		 if(!is_dir("$directory/thumbs"))
		    {
		        $res = @mkdir("$directory/thumbs",0777);
		        
		        if(!$res)
		        {
		            echo "Geen rechten om thumbnails aan te maken.";
		            exit();
		        }
		        else
		            chmod("$directory/thumbs",0777);
		    }
		
		    $imagehw = GetImageSize("$directory/$file");
		    $src_width = $imagehw[0];  
		    $src_height = $imagehw[1];
		            
		    $src_width > $src_height ? $dest_width = 75 : $dest_width = 50;
		    
		    $tmp = $src_width / $dest_width;
		    $dest_height = $src_height / $tmp;
		        
		    $src_img = imagecreatefromjpeg("$directory/$file");
		    $dst_img = imagecreatetruecolor($dest_width,$dest_height);
		    
		    imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dest_width,    $dest_height, $src_width, $src_height);
		    imagejpeg($dst_img, "$directory/thumbs/$file", 75);
		    imagedestroy($src_img);
		    imagedestroy($dst_img);
		 	
		    } 
		  }
		  closedir($dir);
		  
		}
			echo "<table border=0 align=center>\n";
			echo "\t<tr>\n\t\t<td colspan=4 align=center><p style=\"text-transform: capitalize; font-size: 24pt\">$album</p></td>\n\t</tr>\n";

				for($i = 0; $i < count($a_jpeg); $i++){
				  echo "\t<tr>\n";
				  if(file_exists($a_jpeg[$i])){
				  echo "\t\t<td align=center><a href=\"?album=" . $album . "&id=" . $i . "\"><img src=\"".$a_jpeg[$i]."\" border=0></td>\n";
			  	  }
			  	  else
			  	  {
				  	  echo "";
			  	  }
				  $i++;
				  if(file_exists($a_jpeg[$i])){
				  echo "\t\t<td align=center><a href=\"?album=" . $album . "&id=" . $i . "\"><img src=\"".$a_jpeg[$i]."\" border=0></td>\n";
			  	  }
			  	  else
			  	  {
				  	  echo "";
			  	  }
				  $i++;
				  if(file_exists($a_jpeg[$i])){
				  echo "\t\t<td align=center><a href=\"?album=" . $album . "&id=" . $i . "\"><img src=\"".$a_jpeg[$i]."\" border=0></td>\n";
			  	  }
			  	  else
			  	  {
				  	  echo "";
			  	  }
				  $i++;
				  if(file_exists($a_jpeg[$i])){
				  echo "\t\t<td align=center><a href=\"?album=" . $album . "&id=" . $i . "\"><img src=\"".$a_jpeg[$i]."\" border=0></td>\n";
			  	  }
			  	  else
			  	  {
				  	  echo "";
			  	  }
				  echo "\t</tr>\n";
				}

			echo "\t<tr>\n\t\t<td colspan=4 align=center>Made by Zim</td>\n\t</tr>\n";
			echo "</table>"; 
		}
	else
	{
		$b_jpeg = array(); 
		if ($dir = @opendir("$directory")) {
			while (($file = readdir($dir)) !== false) {
				$filetype = substr($file,-3,3);
				if ($filetype == "jpg" || $filetype == "JPG" ){
					$b_jpeg[] = $directory."/".$file; 
	   			}
   			$max = count($b_jpeg);
   			}
			closedir($dir);
		}
		   $volgende = $id+1;
		   $volgende2 = $id+2;
		   $vorige = $id-1;
		   $vorige2 = $id;
		   echo "<table border=1 align=center>\n";
			echo "\t<tr>\n\t\t<td colspan=2 align=center><p style=\"text-transform: capitalize; font-size: 24pt\">$album</p></td>\n\t</tr>\n";
				echo "\t<tr>\n";
					echo "\t\t<td width=50% align=right>";
						if($vorige2 >= 1){
							echo "<a href=?album=$album&id=$vorige>Vorige</a>";
						}
						else
						{
							echo "Vorige";
						}
						echo "</td>\n";
						
						echo "\t\t<td width=50% align=left>";
						if($volgende2 <= $max){
							echo "<a href=?album=$album&id=$volgende>Volgende</a>";
						}
						else
						{
							echo "Volgende";
						}
						echo "</td>\n";
		  echo "\t</tr>\n";
				echo "\t<tr>\n";
					echo "\t\t<td colspan=2>";
						  echo "<img src=\"$b_jpeg[$id]\">";
					echo "</td>\n";
				echo "\t</tr>\n";
				echo "\t<tr>\n";
					echo "\t\t<td align=center colspan=2>";
						echo "<a href=?album=$album>Ga terug naar het Album</a>";
					echo "</td>\n";
				echo "\t</tr>\n";
			echo "</table>";
	}
}
else
{
	echo "De directory die jij zoekt ($album) bestaat niet";
}






?> 