<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:charette="http://charette.com/Journals">
	<xsl:import href = "charette.xsl"/>
	<xsl:param name="pageNumber" select="1"/>
	<xsl:param name="sort" select="page"/>
	<xsl:output method="html" encoding="UTF-16"/>
	<xsl:template match="/">
		<xsl:choose>
			<xsl:when test="$sort = 'date'">
				<xsl:apply-templates select="Journals/*/Entry">
					<xsl:sort select= "charette:GetDateNumber(string(Date))" data-type="number"/>
				</xsl:apply-templates>
			</xsl:when>
			<xsl:otherwise>
				<xsl:apply-templates select="Journals/*/Entry"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	<xsl:template match="Entry">
		<A>
			<xsl:attribute name="NAME">Image<xsl:value-of select="position()"/>
			</xsl:attribute>
		</A>
		<xsl:choose>
			<xsl:when test="$pageNumber=''">
				<xsl:call-template name="PrevNext"/>
				<xsl:call-template name="DrawPage"/>
				<xsl:call-template name="PrevNext"/>
			</xsl:when>
			<xsl:when test="position() = $pageNumber">
				<xsl:call-template name="PrevNext"/>
				<xsl:call-template name="DrawPage"/>
				<xsl:call-template name="PrevNext"/>
			</xsl:when>
		</xsl:choose>
	</xsl:template>
	<xsl:template match="Search">
		<P>
			<A TARGET="_blank">
				<xsl:attribute name="HREF">
					http://www.google.com/search?hl=en&amp;lr=&amp;ie=UTF-8&amp;oe=UTF-8&amp;q=%22
					<xsl:value-of select="."/>%22
				</xsl:attribute>
				Search the web for "<xsl:value-of select="."/>"
			</A>
		</P>
	</xsl:template>
	<xsl:template name="DrawPage">
		<H3>
			<xsl:if test="@type='Journal Page'">
				Page <xsl:value-of select="Page"/>. 
			</xsl:if>
			<xsl:copy-of select="Description"/>
		</H3>
		<P>
			<xsl:for-each select="Image">
				<A TARGET="_blank">
					<xsl:attribute name="HREF">
						<xsl:value-of select = "."/>
					</xsl:attribute>
					<IMG HEIGHT="600" BORDER="0" NATURALSIZEFLAG="2">
						<xsl:attribute name="SRC">
							<xsl:value-of select = "."/>
						</xsl:attribute>
						<xsl:attribute name="ALT">
							<xsl:value-of select="../Page"/>. <xsl:value-of select="../Description"/>
						</xsl:attribute>
					</IMG>
				</A>
			</xsl:for-each>
		</P>
		<ADDRESS>
			<xsl:value-of select="Date"/>
		</ADDRESS>
		<xsl:copy-of select="Comments"/>
		<xsl:apply-templates select="Search"/>
	</xsl:template>
	<xsl:template name="PrevNext">
		<FORM>
			<INPUT NAME="previous" TYPE="submit" VALUE="Previous">
				<xsl:attribute name="onclick">ShowPage(<xsl:value-of select="position() - 1"/>, '<xsl:value-of select="$sort"/>')</xsl:attribute>
				<xsl:if test="position() = 1">
					<xsl:attribute name="disabled"/>
				</xsl:if>
			</INPUT> 
			<xsl:text> </xsl:text>
			<xsl:for-each select="preceding::Entry">
				<A >
					<xsl:attribute name="HREF">javascript:ShowPage(<xsl:value-of select="position()"/>, '<xsl:value-of select="$sort"/>')</xsl:attribute>
					<IMG ALIGN="BOTTOM" BORDER="0" NATURALSIZEFLAG="3" WIDTH="12" HEIGHT="18" SRC="images/pageicon.gif">
						<xsl:attribute name="ALT">
							<xsl:value-of select="Page"/>. <xsl:value-of select="Description"/>
						</xsl:attribute>
					</IMG>
				</A>
			</xsl:for-each> 
			<IMG ALIGN="BOTTOM" SRC="images/thispageicon.gif"/>
			<xsl:for-each select="following::Entry">
				<A>
					<xsl:attribute name="HREF">javascript:ShowPage(<xsl:value-of select="count(preceding::Entry) + 1"/>, '<xsl:value-of select="$sort"/>')</xsl:attribute>
					
					<IMG ALIGN="BOTTOM" BORDER="0" SRC="images/pageicon.gif">
						<xsl:attribute name="ALT">
							<xsl:value-of select="Page"/>. <xsl:value-of select="Description"/>
						</xsl:attribute>
					</IMG>
				</A>
			</xsl:for-each> 
			<xsl:text> </xsl:text>
			<INPUT NAME="next" TYPE="submit" VALUE="Next">
				<xsl:attribute name="onclick">ShowPage(<xsl:value-of select="position() + 1"/>, '<xsl:value-of select="$sort"/>')</xsl:attribute>
				<xsl:if test="position() = last()">
					<xsl:attribute name="disabled"/>
				</xsl:if>
			</INPUT>
		</FORM>
	</xsl:template>
</xsl:stylesheet>
