<div style="border: 0; height: 482px; margin: 32px 0px 30px 42px; width: 784px; background-color: white;">
<div style="width: 784px; height: 20px;  margin: 0px; padding: 0px; border-style: solid; border-color: gray; border-width: 0px 0px 1px 0px; text-align: center; font-family: tahoma, sans-serif; color: black; letter-spacing: 2.5px; text-transform: uppercase; vertical-align: middle;  font-size: 12pt;">

<?php
	$sx = $_GET['sx'];
	$sx = str_replace("~", " ", $sx);  // turns the tildes into spaces
	echo "$sx - Before & After Photos\n";
?>

</div>				
<div style="float: left; text-align: center; height: 350px; width: 606px; background-color: white; padding: 0px; margin-top:0px; margin-bottom: 0px;"> <!-- div for the main image -->

<?php
	$pt = $_GET['pt'];
	
	$notes = "";
	if (file_exists("photos/$pt.dat"))
	{
		$stats_notes = file_get_contents("photos/$pt.dat");
		$stats_notes = str_replace("\n", "<br>", $stats_notes);
		
		$stats = $stats_notes;
		list($stats, $notes) = explode("^", $stats_notes);
		echo "<div style='height: 100px; width: 606px; text-align: center; background-color: white; overflow: hidden; ' class='caption_text'>\n";

		if (strlen($notes) > 2)
		{
			echo "<div id='stats'>";
			echo "$stats\n";
			echo "</div>\n";
			echo "<div id='notes'>";
			echo "$notes\n";
			echo "</div>\n";
			echo "<div style='clear: both;'></div>";
	
		}
		else
		{
			echo "<div id='stats' style='width: 600px;'>";
			echo "$stats\n</div>\n";
		}
		
		echo "</div>\n"; /*<!-- closes stats and notes div -->*/
	}
	else
	{
		// echo "<div style='height: 35px'>&nbsp;</div>\n";
	
	}
?>

	
<?php
	$views = array("ap" => 0, "ol" => 0, "ll" => 0, "pa" => 0, "lr" => 0, "or" => 0);
	$thviews = array("ap" => 0, "ol" => 0, "ll" => 0, "pa" => 0, "lr" => 0, "or" => 0);
    $thcount = 0;
	foreach (glob("photos/$pt*.jpg") as $filename) /* find the images for this patient */
	{

	    list($surg, $ptname, $view, $thumb) = split("[-.]", $filename);
	    
	    if ($surg != "th")
	    {
			if (($view <> "") and (in_array($view, $views)))
			{
				++$views[$view];
				++$thcount;
			}
		}
	}

	if (isset($_GET["mainview"]))
	{
		$mainview = $_GET['mainview'];
	}
	else
	{
		$mainview = array_search(1, $views);;
	}

	if ($mainview)
	{
		echo "<IMG id='ptphoto' width=596 height=320 SRC='photos/$pt-$mainview.jpg' style='padding: 5px;' ><br><br>";
		echo "<img src='images/beforeafter-big.gif' border=0 alt='before and after'><br><br>\n";
	}

	echo "</div>\n";

	if ($thcount > 1)
	{
echo "<div class='caption_text' style='float: right; width: 174px; border-style: solid; border-color: gray; border-width: 0px 1px 1px 1px; padding-bottom: 2px; padding-right: 2px; text-align: center;'>\n";
		echo "More views of this patient<br style='line-height: 3px;'>(click to enlarge):<BR>\n";
echo "<div style='overflow: auto; width: 174px; height: 424px; background-color: white; text-align: center;'>\n";

		$sx = str_replace(" ", "~", $sx);  // turns the spaces back into tildes
		foreach ($views as $view => $n) 
		{
			if ($n > 0)
			{

				echo "<a><IMG class='graphics' BORDER=0 align=middle SRC='photos/$pt-$view.jpg' width=140 height=75 onClick='document.getElementById(&quot;ptphoto&quot;).src=this.src;' style='cursor: pointer; padding: 3px; margin: 2px; border: solid gray 1px;'></a>\n";

			}
		}
	//	echo "<div style='clear: both;'></div>\n";
	//	echo "<div style='clear: both;'></div>\n";

	}
?>				
</div>
</div>
	<div style='clear: both;'></div>

</div>
