#!/usr/bin/perl

($IP)=($ENV{"REMOTE_ADDR"}=~s/\.//g);
srand($$+$IP);
$seed=int rand(10000000);

$title = "www.olmer.ru - Fanatsy Gallery";

$bgcolor = "000000";

$border = "0";

$dir_url = "http://www.perumov.rus.net/arhiv/images/img39b";

$tn_dir_url = "http://olmer.ru/arhiv/images/img39";

$tn_dir = "/home/olmer.ru/htdocs/arhiv/images/img39";

$caption_file = "";

$script_name = "picture_frame39.pl";

$header = <<EOM;
<!-- begin header -->

<div align="center">
  <table cellpadding="0" cellspacing="1" width="700">
    <tr>
      <td  align="right"> 
<!-- end header -->
EOM
1;


$header1 = <<EOM;
<!-- begin header1 -->
      </td>
    </tr>
    <tr>
      <td align="right">
<!-- end header1 -->
EOM
1;


$header2 = <<EOM;
<!-- begin header2 -->
      </td>
    </tr>
    <tr>
      <td width="700" height="12">
&nbsp;
      </td>
    </tr>
    <tr>
      <td width="700">
<center><h3>Citadel of Olmer Fantasy Gallery</h3>
<h4>Jonas Jakobsson Gallery</h4>
</center>
Back to <a href="http://olmer.ru/arhiv/images/index.shtml">Main Gallery</a><p>
Back to <a href="$script_name">Jonas Jakobsson Gallery</a><p>

<!-- end header2 -->
EOM
1;


$footer = <<EOM;
<!-- begin footer -->
      </td>
    </tr>
    <tr>
      <td width="700" height="14">
&nbsp;
      </td>
    </tr>
    <tr>
      <td width="700">
        &nbsp;
        <div align="center">
          <center>
          <table border="0" cellpadding="0" cellspacing="0" width="580">
            <tr>
              <td width="520" align="center">

              </td>
            </tr>
            <tr>
              <td width="530" align="center">

<!-- SpyLOG f:0200 -->
<script language="javascript"><!--
Mu="u411.13.spylog.com";Md=document;Mnv=navigator;Mp=1;
Mn=(Mnv.appName.substring(0,2)=="Mi")?0:1;Mrn=Math.random();
Mt=(new Date()).getTimezoneOffset();
Mz="p="+Mp+"&rn="+Mrn+"&tl=0&ls=0&ln=0&t="+Mt;
My="";
My+="<img src='http://"+Mu+"/cnt?cid=41113&"+Mz+"&r="+escape(Md.referrer)+"&pg="+escape(window.location.href)+"' border=0  width=1 height=1 align=left alt='SpyLOG'>";
Md.write(My);//--></script><noscript>
<img src="http://u411.13.spylog.com/cnt?cid=41113&p=1" alt='SpyLOG' border='0'  align=left  width=1 height=1 >
</noscript>
<!-- SpyLOG  -->
<script language="javascript"><!--
Mrn=Math.random();Mz="";
My="<a href='http://u411.13.spylog.com/cnt?cid=41113&f=3&rn="+Mrn+"' target='_blank'><img src='http://u411.13.spylog.com/cnt?cid=41113&";
My+="p=1&f=4&rn="+Mrn+Mz+"' border=0   alt='SpyLOG'></a>";Md.write(My); 
//--></script><noscript>
<a href="http://u411.13.spylog.com/cnt?cid=41113&f=3&p=1" target="_blank">
<img src="http://u411.13.spylog.com/cnt?cid=41113&p=1&f=4" alt='SpyLOG' border='0' ></a> 
</noscript>

<!-- RLE code START -->
<script language="JavaScript">
<!--
var RndNum4NoCash = Math.round(Math.random() * 1000000000);
document.write(
'<iframe src="http://ad.adriver.ru/cgi-bin/erle.cgi'
+ '?sid=6713&target=blank&bt=1&pz=0&rnd=' + RndNum4NoCash
+ '" frameborder=0 vspace=0 hspace=0 width=468 height=60 marginwidth=0 marginheight=0 scrolling=no>'
+ '<a href="http://ad.adriver.ru/cgi-bin/click.cgi'
+ '?sid=6713&bt=1&pz=0&rnd=' + RndNum4NoCash + '" target=_blank>'
+ '<img src="http://ad.adriver.ru/cgi-bin/rle.cgi?'
+ 'sid=6713&bt=1&pz=0&rnd=' + RndNum4NoCash
+ '" alt="-AdRiver-" border=0 width=468 height=60></a></iframe>')
// -->
</script>
<noscript>
<iframe src="http://ad.adriver.ru/cgi-bin/erle.cgi?sid=6713&target=blank&bt=1&pz=0&rnd=930919299" frameborder=0 vspace=0 hspace=0 width=468 height=60 marginwidth=0 marginheight=0 scrolling=no>
<a href="http://ad.adriver.ru/cgi-bin/click.cgi?sid=6713&bt=1&pz=0&rnd=930919299" target=_blank>
<img src="http://ad.adriver.ru/cgi-bin/rle.cgi?sid=6713&bt=1&pz=0&rnd=930919299" alt="-AdRiver-" border=0 width=468 height=60></a></iframe>
</noscript>
<!-- RLE code END -->

</td>
            </tr>
          </table>
          </center>
        </div>
        &nbsp;
      </td>
    </tr>
    <tr>
      <td width="700" height="14" valign="middle">
<!-- end footer -->
EOM
1;

$footer1 = <<EOM;
<!-- begin footer1 -->
 </td>
    </tr>
  </table>
</div>

<!-- end footer1 -->
EOM
1;


#####################################
if ($ENV{'QUERY_STRING'} eq ""){
   &table;
   exit;
}
else {
   &display;
   exit;
}
#########################
# Display requested picture

sub display {

   $file = "$ENV{'QUERY_STRING'}";
   print "Content-type: text/html\n\n";
   print "<html><head><title>$title: $file</title><LINK href=\"http://olmer.ru/styles.css\" type=text/css rel=stylesheet></head>\n";
   print "<body text=#FFFFFF bgcolor=$bgcolor>\n";
   print "$header\n";
   open (MYFILE,"/home/olmer.ru/cgi-bin/log.shtml");
   while (<MYFILE>) { 
   print "$_";}
   close MYFILE;
   print "$header1\n";
   print "$header2\n";
   print "<p><hr><center><img border=$border src=\"$dir_url/$file\"></center><hr><p>\n";
   print "$footer\n";
   open (MYFILE,"/home/olmer.ru/cgi-bin/nm.shtml");
   while (<MYFILE>) { 
   print "$_";}
   close MYFILE;
   print "$footer1\n";
   print "</body></html>\n";
}
#######################
# Make table page

sub table {
   if ($caption_file ne "") {
      open(CAPS,"$caption_file");
      while (<CAPS>) {
        chop;
        ($key,$value) = split(/:/);
        $photos{$key} = $value;
      }
      close(CAPS);

      foreach (sort keys %photos) {
         push (@tnlist,$_);
         push (@captions,$photos{$_});
      }
   }
   else {
      opendir (TN, "$tn_dir");
      rewinddir (TN);
      @tnlist =  grep(!/^\.\.?$/, readdir (TN));
      closedir (TN);
      $temp = pop @tnlist;
      @tntemp = reverse(@tnlist);
      push (@tntemp,$temp);
      @tnlist = reverse(@tntemp);
   }

   $tnnum = @tnlist;
   $anum = int ($tnnum / 3);
   $bnum = ((($tnnum / 3) - $anum) * 3);
   print "Content-type: text/html\n\n";
   print "<html><head><title>$title</title><LINK href=\"http://olmer.ru/styles.css\" type=text/css rel=stylesheet></head>\n";
   print "<body text=#FFFFFF bgcolor=$bgcolor>\n";
   print "$header\n";
   open (MYFILE,"/home/olmer.ru/cgi-bin/log.shtml");
   while (<MYFILE>) { 
   print "$_";}
   close MYFILE;
   print "$header1\n";
   print "$header2\n";

   if ($bnum eq "0") {
      &main_table;
   }
   if ($bnum eq "1") {
      &main_table;
      print "<table width=100% border=0 cellpadding=3>\n";
      print "<tr align=center>\n";
      print "<td width=33%></td>\n";
      print "<td width=33%><a href=\"$script_name\?$tnlist[($anum * 3)]\"><img img border=0 src=\"$tn_dir_url/$tnlist[($anum * 3)]\"></a><br>$captions[($anum * 3)]<br></td>\n";
      print "<td width=33%></td>\n";
      print "</tr></table>\n";
   }
   if ($bnum eq "2") {
      &main_table;
      print "<table width=100% border=0 cellpadding=3>\n";
      print "<tr align=center>\n";
      print "<td width=33%><a href=\"$script_name\?$tnlist[($anum * 3)]\"><img img border=0 src=\"$tn_dir_url/$tnlist[($anum * 3)]\"></a><br>$captions[($anum * 3)]<br></td>\n";
      print "<td width=34%></td>\n";
      print "<td width=33%><a href=\"$script_name\?$tnlist[($anum * 3) + 1]\"><img img border=0 src=\"$tn_dir_url/$tnlist[($anum * 3) + 1]\"></a><br>$captions[($anum * 3) + 1]<br></td>\n";
      print "</tr></table>\n";
   }
   open (MYFILE,"/home/olmer.ru/cgi-bin/nm.shtml");
   while (<MYFILE>) { 
   print "$_";}
   close MYFILE;
   print "$footer\n";
   print "</body></html>\n";
}
sub main_table {
   $dnum = ($anum * 3);
   $cnum = "0";
   while ($dnum > $cnum) {
      print "<table width=100% border=0 cellpadding=3>\n";
      print "<tr align=center>\n";
      print "<td width=33%><a href=\"$script_name\?$tnlist[$cnum]\"><img border=0 src=\"$tn_dir_url/$tnlist[$cnum]\"></a><br>$captions[$cnum]<br></td>\n";
      print "<td width=33%><a href=\"$script_name\?$tnlist[$cnum + 1]\"><img border=0 src=\"$tn_dir_url/$tnlist[$cnum + 1]\"></a><br>$captions[$cnum + 1]<br></td>\n";
      print "<td width=33%><a href=\"$script_name\?$tnlist[$cnum + 2]\"><img border=0 src=\"$tn_dir_url/$tnlist[$cnum + 2]\"></a><br>$captions[$cnum + 2]<br></td>\n";
      print "</tr></table>\n";
      $cnum = $cnum + 3;
      print "<hr>\n";
   }
   print "$footer1\n";
   print "</body></html>\n";
}
