<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
  
	// load viewer library
	$libraryPath = 'admin/lib/viewer_functions.php';
	$dirsToCheck = array('/home7/mizrahio/public_html/hunt_dev/','','../','../../','../../../');
	foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
	if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }
	
	// load section nav
	list($subnav, $subnavCategory) = getCategories(array(
		'tableName'     => 'archives',
		'defaultCategory'	=> 'first',
		'categoryFormat'=> 'onelevel',
	));
	
	// load page content
	list($page, $pageMetaData) = getRecords(array(
		'tableName'   => 'archives',
		'where'       => whereRecordNumberInUrl(1),
		'limit'       => '1',
	));
	$page = @$page[0]; // get first record

?>

<?php
	
	$pagetitle = $page['name'];
	$sectiontitle = "Archives";
	$bodyclass = "archives";
	include("../includes/header.inc.php");

?>

		
<div class="sidebar">
	
	<h3><?php echo $sectiontitle ?></h3>
	
	<?php include("../includes/subnav.inc.php"); ?>

</div><!-- /subnav -->

<div class="maincontent">
	
	<h2><?php echo htmlencode($page['name']) ?></h2>
	
	<div class="
		<?php if ($page['two_column_layout']): ?>
			twocolumn
		<?php else: ?>
			onecolumn
		<?php endif ?>
	 group">
	
		<div class="primary">
			
			<?php echo $page['primary_content']; ?>
							
			<?php	
				
				if ($page['num'] == "2"):
				
				// online collections
				list($collections, $collectionsMetaData) = getRecords(array(
				  'tableName'   => 'online_collections',
				  'loadUploads' => true,
				  'allowSearch' => false,
				));
				
				// create array 
				$recordsByFirstLetter = array('A' => array(),'B' => array(), 'C' => array(), 'D' => array(),'E' => array(), 'F' => array(),
				                     	      'G' => array(),'H' => array(), 'I' => array(),'J' => array(),'K' => array(), 'L' => array(),
				                    	      'M' => array(),'N' => array(), 'O' => array(),'P' => array(),'Q' => array(), 'R' => array(),
				                    	      'S' => array(),'T' => array(), 'U' => array(),'V' => array(),'W' => array(), 'X' => array(),
				                    	      'Y' => array(),'Z' => array()); 
				
				// populate array 
				foreach($collections as $record){
					// get the first letter of the service_desc 
					$firstLetter = strtoupper(substr(trim($record['title']),0,1)); 
					
					// add record to the array based on it's first letter 
					$recordsByFirstLetter[$firstLetter][]=$record;
				}
			
			?>
				
				<script type="text/javascript">
				    $(function() {
				        var availableTags = [
				            <?php foreach($collections as $record): ?>
				            	"<?php echo $record['title'] ?>",
				            <?php endforeach ?>
				        ];
				        $("#tags").autocomplete({
				            source: availableTags
				        });
				    });
				</script>
				
				<div class="ui-widget archiveSearch">
					<label for="tags">"Live search"</label>
					<input id="tags" />
				</div><!-- /archiveSearch -->

				<div class="archiveSearch">
					<form id="form1" method="POST" action="search.php" >
						<input type="text" name="archives" placeholder="Search..."><input type="submit" value="search">
					</form>
				</div>
			
				<div class="filter section">
					<?php foreach($recordsByFirstLetter as $firstLetter => $records): ?>
						<?php if($records):?>
							<a href="#<?php echo $firstLetter ?>"><?php echo $firstLetter ?></a>
						<?php else: ?>
							<span><?php echo $firstLetter ?></span>
						<?php endif ?>
					<?php endforeach ?>
				</div><!-- /filter -->
				
				<div class="divider">
					
					<?php foreach($recordsByFirstLetter as $firstLetter => $records):?>  

						<?php if($records):?>
							<h3>
								<a name="<?php echo $firstLetter; ?>"></a>
								<?php echo $firstLetter; ?>
							</h3>
						<?php endif ?>

						<ul class="collections">
							
							<?php foreach($records as $record): ?>
							
								<li>
									<h4>
										<?php if ($record['show_expanded'] && $record['primary_content']): ?>
											<a href="detail.php?<?php echo $record['num'] ?>"><?php echo $record['title'] ?></a>
										<?php else: ?>
											<?php echo $record['title'] ?>
										<?php endif ?>
									</h4>
									<?php echo $record['short_description'] ?>
								</li>
							
							<?php endforeach ?>  
							
						</ul>
						
					<?php endforeach ?>
				
				</div><!-- /divider -->
					
			<?php endif ?>
					
		</div><!-- /primary -->
		
		<div class="secondary">
			
			<?php echo $page['secondary_content']; ?>
			
		</div><!--/secondary-->
	
	</div>
	
</div><!--/maincontent-->

<?php include("../includes/footer.inc.php"); ?>
