<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN'
    'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<:
	# Path setting - this is the path to the images
	my $level = num('parent_albums')-1;
	$PATH = Theme_URL();
	$CSS = "<link rel='stylesheet' type='text/css' href='". $PATH . "/Style.css' />";
	my $album = Album_Filename();
	my $path = $album;  $path =~ s|[^/]+$||;
	$path = "." unless $path;
	
	sub listImages {
		my $pic = $_[0];
		while ($pic) {
			print "<p><div class=\"albumthumb\">" . Get($pic, 'href', 'image') . Image($pic, 'thumb') . "</div></p>\n";
		    $pic = Next($pic);
		}
	}
:>
<html xmlns='http://www.w3.org/1999/xhtml'>
	<head>
		<meta http-equiv="Content-type" content="text/html; charset=<:=Option('charset'):>" />
		<: Meta() :>
		<title><:= Trans('Album:') :> <:= Path('album_name') :></title>
		<:  if ($level == 0) {
				if ( my $dir = First('dirs') ) {
					print "<meta http-equiv=\"refresh\" content=\"0;url=" . Get($dir, 'name') . "/index.html\" />\n";
				}
			} else {
				print $CSS;
			}
		:>
	</head>
	
	<body>
		<div id="head">
			<div id="headinner">
				<: if (isHeader()) { _:>
					<h1><:pHeader():></h1>
				<: }
				print "<h2><div class=\"breadcrumbs\">" . Parent_Albums(' » ') .  " » " . Name(This_Image) . "</div></h2>";
				_:>
			</div>
		</div>
		
		<div id="container">
			<div class="inner">
				<: if ($level == 1) { 
						if ( my $dir = First('dirs') ) { :>
							<table>
							<: while ($dir) {
								print "<tr><td><div class=\"albumthumb\">" . Get($dir, 'href', 'dir');
								if (my $img = Image($dir, 'thumb')) {
									print $img;
								}
								print "</a>&nbsp;</div></td><td valign='top'>";
								print "<div class=\"albumname\">&nbsp;" . Get($dir, 'name') . "</div>";
								my $numPics = Get($dir, 'num_pics');
								if ( $numPics > 0) {
									print "<br/><div class=\"picnum\">&nbsp;<strong>$numPics</strong> слика</div>";
								}
								print "</td></tr>\n";
							    $dir = Next($dir);
							} :>
							</table>
						<: }
					}
					if ( my $pic = First('pics') ) {
						my $thumbdir = Option('dir');
						my $imgpath = Image(This_Image, 'medium');
						$imgpath =~ s|src='|src='$thumbdir/|; :>
				
						<table cellspacing='5' width='100%'>
							<tr>
								<td>
									<: print "<div class=\"mediumimg\">" . $imgpath . "</div><br/><br/>"; :>
								</td>
								<td valign='top'>
									<table width='100%'>
										<tr>
											<: if (my $Prev = Prev($pic, $opt->{image_loop})) { _:>
												<td align='right'>
											      <: my $picName = Get($Prev, 'name');
											         $prevLine = Get($Prev, 'href', 'album_page', 'image') . "<div class=\"imgnavigation\">" . Trans('Prev') . "</div>";
											         $prevLine =~ s|html'|html#$picName'|; print $prevLine;
											      :></a>
												</td>
											<: } _:>
											<: if (my $Next = Next(This_Image, $opt->{image_loop})) { _:>
												<td align='right'>
												  <: my $picName = Get($Next, 'name');
												     $nextLine = Get($Next, 'href', 'album_page', 'image') . "<div class=\"imgnavigation\">" . Trans('Next') . "</div>";
												     $nextLine =~ s|html'|html#$picName'|; print $nextLine;
												      :></a></div>
												</td>
											<: } _:>
										</tr>
									</table>
								</td>
							</tr>
							<tr>
								<td colspan="2">
									<: print "<div class=\"imgcaption\">" . Name(This_Image) . "</div><br/>"; :>
								</td>
							</tr>
						</table>
				<: } :>
			</div>
		</div>
		
		<div id="sidebar">
			<div class="inner">
				<:  if ($level == 1) {
						if ( my $pic = First('pics') ) {
							# Some albums don't have sub-albums
							listImages($pic);
						} else {
							# Recurse to sub-albums
							my $filepath = $path . "../" . Parent_Album($level) . ".tmp";
							open ( INCLUDEFILE, $filepath ) || die( "Cannot open file " . $filepath ) ;
							while ( defined ($line = <INCLUDEFILE> ) ) {
								print $line;
							}
							close (INCLUDEFILE);
						}
					} elsif ($level == 2) {
						# List all thumbnails for given album
						if ( my $pic = First('pics') ) {
							listImages($pic);
						}
					}
				:>
			</div>
		</div>
		
		<div id="foot">
			<: if (isFooter()) { _:>
				<:pFooter():>
			<: } _:>
			<br/><div id="credit"><:=Credit() :></div>
		</div>
	<body>
</html>

<:
	if ( $level == 0 ) {
		if ( my $dir = First('dirs') ) {
			while ($dir) {
				my $dirName = Get($dir, 'name');
				open(STDOUT, ">$path/$dirName.tmp") || die( "Can't write directory-specific index [$path/$dirName.tmp]\n");
				
				my $dirInner = First('dirs');
				while ( $dirInner ) {
					my $dirInnerName = Get($dirInner, 'name');
					if ( $dirName == $dirInnerName ) {
						print "<p><div class=\"sidenavitem\">" . $dirInnerName . "</div></p>\n";
					} else {
						my $dirLink = Get($dirInner, 'cap');
						if ( ! $dirLink ) {
							$dirLink = Get($dirInner, 'name');
						}
						print "<p><div class=\"sidenavitem\"><a href='../" . $dirLink . "/index.html'>" . $dirInnerName . "</a></div></p>\n";
					}
					$dirInner = Next($dirInner);
				}
				close STDOUT;
			    $dir = Next($dir);
			}
		}
	}
	# Spill all pictures as well
	if ( my $pic = First('pics') ) {
		open(STDOUT, ">$path/Pics.tmp") || die( "Can't write picture index [$path/Pics.tmp]\n");
		while ( $pic ) {
			my $picName = Get($pic, 'name');
			my $line = "<p><div class=\"albumthumb\">" . Get($pic, 'href', 'image') . Image($pic, 'thumb') . "</a></div></p>\n";
			# To keep correct links and add anchor
			$line =~ s|href='|name='$picName' href='../|;
			$line =~ s|src='|src='../|;
			print $line;
			$pic = Next($pic);
		}
		close STDOUT;
	}
:>
