<div style="text-align: center;">
<div style="width: 783px; height: 20px; border-style: solid; border-color: gray; border-width: 0px 0px 1px 0px; text-align: center; font-family: arial, sans-serif; color: black; letter-spacing: 2.5px; text-transform: uppercase; vertical-align: middle; margin-left: -2px;">


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

<span style="position: absolute; left: 687px;"><a href="#" class="lbAction" rel="deactivate"><img src="images/close-box.gif" border=0 ></a></span>
</div>				

<div style="float: left; ">

<?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: 120px; width: 600px; text-align: center; background-color: white;' 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'>";
			echo "$stats\n</div>\n";
		}
		
		echo "</div>\n"; /*<!-- closes stats and notes div -->*/
	}
	else
	{
		echo "<div style='height: 35px'>&nbsp;</div>\n";
	
	}
?>


<div style="height: 350px; width: 600px; text-align: center; background-color: white; " class="caption_text">  <!-- div for the main image -->
	
<?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'><br><br>";
		echo "<img src='images/beforeafter-big.gif' border=0 alt='before and after'><br><br>\n";
	}

	echo "</div>\n";
	echo "</div>\n";

	if ($thcount > 1)
	{
echo "<div class='caption_text' style='float: left; 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: 436px; 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>


