#!/usr/bin/perl -wT

use strict;

my $http_cookie = $ENV{'HTTP_COOKIE'};
my $script_name = $ENV{'SCRIPT_NAME'};
my @paths;
my $file = "random_art.txt";
my $buf;
my @linkslist;
my @link;
my $i;
my $random_link;
my $random_art;
my $misties = "";
my @comments;
my $random;

open (FH, $file) or die "cannot open $file";
read (FH, $buf, 1024);
@linkslist = split (/\n/,$buf);
@link = split(/&/,$linkslist[int(rand(@linkslist))]);

if(defined($link[1])){
  $random_art = "<a href = \"$link[1]\"><img border = \"0\" src = $link[0] height = \"150\" width =\"200\"></a>";
}
else{
  $random_art = "<img src = $link[0] height = \"150\" width =\"200\">";
}
close (FH);

$file = "random_link.txt";
open (FH, $file) or die "cannot open $file";
read (FH, $buf, 1024);
@linkslist = split (/\n/,$buf);
@link = split(/&/,$linkslist[int(rand(@linkslist))]);

if(defined($link[1])){
  $random_link = "<a href = \"$link[1]\"><img border = \"0\" src = $link[0]></a>";
}
else{
  $random_link = "<img src = $link[0]>";
}
close (FH);

if($http_cookie =~ "mst3k=1")
{
  $file = "templates/mst3k.html";
  open(FH, $file);
  read(FH, $misties, 8192);
  close(FH);
  @paths = split (/\//,$script_name);
  $file = 'comments/' . pop(@paths) . '.txt';
  $misties =~ s/FILENAME/$file/;
  if(open(FH, $file))
  {
    read(FH, $buf, 1024);
    close(FH);
    @comments = split(/\n/,$buf);
    
    for($i = 0;$i < 3;$i++)
    {
      $random = int(rand(@comments));
      $random = splice(@comments,$random,1);
      $misties =~ s/TEXT/$random/;
    }
  }
  else
  {
    for($i = 0;$i < 3;$i++)
    {
      $misties =~ s/TEXT//;
    }
  }
}


print "Content-type: text/html\n\n";

print <<END_OF_PAGE;

<html> 
<head> 
<title>Michael Fahmie's Homepage</title>
</head>
<style type="text/css">
        body { font-family : "arial";
        background : #005050 ;
        color : white; }
        A:link, A:visited { text-decoration : none }
        A:visited { color : #20A0D0 }
        A:link { color : #20A0D0 }
        A:hover { color : #80E0F0;
	background :  ;}

</style>
<body>
<br>
<center>
<!-- SiteSearch Google -->
<form method="get" action="http://www.google.com/custom" target="_top">
<table border="0" bgcolor="#003030">
<tr><td nowrap="nowrap" valign="top" align="left" height="32">
<a href="http://www.google.com/">
<img src="http://www.google.com/logos/Logo_25blk.gif"
border="0" alt="Google"></img></a>
</td>
<td nowrap="nowrap">
<input type="hidden" name="domains" value="www.yikes.com"></input>
<input type="text" name="q" size="31" maxlength="255" value=""></input>
<input type="submit" name="sa" value="Search"></input>
</td></tr>
<tr>
<td>&nbsp;</td>
<td nowrap="nowrap">
<table>
<tr>
<td>
<input type="radio" name="sitesearch" value="" 
checked="checked"></input>
<font size="-1" color="#ffffff">Web</font>
</td>
<td>
<input type="radio" name="sitesearch" value="www.yikes.com"></input>
<font size="-1" color="#ffffff">www.yikes.com</font>
</td>
</tr>
</table>
<input type="hidden" name="client" value="pub-4938435996847465"></input>
<input type="hidden" name="forid" value="1"></input>
<input type="hidden" name="ie" value="ISO-8859-1"></input>
<input type="hidden" name="oe" value="ISO-8859-1"></input>
<input type="hidden" name="cof" 
value="GALT:#FFFFFF;GL:1;DIV:#336666;VLC:FFFFFF;AH:center;BGC:003333;LBGC:000000;ALC:66CCCC;LC:66CCCC;T:90DCEC;GFNT:66CCCC;GIMP:66CCCC;LH:57;LW:200;L:http://www.yikes.com/images/gleepi.gif;S:http://www.yikes.com;FORID:1;"></input>
<input type="hidden" name="hl" value="en"></input>

</td></tr></table>
</form>
<!-- SiteSearch Google -->

<br><br>
<table cellpadding = "0" cellspacing = "0" border = "0">
 <tr>
  <td bgcolor = "007070" rowspan = "4" colspan = "5" align = "center" valign = "center">
   $random_art
  </td>
  <td width = "30" height = "30"></td>
  <td width = "10" rowspan = "7"></td>
  <td width = "10" rowspan = "11"></td>
  <td width = "20"></td>
  <td width = "50"></td>
  <td width = "70"></td>
  <td width = "20"></td>
 </tr>
 <tr>
  <td bgcolor = "002020" height = "20"></td>
  <td bgcolor = "006060" colspan = "3" rowspan = "8" valign = "center" align = "left">
  <ul>
   <font face = "Times" size = "+1">
   <a href = "stuff.cgi">Stuff</a><br><br>
   <a href = "images/">Pictures</a><br><br>
   <a href = "projects.html">Projects</a><br><br>
   <a href = "resume/">Resumé</a><br><br>
   <a href = "links.cgi">Links</a><br>
   </font>
  </ul>
  </td>
  <td></td>
 </tr>
 <tr>
  <td bgcolor = "002020" height = "80"></td>
  <td bgcolor = "002020"></td>
 </tr>
 <tr>
  <td bgcolor = "002020" height = "50"></td>
  <td bgcolor = "002020"></td>
 </tr>
 <tr>
  <td width = "30" height = "30"></td>
  <td bgcolor = "002020" width = "50"></td>
  <td bgcolor = "002020" width = "40"></td>
  <td bgcolor = "002020" width = "60"></td>
  <td bgcolor = "002020" width = "50"></td>
  <td bgcolor = "002020"></td>
  <td bgcolor = "002020"></td>
 </tr>
 <tr>
  <td height = "10" colspan = "7"></td>
  <td bgcolor = "002020"></td>
 </tr>
 <tr>
  <td height = "40"></td>
  <td></td>
  <td bgcolor = "008080" rowspan = "4" colspan = "3" align = "center" valign = "center">
   $random_link
  </td>
  <td></td>
  <td bgcolor = "002020"></td>
 </tr>
 <tr>
  <td height = "50"></td>
  <td></td>
  <td bgcolor = "002020"></td>
  <td bgcolor = "002020"></td>
  <td bgcolor = "002020"></td>
 </tr>
 <tr>
  <td height = "50"></td>
  <td></td>
  <td bgcolor = "002020"></td>
  <td bgcolor = "002020"></td>
  <td bgcolor = "002020"></td>
 </tr>
 <tr>
  <td height = "20"></td>
  <td></td>
  <td bgcolor = "002020"></td>
  <td bgcolor = "002020"></td>
  <td></td>
  <td bgcolor = "002020"></td>
  <td bgcolor = "002020"></td>
  <td bgcolor = "002020"></td>
 </tr>
 <tr>
  <td height = "40"></td>
  <td></td>
  <td></td>
  <td bgcolor = "002020"></td>
  <td bgcolor = "002020"></td>
  <td bgcolor = "002020"></td>
  <td bgcolor = "002020"></td>
  <td></td>
  <td colspan = "3" align = "right"><font color ="70FFFF">pengo<FONT FACE="Wingdings">&#91</font>yikes.com</td>
 </tr>
</table>
</center>
$misties
</body>
</html>
END_OF_PAGE

