<?xml version="1.0"?>
<xsl:stylesheet version="1.0"  xmlns="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fn="http://www.w3.org/2002/08/xquery-functions" xmlns:date="http://exslt.org/dates-and-times" xmlns:str="http://exslt.org/strings" xmlns:func="http://exslt.org/functions" xmlns:math="http://exslt.org/math" xmlns:exsl="http://exslt.org/common">
	<xsl:output method="xml" encoding="UTF-8" omit-xml-declaration="yes" indent="yes" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" />

	<xsl:variable name="author" select="concat(/blog/author/forename, ' ', /blog/author/surname)" />

	<!-- <CALENDAR> -->
	<xsl:variable name="start" select="/blog/calendar/@start" />
	<xsl:variable name="count" select="/blog/calendar/@days" />
	<xsl:variable name="total" select="$start + $count - 1" />
	<xsl:variable name="limit" select="$total mod 7" />

	<xsl:variable name="elements">
		<xsl:choose>
			<xsl:when test="$limit > 0"><xsl:value-of select="$total + 7 - $limit" /></xsl:when>

			<xsl:otherwise><xsl:value-of select="$total" /></xsl:otherwise>
		</xsl:choose>
	</xsl:variable>

	<xsl:template name="calendar">
		<xsl:param name="month" />
		<xsl:param name="link" />

		<table id="calendar" cellpadding="0" cellspacing="2">
			<tr>
				<th class="cTitle" colspan="7"><xsl:value-of select="concat($month, ' ', /blog/calendar/@year)" /></th>
			</tr>

			<tr>
				<th>Mon</th>
				<th>Tue</th>
				<th>Wed</th>
				<th>Thu</th>
				<th>Fri</th>
				<th>Sat</th>
				<th>Sun</th>
			</tr>

			<xsl:call-template name="month">
				<xsl:with-param name="link" select="$link" />
			</xsl:call-template>
		</table>
	</xsl:template>

	<xsl:template name="month">
		<xsl:param name="link" />
		<xsl:param name="i" select="1" />

		<xsl:if test="$i &lt; $elements">
			<xsl:call-template name="week">
				<xsl:with-param name="link" select="$link" />
				<xsl:with-param name="i" select="$i" />
			</xsl:call-template>

			<xsl:call-template name="month">
				<xsl:with-param name="link" select="$link" />
				<xsl:with-param name="i" select="$i + 7" />
			</xsl:call-template>
		</xsl:if>
	</xsl:template>

	<xsl:template name="week">
		<xsl:param name="link" />
		<xsl:param name="i" select="1" />

		<tr>
			<xsl:call-template name="days">
				<xsl:with-param name="link" select="$link" />
				<xsl:with-param name="i" select="$i" />
				<xsl:with-param name="counter" select="$i + 6" />
			</xsl:call-template>
		</tr>
	</xsl:template>

	<xsl:template name="days">
		<xsl:param name="link" />
		<xsl:param name="i" select="1" />
		<xsl:param name="counter" select="1" />

		<xsl:choose>
			<xsl:when test="$i &lt; $start">
				<td></td>
			</xsl:when>

			<xsl:when test="$i - $start + 1 > $count"></xsl:when>

			<xsl:when test="$i > $start - 1">
				<xsl:variable name="cur" select="$i - $start + 1" />
				<xsl:variable name="x"><xsl:if test="$cur &lt; 10">0</xsl:if><xsl:value-of select="$cur" /></xsl:variable>

				<td>
					<xsl:choose>
						<xsl:when test="/blog/calendar/day = $x">
							<xsl:attribute name="class">archive</xsl:attribute>

							<a href="{$link}{$x}/"><xsl:value-of select="$cur" /></a>
						</xsl:when>

						<xsl:otherwise>
							<xsl:attribute name="class">day</xsl:attribute>

							<xsl:value-of select="$x" />
						</xsl:otherwise>
					</xsl:choose>
				</td>
			</xsl:when>
		</xsl:choose>

		<xsl:if test="$counter > $i">
			<xsl:call-template name="days">
				<xsl:with-param name="link" select="$link" />
				<xsl:with-param name="i" select="$i + 1" />
				<xsl:with-param name="counter" select="$counter" />
			</xsl:call-template>
		</xsl:if>
	</xsl:template>
	<!-- </CALENDAR> -->

	<xsl:template name="formatDate">
		<xsl:param name="date" />
		<xsl:param name="time" />

		<xsl:value-of select="concat(date:day-abbreviation($date), ', ', date:day-in-month($date), ' ', date:month-name($date), ' ', date:year($date), ', ', $time)" />
	</xsl:template>

	<xsl:template name="head">
		<xsl:param name="title" />

		<head>
			<title><xsl:value-of select="$title" /></title>

			<link type="text/css" rel="stylesheet" href="http://styles.speeple.com/blogs/1.css" />
			<link rel="alternate" type="application/rss+xml" href="/blog/feed.xml" title="{/blog/title} - RSS Feed" />

			<xsl:if test="/blog/@index = 'post'">
				<script type="text/javascript" src="http://styles.speeple.com/blogs/1.js"></script>
			</xsl:if>
		</head>
	</xsl:template>

	<xsl:template name="header">
		<div id="head">
			<div id="speeple">
				<div>
					<p><img alt="Speeple" src="http://styles.speeple.com/blogs/images/1/speeple.gif" /> | <xsl:choose>
						<xsl:when test="/blog/user/@relationship = 'none'">
							<a style="font-weight: bold" href="http://speeple.com/sign-up/">Join Speeple</a>
						</xsl:when>

						<xsl:otherwise>
							<a style="font-weight: bold" href="http://members.speeple.com/">Control Panel</a>
						</xsl:otherwise>
					</xsl:choose> | <a href="http://speeple.com/">People</a> | <a href="http://groups.speeple.com/">Groups</a> | <a href="http://blogs.speeple.com/">Blogs</a> | <a href="http://news.speeple.com/">News</a></p>
				</div>
			</div>

			<div id="title">
				<h1><xsl:value-of select="/blog/title" /><xsl:if test="/blog/description"><small> - <xsl:value-of select="/blog/description" /></small></xsl:if></h1>
			</div>
		</div>
	</xsl:template>

	<xsl:template name="hMenu">
		<xsl:param name="links" />
		<xsl:param name="q" />

		<div id="hMenu">
			<form action="http://go.speeple.com/search-blogs/" method="post">
				<table cellpadding="0" cellspacing="0">
					<tr>
						<td class="links"><xsl:value-of disable-output-escaping="yes" select="$links" /></td>

						<td class="searchBox">
							<input name="blog" type="hidden" value="{/blog/@id}" />

							<input class="small" type="text" name="q" size="25">
								<xsl:if test="$q"><xsl:attribute name="value"><xsl:value-of select="$q" /></xsl:attribute></xsl:if>
							</input>

							<input class="small" type="submit" value="Search" />
						</td>
					</tr>
				</table>
			</form>
		</div>
	</xsl:template>

	<xsl:template name="tagCloud">
		<xsl:param name="title" select="'Tag Cloud'" />

		<xsl:if test="/blog/tags">
			<xsl:variable name="min" select="math:min(/blog/tags/tag/@count)" />
			<xsl:variable name="max" select="math:max(/blog/tags/tag/@count)" />

			<xsl:variable name="spread">
				<xsl:choose>
					<xsl:when test="($max - $min) = 0">
						<xsl:value-of select="1" />
					</xsl:when>

					<xsl:otherwise>
						<xsl:value-of select="$max - $min" />
					</xsl:otherwise>
				</xsl:choose>
			</xsl:variable>

			<xsl:variable name="step" select="50 div $spread" />

			<h2><xsl:value-of select="$title" /></h2>

			<p id="tags">
				<xsl:for-each select="/blog/tags/tag">
					<xsl:sort select="." order="ascending" />

					<xsl:if test="position() != 1">, </xsl:if>

					<a>
						<xsl:attribute name="style"><xsl:value-of select="concat('font-size: ', 100 + ((@count - $min) * $step), '%')" /></xsl:attribute>
						<xsl:attribute name="href">/blog/tags/<xsl:value-of select="str:replace(fn:escape-uri(., false()), '%20', '+')" />/</xsl:attribute>

						<xsl:value-of select="." />
					</a>
				</xsl:for-each>
			</p>
		</xsl:if>
	</xsl:template>

	<xsl:template name="postTags">
		<xsl:for-each select="tag">
			<xsl:sort select="@match" order="descending" />

			<xsl:if test="position() != 1">, </xsl:if>

			<a>
				<xsl:attribute name="href">/blog/tags/<xsl:value-of select="str:replace(fn:escape-uri(., false()), '%20', '+')" />/</xsl:attribute>

				<xsl:choose>
					<xsl:when test="@match='true'">
						<strong><xsl:value-of select="." /></strong>
					</xsl:when>

					<xsl:otherwise>
						<xsl:value-of select="." />
					</xsl:otherwise>
				</xsl:choose>
			</a>
		</xsl:for-each>
	</xsl:template>

	<xsl:template name="postList">
		<xsl:param name="title" />
		<xsl:param name="paging" />
		<xsl:param name="tagText" />

		<xsl:variable name="URLStart">
			<xsl:if test="/blog/@index != 'search'">/blog/</xsl:if>
		</xsl:variable>

		<h1><xsl:value-of disable-output-escaping="yes" select="$title" /></h1>

		<xsl:if test="/blog/@index != 'home'">
			<h2 id="resultsNav">
				<xsl:choose>
					<xsl:when test="$paging != 'search'">
						<xsl:if test="/blog/@page &gt; 1">
							<a>
								<xsl:attribute name="href">
									<xsl:choose>
										<xsl:when test="/blog/@page != 2"><xsl:value-of select="/blog/@page - 1" />.html</xsl:when>

										<xsl:otherwise>./</xsl:otherwise>
									</xsl:choose>
								</xsl:attribute>«</a><xsl:text> </xsl:text>
						</xsl:if>Page <strong><xsl:value-of select="/blog/@page" /></strong> of <strong><xsl:value-of select="ceiling(/blog/posts/@count div 5)" /></strong><xsl:if test="/blog/@page &lt; ceiling(/blog/posts/@count div 5)"><xsl:text> </xsl:text><a href="{/blog/@page + 1}.html">»</a></xsl:if>
					</xsl:when>

					<xsl:otherwise>
						<xsl:if test="/blog/@page &gt; 1">
							<a>
								<xsl:attribute name="href">
									<xsl:choose>
											<xsl:when test="/blog/@page != 2"><xsl:value-of select="/blog/@page - 1" />.html</xsl:when>

											<xsl:otherwise>./</xsl:otherwise>
									</xsl:choose>
								</xsl:attribute>«</a><xsl:text> </xsl:text>
							</xsl:if>Results <strong><xsl:value-of select="(10 * (/blog/@page - 1)) + 1" /></strong> to <strong><xsl:choose>
							<xsl:when test="(/blog/@page * 10) &lt; /blog/posts/@count"><xsl:value-of select="/blog/@page * 10" /></xsl:when>

							<xsl:otherwise><xsl:value-of select="/blog/posts/@count" /></xsl:otherwise>
						</xsl:choose></strong> of <strong><xsl:value-of select="/blog/posts/@count" /></strong><xsl:if test="ceiling(/blog/posts/@count div 10) &gt; /blog/@page"><xsl:text> </xsl:text><a href="{/blog/@page + 1}.html">»</a></xsl:if>
					</xsl:otherwise>
				</xsl:choose>
			</h2>
		</xsl:if>

		<ol id="postList">
			<xsl:for-each select="/blog/posts/post">
				<xsl:variable name="postURL" select="concat('/blog/', str:replace(fn:escape-uri(@id, false()), '%20', '+'), '.htm')" />

				<li class="post">
					<h2><a href="{$postURL}"><xsl:value-of select="title" disable-output-escaping="yes" /></a></h2>

					<p class="postInfo">Published: <xsl:call-template name="formatDate">
							<xsl:with-param name="date" select="substring(@published, 1, 10)" />
							<xsl:with-param name="time" select="substring(@published, 12, 5)" />
						</xsl:call-template>

						<xsl:if test="@comments &gt; 0">, <a href="{$postURL}#comments"><xsl:value-of select="@comments" /> comments</a></xsl:if><xsl:if test="tag">, <xsl:value-of select="$tagText" />: <xsl:call-template name="postTags" /></xsl:if>
					</p>

					<div class="body">
						<xsl:value-of disable-output-escaping="yes" select="body" />

						<xsl:if test="body/@content = 'limited'">
							<p><strong>…</strong><xsl:text> </xsl:text><a href="{$postURL}">Continue Reading »</a></p>
						</xsl:if>
					</div>

					<xsl:call-template name="related">
						<xsl:with-param name="related" select="related" />
					</xsl:call-template>
				</li>
			</xsl:for-each>
		</ol>
	</xsl:template>

	<xsl:template name="related">
		<xsl:param name="related" />

		<xsl:if test="$related">
			<div class="related">
				<xsl:if test="$related[@type='blog']">
					<h3>Related Blog Posts</h3>

					<ul>
						<xsl:for-each select="$related[@type='blog']">
							<li><a href="{@href}"><xsl:value-of select="." disable-output-escaping="yes" /></a> <small> - <xsl:call-template name="formatDate">
									<xsl:with-param name="date" select="substring(@published, 1, 10)" />
									<xsl:with-param name="time" select="substring(@published, 12, 5)" />
								</xsl:call-template></small></li>
						</xsl:for-each>
					</ul>
				</xsl:if>

				<xsl:if test="$related[@type='news']">
					<h3>Related News</h3>

					<ul>
						<xsl:for-each select="$related[@type='news']">
							<li><a href="{@href}"><xsl:value-of select="." disable-output-escaping="yes" /></a> <small> - <xsl:call-template name="formatDate">
									<xsl:with-param name="date" select="substring(@published, 1, 10)" />
									<xsl:with-param name="time" select="substring(@published, 12, 5)" />
								</xsl:call-template></small></li>
						</xsl:for-each>
					</ul>
				</xsl:if>
			</div>
		</xsl:if>
	</xsl:template>

	<xsl:template name="comments">
		<xsl:param name="comments" />
		<xsl:param name="i" select="1" />

		<ol>
			<xsl:choose>
				<xsl:when test="$i != 1">
					<xsl:attribute name="class">thread</xsl:attribute>
				</xsl:when>

				<xsl:otherwise>
					<xsl:attribute name="id">thread</xsl:attribute>
				</xsl:otherwise>
			</xsl:choose>

			<xsl:for-each select="$comments">
				<li class="comment">
					<div class="commentBody" id="c{@id}">
						<p class="commentInfo"><span><a href="http://{author/@id}.speeple.com/"><xsl:value-of select="author" /></a><xsl:text>, </xsl:text>
						<xsl:call-template name="formatDate">
								<xsl:with-param name="date" select="substring(@published, 1, 10)" />
								<xsl:with-param name="time" select="substring(@published, 12, 5)" />
							</xsl:call-template> wrote:</span>
						</p>

						<div>
							<xsl:value-of disable-output-escaping="yes" select="body" />
						</div>

						<p class="stats"><strong><xsl:value-of select="@replies" /></strong> replies, <strong><xsl:value-of select="@children" /></strong> direct<xsl:if test="/blog/post/@commenting = 'enabled'"> | <a href="/blog/{/blog/post/@href}?rid={@id}" onclick="return r({@id})">Reply to this »</a></xsl:if></p>
					</div>

					<xsl:if test="comment">
						<xsl:call-template name="comments">
							<xsl:with-param name="comments" select="comment" />
							<xsl:with-param name="i" select="$i + 1" />
						</xsl:call-template>
					</xsl:if>
				</li>
			</xsl:for-each>
		</ol>
	</xsl:template>

	<xsl:template name="footer">
		<p id="footer"><a href="http://blogs.speeple.com/copyright.html">Copyright © <xsl:value-of select="$author" /></a> - Speeple and related logos <a href="http://speeple.com/copyright.html">Copyright © Speeple™</a></p>
	</xsl:template>

	<xsl:template match="/">
		<html>
			<xsl:choose>
				<xsl:when test="/blog/@index = 'home'">
					<xsl:variable name="month" select="date:month-name()" />

					<xsl:call-template name="head">
						<xsl:with-param name="title" select="concat(/blog/title, ' by ', $author)" />
					</xsl:call-template>

					<body>
				  	<xsl:call-template name="header" />

				  	<div id="build">
							<xsl:call-template name="hMenu">
								<xsl:with-param name="links"><![CDATA[<a href="/">]]><xsl:value-of select="$author" /><![CDATA['s Profile</a> | <a href="tags/">Tag Cloud</a>]]></xsl:with-param>
							</xsl:call-template>

							<div id="content">
								<div id="vMenu">
									<xsl:call-template name="calendar">
										<xsl:with-param name="month" select="$month" />
										<xsl:with-param name="link" select="concat(/blog/calendar/@year, '/', /blog/calendar/@month, '/')" />
									</xsl:call-template>

									<xsl:call-template name="tagCloud" />

									<h2>Yearly Archives</h2>

									<ol>
										<xsl:for-each select="/blog/archives/archive">
											<li><a href="{.}/"><xsl:value-of select="." /></a> (<xsl:value-of select="@count" />)</li>
										</xsl:for-each>
									</ol>

									<xsl:if test="/blog/posts/comment">
										<h2>Comment Stream</h2>

										<ol id="commentStream">
											<xsl:for-each select="/blog/posts/comment">
												<li>“<a href="{post/@id}.htm#c{@id}"><xsl:value-of disable-output-escaping="yes" select="body" /></a>” <small><xsl:text>- </xsl:text><xsl:call-template name="formatDate">
													<xsl:with-param name="date" select="substring(@published, 1, 10)" />
													<xsl:with-param name="time" select="substring(@published, 12, 5)" />
												</xsl:call-template></small></li>
											</xsl:for-each>
										</ol>
									</xsl:if>

									<p id="rss"><a href="/blog/feed.xml"><img alt="RSS Feed" src="http://imageserver.speeple.com/common/feed_b.gif" /></a></p>
								</div>

								<xsl:call-template name="postList">
									<xsl:with-param name="title" select="'Latest Posts'" />
									<xsl:with-param name="tagText" select="'tagged'" />
								</xsl:call-template>
							</div>
						</div>

						<xsl:call-template name="footer" />
					</body>
				</xsl:when>

				<xsl:when test="/blog/@index = 'search'">
					<xsl:variable name="q">
						<xsl:value-of select="/blog/posts/@search" /><xsl:if test="/blog/posts/@tagged"><xsl:value-of select="concat(' tagged:', /blog/posts/@tagged)" /></xsl:if><xsl:if test="/blog/posts/@lang"><xsl:value-of select="concat(' lang:', /blog/posts/@lang)" /></xsl:if><xsl:if test="/blog/posts/@range"><xsl:value-of select="concat(' pub:last', /blog/posts/@range)" /></xsl:if><xsl:if test="/blog/posts/@groupby"><xsl:value-of select="concat(' groupby:', /blog/posts/@groupby)" /></xsl:if>
					</xsl:variable>

					<xsl:call-template name="head">
						<xsl:with-param name="title" select="concat(/blog/title, ' by ', $author)" />
					</xsl:call-template>

					<body>
				  	<xsl:call-template name="header" />

				  	<div id="build">
							<xsl:call-template name="hMenu">
								<xsl:with-param name="links"><![CDATA[<a href="/blog/">]]><xsl:value-of select="/blog/title" /><![CDATA[</a>]]> » <![CDATA[<strong>Search</strong>]]></xsl:with-param>
								<xsl:with-param name="q" select="$q" />
							</xsl:call-template>

							<div id="content">
								<xsl:choose>
									<xsl:when test="/blog/posts/@count &gt; 0">
										<div id="vMenu">
											<xsl:call-template name="tagCloud" />

											<xsl:variable name="s" select="concat('/blog/search/', str:replace(fn:escape-uri(/blog/posts/@search, false()), '%20', '+'))" />

											<xsl:variable name="qLink">
												<xsl:value-of select="$s" />

												<xsl:if test="/blog/posts/@lang"><xsl:value-of select="concat('+lang%3A', fn:escape-uri(/blog/posts/@lang, false()))" /></xsl:if>

												<xsl:if test="/blog/posts/@range"><xsl:value-of select="concat('+pub%3Alast', /blog/posts/@range)" /></xsl:if>

												<xsl:if test="/blog/posts/@groupby"><xsl:value-of select="concat('+groupby%3A', /blog/posts/@groupby)" /></xsl:if>
											</xsl:variable>

											<xsl:variable name="p">
												<xsl:value-of select="$s" />

												<xsl:if test="/blog/posts/@lang"><xsl:value-of select="concat('+lang%3A', fn:escape-uri(/blog/posts/@lang, false()))" /></xsl:if>

												<xsl:if test="/blog/posts/@groupby"><xsl:value-of select="concat('+groupby%3A', /blog/posts/@groupby)" /></xsl:if>
											</xsl:variable>

											<xsl:variable name="g">
												<xsl:value-of select="$s" />

												<xsl:if test="/blog/posts/@lang"><xsl:value-of select="concat('+lang%3A', fn:escape-uri(/blog/posts/@lang, false()))" /></xsl:if>

												<xsl:if test="/blog/posts/@range"><xsl:value-of select="concat('+pub%3Alast', /blog/posts/@range)" /></xsl:if>
											</xsl:variable>

											<xsl:variable name="o">
												<xsl:choose>
													<xsl:when test="/blog/posts/@sort = 'popularity'">
														<xsl:value-of select="'popular/'" />
													</xsl:when>

													<xsl:when test="/blog/posts/@sort = 'latest'">
														<xsl:value-of select="'latest/'" />
													</xsl:when>
												</xsl:choose>
											</xsl:variable>

											<div id="searchMenu">
												<p>Sort by:</p>

												<ul>
													<xsl:choose>
														<xsl:when test="/blog/posts/@sort = 'relevance'">
															<li class="selected">Relevance</li>
															<li><a href="{$qLink}/latest/">Date</a></li>
															<li><a href="{$qLink}/popular/">Comments</a></li>
														</xsl:when>

														<xsl:when test="/blog/posts/@sort = 'latest'">
															<li><a href="{$qLink}/">Relevance</a></li>
															<li class="selected">Date</li>
															<li><a href="{$qLink}/popular/">Comments</a></li>
														</xsl:when>

														<xsl:when test="/blog/posts/@sort = 'popularity'">
															<li><a href="{$qLink}/">Relevance</a></li>
															<li><a href="{$qLink}/latest/">Date</a></li>
															<li class="selected">Comments</li>
														</xsl:when>
													</xsl:choose>
												</ul>

												<p>Published:</p>

												<ul>
													<xsl:choose>
														<xsl:when test="/blog/posts/@range = 'hour'">
															<li class="selected">Last hour</li>
															<li><a href="{$p}+pub%3Alast12hours/{$o}">Last 12 hours</a></li>
															<li><a href="{$p}+pub%3Alastday/{$o}">Last day</a></li>
															<li><a href="{$p}+pub%3Alastweek/{$o}">Last week</a></li>
															<li><a href="{$p}+pub%3Alastmonth/{$o}">Last month</a></li>
															<li><a href="{$p}/{$o}">Anytime</a></li>
														</xsl:when>

														<xsl:when test="/blog/posts/@range = '12hours'">
															<li><a href="{$p}+pub%3Alasthour/{$o}">Last hour</a></li>
															<li class="selected">Last 12 hours</li>
															<li><a href="{$p}+pub%3Alastday/{$o}">Last day</a></li>
															<li><a href="{$p}+pub%3Alastweek/{$o}">Last week</a></li>
															<li><a href="{$p}+pub%3Alastmonth/{$o}">Last month</a></li>
															<li><a href="{$p}/{$o}">Anytime</a></li>
														</xsl:when>

														<xsl:when test="/blog/posts/@range = 'day'">
															<li><a href="{$p}+pub%3Alasthour/{$o}">Last hour</a></li>
															<li><a href="{$p}+pub%3Alast12hours/{$o}">Last 12 hours</a></li>
															<li class="selected">Last day</li>
															<li><a href="{$p}+pub%3Alastweek/{$o}">Last week</a></li>
															<li><a href="{$p}+pub%3Alastmonth/{$o}">Last month</a></li>
															<li><a href="{$p}/{$o}">Anytime</a></li>
														</xsl:when>

														<xsl:when test="/blog/posts/@range = 'week'">
															<li><a href="{$p}+pub%3Alasthour/{$o}">Last hour</a></li>
															<li><a href="{$p}+pub%3Alast12hours/{$o}">Last 12 hours</a></li>
															<li><a href="{$p}+pub%3Alastday/{$o}">Last day</a></li>
															<li class="selected">Last week</li>
															<li><a href="{$p}+pub%3Alastmonth/{$o}">Last month</a></li>
															<li><a href="{$p}/{$o}">Anytime</a></li>
														</xsl:when>

														<xsl:when test="/blog/posts/@range = 'month'">
															<li><a href="{$p}+pub%3Alasthour/{$o}">Last hour</a></li>
															<li><a href="{$p}+pub%3Alast12hours/{$o}">Last 12 hours</a></li>
															<li><a href="{$p}+pub%3Alastday/{$o}">Last day</a></li>
															<li><a href="{$p}+pub%3Alastweek/{$o}">Last week</a></li>
															<li class="selected">Last month</li>
															<li><a href="{$p}/{$o}">Anytime</a></li>
														</xsl:when>

														<xsl:otherwise>
															<li><a href="{$p}+pub%3Alasthour/{$o}">Last hour</a></li>
															<li><a href="{$p}+pub%3Alast12hours/{$o}">Last 12 hours</a></li>
															<li><a href="{$p}+pub%3Alastday/{$o}">Last day</a></li>
															<li><a href="{$p}+pub%3Alastweek/{$o}">Last week</a></li>
															<li><a href="{$p}+pub%3Alastmonth/{$o}">Last month</a></li>
															<li class="selected">Anytime</li>
														</xsl:otherwise>
													</xsl:choose>
												</ul>

												<p>Group by:</p>

												<ul>
													<xsl:choose>
														<xsl:when test="/blog/posts/@groupby = 'day'">
															<li class="selected">Day</li>
															<li><a href="{$g}+groupby%3Amonth/{$o}">Month</a></li>
															<li><a href="{$g}+groupby%3Ayear/{$o}">Year</a></li>
															<li><a href="{$g}/{$o}">No grouping</a></li>
														</xsl:when>

														<xsl:when test="/blog/posts/@groupby = 'month'">
															<li><a href="{$g}+groupby%3Aday/{$o}">Day</a></li>
															<li class="selected">Month</li>
															<li><a href="{$g}+groupby%3Ayear/{$o}">Year</a></li>
															<li><a href="{$g}/{$o}">No grouping</a></li>
														</xsl:when>

														<xsl:when test="/blog/posts/@groupby = 'year'">
															<li><a href="{$g}+groupby%3Aday/{$o}">Day</a></li>
															<li><a href="{$g}+groupby%3Amonth/{$o}">Month</a></li>
															<li class="selected">Year</li>
															<li><a href="{$g}/{$o}">No grouping</a></li>
														</xsl:when>

														<xsl:otherwise>
															<li><a href="{$g}+groupby%3Aday/{$o}">Day</a></li>
															<li><a href="{$g}+groupby%3Amonth/{$o}">Month</a></li>
															<li><a href="{$g}+groupby%3Ayear/{$o}">Year</a></li>
															<li class="selected">No grouping</li>
														</xsl:otherwise>
													</xsl:choose>
												</ul>

												<xsl:if test="count(/blog/search/term) &gt; 1">
													<p>Also try:
														<xsl:for-each select="/blog/search/term">
															<xsl:sort select="@posts" order="descending" />

															<xsl:if test="position() != 1">, </xsl:if>

															<a><xsl:attribute name="href">/blog/search/<xsl:value-of select="str:replace(fn:escape-uri(., false()), '%20', '+')" />/</xsl:attribute>
																<xsl:value-of select="." />
															</a> (<xsl:value-of select="@posts" />)
														</xsl:for-each>
													</p>
												</xsl:if>
											</div>
										</div>

										<xsl:call-template name="postList">
											<xsl:with-param name="title">Searched for: <![CDATA[<strong>]]><xsl:value-of select="$q" /><![CDATA[</strong>]]></xsl:with-param>
											<xsl:with-param name="paging" select="'search'" />
											<xsl:with-param name="tagText" select="'tagged'" />
										</xsl:call-template>
									</xsl:when>

									<xsl:otherwise>
										<h1>Searched for: <strong><xsl:value-of select="$q" /></strong></h1>

										<p>No results were found that matched your query.</p>

										<ul>
											<li>Ensure words are spelled correctly.</li>
											<li>Try rephrasing keywords or using synonyms.</li>
											<li>Try less specific keywords.</li>
											<li>Make your queries as concise as possible.</li>
										</ul>
									</xsl:otherwise>
								</xsl:choose>
							</div>
						</div>

						<xsl:call-template name="footer" />
					</body>
				</xsl:when>

				<xsl:when test="/blog/@index = 'post'">
					<xsl:variable name="month" select="date:month-name(concat(/blog/calendar/@year, '-', /blog/calendar/@month, '-01'))" />

					<xsl:call-template name="head">
						<xsl:with-param name="title" select="/blog/post/@title" />
					</xsl:call-template>

					<body>
				  	<xsl:call-template name="header" />

				  	<div id="build">
							<xsl:call-template name="hMenu">
								<xsl:with-param name="links"><![CDATA[<a href="/blog/">]]><xsl:value-of select="/blog/title" /><![CDATA[</a> » <a href="../../">]]><xsl:value-of select="/blog/calendar/@year" /><![CDATA[</a>  » <a href="../">]]><xsl:value-of select="$month" /><![CDATA[</a>  » <a href="./">]]><xsl:value-of select="/blog/calendar/@day" /><![CDATA[</a>]]></xsl:with-param>
							</xsl:call-template>

							<div id="content">
								<div style="margin-left: 1em" id="vMenu">
									<xsl:call-template name="calendar">
										<xsl:with-param name="month" select="$month" />
										<xsl:with-param name="link" select="'../'" />
									</xsl:call-template>

									<xsl:if test="/blog/post/next">
										<p>Next: <a>
												<xsl:attribute name="href">/blog/<xsl:value-of select="fn:escape-uri(/blog/post/next/@id, false())" />.htm</xsl:attribute>

												<xsl:value-of select="/blog/post/next" />
											</a>
										</p>
									</xsl:if>

									<xsl:if test="/blog/post/previous">
										<p>Previous: <a>
												<xsl:attribute name="href">/blog/<xsl:value-of select="fn:escape-uri(/blog/post/previous/@id, false())" />.htm</xsl:attribute>

												<xsl:value-of select="/blog/post/previous" />
											</a>
										</p>
									</xsl:if>
								</div>

								<h1><xsl:value-of disable-output-escaping="yes" select="/blog/post/title" /></h1>

								<p class="postInfo">Published: <xsl:call-template name="formatDate">
										<xsl:with-param name="date" select="substring(/blog/post/@published, 1, 10)" />
										<xsl:with-param name="time" select="substring(/blog/post/@published, 12, 5)" />
									</xsl:call-template>

									<xsl:if test="/blog/post/@comments &gt; 0">, <a href="#comments"><xsl:value-of select="/blog/post/@comments" /> comments</a></xsl:if>

									<xsl:if test="/blog/post/tag">, tagged:
										<xsl:for-each select="/blog/post/tag">
											<xsl:if test="position() != 1">, </xsl:if>

											<a>
												<xsl:attribute name="href">/blog/tags/<xsl:value-of select="str:replace(fn:escape-uri(., false()), '%20', '+')" />/</xsl:attribute>

												<xsl:value-of select="." />
											</a>
										</xsl:for-each>
									</xsl:if>
								</p>

								<div class="body">
									<xsl:value-of select="/blog/post/body" disable-output-escaping="yes" />
								</div>

								<xsl:call-template name="related">
									<xsl:with-param name="related" select="/blog/post/related" />
								</xsl:call-template>

								<xsl:if test="/blog/post/comment">
									<h2 id="comments">Comments</h2>

									<xsl:call-template name="comments">
										<xsl:with-param name="comments" select="/blog/post/comment" />
									</xsl:call-template>
								</xsl:if>

								<xsl:if test="/blog/post/@commenting = 'enabled'">
									<form id="comment" action="http://blogs.speeple.com/post-comment/" method="post">
										<div>
											<h2>Comment:</h2>

											<textarea style="border: #ccc 1px solid; padding: 0.3em; font-family: Verdana, sans-serif; font-size: 1em" name="comment" rows="10" cols="50"></textarea>

											<p>
												<input id="parent" name="parent" type="hidden" value="0" />

												<input name="id" type="hidden">
													<xsl:attribute name="value"><xsl:value-of select="concat(/blog/@id, '/', /blog/post/@id)" /></xsl:attribute>
												</input>

												<input type="submit" value="Submit" /></p>
										</div>
									</form>
								</xsl:if>
							</div>
						</div>

						<xsl:call-template name="footer" />
					</body>
				</xsl:when>

				<xsl:when test="/blog/@index = 'archive-yearly'">
					<xsl:variable name="month" select="date:month-name(concat(/blog/calendar/@year, '-', /blog/calendar/@month, '-01'))" />

					<xsl:call-template name="head">
						<xsl:with-param name="title" select="concat(/blog/calendar/@year, ' Archive - ', /blog/title)" />
					</xsl:call-template>

					<body>
				  	<xsl:call-template name="header" />

				  	<div id="build">
							<xsl:call-template name="hMenu">
								<xsl:with-param name="links"><![CDATA[<a href="../">]]><xsl:value-of select="/blog/title" /><![CDATA[</a> » <strong>]]><xsl:value-of select="/blog/calendar/@year" /><![CDATA[</strong>]]></xsl:with-param>
							</xsl:call-template>

							<div id="content">
								<div id="vMenu">
									<xsl:call-template name="calendar">
										<xsl:with-param name="month" select="$month" />
										<xsl:with-param name="link" select="concat(/blog/calendar/@month, '/')" />
									</xsl:call-template>

									<xsl:call-template name="tagCloud" />

									<h2>Monthly Archives</h2>

									<ol>
										<xsl:for-each select="/blog/archives/archive">
											<li><a href="{.}/"><xsl:value-of select="@title" /></a> (<xsl:value-of select="@count" />)</li>
										</xsl:for-each>
									</ol>

									<p id="rss"><a href="/blog/feed.xml"><img alt="RSS Feed" src="http://imageserver.speeple.com/common/feed_b.gif" /></a></p>
								</div>

								<xsl:call-template name="postList">
									<xsl:with-param name="title" select="concat(/blog/calendar/@year, ' Archive')" />
									<xsl:with-param name="tagText" select="'tagged'" />
								</xsl:call-template>
							</div>
						</div>

						<xsl:call-template name="footer" />
					</body>
				</xsl:when>

				<xsl:when test="/blog/@index = 'archive-monthly'">
					<xsl:variable name="month" select="date:month-name(concat(/blog/calendar/@year, '-', /blog/calendar/@month, '-01'))" />

					<xsl:call-template name="head">
						<xsl:with-param name="title" select="concat($month, ' ', /blog/calendar/@year, ' Archive - ', /blog/title)" />
					</xsl:call-template>

					<body>
				  	<xsl:call-template name="header" />

				  	<div id="build">
							<xsl:call-template name="hMenu">
								<xsl:with-param name="links"><![CDATA[<a href="../../">]]><xsl:value-of select="/blog/title" /><![CDATA[</a> » <a href="../">]]><xsl:value-of select="/blog/calendar/@year" /><![CDATA[</a> » <strong>]]><xsl:value-of select="$month" /><![CDATA[</strong>]]></xsl:with-param>
							</xsl:call-template>

							<div id="content">
								<div id="vMenu">
									<xsl:call-template name="calendar">
										<xsl:with-param name="month" select="$month" />
									</xsl:call-template>

									<xsl:call-template name="tagCloud" />

									<p id="rss"><a href="/blog/feed.xml"><img alt="RSS Feed" src="http://imageserver.speeple.com/common/feed_b.gif" /></a></p>
								</div>

								<xsl:call-template name="postList">
									<xsl:with-param name="title" select="concat($month, ' ', /blog/calendar/@year, ' Archive')" />
									<xsl:with-param name="tagText" select="'tagged'" />
								</xsl:call-template>
							</div>
						</div>

						<xsl:call-template name="footer" />
					</body>
				</xsl:when>

				<xsl:when test="/blog/@index = 'archive-daily'">
					<xsl:variable name="month" select="date:month-name(concat(/blog/calendar/@year, '-', /blog/calendar/@month, '-01'))" />

					<xsl:call-template name="head">
						<xsl:with-param name="title" select="concat($month, ' ', /blog/calendar/@day, ' ', /blog/calendar/@year, ' Archive - ', /blog/title)" />
					</xsl:call-template>

					<body>
				  	<xsl:call-template name="header" />

				  	<div id="build">
							<xsl:call-template name="hMenu">
								<xsl:with-param name="links"><![CDATA[<a href="../../../">]]><xsl:value-of select="/blog/title" /><![CDATA[</a> » <a href="../../">]]><xsl:value-of select="/blog/calendar/@year" /><![CDATA[</a> » <a href="../">]]><xsl:value-of select="$month" /><![CDATA[</a> » <strong>]]><xsl:value-of select="/blog/calendar/@day" /><![CDATA[</strong>]]></xsl:with-param>
							</xsl:call-template>

							<div id="content">
								<div id="vMenu">
									<xsl:call-template name="calendar">
										<xsl:with-param name="month" select="$month" />
										<xsl:with-param name="link" select="'../'" />
									</xsl:call-template>

									<xsl:call-template name="tagCloud" />

									<p id="rss"><a href="/blog/feed.xml"><img alt="RSS Feed" src="http://imageserver.speeple.com/common/feed_b.gif" /></a></p>
								</div>

								<xsl:call-template name="postList">
									<xsl:with-param name="title" select="concat($month, ' ', /blog/calendar/@day, ' ', /blog/calendar/@year, ' Archive')" />
									<xsl:with-param name="tagText" select="'tagged'" />
								</xsl:call-template>
							</div>
						</div>

						<xsl:call-template name="footer" />
					</body>
				</xsl:when>

				<xsl:when test="/blog/@index = 'tag'">
					<xsl:call-template name="head">
						<xsl:with-param name="title" select="concat(/blog/posts/@title, ' - Tags - ', /blog/title)" />
					</xsl:call-template>

					<body>
				  	<xsl:call-template name="header" />

				  	<div id="build">
							<xsl:call-template name="hMenu">
								<xsl:with-param name="links"><![CDATA[<a href="../../">]]><xsl:value-of select="/blog/title" /><![CDATA[</a> » <a href="../">Tags</a> » <strong>]]><xsl:value-of select="/blog/posts/@title" /><![CDATA[</strong>]]></xsl:with-param>
							</xsl:call-template>

							<div id="content">
								<div id="vMenu">
									<xsl:call-template name="tagCloud">
										<xsl:with-param name="title" select="'Related Tags'" />
									</xsl:call-template>

									<p id="rss"><a href="/blog/feed.xml"><img alt="RSS Feed" src="http://imageserver.speeple.com/common/feed_b.gif" /></a></p>
								</div>

								<xsl:call-template name="postList">
									<xsl:with-param name="title">Tagged <![CDATA[<strong>]]><xsl:value-of select="/blog/posts/@title" /><![CDATA[</strong>]]></xsl:with-param>
									<xsl:with-param name="tagText" select="'also tagged'" />
								</xsl:call-template>
							</div>
						</div>

						<xsl:call-template name="footer" />
					</body>
				</xsl:when>

				<xsl:when test="/blog/@index = 'tagcloud'">
					<xsl:call-template name="head">
						<xsl:with-param name="title" select="concat('Tag Cloud - ', /blog/title)" />
					</xsl:call-template>

					<body>
						<xsl:call-template name="header" />

						<div id="build">
							<xsl:call-template name="hMenu">
								<xsl:with-param name="links"><![CDATA[<a href="../">]]><xsl:value-of select="/blog/title" /><![CDATA[</a> » <strong>Tag Cloud</strong>]]></xsl:with-param>
							</xsl:call-template>

							<div id="content">
								<xsl:if test="/blog/tags">
									<div id="vMenu">
										<p><xsl:value-of select="$author" /> has tagged <strong><xsl:value-of select="/blog/tags/@posts" /></strong> posts <strong><xsl:value-of select="/blog/tags/@count" /></strong> times using <strong><xsl:value-of select="/blog/tags/@unique" /></strong> unique tags.</p>

										<ul>
											<li><strong><xsl:value-of select="round(/blog/tags/@count div /blog/tags/@posts)" /></strong> tags per post average</li>
											<li><strong><xsl:value-of select="round(100 * (/blog/tags/@unique div /blog/tags/@count))" />%</strong> unique tags</li>
										</ul>
									</div>

									<h1>Tag Cloud</h1>

									<xsl:variable name="min" select="math:min(/blog/tags/tag/@count)" />
									<xsl:variable name="max" select="math:max(/blog/tags/tag/@count)" />

									<xsl:variable name="spread">
										<xsl:choose>
											<xsl:when test="($max - $min)=0">
												<xsl:value-of select="1" />
											</xsl:when>

											<xsl:otherwise>
												<xsl:value-of select="$max - $min" />
											</xsl:otherwise>
										</xsl:choose>
									</xsl:variable>

									<xsl:variable name="step" select="50 div ($max - $min)" />

									<p id="tags">
										<xsl:for-each select="/blog/tags/tag">
											<xsl:sort select="." order="ascending" />

											<xsl:if test="position() != 1">, </xsl:if>

											<a>
												<xsl:attribute name="style"><xsl:value-of select="concat('font-size: ', 100 + ((@count - $min) * $step), '%')" /></xsl:attribute>
												<xsl:attribute name="href">/blog/tags/<xsl:value-of select="str:replace(fn:escape-uri(., false()), '%20', '+')" />/</xsl:attribute>

												<xsl:value-of select="." />
											</a>
										</xsl:for-each>
									</p>
								</xsl:if>
							</div>
						</div>

						<xsl:call-template name="footer" />
					</body>
				</xsl:when>
			</xsl:choose>
		</html>
	</xsl:template>
</xsl:stylesheet>