#!/usr/bin/perl

use strict;

$|= 1;

# ****************************************************************
# Configuration - These need to be modified for your needs 
# ****************************************************************

# wo liegen die Bilder
my $IMAGEDIR = ".../htdocs/bilder/freak";

# Endlosschleife = 1, nur ein Durchlauf = 0
my $Continuous = 1;

# Liste der Bilder und Dauer der Wartezeit
my @images = (
              {'name' => "freak1.gif",'sleeptime' => 1},
              {'name' => "freak2.gif",'sleeptime' => 1},
              {'name' => "freak3.gif",'sleeptime' => 1},
              {'name' => "freak4.gif",'sleeptime' => 1},
              {'name' => "freak5.gif",'sleeptime' => 1},
              {'name' => "freak6.gif",'sleeptime' => 1},
              {'name' => "freak7.gif",'sleeptime' => 1},
              {'name' => "freak8.gif",'sleeptime' => 1},
              );

# ****************************************************************

my $ANHEAD="Content-type: multipart/x-mixed-replace;boundary=135792468TraLaLa00\n";
my $BOUNDARY="\n--135792468TraLaLa00\n";
my $ENDBOUNDS="\n--135792468TraLaLa00--\n";
my $GIFTYPE="Content-type: image/gif\n\n";
my $JPGTYPE="Content-type: image/jpeg\n\n";
my $HTMLTYPE="Content-type: text/html\n\n";

# ****************************************************************
# Main Routine
# ****************************************************************

&animate;
exit(0);

# ****************************************************************
# Animate - Routine to display server push animation 
# ****************************************************************

sub animate
  {
  my ($TYPE, $image, $count, $image_file, $data, $bc);
  print $ANHEAD;
  print $BOUNDARY;
  $count = 0;
  while(1)
    {
    $image_file = "$IMAGEDIR/$images[$count]->{'name'}"; 
    $TYPE = $GIFTYPE if ($image_file =~ /gif$/i);
    $TYPE = $JPGTYPE if ($image_file =~ /jpg$/i);
    $TYPE = $HTMLTYPE if ($image_file =~ /html$/i);
    print $TYPE;
    open (DAT,$image_file) || print "cannot open $image_file: $!\n";
    while (read(DAT,$data,8192,$bc))
      { print $data; }
    close DAT;
    print $BOUNDARY;
    sleep($images[$count]->{'sleeptime'});
    $count++;
    if ($count == $#images+1)
      {
      last if (! $Continuous);
      $count = 0;
      }
    } 
  print $ENDBOUNDS;
  }
