<?php
$page=(isset($_GET['page']))?intval($_GET['page']):0;
$xhtml = preg_match('/application\/xhtml\+xml(?![+a-z])(;q=(0\.\d{1,3}|[01]))?/i', 
$_SERVER['HTTP_ACCEPT'], $xhtml) && (isset($xhtml[2])?$xhtml[2]:1) > 0 || 
strpos($_SERVER["HTTP_USER_AGENT"], "W3C_Validator")!==false || 
strpos($_SERVER["HTTP_USER_AGENT"], "WebKit")!==false;
header('Content-Type: '.($xhtml?'application/xhtml+x':'text/ht').'ml; charset="utf-8"');
require('init.php');
echo '<?xml version="1.0" encoding="utf-8"?>'
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl">
<head>
	<title>Galeria</title>
	<link type="text/css" href="style.css" rel="stylesheet" />
	<script type="text/javascript" src="script.js"></script>
</head>
<body onload="javascipt:init()">
	<div id="page">
		<div id="images_outer">
			<table id="images"><tr>
			<?php
				$result = mysql_query('SELECT * FROM photos LIMIT '.($page*$per_page).', '.$per_page);
				for($i=$page*$per_page; $row = mysql_fetch_assoc($result); $i++) {
					echo '<td class="image_outer" onclick="javascript:previewImage('.$i.')"><img alt="'.$row['photo_name'].'" src="'.$row['thumb_name'].'" class="image" /></td>';
					if($i%3==2 && $i!=$count-1) echo '</tr><tr>';
				
		    		}
				while($i%3) {
					$i++;
					echo '<td class="image_outer_black">&nbsp;</td>';
				}
			?>
			</tr>
			</table>
		</div>
		<div id="pages_outer">
			<div id="pages">Strony: 
		<?php
			$pcount = ceil($count/$per_page)-1;
			for($i=0; $i<$page; $i++) {
				echo '<a href="?page='.$i.'">'.($i+1).'</a> | ';
			}
			if($page!=$pcount) echo ($page+1).' | ';
			else echo ($page+1);
			for($i=$page+1; $i<$pcount; $i++) {
				echo '<a href="?page='.$i.'">'.($i+1).'</a> | ';
			}
			if($page!=$pcount) echo '<a href="?page='.($pcount).'">'.($pcount+1).'</a>';
		?>
			</div>
		</div>
		<div id="disp">
			<div id="disp_middle">
			<div id="disp_inner">
				<div><h3 id="disp_name"> </h3></div>
				<div id="disp_top">
					<img id="disp_prev" src="img/prev.png" onclick="javascript:prev()" alt="Poprzedni"></img>
					<a id="disp_a" href=""><img id="disp_img" src="" alt="Zdjęcie" /></a>
					<img id="disp_next" src="img/next.png" onclick="javascript:next()" alt="Następny"></img>			
				</div>
				<div id="disp_info"></div>
				<div><b>Autor:</b> <a id="disp_author"> </a></div>
				<a id="disp_close" onclick="javascript:closeDisp()">Zamknij</a>
			</div>
			</div>
		</div>
		<div id="icons">
			<a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml11" alt="Valid XHTML 1.1" height="31" width="88" /></a>
			<a href="http://jigsaw.w3.org/css-validator/check/referer"><img width="88px" height="31px" src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Poprawny CSS!" /></a>
		</div>
	</div>
</body>
</html>