#!/usr/bin/perl

#-----------------------
# GuzZzt Show
# Ver. 1.0
# ----------------------
# Gustav Evertsson
# www.guzzzt.com
# me@guzzzt.com
#-----------------------
# This script is FREEWARE but please send an email so I can add
# a link to your site in the "Sites That Use GuzZzt Show"
# If you should modify any part of this script (except for paths),
# send me an email with your changes.
# 
#----------------------------------------------
# THIS HEADER MUST BE LEFT INTACT AT ALL TIMES
#----------------------------------------------
#
# Should have any problems, please send me an email and I will
# try to help you!
#

# The URL to the script
$cgi_url='http://www.vdsteenoven.com/cgi-bin';

# The URL to the images
$image_url='http://www.vdsteenoven.com/aquarius/images';

# The path to the images
# $image_path='../html/aquarius/images';
# $image_path='/ext/v/vd/vdsteenoven.com/html/aquarius/images';
$image_path='/data/a/f/af3d46ca-4d31-4fa6-9b16-8e13efa1838b/vdsteenoven.com/www/aquarius/images';
# $image_path='../../images';
# $image_path='/DATA/volData/Diverse/documents/Webpages/nieuw/images';


#----------------------------------------------
# DON'T CHANGE ANYTHING BELLOW THIS LINE!!!
#----------------------------------------------

use File::Find;

require "showhtml.pl";
require "imginfo.pl";
&parse_query;

local @filenames;


# foreach $filename (@filenames) {
#    print "$filename\n";
# }

# opendir (DATA, "$image_path");
# @filenames = grep (!/^\.\.?$/, readdir (DATA));
# closedir (DATA);

$category = $query{'cat'};
if (( $category < 0 ) || ( $category == 3 ) || ( $category > 4 )) {
   $category = 0;
}

$catpath = "" if ( $category == 0 );
$catpath = "/inventory" if ( $category == 1 );
$catpath = "/techinfo" if ( $category == 2 );
$catpath = "/software" if ( $category == 4 );
$image_path = $image_path . $catpath;
$image_url = $image_url . $catpath;

find( \&Wanted, "$image_path" );

$image_name = $filenames[$query{'nr'}];
$nextnr = $query{'nr'} + 1;
$prevnr = $query{'nr'} - 1;
$nextnr = 0              if($nextnr > @filenames-1); 
$prevnr = @filenames-1   if($prevnr < 0);
$startnr = $query{'nr'} - 2;
$startnr = @filenames + $startnr if($startnr < 0);

# print "IMAGE: $image_name\n";
# die "TheEnd";

&html_main;

sub parse_query {
  @pairs = split(/&/, $ENV{'QUERY_STRING'});
  foreach $pair (@pairs) {
    ($name, $value) = split(/=/, $pair);
    $query{$name} = $value;
  }
}

sub Wanted {
	if ( -f "$File::Find::name" && ( /jpg$/i || /jpeg$/i )) {
		push( @filenames, substr( "$File::Find::name", length("$image_path")+1) );
	}
}
