<?
$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)
	{
	?>
	
			<script language="JavaScript">

			var imgArr = new Array();
			var k=0;

			var Foto = new Array();

			<?
			$i=0;
			foreach ($am as $ams)
				{
    			echo("\n Foto[".$i."] = '".$ams[0]."';");
				$i++;
				}
			?>
			
			
			function toTek(j) {
        	eval("imgObj" + j + "= new Image()");
        	eval("imgObj" + j + ".src = '" + Foto[j] + "'");
 			eval("document.vvr.src = imgObj"+j+".src");
			k=j;
			}

			function toTekd() {
			k=k+1;
			if(!Foto[k]) k=0;
        	eval("imgObj" + k + "= new Image()");
        	eval("imgObj" + k + ".src = '" + Foto[k] + "'");
 			eval("document.vvr.src = imgObj"+k+".src");
			}

			</script>
	
	

	<table width="100%"><tr>
	<td width=100%>
	<div align="center">
	<?
	foreach($am as $index=>$aa)
		{
		?>
		<a onclick="toTek(<?=$index?>)"><img height="70" border=0 class="imground" src="<?=$aa[1]?>" /></a>
		<?
		}
		?>
	</div>
	<br>
	<center><a onclick="toTekd()"><img name="vvr" alt="<?=$rr['zag'].'. '.$name_region?>" class="imground" border=0 src="<?=$am[0][0]?>"></a></center>
	</tr></table>
	<?
	}
else echo '<center><img alt="'.$rr['zag'].'. '.$name_region.'" class="imground" border=0 src="'.$am[0][0].'"></center>';
}
?>
