<?php	
	/*
	// Set standard timezone for timestamp comparison
	date_default_timezone_set('UTC');

	// Load Zend Gdata libraries
	require_once 'Zend/Loader.php';
	Zend_Loader::loadClass('Zend_Gdata_Spreadsheets');
	Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
	
	// Set credentials for ClientLogin authentication
	$user = "hemehouse@gmail.com";
	$pass = "KarcinomA5^7";
	
	try {  
    // Connect to API
    $service = Zend_Gdata_Spreadsheets::AUTH_SERVICE_NAME;
    $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
    $service = new Zend_Gdata_Spreadsheets($client);

    // Get specific worksheet entry (Heme New Atlas)
    $query = new Zend_Gdata_Spreadsheets_DocumentQuery();
    $query->setSpreadsheetKey('0AuPh9cI948YxdEoxRFg4VUkyc0FlNzE1Wjl1Ul9wQlE');
    $query->setWorksheetId('od6');
    $wsEntry = $service->getWorksheetEntry($query);      
  } catch (Exception $e) {
    die('ERROR: ' . $e->getMessage());
  }
	
	$atlas_php_last_updated = strtotime($wsEntry->updated); // Dynamic
	$atlas_html_last_updated = strtotime(date("F d Y H:i:s.", filemtime('atlas.html'))); // Static
	
	if (empty($compare_topics) && empty($atlas_topic_row)) {
		// Redirect to previously generated static html page if no recent Google Spreadsheets update
		if ($atlas_php_last_updated < $atlas_html_last_updated) {
	
			header('Location: atlas.html');
			exit;
		}
	}
	*/
	
	header('Location: atlas.html');
	exit;
	
	if (empty($compare_topics) && empty($atlas_topic_row)) {
		// Else the rest of the php script below will run and overwrite atlas.html file
		// Sends me an email of atlas updates
		$to      = 'vietomatic@gmail.com';
		$subject = 'Atlas updated!';
		$message = 'The atlas was recently updated.  Please run the atlas_generate script to update static pages.';
		$headers = 'From: vietomatic@gmail.com' . "\r\n" .
		  				 'Reply-To: vietomatic@gmail.com' . "\r\n" .
		  				 'X-Mailer: PHP/' . phpversion();
		
		mail($to, $subject, $message, $headers);
	}
?>

<link rel='stylesheet' href='/includes/colorbox.css'>
<script type="text/javascript" src="/includes/overlib_mini.js"></script>
<script type='text/javascript' src='/includes/jquery-min.js'></script>
<script type='text/javascript' src='/includes/jquery-ui-1.8.18.custom.min.js'></script>
<script type="text/javascript">
	function getParameterByName(name) {
		name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
		var regexS = "[\\?&]" + name + "=([^&#]*)";
		var regex = new RegExp(regexS);
		var results = regex.exec(window.location.search);
		if(results == null)
	  	return "";
		else
	  	return decodeURIComponent(results[1].replace(/\+/g, " "));
	}
</script>

<?php
	if (empty($compare_topics)) {
		?>
		<script type='text/javascript' src='/includes/jquery.colorbox-min.js'></script>
		<?php
	} else {
		?>
		<script type='text/javascript' src='/includes/jquery.colorbox.js'></script>
		<?php
	}
?>

<style type="text/css">
	tr.popup:hover { background: lightblue; }
	table.popup a:visited { color: #666; }
</style>

<?php	
	try {  
		$query = new Zend_Gdata_Spreadsheets_CellQuery();
		$query->setSpreadsheetKey("0AuPh9cI948YxdEoxRFg4VUkyc0FlNzE1Wjl1Ul9wQlE");
		$query->setWorksheetId("od6");
	} catch (Exception $e) {
	  die('ERROR: ' . $e->getMessage());
	}
	
	// Grab full atlas hierarchy list to generate links for main image map page
	if (empty($compare_topics)) {
		// Get a list of the 2nd to 8th row and put into an array
		// 1:Parent Node | 2:Level 1 | 3:Level 2 | 4:Level 3 | 5:Level 4 | 6:Level 5 | 7:Topic Name
		$max_columns = 8;
		$query->setReturnEmpty(true);
		$query->setMinCol(2);
		$query->setMaxCol($max_columns);
		$query->setMinRow(2);
		
		$cellFeed = $service->getCellFeed($query);
		
		// Populate the data_arrays
		$array_counter = 1;
		foreach ($cellFeed as $cellEntry) {		
			if ($array_counter == 1) {
				$atlas_parent_nodes[] = $cellEntry->getCell()->getText();
			} elseif ($array_counter == 2) {
				$atlas_level1[] = $cellEntry->getCell()->getText();
			} elseif ($array_counter == 3) {
				$atlas_level2[] = $cellEntry->getCell()->getText();
			} elseif ($array_counter == 4) {
				$atlas_level3[] = $cellEntry->getCell()->getText();
			} elseif ($array_counter == 5) {
				$atlas_level4[] = $cellEntry->getCell()->getText();
			} elseif ($array_counter == 6) {
				$atlas_level5[] = $cellEntry->getCell()->getText();
			} elseif ($array_counter == 7) {
				$atlas_topic_names[] = $cellEntry->getCell()->getText();
				$atlas_rows[] = $cellEntry->getCell()->getRow();
			} 
		
			// Reset array counter when all of row data (end of column) is entered
			$array_counter < ($max_columns - 1) ? $array_counter++ : $array_counter = 1;
		}
	} elseif (isset($compare_topics)) {		
		// Get a list of the 2nd to 16th row and put into an array
		// 0:Parent Node | 1:Level 1 | 2:Level 2 | 3:Level 3 | 4:Level 4 | 5:Level 5 | 6:Topic Names | 7:Microscopic Features | 8:Normal Values | 9:May Resemble | 10:Differential Diagnosis | 11: Classic Immunophenotype | 12:Cartoon | 13:Image | 14:Misc | 15:Additional Images
		$max_columns = 17;
		$query->setReturnEmpty(true);
		$query->setMinCol(2);
		$query->setMaxCol($max_columns);
		$query->setMinRow(min($compare_topics));
		$query->setMaxRow(max($compare_topics));
		
		$cellFeed = $service->getCellFeed($query);
		
		// Populate the data_arrays
		$x = 0;
		$y = 0;
		$all_fields = array ("parent_node", "level_1", "level_2", "level_3", "level_4", "level_5", "topic_name", "microscopic_features", "normal_values", "may_resemble", "differential_diagnoses", "classic_immunophenotype", "cartoon", "image", "misc", "additional_images");
		foreach ($cellFeed as $cellEntry) {	// Make a 2-dimensional array of all topics selected
			if (in_array($cellEntry->getCell()->getRow(), $compare_topics)) {
				$atlas_data[$x][$all_fields[$y]] = $cellEntry->getCell()->getText();
				$y++;
				if ($y == ($max_columns - 1)) {
					$y = 0;
					$x++;
				}
			}
		}	

		for ($x = 0; $x < count($atlas_data); $x++) {
			if (stristr($atlas_data[$x]["topic_name"], "diagram")) { // Show full page diagram
				echo "<b>&lsaquo; <i><a href='/atlas.html'>Back to Main Atlas</a></i></b> <br><br>\n";
				echo "<span class='topic_text_shadow'><b>" . $atlas_data[$x]["topic_name"] . "</b></span><br><br>\n";	
				echo "<table width=100% bgcolor='#ffffff'><tr><td align='center' valign='top'>\n";
				if (isset($atlas_data[$x]["image"])) {
					echo "<img usemap='#diagram_map' border='1' src=" . GRAPHICS_DIR . "/" . $atlas_data[$x]["image"] . " />\n";
				} else {
					echo "<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>\n";
				}
				
				if (isset($atlas_data[$x]["misc"])) { // Show caption (uses "misc" column)
					echo "<tr><td align='center'><table border=0><tr><td width=1024><br><b>" . $atlas_data[$x]["misc"] . "</b></td></tr></table></td></tr>\n";
				}
				
				echo "</td></tr></table>\n";
				print_footer();
				exit;
			} else { // Print out topic
				print_topic($x);
				if ($x % 2 == 1) echo "<br clear='all'/><hr>\n"; // Split every two
			}
		}
		print_footer();
		exit;
	}
	
	function print_topic($topic_row) {
		?>
		
		<script type="text/javascript">			                                   			
			$.colorbox.settings.opacity = 0;
			$.colorbox.settings.close = 'Close';
			
			$(document).ready(function(){				
				$(".group1").colorbox({rel:'nofollow', top:"50"});					
				$(".iframe").colorbox({iframe:true, fixed:false, transition:"none", width:"50%", height:"50%", left:"48%", top:"0"});	
				$(".iframe1").colorbox({iframe:true, fixed:false, transition:"none", width:"50%", height:"50%", left:"48%", top:"0"});	
				$(".iframe2").colorbox({iframe:true, fixed:false, transition:"none", width:"50%", height:"50%", left:"0%", top:"0"});	
			});
		</script>
		
		<?php
		global $atlas_data, $popup;
		
		if ($popup == 'true') { 
			echo "<div class='drop-shadow2 raised'>\n";
		} else {
			echo "<div class='drop-shadow raised'>\n";
		}
		?>
		
		<script type="text/javascript">
			document.write("<b>&lsaquo; <i><a href='/atlas.html?cb=" + getParameterByName("cb") + "'>Back to Main Atlas</a></i></b><br>");
		</script>
		
		<?php
			echo "<b>" . $atlas_data[$topic_row]["parent_node"] . " &rsaquo;&rsaquo; " . $atlas_data[$topic_row]["level_1"] . " &rsaquo;&rsaquo; " . $atlas_data[$topic_row]["level_5"] . "</b><br><br>\n";
			echo "<span class='topic_text_shadow'><b>" . $atlas_data[$topic_row]["topic_name"] . "</b></span><br><br><br>\n";	
					
			if ($atlas_data[$topic_row]["image"] != '') { // Print out javascript code for each magnification effect
				?>
			
				<script type="text/javascript">
					// Magnification function
					$(document).ready(function() {
						var left	= 0,
								top		= 0,
								sizes	= { retina<?=$topic_row?>: { width:190, height:190 }, scope_image<?=$topic_row?>:{ width:300, height:225 } },
								scope_image<?=$topic_row?>	= $('#scope_image<?=$topic_row?>'),
								offset	= { left: scope_image<?=$topic_row?>.offset().left, top: scope_image<?=$topic_row?>.offset().top },
								retina<?=$topic_row?>	= $('#retina<?=$topic_row?>');
					
						if(navigator.userAgent.indexOf('Chrome')!=-1) retina<?=$topic_row?>.addClass('chrome');
						
						scope_image<?=$topic_row?>.mousemove(function(e) {
							left = (e.pageX-offset.left);
							top = (e.pageY-offset.top);
					
							if(retina<?=$topic_row?>.is(':not(:animated):hidden')){
								scope_image<?=$topic_row?>.trigger('mouseenter');
							}
					
							if(left<0 || top<0 || left > sizes.scope_image<?=$topic_row?>.width || top > sizes.scope_image<?=$topic_row?>.height) {
								if(!retina<?=$topic_row?>.is(':animated')){
									scope_image<?=$topic_row?>.trigger('mouseleave');
								}
								return false;
							}
					
							retina<?=$topic_row?>.css({
								left				: left - sizes.retina<?=$topic_row?>.width/2,
								top					: top - sizes.retina<?=$topic_row?>.height/2,
								backgroundPosition	: '-'+(1.6*left)+'px -'+(1.35*top)+'px'
							});
							
						}).mouseleave(function(){
							retina<?=$topic_row?>.stop(true,true).fadeOut('fast');
						}).mouseenter(function(){
							retina<?=$topic_row?>.stop(true,true).fadeIn('fast');
						});
						
						// Draggable RBC function						
			  		$('.dg').draggable({
			    		cursor: 'move',        
			    		opacity: 1,         
			    		revert: true,          
			    		revertDuration: 900
			  		});
						
					});
				</script>
			
				<style>
					#scope_image<?=$topic_row?> { /* the image details*/
						width:300px;
						height:225px;
						position:relative;
					}
						
					#retina<?=$topic_row?>.chrome{ /* A special chrome version of the cursor */
						cursor:url('<?=GRAPHICS_DIR?>/blank_google_chrome.cur'),default;
					}
					
					#main{ /* The main div */
						position:relative;
					}
					
					#retina<?=$topic_row?>{ /* The Retina effect */
						background:url('<?=GRAPHICS_DIR?>/<?=$atlas_data[$topic_row]["image"]?>') no-repeat center center white;
						border:2px solid white;
					
						/* Positioned absolutely, so we can move it around */
						position:absolute;
						height:180px;
						width:180px;
					
						display:none; /* Hidden by default */
					
						cursor:url('<?=GRAPHICS_DIR?>/blank.cur'),default; 	/* A blank cursor, notice the default fallback */
						
						/* CSS3 Box Shadow */
						-moz-box-shadow:0 0 5px #777, 0 0 10px #aaa inset;
						-webkit-box-shadow:0 0 5px #777;
						box-shadow:0 0 5px #777, 0 0 10px #aaa inset;
						
						/* CSS3 rounded corners */
						-moz-border-radius:90px;
						-webkit-border-radius:90px;
						border-radius:90px;
					}
				</style>
				
				<div id="main">
					<center>
			    	<div id="scope_image<?=$topic_row?>">
							<img border='1' src="<?=GRAPHICS_DIR?>/<?=$atlas_data[$topic_row]["image"]?>" width="300" height="225" />
			        	<div id="retina<?=$topic_row?>"></div>
			      </div>
			     </center>
				</div>
	
				<?php
				echo "<img align='absbottom' src='" . GRAPHICS_DIR . "/magnify_icon.gif'> <a class='group1' title='" . $atlas_data[$topic_row]["topic_name"] . "' href='" . GRAPHICS_DIR . "/" . $atlas_data[$topic_row]["image"] . "'>Click Here for Full Size</a><br><br><hr><br>\n";
				
				if (!empty($atlas_data[$topic_row]["additional_images"])) {
					unset($additional_images);
					$additional_images = explode(",", str_replace(" ", "", $atlas_data[$topic_row]["additional_images"]));
					for ($n = 0; $n < count($additional_images); $n++) {					
						$num = $n + 1;
						echo "<a class='group1' title='Additional Image: " . $atlas_data[$topic_row]["topic_name"] . "' href='" . GRAPHICS_DIR . "/" . $additional_images[$n] . "'>Additional Image $num</a>\n";
					}
					
					echo "<br><br>\n";
				}
			}
			
			echo "<img align='absbottom' src='" . GRAPHICS_DIR . "/scope_icon.gif'> &rsaquo; <b><u>Microscopic Features:</u></b><ul><b><li> " . str_replace("\n", "<li> ", $atlas_data[$topic_row]["microscopic_features"]) . "</b></ul>\n";
			if (!empty($atlas_data[$topic_row]["normal_values"])) echo "<img align='absbottom' src='" . GRAPHICS_DIR . "/normal_icon.gif'> &rsaquo; <b><u>Normal % blood-PB, marrow-BM, lymphoid tissue-LN:</u></b><ul><b><li> " . str_replace("\n", "<li> ", $atlas_data[$topic_row]["normal_values"]) . "</b></ul>\n";	
			
			// Show popup link [set by {row_id} within the Atlas Google Spreadsheet]
			if (preg_match_all('#\{(.*?)\}#', $atlas_data[$topic_row]["may_resemble"], $match, PREG_PATTERN_ORDER)) {
				for ($r = 0; $r < count($match[1]); $r++) {
					$patterns[] = '/' . $match[1][$r] . '/';
					if ($topic_row % 2 == 1) { // Show popup on the correct side
						$replacements[] = "<a class='iframe2' href='/index.php?SCREEN=atlas_topic&compare_topics[]=" . $match[1][$r] . "'><b>[Compare]$popup_side</b></a>";
					} else {
						$replacements[] = "<a class='iframe1' href='/index.php?SCREEN=atlas_topic&compare_topics[]=" . $match[1][$r] . "'><b>[Compare]$popup_side</b></a>";
					}
				}
				
				$atlas_data[$topic_row]["may_resemble"] = preg_replace($patterns, $replacements, $atlas_data[$topic_row]["may_resemble"], 1);
			}
			
			$brackets = array("{", "}");
			$atlas_data[$topic_row]["may_resemble"] = str_replace($brackets, "", $atlas_data[$topic_row]["may_resemble"]);
							
			echo "<img align='absbottom' src='" . GRAPHICS_DIR . "/resemble_icon.gif'> &rsaquo; <b><u>May Resemble:</u></b><ul><b><li> " . str_replace("\n", "<li> ", $atlas_data[$topic_row]["may_resemble"]) . "</b></ul>\n";
			if (!empty($atlas_data[$topic_row]["differential_diagnoses"])) {
				echo "<img align='absbottom' src='" . GRAPHICS_DIR . "/ddx_icon.gif'> &rsaquo; <b><u>Differential Diagnoses:</u></b><br><br>\n";
				echo "<table align='center' width='95%' bgcolor='#A9E2F3' border='0' cellpadding='5'><tr><td><b>" . str_replace("\n", "<br>", $atlas_data[$topic_row]["differential_diagnoses"]) . "</b></td></tr></table><br>\n";
			}
			if (!empty($atlas_data[$topic_row]["classic_immunophenotype"])) echo "<img align='absbottom' src='" . GRAPHICS_DIR . "/immuno_icon.gif'> &rsaquo; <b><u>Classic Immunophenotype:</u></b><ul><b><li> " . str_replace("\n", "<li> ", $atlas_data[$topic_row]["classic_immunophenotype"]) . "</b></ul>\n";
			if (!empty($atlas_data[$topic_row]["cartoon"])) {
				echo "<img align='absbottom' src='" . GRAPHICS_DIR . "/cartoon_icon.gif'> &rsaquo; <b><u>Cartoon Image:</u></b><center><br><br><img border='1' src='" . GRAPHICS_DIR . "/" . $atlas_data[$topic_row]["cartoon"] . "'></center><br>\n";
				
				// Adjust RBC size according to cartoon scale
				$factor_twos = Array ('Megakaryocyte*','Dyslobated (Abnormal Lobation) Megakaryocyte*','Hypolobated Megakaryocytes (Increased)*','Staghorn-shaped Megakaryocyte*');
				$no_shows = Array ('Normal Lymph Node*','Rouleaux*','Infectious-Microfilaria*','Infectious-Trypanosoma*','Follicular Lymphoma*','Mantle Cell Lymphoma*','Burkitt Lymphoma*','MALT Lymphoma (e.g. Gastric)*');
				if (in_array($atlas_data[$topic_row]["topic_name"], $factor_twos)) {
					$factor = 97/2;
				} else {
					$factor = 97/1; 
				}
				
				if (!(bool) strpos($_SERVER['HTTP_USER_AGENT'],'iPad')) {
					if (!in_array($atlas_data[$topic_row]["topic_name"], $no_shows)) {
						echo "<center>Click and drag<br><img src='" . GRAPHICS_DIR . "/rbc_clear.gif' alt='RBC' width='$factor' class='dg' /><br>for direct comparison</center><br>";
					}
				}
			}
			if (!empty($atlas_data[$topic_row]["misc"])) echo "<img align='absbottom' src='" . GRAPHICS_DIR . "/misc_icon.gif'> &rsaquo; <b><u>Misc:</u></b><ul><b><li> " . $atlas_data[$topic_row]["misc"] . "</b></ul>\n";
		echo "</div>\n";
	}
	
	/////////////////////////////////////////////////////////////////////////////////////////////////
	// DEFAULT VIEW - FLOWCHART
	if (empty($atlas_topic_row) && empty($compare_topics)) {
		?>
		
		<script type="text/javascript">                                         
			
		
			var ol_shadowcolor = '#000000';
			var ol_shadowopacity = 60;
			
			$.colorbox.settings.opacity = 0.7;
			$.colorbox.settings.close = 'Return to Mindmap';
			
			$(document).ready(function(){
				var modal = getParameterByName("cb");

				if(modal != "") {
					$.colorbox({
						href: "#" + modal,
						inline: true,
						width:"75%"
					});
				}
				
				$(".inline").colorbox({inline:true, width:"75%"});	
				$(".overview").colorbox({inline:true, width:"100%"});	
			});
		</script>
		
		<center>
			<img src="<?=GRAPHICS_DIR?>/hematology_atlas_flowchart.jpg" class="map" usemap="#squidhead" border="0" width="928" height="704" alt="" />
			<map name="squidhead">
				<area href="javascript:void(0);" onClick="return overlib('The central (primary) hematopoietic and lymphoid tissues include the bone marrow and thymus. They generate myeloid and lymphoid cells.  All hematopoietic cells originate from bone marrow.  B-cells start maturing within the bone marrow while T-cells mature in the thymus.', CAPTION, 'Primary Hematopoietic & Lymphoid Tissue', BGCOLOR, '#FDD017', FGCOLOR, '#cccccc', CAPCOLOR, '#000000', SHADOW, WIDTH, 300, VAUTO);" onmouseout="return nd();" shape="rect" coords="159,140,327,186" />
				<area href="javascript:void(0);" onClick="return overlib('Secondary lymphoid tissues, also known as peripheral lymphoid organs, include lymph nodes, mucosa-associated lymphoid tissue (MALT), and the spleen. The mature T-cells from the thymus may take residence in these tissues/organs. Additionally, B-cells complete their maturation cycle within these tissues/organs and specialized compartments of secondary follicles known as germinal centers. Most B-cells reside in the follicles whereas most T-cells reside between the follicles (in the interfollicular areas).', CAPTION, 'Secondary Lymphoid Organs', BGCOLOR, '#348017', FGCOLOR, '#cccccc', SHADOW, WIDTH, 300, VAUTO);" onmouseout="return nd();" shape="rect" coords="159,354,359,388" />
				<area href="javascript:void(0);" onClick="return overlib('The blood consists of cellular and plasma components. The cellular component is comprised of red blood cells, platelets, and white blood cells (neutrophils, lymphocytes, monocytes, eosinophils, and basophils; in order of prevalance).', CAPTION, 'Peripheral Blood Components', BGCOLOR, '#800517', FGCOLOR, '#cccccc', SHADOW, WIDTH, 300, VAUTO);" onmouseout="return nd();" shape="rect" coords="159,540,434,574" />
				<area href="javascript:void(0);" onClick="return overlib('The bone marrow is a spongy tissue found within bone and is where the hematopoietic cells originate, including the myeloid and lymphoid lineages.', CAPTION, 'Bone Marrow', BGCOLOR, '#FDD017', FGCOLOR, '#cccccc', CAPCOLOR, '#000000', SHADOW, WIDTH, 300, VAUTO);" onmouseout="return nd();" shape="rect" coords="379,145,480,180" />
				<area class="overview" href="#overview_content_100" shape="rect" coords="64,13,406,88" />
				<area class="inline" href="#inline_content_4" alt="Thymus" shape="rect" coords="381,245,449,280" />
				<area class="inline" href="#inline_content_1" alt="Lymph Node" shape="rect" coords="398,306,488,340" />
				<area class="inline" href="#inline_content_3" alt="Mucosa-Associated Lymphoid Tissue" shape="rect" coords="398,353,656,388" />
				<area class="inline" href="#inline_content_2" alt="Spleen" shape="rect" coords="398,400,459,435" />
				<area class="inline" href="#inline_content_5" alt="Peripheral Blood/Red Blood Cells" shape="rect" coords="474,421,580,456" />
				<area class="inline" href="#inline_content_6" alt="Peripheral Blood/Neutrophils" shape="rect" coords="472,469,562,504" />
				<area class="inline" href="#inline_content_7" alt="Peripheral Blood/Lymphocytes" shape="rect" coords="473,515,569,550" />
				<area class="inline" href="#inline_content_8" alt="Peripheral Blood/Monocytes" shape="rect" coords="473,563,557,598" />
				<area class="inline" href="#inline_content_9" alt="Peripheral Blood/Eosinophils/Basophils" shape="rect" coords="474,610,620,645" />
				<area class="inline" href="#inline_content_10" alt="Peripheral Blood/Platelets" shape="rect" coords="474,658,544,692" />
				<area href="javascript:void(0);" onClick="return overlib('Myeloid cells refer to cells that are originally from myeloid stem cells, which include cells from the erythroid, granulocytic, monocytic, and megakaryocytic series.', CAPTION, 'Bone Marrow - Myeloid', BGCOLOR, '#6698FF', FGCOLOR, '#cccccc', SHADOW, WIDTH, 300, VAUTO);" onmouseout="return nd();" shape="rect" coords="517,75,585,109" />
				<area href="javascript:void(0);" onClick="return overlib('Lymphoid cells originate from lymphoid precursors which give rise to T-cells, B-cells, and NK-cells.', CAPTION, 'Bone Marrow - Lymphoid', BGCOLOR, '#8B31C7', FGCOLOR, '#cccccc', SHADOW, WIDTH, 300, VAUTO);" onmouseout="return nd();" shape="rect" coords="519,239,595,273" />
				<area class="inline" href="#inline_content_15" alt="Bone Marrow/Erythroid" shape="rect" coords="623,4,805,39" />
				<area class="inline" href="#inline_content_21" alt="Bone Marrow/Granulocytes and Precursors" shape="rect" coords="623,52,791,87" />
				<area class="inline" href="#inline_content_19" alt="Bone Marrow/Monocytes and Precursors" shape="rect" coords="624,97,778,133" />
				<area class="inline" href="#inline_content_20" alt="Bone Marrow/Megakaryocytes and Precursors" shape="rect" coords="624,145,804,181" />
				<area class="inline" href="#inline_content_11" alt="Bone Marrow/Lymphoid/T-cells" shape="rect" coords="633,194,693,230" />
				<area href="javascript:void(0);" onClick="return overlib('B-cells include early and maturing/mature B-cells. Plasma cells are terminally differentiated B-cells.', CAPTION, 'Bone Marrow - Lymphoid - B-cell Lineage', BGCOLOR, '#8B31C7', FGCOLOR, '#cccccc', SHADOW, WIDTH, 300, VAUTO);" onmouseout="return nd();" shape="rect" coords="633,238,729,274" />
				<area class="inline" href="#inline_content_14" alt="Bone Marrow/Lymphoid/NK Cells" shape="rect" coords="633,283,703,319" />
				<area class="inline" href="#inline_content_16" alt="Bone Marrow/Granulocytes/Neutrophilic" shape="rect" coords="830,3, 920,39" />
				<area class="inline" href="#inline_content_17" alt="Bone Marrow/Granulocytes/Eosinophilic" shape="rect" coords="830,51,920,87" />
				<area class="inline" href="#inline_content_18" alt="Bone Marrow/Granulocytes/Basophilic" shape="rect" coords="830,98,909,134" />
				<area class="inline" href="#inline_content_12" alt="Bone Marrow/Lymphoid/B-cells" shape="rect" coords="768,215,827,251" />
				<area class="inline" href="#inline_content_13" alt="Bone Marrow/Lymphoid/Plasma Cells" shape="rect" coords="768,262,858,298" />
				<area href="http://itunes.apple.com/us/app/hematology-outlines/id521029633?mt=8&ls=1" shape="rect" coords="749,643,925,701" />
			</map>
		</center>

		<?php
	} // END DEFAULT VIEW
?>

<!-- Hematopoiesis Overview -->
<div style='display:none'>
	<div id='overview_content_100' style='padding:10px; background:#fff;'>
		<table class="content" bgcolor='#000000' width='100%' cellpadding='0'>
				<tr>
						<td bgcolor='#ffffff'>
							<center>
								<b>Click image for full size</b><br>
								<a href="<?=GRAPHICS_DIR?>/Hematopoiesis_Overview.jpg"><img width='1000' border=0 src="<?=GRAPHICS_DIR?>/Hematopoiesis_Overview.jpg"></a><br><br>
							</center>
						</td>
				</tr>
		</table>			
	</div>
</div> 

<!-- Erythroid -->
<div style='display:none'>
	<div id='inline_content_15' style='padding:10px; background:#fff;'>
		<table class="content" bgcolor='#6698FF' width='100%' cellpadding='5'>
				<tr>
						<td bgcolor='#ffffff'><h2>Bone Marrow: Erythroid (RBCs and Precursors) </h2></td>
				</tr>
				<tr>
						<td bgcolor='#ffffff'>
							<?php	display_subcategory('inline_content_15', 'Primary Hematopoietic and Lymphoid Tissue', 'Bone Marrow', 'Myeloid', 'Erythroid (RBCs & Precursors)', ''); ?>
						</td>
				</tr>
		</table>			
	</div>
</div> 

<!-- Granulocytes and Precursors -->
<div style='display:none'>
	<div id='inline_content_21' style='padding:10px; background:#fff;'>
		<table class="content" bgcolor='#6698FF' width='100%' cellpadding='5'>
				<tr>
						<td bgcolor='#ffffff'><h2>Bone Marrow: Granulocytes and Precursors </h2></td>
				</tr>
				<tr>
						<td bgcolor='#ffffff'>
							<?php	display_subcategory('inline_content_21', 'Primary Hematopoietic and Lymphoid Tissue', 'Bone Marrow', 'Myeloid', 'Granulocytes & Precursors', ''); ?>
						</td>
				</tr>
		</table>			
	</div>
</div> 

<!-- Neutrophilic -->
<div style='display:none'>
	<div id='inline_content_16' style='padding:10px; background:#fff;'>
		<table class="content" bgcolor='#6698FF' width='100%' cellpadding='5'>
				<tr>
						<td bgcolor='#ffffff'><h2>Bone Marrow: Neutrophilic </h2></td>
				</tr>
				<tr>
						<td bgcolor='#ffffff'>
							<?php	display_subcategory('inline_content_16', 'Primary Hematopoietic and Lymphoid Tissue', 'Bone Marrow', 'Myeloid', 'Granulocytes & Precursors', 'Neutrophilic'); ?>
						</td>
				</tr>
		</table>			
	</div>
</div> 

<!-- Eosinophilic -->
<div style='display:none'>
	<div id='inline_content_17' style='padding:10px; background:#fff;'>
		<table class="content" bgcolor='#6698FF' width='100%' cellpadding='5'>
				<tr>
						<td bgcolor='#ffffff'><h2>Bone Marrow: Eosinophilic </h2></td>
				</tr>
				<tr>
						<td bgcolor='#ffffff'>
							<?php	display_subcategory('inline_content_17', 'Primary Hematopoietic and Lymphoid Tissue', 'Bone Marrow', 'Myeloid', 'Granulocytes & Precursors', 'Eosinophilic'); ?>
						</td>
				</tr>
		</table>			
	</div>
</div> 

<!-- Basophilic -->
<div style='display:none'>
	<div id='inline_content_18' style='padding:10px; background:#fff;'>
		<table class="content" bgcolor='#6698FF' width='100%' cellpadding='5'>
				<tr>
						<td bgcolor='#ffffff'><h2>Bone Marrow: Basophilic </h2></td>
				</tr>
				<tr>
						<td bgcolor='#ffffff'>
							<?php	display_subcategory('inline_content_18', 'Primary Hematopoietic and Lymphoid Tissue', 'Bone Marrow', 'Myeloid', 'Granulocytes & Precursors', 'Basophilic'); ?>
						</td>
				</tr>
		</table>			
	</div>
</div> 

<!-- Monocytes and Precursors -->
<div style='display:none'>
	<div id='inline_content_19' style='padding:10px; background:#fff;'>
		<table class="content" bgcolor='#6698FF' width='100%' cellpadding='5'>
				<tr>
						<td bgcolor='#ffffff'><h2>Bone Marrow: Monocytes and Precursors </h2></td>
				</tr>
				<tr>
						<td bgcolor='#ffffff'>
							<?php	display_subcategory('inline_content_19', 'Primary Hematopoietic and Lymphoid Tissue', 'Bone Marrow', 'Myeloid', 'Monocytes & Precursors', ''); ?>
						</td>
				</tr>
		</table>			
	</div>
</div> 

<!-- Megakaryocytes and Precursors -->
<div style='display:none'>
	<div id='inline_content_20' style='padding:10px; background:#fff;'>
		<table class="content" bgcolor='#6698FF' width='100%' cellpadding='5'>
				<tr>
						<td bgcolor='#ffffff'><h2>Bone Marrow: Megakaryocytes and Precursors </h2></td>
				</tr>
				<tr>
						<td bgcolor='#ffffff'>
							<?php	display_subcategory('inline_content_20', 'Primary Hematopoietic and Lymphoid Tissue', 'Bone Marrow', 'Myeloid', 'Megakaryocytes & Precursors', ''); ?>
						</td>
				</tr>
		</table>			
	</div>
</div> 

<!-- Bone Marrow: T-cells -->
<div style='display:none'>
	<div id='inline_content_11' style='padding:10px; background:#fff;'>
		<table class="content" bgcolor='#461B7E' width='100%' cellpadding='5'>
				<tr>
						<td bgcolor='#ffffff'><h2>Bone Marrow: T-cells </h2></td>
				</tr>
				<tr>
						<td bgcolor='#ffffff'>
							<?php	display_subcategory('inline_content_11', 'Primary Hematopoietic and Lymphoid Tissue', 'Bone Marrow', 'Lymphoid', 'T-cells', ''); ?>
						</td>
				</tr>
		</table>			
	</div>
</div> 

<!-- B-cells -->
<div style='display:none'>
	<div id='inline_content_12' style='padding:10px; background:#fff;'>
		<table class="content" bgcolor='#C031C7' width='100%' cellpadding='5'>
				<tr>
						<td bgcolor='#ffffff'><h2>Bone Marrow: B-cells </h2></td>
				</tr>
				<tr>
						<td bgcolor='#ffffff'>
							<?php	display_subcategory('inline_content_12', 'Primary Hematopoietic and Lymphoid Tissue', 'Bone Marrow', 'Lymphoid', 'B-cells', ''); ?>
						</td>
				</tr>
		</table>			
	</div>
</div> 

<!-- Plasma Cells -->
<div style='display:none'>
	<div id='inline_content_13' style='padding:10px; background:#fff;'>
		<table class="content" bgcolor='#C031C7' width='100%' cellpadding='5'>
				<tr>
						<td bgcolor='#ffffff'><h2>Bone Marrow: Plasma Cells </h2></td>
				</tr>
				<tr>
						<td bgcolor='#ffffff'>
							<?php	display_subcategory('inline_content_13', 'Primary Hematopoietic and Lymphoid Tissue', 'Bone Marrow', 'Lymphoid', 'Plasma Cells', ''); ?>
						</td>
				</tr>
		</table>			
	</div>
</div>

<!-- NK Cells -->
<div style='display:none'>
	<div id='inline_content_14' style='padding:10px; background:#fff;'>
		<table class="content" bgcolor='#461B7E' width='100%' cellpadding='5'>
				<tr>
						<td bgcolor='#ffffff'><h2>Bone Marrow: NK Cells </h2></td>
				</tr>
				<tr>
						<td bgcolor='#ffffff'>
							<?php	display_subcategory('inline_content_14', 'Primary Hematopoietic and Lymphoid Tissue', 'Bone Marrow', 'Lymphoid', 'NK Cells', ''); ?>
						</td>
				</tr>
		</table>			
	</div>
</div> 

<!-- Thymus -->
<div style='display:none'>
	<div id='inline_content_4' style='padding:10px; background:#fff;'>
		<table class="content" bgcolor='#FDD017' width='100%' cellpadding='5'>
				<tr>
						<td bgcolor='#ffffff'><h2>Thymus </h2></td>
				</tr>
				<tr>
						<td bgcolor='#ffffff'>
							<?php	display_subcategory('inline_content_4', 'Primary Hematopoietic and Lymphoid Tissue', 'Thymus', 'Thymus', 'Thymus', ''); ?>
						</td>
				</tr>
		</table>			
	</div>
</div> 

<!-- Lymph Node -->
<div style='display:none'>
	<div id='inline_content_1' style='padding:10px; background:#fff;'>
		<table class="content" bgcolor='#59E817' width='100%' cellpadding='5'>
				<tr>
						<td bgcolor='#ffffff'><h2>Lymph Node </h2></td>
				</tr>
				<tr>
						<td bgcolor='#ffffff'>
							<?php	display_subcategory('inline_content_1', 'Secondary Lymphoid Tissues', 'Lymph Node', 'Lymph Node', 'Lymph Node', ''); ?>
						</td>
				</tr>
		</table>			
	</div>
</div> 

<!-- Mucosa-Associated Lymphoid Tissue -->
<div style='display:none'>
	<div id='inline_content_3' style='padding:10px; background:#fff;'>
		<table class="content" bgcolor='#59E817' width='100%' cellpadding='5'>
				<tr>
						<td bgcolor='#ffffff'><h2>Mucosa-Associated Lymphoid Tissue (MALT) </h2></td>
				</tr>
				<tr>
						<td bgcolor='#ffffff'>
							<?php	display_subcategory('inline_content_3', 'Secondary Lymphoid Tissues', 'Mucosa-Associated Lymphoid Tissue (MALT)', 'MALT', 'MALT', ''); ?>
						</td>
				</tr>
		</table>			
	</div>
</div> 

<!-- Spleen -->
<div style='display:none'>
	<div id='inline_content_2' style='padding:10px; background:#fff;'>
		<table class="content" bgcolor='#59E817' width='100%' cellpadding='5'>
				<tr>
						<td bgcolor='#ffffff'><h2>Spleen </h2></td>
				</tr>
				<tr>
						<td bgcolor='#ffffff'>
							<?php	display_subcategory('inline_content_2', 'Secondary Lymphoid Tissues', 'Spleen', 'Spleen', 'Spleen', ''); ?>
						</td>
				</tr>
		</table>			
	</div>
</div> 

<!-- Red Blood Cells: In Blood-->
<div style='display:none'>
	<div id='inline_content_5' style='padding:10px; background:#fff;'>
		<table class="content" bgcolor='#E41B17' width='100%' cellpadding='5'>
				<tr>
						<td bgcolor='#ffffff'><h2>Peripheral Blood: Red Blood Cells </h2></td>
				</tr>
				<tr>
						<td bgcolor='#ffffff'>
							<?php	display_subcategory('inline_content_5', 'Blood/Blood Cells and Cellular Components', 'Red Blood Cells', 'Red Blood Cells', 'Red Blood Cells', ''); ?>
						</td>
				</tr>
		</table>			
	</div>
</div> 

<!-- Neutrophils: In Blood -->
<div style='display:none'>
	<div id='inline_content_6' style='padding:10px; background:#fff;'>

	<table class="content" bgcolor='#E41B17' width='100%' cellpadding='5'>
			<tr>
					<td bgcolor='#ffffff'><h2>Peripheral Blood: Neutrophils </h2></td>
			</tr>
			<tr>
					<td bgcolor='#ffffff'>
						<?php	display_subcategory('inline_content_6', 'Blood/Blood Cells and Cellular Components', 'Neutrophils', 'Neutrophils', 'Neutrophils', ''); ?>
					</td>
			</tr>
	</table>			

	</div>
</div> 

<!-- Eosinophils: In Blood -->
<div style='display:none'>
	<div id='inline_content_9' style='padding:10px; background:#fff;'>
		<table class="content" bgcolor='#E41B17' width='100%' cellpadding='5'>
				<tr>
						<td bgcolor='#ffffff'><h2>Peripheral Blood: Eosinophils and Basophils</h2></td>
				</tr>
				<tr>
						<td bgcolor='#ffffff'>
							<?php	display_subcategory('inline_content_9', 'Blood/Blood Cells and Cellular Components', 'Eosinophils and Basophils', 'Eosinophils', 'Eosinophils', ''); ?>
						</td>
				</tr>
		</table>			
	</div>
</div> 

<!-- Monocytes: In Blood -->
<div style='display:none'>
	<div id='inline_content_8' style='padding:10px; background:#fff;'>
		<table class="content" bgcolor='#E41B17' width='100%' cellpadding='5'>
				<tr>
						<td bgcolor='#ffffff'><h2>Peripheral Blood: Monocytes </h2></td>
				</tr>
				<tr>
						<td bgcolor='#ffffff'>
							<?php	display_subcategory('inline_content_8', 'Blood/Blood Cells and Cellular Components', 'Monocytes', 'Monocytes', 'Monocytes', ''); ?>
						</td>
				</tr>
		</table>			
	</div>
</div> 

<!-- Lymphocytes: In Blood -->
<div style='display:none'>
	<div id='inline_content_7' style='padding:10px; background:#fff;'>
		<table class="content" bgcolor='#E41B17' width='100%' cellpadding='5'>
				<tr>
						<td bgcolor='#ffffff'><h2>Peripheral Blood: Lymphocytes </h2></td>
				</tr>
				<tr>
						<td bgcolor='#ffffff'>
							<?php	display_subcategory('inline_content_7', 'Blood/Blood Cells and Cellular Components', 'Lymphocytes', 'Lymphocytes', 'Lymphocytes', ''); ?>
						</td>
				</tr>
		</table>			
	</div>
</div> 

<!-- Platelets: In Blood -->
<div style='display:none'>
	<div id='inline_content_10' style='padding:10px; background:#fff;'>
		<table class="content" bgcolor='#E41B17' width='100%' cellpadding='5'>
				<tr>
						<td bgcolor='#ffffff'><h2>Peripheral Blood: Platelets </h2></td>
				</tr>
				<tr>
						<td bgcolor='#ffffff'>
							<?php	display_subcategory('inline_content_10', 'Blood/Blood Cells and Cellular Components', 'Platelets', 'Platelets', 'Platelets', ''); ?>
						</td>
				</tr>
		</table>			
	</div>
</div> 

<?php	
	// Function to display subcategory
	function display_subcategory($cb, $parent_node, $level1, $level2, $level3, $level4) {
		global $atlas_parent_nodes, $atlas_level1, $atlas_level2, $atlas_level3, $atlas_level4, $atlas_level5, $atlas_topic_names, $atlas_rows;
		
		echo "<form name='comparison' action='index.php' method='GET'>\n";
		echo "<input type='hidden' name='cb' value='$cb'>\n";
		echo "<input type='hidden' name='SCREEN' value='atlas'>\n";
		echo "<table class='popup' border='0' cellspacing='0' cellpadding='1' width='100%'>\n";
		
		// Default view
		for ($x = 0; $x < count($atlas_parent_nodes); $x++) { // Loop through all entries
			if ($atlas_parent_nodes[$x] == $parent_node && $atlas_level1[$x] == $level1 && $atlas_level2[$x] == $level2 && $atlas_level3[$x] == $level3 && $atlas_level4[$x] == $level4) {
				$bgcolor == '#eeeeee' ? $bgcolor = '#dddddd' : $bgcolor = '#eeeeee';
				$cellcolor == '#cccccc' ? $cellcolor = '#bbbbbb' : $cellcolor = '#cccccc';
				
				if ($atlas_topic_names[$x] == '') break;
				
				echo "<tr class='popup' valign='top' bgcolor='$bgcolor'>\n";
					if ($atlas_level5[$x] == 'Normal') {
						echo "<td><font color='#347C17'><b>" . $atlas_level5[$x] . "</b></font></td>\n";
					} elseif ($atlas_level5[$x] == 'Abnormal') {
						echo "<td><font color='#800517'><b>" . $atlas_level5[$x] . "</b></font></td>\n";
					} else {
						echo "<td><b>" . $atlas_level5[$x] . "</b></td>\n";
					}

					if (!stristr($atlas_topic_names[$x], 'diagram')) { // Link to show diagram only page
						echo "<td width='20'><input type='checkbox' name='compare_topics[]' value='$atlas_rows[$x]'></td>\n";
					} else {
						echo "<td width='20'>&#9658;</td>\n";
					}
					
					echo "<td><a href='/atlas_topics/$atlas_rows[$x].html?topic=$atlas_topic_names[$x]&cb=$cb'>" . $atlas_topic_names[$x] . "</a></td>\n";
					echo "</tr>\n";
				}
		}
		
		echo "<tr><td colspan='2'>&nbsp;</td><td><input name='compare' class='mono11' type='submit' value='Compare Selected'> <input type='reset' class='mono11' value='Reset All'></td></tr>\n";
		echo "</table>\n";
		echo "</form>\n";
	}
	
	echo "<center><br><br>\n";
	echo "<img src='" . GRAPHICS_DIR . "/grad_cap.gif'> <b>Test your knowledge:</b> <a href='index.php?SCREEN=atlas_peripheral_blood'>Peripheral Blood Smear</a><br>\n";
	echo "<img src='" . GRAPHICS_DIR . "/grad_cap.gif'> <b>Test your knowledge:</b> <a href='index.php?SCREEN=atlas_BM_quiz'>Multiple Choice Quiz (Bone Marrow Components)</a><br>\n";
	echo "<img src='" . GRAPHICS_DIR . "/grad_cap.gif'> <b>Test your knowledge:</b> <a href='index.php?SCREEN=atlas_PB_quiz'>Multiple Choice Quiz (Peripheral Blood Components)</a><br>\n";
	echo "<img src='" . GRAPHICS_DIR . "/grad_cap.gif'> <b>Test your knowledge:</b> <a href='index.php?SCREEN=glossary_matching_all'>Glossary Matching - All Terms</a><br><br>\n";
	echo "</center>\n";
	
	// Write php output to static atlas.html file
	print_footer();
	
	if (empty($compare_topics) && empty($atlas_topic_row)) {
		file_put_contents('atlas.html', ob_get_contents());	
	}
	
	ob_end_flush(); 
	exit;
?>