<?php

	/* --- Asset Lists --- */
	$images = 				Flatfile::getFileTable("image", $this->info("id"));

	/* --- Page Settings --- */
	$page_title = 			$this->getTypedValue($page_data, "settings", "page_title");
	$description = 			$this->getTypedValue($page_data, "settings", "description");
	$show_captions_bool = 		$this->getTypedValue($page_data, "settings", "show_captions_bool");
	$use_watermark_bool = 		$this->getTypedValue($page_data, "settings", "use_watermark_bool");
	$image_placement = 		$this->getTypedValue($page_data, "settings", "image_placement");
	$slideshow_timer_num = 		$this->getTypedValue($page_data, "settings", "slideshow_timer_num");

	/* --- Page Settings --- */
	if ($slideshow_timer_num==null) {
		$slideshow_timer_num = 3;
	}
	$hasDescription = 		$description["value"]!="" || $page_title["value"]!="";
	$hasImages = 			count($images)>0;
	if ($use_watermark_bool==false) {
		$watermark_bool = false;
		$crosshairs_bool = false;
	}
	$i = 0;
	$maxheight = 0;
	$maxwidth = 0;
	$imagewidth = $image_placement=="left"||$image_placement=="right" ? 600 : $body_width_num;
	$parsed = array();
	foreach ($images as $key => $row) {
		$graphic = new Graphic($row);
		$graphic->encode(false);
		$graphic->caption($show_captions_bool);
		$graphic->setBasepath($this->info("id"));
		$graphic->watermark($watermark_bool, $watermark_asset, $watermark_x_num, $watermark_y_num, $watermark_alpha_num, $crosshairs_bool, $crosshairs_color, $crosshairs_alpha_num);
		$graphic->resample($resample_display_bool, $resampling_quality_num, $resample_sharpen_bool, $resample_use_imagick_bool);
		$graphic->setSize($imagewidth);
		$graphic->setMultiplier("{MULTIPLIER}");
		$size = $graphic->dimensions();
		if ($size[0]>$maxwidth) $maxwidth = $size[0];
		if ($size[1]>$maxheight) $maxheight = $size[1];
		$str = $graphic->render();
		$parsed[] = str_replace('class="Graphic', 'id="g_' . $i . '" class="Graphic', $graphic->render());
		++$i;
	}

	if (!$hasDescription&&($image_placement=="left"||$image_placement=="right")) $image_placement = "top";
	else if (!$hasImages&&($image_placement=="left"||$image_placement=="right")) $image_placement = "top";

	if ($image_placement=="top"||$image_placement=="left") {

?>
<?php 	if ($hasImages) { ?>
<div class="Column1<?php echo $image_placement=="left" ? "" : "Borf"; ?>">
	<div class="Slideshow">
		<noscript>
<?php
			foreach ($parsed as $str) {
				echo "\t\t\t" . str_replace(":{MULTIPLIER}", "", $str) . "\n";
			}
?>
		</noscript>
	</div>
</div>
<?php 	}
		if ($hasDescription) { ?>
<div class="Column2<?php echo $image_placement=="left" ? "" : "Borf"; ?>">
	<div class="Context">
		<?php if ($page_title["value"]!="") { ?><h1><?php echo $page_title["html"]; ?></h1><?php } ?>
		<div class="Description"><?php echo $description["markdown"]; ?>
		</div><!-- End .Description -->
	</div>
</div>
<?php		}
	} else if ($image_placement=="right"||$image_placement=="bottom") {
		if ($hasDescription) { ?>
<div class="Column1<?php echo $image_placement=="right" ? "" : "Borf"; ?>">
	<div class="Context">
		<?php if ($page_title["value"]!="") { ?><h1><?php echo $page_title["html"]; ?></h1><?php } ?>
		<div class="Description"><?php echo $description["markdown"]; ?>
		</div><!-- End .Description -->
	</div>
</div>
<?php 	}
		if ($hasImages) { ?>
<div class="Column2<?php echo $image_placement=="right" ? "" : "Borf"; ?>">
	<div class="Slideshow">
		<noscript>
<?php
			foreach ($parsed as $str) {
				echo "\t\t\t" . $str . "\n";
			}
?>
		</noscript>
	</div>
</div>
<?php 	}
	}
	if ($hasImages) { ?>
<script type="text/javascript">
	Slideshow.setTimer(<?php echo $slideshow_timer_num; ?>);
	Slideshow.setAspect(<?php echo @($maxheight/$maxwidth); ?>);
<?php 	foreach ($parsed as $str) { ?>
	Slideshow.setGraphic('<?php echo str_replace("'", "\'", $str); ?>');
<?php 	} ?>
	Slideshow.start();
</script>
<?php } ?>
<div class="clear"></div>