<?
$rf = mysql_query ("SELECT * FROM foto WHERE id = '".$id."' ORDER BY id_foto") or die(mysql_error());
$i=0;

$pf='foto';
while($rrf = mysql_fetch_assoc($rf))
	{
	if(file_exists($bp.$pf.'/'.$rrf['papka'].'/'.$rrf['id_foto'].'s.jpg') 
	&& file_exists($bp.$pf.'/'.$rrf['papka'].'/'.$rrf['id_foto'].'b.jpg'))
		{
		$am[$i][0]=$bp.$pf.'/'.$rrf['papka'].'/'.$rrf['id_foto'].'b.jpg';
		$am[$i][1]=$bp.$pf.'/'.$rrf['papka'].'/'.$rrf['id_foto'].'s.jpg';
		$i++;

		}
	}

$rez=count($am);
if($rez>0)
{

	if($rez>1)
	{
	foreach($am as $aa)
		{
		?>
		<a class="gallery" rel="group" href="<?=$aa[0]?>"><img  class="imground" border=0 src="<?=$aa[1]?>" /></a>
		<?
		}
	}
else echo '<img alt="'.$rr['zag'].'. '.$name_region.'" class="imground" border=0 src="'.$am[0][0].'">';
}
?>
