<?xml version="1.0" encoding="utf-8"?>
<!-- Mapix default theme template -->
<xsl:stylesheet version="1.0"
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:xhtml="http://www.w3.org/1999/xhtml"
	xmlns:lang="exslt://mapix/lang"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:noNamespaceSchemaLocation="http://mapixcms.org/schemas/stylesheet.xsd"
	exclude-result-prefixes="lang xsi">
	<xsl:output
		method="xml"
		doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
		doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
		encoding="utf-8" />

	<!-- Page template -->
	<xsl:template name="page">
		<xsl:param name="lang" select="lang:detect()"/>
		<xsl:param name="menu" select="null"/>
		<xsl:param name="content" select="null"/>
		<xsl:param name="theme-dir" select="'/mapix/themes/default'"/><!-- TODO Remove default value -->
		<xsl:param name="messages" select="null"/>
		<html xml:lang="{$lang}" lang="{$lang}">
			<head>
				<base href="/{$lang}/"/><!-- TODO Rewrite all links using content-dir base instead of using this -->
				<xsl:copy-of select="$content//xhtml:head/xhtml:*"/>
				<link rel="stylesheet" type="text/css" href="{$theme-dir}/style.css"/>
				<link rel="shortcut icon" href="{$theme-dir}/images/mapix.ico"/>
				<xsl:comment><![CDATA[ [if IE]><link rel="stylesheet" type="text/css" href="]]><xsl:value-of select="$theme-dir"/><![CDATA[/iefix.css"/><![endif] ]]></xsl:comment>
			</head>
			<body>
				<div id="page">
					<div id="header">
						<xsl:copy-of select="lang:__('header',$messages)/text()|lang:__('header',$messages)/*"/>
						<xsl:call-template name="lang:menu">
							<xsl:with-param name="lang" select="$lang"/>
						</xsl:call-template>
						<xsl:apply-templates select="$menu//xhtml:body/xhtml:*" />
					</div>
					<div id="content">
						<xsl:for-each select="$content/xhtml:html">
							<div class="content" id="content_{position()}">
								<h1><xsl:value-of select="xhtml:head/xhtml:title"/></h1>
								<xsl:apply-templates select="xhtml:body/xhtml:*" />
							</div>
						</xsl:for-each>
					</div>
					<div id="footer">
						<xsl:apply-templates select="$menu//xhtml:body/xhtml:*" />
						<xsl:copy-of select="lang:__('footer',$messages)/text()|lang:__('footer',$messages)/*"/>
					</div>
				</div>
			</body>
		</html>
	</xsl:template>
	<!-- Copy a XHTML element without additional namespaces -->
	<!-- TODO Generalize and create a EXSLT function like copy-exclude-ns() -->
	<xsl:template match="xhtml:*">
		<xsl:element name="{name()}" namespace="{namespace-uri()}">
			<xsl:copy-of select='@*'/>
			<xsl:apply-templates select='node()'/>
		</xsl:element>
	</xsl:template>
</xsl:stylesheet>
