<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
	$libraryPath = 'admin/lib/viewer_functions.php';
	$dirsToCheck = array('/home/content/j/d/a/jdancisin/html/clientdev/lasasections/','','../','../../','../../../');
	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 sections for drop down menu
	list($sectionsdropdown, $sectionsdropdownMetaData) = getRecords(array(
		'tableName'   => 'sections',
		'loadUploads' => '0',
		'allowSearch' => '0',
	));

	// load news categories
	list($news_categories, $news_categoriesMetaData) = getRecords(array(
		'tableName'   => 'news_categories',
		'allowSearch' => '0',
	));

	// load events categories
	list($events_categories, $events_categoriesMetaData) = getRecords(array(
		'tableName'   => 'events_categories',
		'allowSearch' => '0',
	));

	// load general section info
	list($sectionsRecords, $sectionsMetaData) = getRecords(array(
		'tableName'   => 'sections',
		'where'       => "id='template'",
		'limit'       => '1',
		'allowSearch' => '0',
	));
	$sectionsRecord = @$sectionsRecords[0]; // get first record

	// load main navigation
	list($categoryRecords, $selectedCategory) = getCategories(array(
	  'tableName'     => 'pages_template',
	  'defaultCategory'	=> 'first',
	  'categoryFormat'=> 'onelevel',
	));

	// load page content
	list($pagesRecords, $pagesMetaData) = getRecords(array(
		'tableName'   => 'pages_template',
		'where'       => whereRecordNumberInUrl(1),
		'limit'       => '1',
	));
	$pagesRecord = @$pagesRecords[0]; // get first record

	// load current news
	list($current_news, $current_newsMetaData) = getRecords(array(
		'tableName'   => 'news_items_template',
		'loadUploads' => '0',
	));

	// load upcoming events
	list($upcoming_events, $upcoming_eventsMetaData) = getRecords(array(
		'tableName'   => 'events_template',
		'loadUploads' => '0',
	));


  // load news record details
  list($news_details, $news_items_templateMetaData) = getRecords(array(
    'tableName'   => 'news_items_template',
    'where'       => whereRecordNumberInUrl(1),
    'limit'       => '1',
  ));
  $news_details = @$news_details[0]; // get first record


  // load event record details
  list($events_details, $events_templateMetaData) = getRecords(array(
    'tableName'   => 'events_template',
    'where'       => whereRecordNumberInUrl(1),
    'limit'       => '1',
  ));
  $events_details = @$events_details[0]; // get first record


?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<title><?php echo $pagesRecord['name'] ?> | LASA: <?php echo $sectionsRecord['title'] ?></title>
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<meta name="language" content="<?php echo $sectionsRecord['primary_language'] ?>" />
	<meta name="description" content="<?php echo $sectionsRecord['meta_description'] ?>" />
	<meta name="keywords" content="<?php echo $sectionsRecord['keywords'] ?>" />
	<link href="../styles/reset.css" rel="stylesheet" type="text/css" media="screen, projection, print" />
	<link href="../styles/default.css" rel="stylesheet" type="text/css" media="screen, projection" />
	<!--[if IE 6]><link href="../styles/ie6.css" rel="stylesheet" type="text/css" media="screen, projection" /><![endif]-->
	<!--[if IE 7]><link href="../styles/ie7.css" rel="stylesheet" type="text/css" media="screen, projection" /><![endif]-->
	<link href="../styles/print.css" rel="stylesheet" type="text/css" media="print" />

	<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>

	<!-- jquery cycle plugin -->
		<script type="text/javascript" src="../scripts/jquery.cycle.all.js"></script>
		<script type="text/javascript" src="../scripts/jquery.cycle.trans.js"></script>

	<!-- jquery fancybox -->
		<script type="text/javascript" src="../fancybox/jquery.mousewheel-3.0.4.pack.js"></script>
		<script type="text/javascript" src="../fancybox/jquery.fancybox-1.3.4.js"></script>
		<link rel="stylesheet" type="text/css" href="../fancybox/jquery.fancybox-1.3.4.css" media="screen" />

	<script type="text/javascript" src="../scripts/jquery.common.functions.js"></script>

	<!-- google analytics -->

</head>
<body class="pagetype section">

<div class="pagewrap">
	<div class="other-sections">
		<form name="drop_menu" method="POST">
			<label>Other LASA Sections:</label>
			<select name="other_sections" onchange="window.location.href=this.options[this.selectedIndex].value;">
				<option>-- Select --</option>
				<?php foreach ($sectionsdropdown as $record): ?>
					<option value="<?php if($record['website_url']) echo $record['website_url']; else echo "/".$record['id'];  ?>"<?php if ($sectionsRecord['num']==$record['num']) echo " selected='selected'" ?>>
						<?php echo $record['title'] ?>
					</option>
				<?php endforeach ?>
			</select>
		</form>
	</div>
	<div class="masthead">
		<div class="section-header">
			<h1><a href="./"><?php echo $sectionsRecord['title'] ?></a></h1>
			<p>A Section of the Latin American Studies Association</p>
			<!--
				<img src="images/section-header.jpg" width="720" height="130" alt="Section Name" />
			-->
		</div>
		<a href="http://lasa.international.pitt.edu" class="lasalogo"><img src="../images/lasa-logo.jpg" width="240" height="150" alt="Latin American Studies Association" /></a>
	</div><!--/masthead-->

	<div class="contentwrap group" id="content">

		<h2><?php echo $pagesRecord['name'] ?></h2>

		<div class="nav">
			<ul>
				<?php foreach ($categoryRecords as $categoryRecord): ?>
					<?php echo $categoryRecord['_listItemStart'] ?>

					<?php if ($categoryRecord['_isSelected'] || $categoryRecord['_isDescendantSelected']): ?>
						<span class="current">
							<a href="./?page=<?php echo $categoryRecord['num'] ?>"><?php if($categoryRecord['navigation_text']) echo $categoryRecord['navigation_text']; else echo $categoryRecord['name']; ?></a>
						</span>
					<?php else: ?>
						<a href="./?page=<?php echo $categoryRecord['num'] ?>"><?php if($categoryRecord['navigation_text']) echo $categoryRecord['navigation_text']; else echo $categoryRecord['name']; ?></a>
					<?php endif; ?>

					<?php echo $categoryRecord['_listItemEnd'] ?>
				<?php endforeach; ?>
			</ul>
		</div><!--/nav-->

		<div class="content group">

			<div class="main">


			<?php if($_GET["type"]=="news"): ?>
				<h3><?php echo $news_details['title'] ?></h3>
				<p><?php echo date("D, M jS, Y g:i:s a", strtotime($news_details['date'])) ?></p>
				<?php echo $news_details['content'] ?>

				<?php foreach ($news_details['related_photos'] as $upload): ?>
				<p>
				<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" />
				<div class="photo-caption"><?php echo $upload['info1'] ?></div>
				</p>
				<?php endforeach ?>

				<p><a href="mailto:?subject=<?php echo urlencode(thisPageUrl()) ?>">Email this Page</a></p>
			<?php endif; ?>

			<?php if($_GET["type"]=="event"): ?>

				<h3>Output event details here</h3>
				<p>[in progress]</p>

			<?php endif; ?>


			</div><!-- /main -->

			<div class="sidebar">
				<?php echo $pagesRecord['sidebar'] ?>
			</div><!-- /sidebar -->

		</div><!-- /content -->

	</div><!--/contentwrap-->

	<div class="footer">
		<p>&copy; <?php echo date("Y"); ?> Latin American Studies Association. All rights reserved.</p>
	</div><!--/footer-->

</div><!--/pagewrap-->

</body>
</html>
