Index: main/trunk/greenstone3/web/interfaces/default/transform/layouts/toc.xsl
===================================================================
--- main/trunk/greenstone3/web/interfaces/default/transform/layouts/toc.xsl	(revision 31534)
+++ main/trunk/greenstone3/web/interfaces/default/transform/layouts/toc.xsl	(revision 31535)
@@ -77,7 +77,8 @@
 					<div id="contentsArea">	
 						<!-- show the berry basket if it's turned on -->
-						<gslib:berryBasket/>
-
-						<!-- the contents (if enabled) -->
+						<xsl:call-template name="berryBasket"/>
+						<!-- add in expand and contract document links -->
+						<xsl:call-template name="expandContractDocumentLinks"/>
+						<!-- dynamically get the contents (if enabled) -->
 						<xsl:choose>
 							<xsl:when test="/page/pageResponse/document/@docType = 'paged' or /page/pageResponse/document/@docType = 'pagedhierarchy'">
@@ -93,4 +94,5 @@
 									</xsl:text>
 								</script>
+								
 								<div id="tableOfContents"><xsl:text> </xsl:text></div>
 								<div id="tocLoadingImage" style="text-align:center;">
@@ -101,12 +103,4 @@
 								  <a href="javascript:extractFilteredPagesToOwnDocument();"><button id="extractDocButton"><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'de.extract_pages')"/></button></a>
 								</xsl:if>
-								  
-							<!--	<table style="width:100%;"><tbody><tr>
-									<td><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'doc.filter_pages')"/><xsl:text>: </xsl:text><input id="filterText" type="text"/></td>
-								</tr>
-								<xsl:if test="/page/pageRequest/userInformation and /page/pageRequest/userInformation/@editEnabled = 'true'">
-									<tr><td><a href="javascript:extractFilteredPagesToOwnDocument();"><button id="extractDocButton">Extract these pages to document</button></a></td></tr>
-								</xsl:if>
-								</tbody></table>-->
 							</xsl:when>
 							<xsl:when test="not(/page/pageRequest/paramList/param[@name = 'ed']/@value = '1' or /page/pageRequest/paramList/param[@name = 'ec']/@value = '1')">
@@ -126,7 +120,8 @@
 							</xsl:when>
 							<xsl:otherwise>
-							  <xsl:variable name="doc_url"><xsl:value-of select='$library_name'/>/collection/<xsl:value-of select='/page/pageResponse/collection/@name'/>/document/<xsl:value-of select='/page/pageResponse/document/documentNode/@nodeID'/>?<xsl:if test="/page/pageRequest/paramList/param[@name='p.s']">p.s=<xsl:value-of select="/page/pageRequest/paramList/param[@name='p.s']/@value"/>&amp;</xsl:if></xsl:variable>
+							 
 								<div id="tableOfContents">
-									<xsl:attribute name="class">
+								  <!-- if ed=1 or ec=1 then we have the complete section hierarchy in the page xml source, so we don't need an ajax call to get the table of contents, we just generate it from the list of nodes -->
+									<xsl:attribute name="class"> <!-- do we ever need this ?? -->
 										<xsl:choose>
 											<xsl:when test="count(//documentNode) > 1">visible</xsl:when>
@@ -134,5 +129,4 @@
 										</xsl:choose>
 									</xsl:attribute>
-									<table style="width:100%; text-align:center;"><tr><td><a href="{$doc_url}ed=1"><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'doc.expand_doc')"/></a></td><td><a href="{$doc_url}ed=0"><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'doc.collapse_doc')"/></a></td></tr></table>
 									<xsl:for-each select="documentNode">
 										<xsl:call-template name="documentNodeTOC"/>
@@ -150,13 +144,4 @@
 	<!-- This template is used to display the table of contents -->
 	<xsl:template name="documentNodeTOC">
-
-		<!-- check if this is the currently selected table of contents item -->
-		<xsl:variable name="isCurrent" select="nodeContent"/>
-
-		<!-- formulate the link -->
-		<xsl:variable name="contentsLink">
-			<xsl:value-of select='$library_name'/>?a=d&amp;c=<gslib:collectionNameShort/>&amp;d=<xsl:value-of select='@nodeID'/><xsl:if test="documentNode">.pr</xsl:if>&amp;sib=1
-		</xsl:variable>
-
 		<ul>
 			<table><tr>
@@ -165,5 +150,5 @@
 					<td>
 						<xsl:choose>
-							<xsl:when test="not(nodeContent and not(documentNode))">
+							<xsl:when test="documentNode">
 								<img id="ttoggle{@nodeID}" onclick="toggleSection('{@nodeID}');" class="icon">
 									<xsl:attribute name="src">
@@ -189,5 +174,5 @@
 				<td>
 					<img>
-						<xsl:if test="nodeContent and not(documentNode)">
+						<xsl:if test="not(documentNode)">
 							<xsl:attribute name="class">leafNode</xsl:attribute>
 						</xsl:if>
@@ -195,5 +180,5 @@
 						<xsl:attribute name="src">
 							<xsl:choose>
-								<xsl:when test="nodeContent and not(documentNode)">
+								<xsl:when test="not(documentNode)">
 									<xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'page_image')"/> 
 								</xsl:when>
