<?php
$start_time = microtime(true);

include_once("config.php");

if($mode == "imagecache") {
  include_once($UTIL_DIR. "/imagecache.php");
  getCachedImage($uri, $mod, $cat);
  return;
}

include_once($MODULES_DIR . "/config.php");

$config = new Config($DATA_DIR . "/config.xml");

header("Content-Type: text/html; charset=UTF-8");

include_once($UTIL_DIR . "/login.php");
if($page == "admin") checklogin();

include_once($MODULES_DIR . "/pages.php");

$pages = new Pages($DATA_DIR . "/pages.xml");

if($config->value('splash') == "true") {
	if($_GET["skipsplash"]) {
		setcookie("skipsplash", "true", time()+$config->value('splashreshow'));
	}

	if($GLOBALS["skipsplash"] != "true") {
?><?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title><?php echo $config->value('title');?></title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
	<meta name="MSSmartTagsPreventParsing" content="true"/>
	<meta http-equiv="Content-Type" content="text/html"/>
	<link rel="alternate" type="application/rss+xml" title="RSS" href="rss.xml" />
	<link rel="author" title="Bent Bisballe Nyeng" href="http://www.aasimon.org"/>
	<link href="/favicon.ico" rel="shortcut icon"/>
	<link rel="stylesheet" type="text/css" href="<?php echo $CSS; ?>" media="screen"/>
</head>
<body>
  <div class="splash">
<?php
    $p = $pages->getPage($config->value('splashpage'));
		$p->show();
?>
    <div class="splash_enter"><a href="?skipsplash=true"><span class="splash_enter_text">Enter Site</span></a></div>
  </div>
</body>
</html>
<?php
		return;
	} 
}


?>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title><?php echo $config->value('title');?></title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
	<meta name="MSSmartTagsPreventParsing" content="true"/>
	<meta http-equiv="Content-Type" content="text/html"/>
	<link rel="alternate" type="application/rss+xml" title="RSS" href="rss.xml" />
	<link rel="author" title="Bent Bisballe Nyeng" href="http://www.aasimon.org"/>
	<link href="/favicon.ico" rel="shortcut icon"/>
	<link rel="stylesheet" type="text/css" href="<?php echo $CSS; ?>" media="screen"/>
	<link rel="stylesheet" type="text/css" href="handheld.css" media="handheld"/>
	<link rel="stylesheet" type="text/css" href="admin.css" media="screen"/>
	<script type="text/javascript">
	// <!--
    function externalLinks() {
    	if (!document.getElementsByTagName) return;
    	var anchors = document.getElementsByTagName("a");
    	for (var i=0; i<anchors.length; i++) {
    		var anchor = anchors[i];
    		if (anchor.getAttribute("href") &&
    				anchor.getAttribute("rel") == "external")
    			anchor.target = "_blank";
    	}
    }
    window.onload = externalLinks;
// -->
  </script>
</head>
<body>
<div style="display: none;">
<?php
$_ps = $config->value('preload');
foreach($_ps as $_p) {
	echo "	<img alt=\"preload\" src=\"".$_p."\"/>\n";
}
?>
</div>
<div class="page">
  <div class="menu">
<?php
$menu = $config->value('menu');
if(sizeof($menu)) {
	$idx = 1;
	foreach($menu as $_m => $_t) {
		if($idx != 1) {
			echo "    <div class=\"seperator\"></div>\n";
		}
		echo "    <a href=\"?page=".$_m."\" class=\"menu_entry_".$_m."\"></a>\n";
		echo "    <a href=\"?page=".$_m."\" class=\"menutitle\">".$_t."</a>\n";
		$idx++;
	}
}
?>
  </div>
  <div class="wrapper">
  <div class="content">
<?php
if($page == "admin") {
	include($UTIL_DIR."/admin.php");
} else {
	if($page) $_p = $pages->getPage($page);
	else $_p = $pages->getPage($config->value('default'));
	if($_p) $_p->show();
}
?>
  </div>
  <div class="column">
<?php
$_p = $pages->getPage("column");
if($_p) $_p->show();
?>
  </div>
  </div>
  <div class="footer">
<?php
$_p = $pages->getPage("footer");
if($_p) $_p->show();
?>
  </div>
	<div class="generationtime">This document was generated in <?php $stop_time = microtime(true); echo $stop_time - $start_time; ?> seconds</div>
</div>
<div>
<a href="?page=admin" class="admin_link"></a>
<a href="?page=admin" class="admin_link_text">Admin</a>
</div>
</body>
</html>