<?php
function FormatURI(URI $uri, $base=""){
	$image=$uri->GetImage();
	$imageHTML="";
	if ($image!="")
		$imageHTML='<img src="'.$uri->GetImage().'" />';
	return '<a href="'.$base.$uri->GetLinkLocation().'">'.$imageHTML.$uri->GetText().'</a>';
}
?>

<!DOCTYPE html>
<html>
	<head>
		<title>
			{@Title}<?php
				$__crumbs=Breadcrumbs::GetAll();
				foreach ($__crumbs as $crumb)
					echo ' &gt; ',$crumb['text'];
			?> | Robware
		</title>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0"/>
		<link href="/css/style.css" rel="stylesheet" type="text/css" />
		<link href="/css/style-med.css" rel="stylesheet" media="(max-width:1023px)" type="text/css" />
		<link href="/css/style-small.css" rel="stylesheet" media="(max-width:680px)" type="text/css" />
		<style type="text/css">
			{@CSS}
		</style>
		<style media="(max-width:1023px)">
			{@CSSMed}
		</style>
		<style media="(max-width:680px)">
			{@CSSSmall}
		</style>
		<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
		<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
		<script src="/javascript.js"></script>
		<script type="text/javascript">
			{@JavaScript}
		</script>
	</head>
	<body>
		<div id="main-header">
			<div class="header">
				<img src="/images/menu.svg" id="menu-button" /><?php // using php tags to remove HTML space but to keep source tidy
				?><h2><?php // Shitty, I know, but eh...
					?><span>{@Title}</span><?php
					$__crumbs=Breadcrumbs::GetAll();
					foreach ($__crumbs as $crumb)
						echo '<span>',$crumb['text'],'</span>';
				?></h2>
			</div>
		</div>
		<div id="menu">
			<div class="header">
				<img src="/images/logo.png" /><h1>Robware</h1>
			</div>
			<div id="nav-container">
				<nav>
					<dl>
						<?php
						$reqUri=trim($_SERVER['REQUEST_URI'],"/");
						$uriParts=explode("/",$reqUri);
						if ($uriParts[0]=="")
							$uriParts[0]="home";
							
						$__controllers=Navigation::Get();
						foreach ($__controllers as $controller){
							$cURI=$controller->GetURI();
							echo '<dt';
							if ($cURI->GetLinkLocation()=='/'.$uriParts[0])
								echo ' class="active"';
							echo'>',FormatURI($cURI);
							$items=$controller->GetItems();
							if (count($items)>0)
								echo '<span class="go">&raquo;</span><span class="expand">+</span>';
							echo '</dt>';
							if (count($items)>0){
								echo '<div class="sub-pages">';
								foreach ($items as $uri)
									echo '<dd>',FormatURI($uri,$cURI->GetLinkLocation().'/'),'</dd>';
								echo '</div>';
							}
						}
						?>
					</dl>
				</nav>
			</div>
		</div>
		<div id="main">
			<div id="buttons">
				<table>
					<tr>
						<td>{@ButtonsLeft}</td>
						<td>{@ButtonsRight}</td>
					</tr>
				</table>
			</div>
			<div id="content">
				<?php if (isset($errors) && count($errors)>0){
					echo '<div class="errors">The following errors were encountered:<ul>';
					foreach ($errors as $e)
						echo '<li>',$e,'</li>';
					echo '</ul>Please rectify them and try again.</div>';
				} ?>
				{@Body}
			</div>
			<div id="footer">{@Footer}</div>
		</div>
		<?php if (!isset($_COOKIE['cookiePopupConfirmed']) || $_COOKIE['cookiePopupConfirmed']!=true) { ?>
			<div id="cookiePopup">
				<p>This site uses cookies. Please leave if you're not OK with this.</p>
				<p>In a hilarious twist of irony, we have to store a cookie to stop this popup appearing on every page.</p>
				<div>
					<button>OK</button>
				</div>
			</div>
		<?php }?>
		<div class="backdrop"></div>
	</body>
</html>