# NRT Theme for MJ's Photo Gallery
# (c) 2003--2012 Martin Mares <mj@ucw.cz>; GPL'ed
# Theme images taken from the cthumb package (c) Carlos Puchol

package UCW::Gallery::Web::NrtBlue;

use strict;
use warnings;

use UCW::Gallery;
use UCW::Gallery::Web;

our @ISA = qw(UCW::Gallery::Web);

my $theme_name = "nrt-blue";
my $navw = 48;
my $navh = 48;
my $thumb_w = 114;
my $thumb_h = 94;
my $interior_margin = 4;
my $left_w = 14;
my $right_w = 18;
my $top_h = 14;
my $bot_h = 18;

sub theme_dir($) {
	my ($self) = @_;
	return $self->get('ThemeUrlPrefix') . $theme_name;
}

sub theme_head_extras($) {
	my ($self) = @_;
	my $stylesheet = $self->theme_dir . "/style.css";
	return "<link rel=stylesheet href='$stylesheet' type='text/css' media=all>\n";
}

sub show_links($$$$) {
	my ($self, $prev, $up, $next) = @_;
	my $theme = $self->theme_dir;
	print "<p class=parent>";
	print "<span class=back style='width: ${navw}px; height: ${navh}px'>";
	print "<a href='$prev'><img src='$theme/prev.png' width=${navw} height=${navh} alt='Back'></a>" if $prev ne "";
	print "</span>\n";
	printf "<span class=fwd style='width: ${navw}px; height: ${navh}px'>";
	printf "<a href='$next'><img src='$theme/next.png' width=${navw} height=${navh} alt='Forward'></a>" if $next ne "";
	print "</span>\n";
	printf "<a href='$up'><img src='$theme/back.png' width=${navw} height=${navh} alt='Up'></a>" if $up ne "";
}

sub show_thumb($) {
	my ($self, $meta, $photo_id, $click_url) = @_;
	my $theme = $self->theme_dir;
	my $m = $meta->{photo}->{$photo_id};
	my $annot = UCW::CGI::html_escape($m->{title});
	my $tf = $self->{thumb_fmt};
	my $tm = $meta->{thumb}->{$tf}->{$photo_id} or die "No thumbnails for format $tf found!\n";
	my $tw = $tm->{w};
	my $th = $tm->{h};
	my $thumb = $self->get('ThumbUrlPrefix') . "$tf/$photo_id.jpg";
	my $side_w = $thumb_w + 2*$interior_margin;
	my $side_h = $thumb_h + 2*$interior_margin;
	my $box_w = $left_w + $side_w + $right_w;
	my $box_h = $top_h + $side_h + $bot_h;
	print "<div class=thf><div class=thumb>\n";
	print "<img src='$theme/top.png' width=$box_w height=$top_h alt='' class=tt>\n";
	print "<img src='$theme/left.png' width=$left_w height=$side_h alt='' class=tl>\n";
	my $ol = $left_w + $interior_margin + int(($thumb_w - $tw)/2);
	my $ot = $top_h + $interior_margin + int(($thumb_h - $th)/2);
	my $tit = ($annot ne "") ? " title=\"$annot\"" : "";
	print "<a href='$click_url'><img src='$thumb' width=$tw height=$th alt='Photo'$tit class=ti style='left: ${ol}px; top: ${ot}px'></a>\n";
	print "<img src='$theme/right.png' width=$right_w height=$side_h alt='' class=tr>\n";
	print "<img src='$theme/bot.png' width=$box_w height=$bot_h alt='' class=tb>\n";
	print "</div></div>\n\n";
}

sub attach($$) {
	my ($class, $gal) = @_;
	my $self = $class->SUPER::attach($gal);
	$self->{thumb_fmt} = $gal->require_thumbnails($thumb_w, $thumb_h);
	return $self;
}

1;
