Index: trunk/gsdl3/web/interfaces/default/transform/document.xsl
===================================================================
--- trunk/gsdl3/web/interfaces/default/transform/document.xsl	(revision 5689)
+++ trunk/gsdl3/web/interfaces/default/transform/document.xsl	(revision 5690)
@@ -4,6 +4,7 @@
   xmlns:java="http://xml.apache.org/xslt/java"
   xmlns:util="xalan://org.greenstone.gsdl3.util.XSLTUtil"
+  xmlns:gsf="http://www.greenstone.org/configformat"
   extension-element-prefixes="java util"
-  exclude-result-prefixes="java util">
+  exclude-result-prefixes="java util gsf">
 
   <xsl:include href="style.xsl"/>
@@ -34,18 +35,14 @@
   <xsl:template match="pageResponse">
     <xsl:variable name="collName"><xsl:value-of select="/page/pageRequest/paramList/param[@name='c']/@value"/></xsl:variable>
-    <!--<center>-->
-      <xsl:call-template name="standardPageBanner">
-	<xsl:with-param name="collName" select="$collName"/>
-      </xsl:call-template>
+    <xsl:call-template name="standardPageBanner">
+      <xsl:with-param name="collName" select="$collName"/>
+    </xsl:call-template>
     <xsl:call-template name="navigationBar">
       <xsl:with-param name="collName" select="$collName"/>
     </xsl:call-template>      
-<!--      <xsl:call-template name="dividerBar"/>-->
-      <!-- display the document -->
-      <xsl:apply-templates select="document">
-	<xsl:with-param name="collName" select="$collName"/>
-      </xsl:apply-templates>
-   <!-- </center>-->
-    
+    <!-- display the document -->
+    <xsl:apply-templates select="document">
+      <xsl:with-param name="collName" select="$collName"/>
+    </xsl:apply-templates>
     <xsl:call-template name="dividerBar"/>
   </xsl:template>
@@ -53,9 +50,7 @@
   <xsl:template match="document">
     <xsl:param name="collName"/>
-    <p/>
     <xsl:call-template name="documentHeading">
       <xsl:with-param name="collName" select="$collName"/>
     </xsl:call-template>
-    <p/>
     <xsl:call-template name="documentContent">
       <xsl:with-param name="collName" select="$collName"/>
@@ -65,18 +60,38 @@
   <xsl:template name="documentHeading">
     <xsl:param name="collName"/>
-    <table width="100%" cellpadding="0" cellspacing="0">
+    <xsl:variable name="doCoverImage" select="/page/pageResponse/format/gsf:option[@name='coverImages']/@value"/>
+    <xsl:variable name="doTOC" select="/page/pageResponse/format/gsf:option[@name='TOC']/@value"/>
+    <xsl:variable name="p.a" select="/page/pageRequest/paramList/param[@name='p.a']/@value"/>
+    <xsl:variable name="p.sa" select="/page/pageRequest/paramList/param[@name='p.sa']/@value"/>
+    <xsl:variable name="p.s" select="/page/pageRequest/paramList/param[@name='p.s']/@value"/>
+    
+    <table><tr><td>
+	  <a href="{$library_name}?a={$p.a}&amp;sa={$p.sa}&amp;s={$p.s}&amp;c={$collName}&amp;rt=r"><xsl:call-template name="openbookimg"><xsl:with-param name="title">Close this book and return to search/browse</xsl:with-param>
+	  </xsl:call-template></a></td>
+	<td valign='top'><b><font size="+1">&#160;<xsl:value-of disable-output-escaping="yes" select="documentNode/metadataList/metadata[@name='Title']"/></font></b></td>
+      </tr></table>
+
+    <table cellpadding="10" cellspacing="0">
       <tr>
-	<td valign="top" align="left" width="200">
-	  <xsl:call-template name="coverImage"/>
-	  <p/>
-	  <xsl:call-template name="enrichServices">
+	<td valign="top" align="left">
+	  <xsl:if test="string($doCoverImage) != 'false' and (@docType='paged' or @docType='hierarchy')">
+	    <xsl:call-template name="coverImage"/>
+	    <p/>
+	  </xsl:if>
+	  
+	  <xsl:call-template name="documentButtons">
 	    <xsl:with-param name="collName" select="$collName"/>
 	  </xsl:call-template>
+	  <!--<xsl:call-template name="enrichServices">
+	    <xsl:with-param name="collName" select="$collName"/>
+	  </xsl:call-template>-->
 	</td>
-	<td valign="top">
-	  <xsl:call-template name="TOC">
-	    <xsl:with-param name="collName" select="$collName"/>
-	  </xsl:call-template>
-	</td>
+	<xsl:if test="string($doTOC) != 'false'">
+	  <td valign="top" align="left">
+	    <xsl:call-template name="TOC">
+	      <xsl:with-param name="collName" select="$collName"/>
+	    </xsl:call-template>
+	  </td>
+	</xsl:if>
       </tr>
     </table>
@@ -85,4 +100,41 @@
   <xsl:template name="coverImage">
     <img><xsl:attribute name='src'><xsl:value-of select="/page/pageResponse/collection/metadataList/metadata[@name='httpPath']"/>/index/assoc/<xsl:value-of select="metadataList/metadata[@name='archivedir']"/>/cover.jpg</xsl:attribute></img>
+  </xsl:template>
+
+  <xsl:template name="documentButtons">
+    <xsl:param name="collName"/>
+    <xsl:variable name="docID" select="/page/pageRequest/paramList/param[@name='d']/@value"/>
+    <xsl:variable name="sib" select="/page/pageRequest/paramList/param[@name='sib']/@value"/>
+    <xsl:variable name="ec" select="/page/pageRequest/paramList/param[@name='ec']/@value"/>
+    <xsl:variable name="et" select="/page/pageRequest/paramList/param[@name='et']/@value"/>
+    <table>
+      <tr><td xsl:use-attribute-sets="td-brownbutton">
+	  <xsl:choose><xsl:when test="string($et)='1'">
+	      <a style="text-decoration:none" href="{$library_name}?a=d&amp;d={$docID}&amp;c={$collName}&amp;sib={$sib}&amp;et=0"><xsl:attribute name="title"><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'doc.contract_text_tip')"/></xsl:attribute>
+		<b><font color='{$colour-button-text}'><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'doc.contract_text_b')"/></font></b>
+	      </a>
+	    </xsl:when>
+	    <xsl:otherwise>
+	  <a style="text-decoration:none" href="{$library_name}?a=d&amp;d={$docID}&amp;c={$collName}&amp;sib={$sib}&amp;et=1"><xsl:attribute name="title"><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'doc.expand_text_tip')"/></xsl:attribute>
+	    <b><font color='{$colour-button-text}'><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'doc.expand_text_b')"/></font></b>
+	  </a>
+	    </xsl:otherwise>
+	  </xsl:choose>
+	</td></tr>
+      <tr><td xsl:use-attribute-sets="td-brownbutton">
+	  <xsl:choose><xsl:when test="string($ec)='1'">
+	      <a style="text-decoration:none" href="{$library_name}?a=d&amp;d={$docID}&amp;c={$collName}&amp;sib={$sib}&amp;ec=0"><xsl:attribute name="title"><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'doc.contract_contents_tip')"/></xsl:attribute>
+		<b><font color='{$colour-button-text}'><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'doc.contract_contents_b')"/></font></b>
+	      </a>
+	    </xsl:when>
+	    <xsl:otherwise>
+	      <a style="text-decoration:none" href="{$library_name}?a=d&amp;d={$docID}&amp;c={$collName}&amp;sib={$sib}&amp;ec=1"><xsl:attribute name="title"><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'doc.expand_contents_tip')"/></xsl:attribute>
+		<b><font color='{$colour-button-text}'><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'doc.expand_contents_b')"/></font></b>
+	      </a>
+	    </xsl:otherwise>
+	  </xsl:choose>
+	</td></tr>
+      <tr><td xsl:use-attribute-sets="td-brownbutton">Detach Page</td></tr>
+    </table>
   </xsl:template>
 
@@ -100,60 +152,67 @@
 	</xsl:call-template>
       </xsl:when>
-      <xsl:otherwise>
-	<!-- just print the title of teh one and only docNode -->
-	<xsl:value-of disable-output-escaping="yes" select="documentNode/metadataList/metadata[@name='Title']"/>
-      </xsl:otherwise>
     </xsl:choose>
   </xsl:template>
-  
+    
   <xsl:template name="hierarchicalContents">
     <xsl:param name="collName"/>
-    <xsl:apply-templates select="documentNode[@nodeID]">
-      <xsl:with-param name="collName" select="$collName"/>
-      <xsl:with-param name="depth" select="0"/>
-    </xsl:apply-templates>
-  </xsl:template>
-  
+    <xsl:variable name="oc" select="/page/pageRequest/paramList/param[@name='oc']/@value"/>
+    <xsl:variable name="d" select="/page/pageRequest/paramList/param[@name='d']/@value"/>
+    <xsl:variable name="sib" select="/page/pageRequest/paramList/param[@name='sib']/@value"/>
+    <xsl:if test="documentNode[@nodeID]">
+      <table>
+	<tr valign='top'><td>
+	    <xsl:choose><xsl:when test="string($oc)='0'">
+		<a href="{$library_name}?a=d&amp;c={$collName}&amp;d={$d}&amp;sib={$sib}&amp;oc=1"><xsl:call-template name="closedfolderimg"><xsl:with-param name="title">open the table of contents</xsl:with-param></xsl:call-template></a>
+	      </xsl:when>
+	      <xsl:otherwise><a href="{$library_name}?a=d&amp;c={$collName}&amp;d={$d}&amp;sib={$sib}&amp;oc=0"><xsl:call-template name="openfolderimg"><xsl:with-param name="title">close the table of contents</xsl:with-param></xsl:call-template></a></xsl:otherwise></xsl:choose>
+	  </td><td>Table of Contents</td></tr>
+	<xsl:if test="string($oc)!='0'">
+	  <tr><td></td><td>
+	      <table>
+		<xsl:for-each select="documentNode/documentNode[@nodeID]">
+		  <xsl:apply-templates select='.'><xsl:with-param name="collName" select="$collName"/></xsl:apply-templates>
+		</xsl:for-each>
+	      </table>
+	    </td></tr>
+	</xsl:if>
+      </table>
+    </xsl:if>
+  </xsl:template>
+  
+  <!-- each icon-title pair is a row in a table. children go in a table in another row -->
   <xsl:template match="documentNode">
     <xsl:param name="collName"/>
-    <xsl:param name="depth"/>
-    <xsl:variable name="space" select="$depth * 25"/>
-    
-    <table>
-      <tr valign="top">
-	<td>
-	  <xsl:if test="not($depth = '0')">
-	    <img src="interfaces/default/images/tocspace.gif" width="{$space}"/>
-	  </xsl:if>
-	</td>
-	
-	<!-- Display the appropriate image, depending on the node type -->
-	<td valign="top">
-	  <a><xsl:attribute name="href"><xsl:value-of select='$library_name'/>?a=d&amp;c=<xsl:value-of select='$collName'/>&amp;d=<xsl:value-of select='@nodeID'/><xsl:if test="documentNode">.pr</xsl:if><xsl:if test="@nodeType='leaf'">&amp;sib=1</xsl:if></xsl:attribute>
-	    <xsl:apply-templates select="." mode="displayNodeIcon"/>
-	  </a>
-	</td>
-	
-	<!-- Display associated title, bolded if the node has content -->
-	<td valign="top">
-	  <xsl:choose>
-	    <xsl:when test="nodeContent">
-	      <b><xsl:value-of  disable-output-escaping="yes" select="metadataList/metadata[@name='Title']"/></b>
-	    </xsl:when>
-	    <xsl:otherwise>
-	      <xsl:value-of  disable-output-escaping="yes" select="metadataList/metadata[@name='Title']"/>
-	    </xsl:otherwise>
-	  </xsl:choose>
-	</td>
-      </tr>
-    </table>    
+    <!-- Display the appropriate image, depending on the node type -->
+    <tr><td valign="top">
+	<a><xsl:attribute name="href"><xsl:value-of select='$library_name'/>?a=d&amp;c=<xsl:value-of select='$collName'/>&amp;d=<xsl:value-of select='@nodeID'/><xsl:if test="documentNode">.pr</xsl:if><xsl:if test="@nodeType='leaf'">&amp;sib=1</xsl:if></xsl:attribute>
+	  <xsl:apply-templates select="." mode="displayNodeIcon"/>
+	</a>
+      </td>
+      
+      <!-- Display associated title, bolded if the node has content -->
+      <td valign="top">
+	<xsl:choose>
+	  <xsl:when test="nodeContent">
+	    <b><xsl:value-of disable-output-escaping="yes" select="metadataList/metadata[@name='Title']"/></b>
+	  </xsl:when>
+	  <xsl:otherwise>
+	    <xsl:value-of disable-output-escaping="yes" select="metadataList/metadata[@name='Title']"/>
+	  </xsl:otherwise>
+	</xsl:choose>
+      </td>
+    </tr>
     <!-- Apply recursively to the children of this node -->
-    <xsl:apply-templates select="documentNode[@nodeID]">
-      <xsl:with-param name="collName" select="$collName"/>
-      <xsl:with-param name="depth" select="$depth + 1"/>
-    </xsl:apply-templates>
-  </xsl:template>
-  
-
+    <xsl:if test="documentNode[@nodeID]">
+      <tr><td></td><td><table>
+	    <xsl:apply-templates select="documentNode[@nodeID]">
+	      <xsl:with-param name="collName" select="$collName"/>
+	      <!--<xsl:with-param name="depth" select="$depth + 1"/>-->
+	    </xsl:apply-templates>
+	  </table>
+	</td></tr>
+    </xsl:if>
+  </xsl:template>
+  
   <!-- default content is to process any nodeContent elements and print out their text -->
   <xsl:template name="documentContent">
@@ -165,20 +224,13 @@
   <xsl:template match="nodeContent">
     <p/>
-    <table width="100%" cellpadding="0" cellspacing="0">
-      <tr>
-	<td align="left">
-	  <xsl:for-each select="node()">
-	    <xsl:choose>
-	      <xsl:when test="not(name())"><xsl:value-of select="." disable-output-escaping="yes"/></xsl:when>
-	      <xsl:otherwise><xsl:apply-templates select="."/></xsl:otherwise>
-	    </xsl:choose>
-	  </xsl:for-each>
-	</td>
-      </tr>
-    </table>
+    <xsl:for-each select="node()">
+      <xsl:choose>
+	<xsl:when test="not(name())"><xsl:value-of select="." disable-output-escaping="yes"/></xsl:when>
+	<xsl:otherwise><xsl:apply-templates select="."/></xsl:otherwise>
+      </xsl:choose>
+    </xsl:for-each>
   </xsl:template>
   
   <!-- match any link nodes -->
-  
   <xsl:template match="link">
     <xsl:variable name="collName" select="/page/pageRequest/paramList/param[@name='c']/@value"/> 
@@ -202,7 +254,5 @@
     <span class="{@type}"><xsl:value-of disable-output-escaping="yes" select="."/></span>
   </xsl:template>
-
-
- 
+  
   <!-- paged naviagtion : INCOMPLETE!!-->
   <xsl:template name="pagedContents">
