# Simple Photo Gallery
# (c) 2003--2005 Martin Mares <mj@ucw.cz>

package Gallery;

use strict;
use warnings;

BEGIN {
	# Standard Perl module stuff
	use Exporter();
	our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
	$VERSION = 1.00;
	@ISA = qw(Exporter);
	@EXPORT = qw(&SetOptions &Start &img &Finish &RawHTML);
	%EXPORT_TAGS = ();
	@EXPORT_OK = qw(%CF);
}

our %CF;
our $th;

BEGIN {
	$CF{"Title"} = "An Unnamed Gallery",
	$CF{"HeadExtras"} = "",
	$CF{"TopExtras"} = "",
	$CF{"BotExtras"} = "",
	$CF{"ParentURL"} = "../",
	$CF{"BackURL"} = "",
	$CF{"FwdURL"} = "",
	$CF{"ImageSubpages"} = 1,
	$CF{"AllowArchives"} = 1,
	$CF{"PhotoUrlPrefix"} = "",
	$CF{"ThumbUrlPrefix"} = "",
	$CF{"MetaDataDir"} = ".",
	$CF{"PhotoDir"} = ".",
	$CF{"ThumbDir"} = ".",
}

sub SetOptions(@) {
	while (my $o = shift @_) {
		my $v = shift @_;
		$CF{$o} = $v;
		if ($o eq "Theme") {
			require $CF{"GalDir"} . "/$v/theme.pm";
			Gallery::Theme::Init($CF{"GalURL"} . "/$v");
		}
	}
}

sub Start() {
	if (defined $ENV{"GATEWAY_INTERFACE"}) {
		require Gallery::Web;
		$th = new Gallery::Web;
	} else {
		if (@ARGV && $ARGV[0] eq "--generate") {
			require Gallery::Generator;
			$th = new Gallery::Generator;
		} else {
			print STDERR "Usage: $0 [--generate]\n";
			exit 1;
		}
	}
	$th->Start();
}

sub img($$) {
	$th->img(@_);
}

sub Finish() {
	$th->Finish();
}

sub RawHTML($) {
	$th->RawHTML($_[0]);
}

1;
