Index: main/trunk/greenstone3/web/interfaces/oran/js/document_scripts.js
===================================================================
--- main/trunk/greenstone3/web/interfaces/oran/js/document_scripts.js	(revision 24467)
+++ main/trunk/greenstone3/web/interfaces/oran/js/document_scripts.js	(revision 24467)
@@ -0,0 +1,252 @@
+/********************
+* EXPANSION SCRIPTS *
+********************/
+
+var collapseImageURL = gs.imageURLs.collapse;
+var expandImageURL = gs.imageURLs.expand;
+var chapterImageURL = gs.imageURLs.chapter;
+var pageImageURL = gs.imageURLs.page;
+
+function toggleSection(sectionID)
+{
+	var docElem = document.getElementById("doc" + sectionID);
+	var tocElem = document.getElementById("toc" + sectionID);
+	
+	var tocToggleElem = document.getElementById("ttoggle" + sectionID);
+	var docToggleElem = document.getElementById("dtoggle" + sectionID);
+	
+	if(docElem.style.display == "none")
+	{
+		docElem.style.display = "block";
+		docToggleElem.setAttribute("src", collapseImageURL);
+		
+		if(tocToggleElem)
+		{
+			tocToggleElem.setAttribute("src", collapseImageURL);
+		}
+		
+		if(tocElem)
+		{
+			tocElem.style.display = "block";
+		}
+	}
+	else
+	{
+		docElem.style.display = "none";
+		
+		//Use the page image if this is a leaf node and the chapter image if it not
+		docToggleElem.setAttribute("src", expandImageURL);
+		
+		if(tocToggleElem)
+		{
+			tocToggleElem.setAttribute("src", expandImageURL);
+		}
+		
+		if(tocElem)
+		{
+			tocElem.style.display = "none";
+		}
+	}
+}
+
+function isExpanded(sectionID)
+{
+	var docElem = document.getElementById("doc" + sectionID);
+	if(docElem.style.display == "block")
+	{
+		return true;
+	}
+	return false;
+}
+
+function isParentOf(parent, child)
+{
+	if(child.indexOf(parent) != -1 && child.length > parent.length && child[parent.length] == '.')
+	{
+		return true;
+	}
+	return false;
+}
+
+function focusSection(sectionID)
+{
+	var tableOfContentsDiv = document.getElementById("tableOfContents");
+	var images = tableOfContentsDiv.getElementsByTagName("img");
+	var nodeArray = new Array();
+	
+	for(var i = 0; i < images.length; i++)
+	{	
+		nodeArray[i] = images[i].getAttribute("id").substring(7);
+	}
+	
+	for(var j = 0; j < nodeArray.length; j++)
+	{
+		//If this is the node that was clicked and it is not expanded then expand it
+		if(nodeArray[j] == sectionID)
+		{
+			if(!isExpanded(nodeArray[j]))
+			{
+				toggleSection(nodeArray[j]);
+			}
+			
+			continue;
+		}
+		
+		//If the node is a parent or child of the node that is clicked and is not expanded then expand it
+		if((isParentOf(nodeArray[j], sectionID) || isParentOf(sectionID, nodeArray[j])) && !isExpanded(nodeArray[j]))
+		{
+			toggleSection(nodeArray[j]);
+		}
+		//If the node is not a parent or child and is expanded then collapse it
+		else if(!(isParentOf(nodeArray[j], sectionID) || isParentOf(sectionID, nodeArray[j])) && isExpanded(nodeArray[j]))
+		{
+			toggleSection(nodeArray[j]);
+		}
+	}
+}
+
+/***********************
+* HIGHLIGHTING SCRIPTS *
+***********************/
+function addHighlight()
+{
+	var spans = document.getElementsByTagName("span");
+	for(var i = 0; i < spans.length; i++)
+	{
+		var currentSpan = spans[i];
+		if(currentSpan.getAttribute("class") == "noTermHighlight")
+		{
+			currentSpan.setAttribute("class", "termHighlight");
+		}
+	}
+	
+	var option = document.getElementById("highlightOption");
+	option.setAttribute("onclick", "removeHighlight();");
+}
+
+function removeHighlight()
+{
+	var spans = document.getElementsByTagName("span");
+	for(var i = 0; i < spans.length; i++)
+	{
+		var currentSpan = spans[i];
+		if(currentSpan.getAttribute("class") == "termHighlight")
+		{
+			currentSpan.setAttribute("class", "noTermHighlight");
+		}
+	}
+	
+	var option = document.getElementById("highlightOption");
+	option.setAttribute("onclick", "addHighlight();");
+}
+
+/**************************
+* REALISTIC BOOKS SCRIPTS *
+**************************/
+
+function bookInit()
+{
+	loadBook(); 
+	hideText(); 
+	showBook(); 
+	swapLinkJavascript(false);
+}
+
+function hideText()
+{
+	var textDiv = document.getElementById("gs-document-text");
+	textDiv.style.visibility = "hidden";
+}
+
+function showText()
+{
+	var textDiv = document.getElementById("gs-document-text");
+	textDiv.style.visibility = "visible";
+}
+
+function hideBook()
+{
+	var bookDiv = document.getElementById("bookdiv");
+	bookDiv.style.visibility = "hidden";
+	bookDiv.style.height = "0px";
+	
+	var bookObject = document.getElementById("bookObject");
+	bookObject.style.visibility = "hidden";
+	bookObject.style.height = "0px";
+	
+	var bookEmbed = document.getElementById("bookEmbed");
+	bookEmbed.style.visibility = "hidden";
+	bookEmbed.style.height = "0px";
+}
+
+function showBook()
+{
+	var bookDiv = document.getElementById("bookdiv");
+	bookDiv.style.visibility = "visible";
+	bookDiv.style.height = "600px";
+	
+	var bookObject = document.getElementById("bookObject");
+	bookObject.style.visibility = "visible";
+	bookObject.style.height = "600px";
+	
+	var bookEmbed = document.getElementById("bookEmbed");
+	bookEmbed.style.visibility = "visible";
+	bookEmbed.style.height = "600px";
+}
+
+function swapLinkJavascript(rbOn)
+{
+	var option = document.getElementById("rbOption");
+	if(rbOn)
+	{
+		option.setAttribute("onclick", "hideText(); showBook(); swapLinkJavascript(false);");
+	}
+	else
+	{
+		option.setAttribute("onclick", "hideBook(); showText(); swapLinkJavascript(true);");
+	}
+}
+
+//Helper function to create param elements
+function createParam(name, value)
+{
+	var param = document.createElement("PARAM");
+	param.setAttribute("name", name);
+	param.setAttribute("value", value);
+	return param;
+}
+
+function loadBook()
+{
+	var doc_url = document.URL; 
+	doc_url = doc_url.replace(/(&|\?)book=[a-z]+/gi,'');
+	doc_url += '&book=flashxml';
+	
+	var img_cover = gs.collectionMetadata.httpPath + '/index/assoc/' + gs.documentMetadata.assocfilepath + '/cover.jpg';
+
+	var flash_plug_html = ""
+	flash_plug_html += '<OBJECT align="middle" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" \n';
+	flash_plug_html += '  height="600px" id="bookObject" swLiveConnect="true" \n';
+	flash_plug_html += '  codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" \n';
+	flash_plug_html += '  width="70%">\n';
+	flash_plug_html += '    <PARAM name="allowScriptAccess" value="always" />\n';
+	flash_plug_html += '    <PARAM name="movie" value="Book.swf';
+	flash_plug_html += '?src_image=' + escape(img_cover);
+	flash_plug_html += '&doc_url=' + escape(doc_url)
+	flash_plug_html += '" />\n';
+	flash_plug_html += '    <PARAM name="quality" value="high" />\n';
+	flash_plug_html += '    <PARAM name="bgcolor" value="#FFFFFF" />\n';
+	flash_plug_html += '    <EMBED align="middle" \n';
+	flash_plug_html += '      allowScriptAccess="always" swLiveConnect="true" \n';
+	flash_plug_html += '      bgcolor="#FFFFFF" height="600px" name="Book" \n';
+	flash_plug_html += '      pluginspage="http://www.macromedia.com/go/getflashplayer" \n';
+	flash_plug_html += '      quality="high" id="bookEmbed"\n';
+	flash_plug_html += '      src="Book.swf';
+	flash_plug_html += '?src_image=' + escape(img_cover);
+	flash_plug_html += '&doc_url=' + escape(doc_url);
+	flash_plug_html += '"\n'; 
+	flash_plug_html += '      type="application/x-shockwave-flash" width="70%" />\n';
+	flash_plug_html += '</OBJECT>\n';
+	var flash_div = document.getElementById("bookdiv");
+	flash_div.innerHTML = flash_plug_html;
+}
Index: main/trunk/greenstone3/web/interfaces/oran/transform/javascript-global-setup.xsl
===================================================================
--- main/trunk/greenstone3/web/interfaces/oran/transform/javascript-global-setup.xsl	(revision 24467)
+++ main/trunk/greenstone3/web/interfaces/oran/transform/javascript-global-setup.xsl	(revision 24467)
@@ -0,0 +1,167 @@
+<xsl:stylesheet version="1.0"
+	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+	xmlns:java="http://xml.apache.org/xslt/java"
+	xmlns:util="xalan://org.greenstone.gsdl3.util.XSLTUtil"
+	xmlns:gslib="http://www.greenstone.org/skinning"
+	extension-element-prefixes="java util"
+	exclude-result-prefixes="java util">
+	
+	<xsl:template name="setup-gs-variable">
+		<script type="text/javascript">
+			gs = new Array();
+			gs.cgiParams = new Array();
+			gs.siteMetadata = new Array();
+			gs.collectionMetadata = new Array();
+			gs.documentMetadata = new Array();
+			gs.imageURLs = new Array();
+			gs.variables = new Array();
+		</script>
+		<xsl:call-template name="populate-cgi-param-values"/>
+		<xsl:call-template name="populate-image-url-values"/>
+		<xsl:call-template name="populate-metadata-values"/>
+		<script type="text/javascript">
+			alert(gs.cgiParams.c);
+			alert(gs.cgiParams.book);
+			alert(gs.siteMetadata.siteDescription);
+			alert(gs.siteMetadata.fr.siteDescription);
+			alert(gs.collectionMetadata.httpPath);
+			alert(gs.documentMetadata.assocfilepath);
+		</script>
+	</xsl:template>
+	
+	<xsl:template name="populate-cgi-param-values">
+		<xsl:for-each select="/page/pageRequest/paramList/param">
+			<script type="text/javascript">
+				<xsl:text disable-output-escaping="yes">var name = "</xsl:text><xsl:value-of select="@name"/><xsl:text disable-output-escaping="yes">";</xsl:text>
+				<xsl:text disable-output-escaping="yes">var value = "</xsl:text><xsl:value-of select="@value"/><xsl:text disable-output-escaping="yes">";</xsl:text>
+				<xsl:text disable-output-escaping="yes">name = name.replace(".", "_");</xsl:text>
+				gs.cgiParams[name] = value;
+			</script>
+		</xsl:for-each>
+	</xsl:template>
+	
+	<xsl:template name="populate-metadata-values">
+		<script type="text/javascript">
+			<xsl:text disable-output-escaping="yes">
+				function addMetadataToList(name, value, list, lang)
+				{
+					name = name.replace(".", "_");
+					if(lang == "" || lang == "en")
+					{
+						list[name] = value;
+					}
+					else
+					{
+						if (list[lang] == undefined)
+						{
+							list[lang] = new Array();
+						}
+						var langList = list[lang];
+						langList[name] = value;
+					}
+				}
+			</xsl:text>
+		</script>
+		<xsl:for-each select="/page/pageResponse/metadataList/metadata">
+			<script type="text/javascript">
+				<xsl:text disable-output-escaping="yes">var name = "</xsl:text><xsl:value-of select="@name"/><xsl:text disable-output-escaping="yes">";</xsl:text>
+				<xsl:text disable-output-escaping="yes">var value = "</xsl:text><xsl:value-of disable-output-escaping="yes" select="."/><xsl:text disable-output-escaping="yes">";</xsl:text>
+				<xsl:text disable-output-escaping="yes">var lang = "</xsl:text><xsl:value-of select="@lang"/><xsl:text disable-output-escaping="yes">";</xsl:text>
+				addMetadataToList(name, value, gs.siteMetadata, lang);
+			</script>
+		</xsl:for-each>
+		
+		<xsl:for-each select="/page/pageResponse/collection/metadataList/metadata">
+			<script type="text/javascript">
+				<xsl:text disable-output-escaping="yes">var name = "</xsl:text><xsl:value-of select="@name"/><xsl:text disable-output-escaping="yes">";</xsl:text>
+				<xsl:text disable-output-escaping="yes">var value = "</xsl:text><xsl:value-of disable-output-escaping="yes" select="."/><xsl:text disable-output-escaping="yes">";</xsl:text>
+				<xsl:text disable-output-escaping="yes">var lang = "</xsl:text><xsl:value-of select="@lang"/><xsl:text disable-output-escaping="yes">";</xsl:text>
+				addMetadataToList(name, value, gs.collectionMetadata, lang);
+			</script>
+		</xsl:for-each>
+		
+		<xsl:for-each select="/page/pageResponse/document/metadataList/metadata">
+			<script type="text/javascript">
+				<xsl:text disable-output-escaping="yes">var name = "</xsl:text><xsl:value-of select="@name"/><xsl:text disable-output-escaping="yes">";</xsl:text>
+				<xsl:text disable-output-escaping="yes">var value = "</xsl:text><xsl:value-of disable-output-escaping="yes" select="."/><xsl:text disable-output-escaping="yes">";</xsl:text>
+				<xsl:text disable-output-escaping="yes">var lang = "</xsl:text><xsl:value-of select="@lang"/><xsl:text disable-output-escaping="yes">";</xsl:text>
+				addMetadataToList(name, value, gs.documentMetadata, lang);
+			</script>
+		</xsl:for-each>
+	</xsl:template>
+	
+	<xsl:template name="populate-image-url-values">
+		<script type="text/javascript">
+			<xsl:text disable-output-escaping="yes">gs.imageURLs.expand = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'expand_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
+			<xsl:text disable-output-escaping="yes">gs.imageURLs.collapse = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'collapse_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
+			<xsl:text disable-output-escaping="yes">gs.imageURLs.page = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'page_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
+			<xsl:text disable-output-escaping="yes">gs.imageURLs.chapter = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'chapter_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
+			<xsl:text disable-output-escaping="yes">gs.imageURLs.realisticBook = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'realistic_books_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
+			<xsl:text disable-output-escaping="yes">gs.imageURLs.highlight = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'highlight_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
+			<xsl:text disable-output-escaping="yes">gs.imageURLs.bookshelf = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'bookshelf_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
+			<xsl:text disable-output-escaping="yes">gs.imageURLs.book = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'book_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
+			<xsl:text disable-output-escaping="yes">gs.imageURLs.loading = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'loading_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
+			<xsl:text disable-output-escaping="yes">gs.imageURLs.pageIcon = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'page_icon_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
+		</script>
+	</xsl:template>
+</xsl:stylesheet>
+
+	<!--
+	USEFUL FOR TESTING ASSOCIATIVE ARRAYS
+	function getKeys(obj)
+	{
+		var keys = [];
+		for(var key in obj)
+		{
+			keys.push(key);
+		}
+		return keys;
+	}
+	-->
+
+	<!-- CAN WE FIND SOME WAY TO MAKE THIS WORK?
+	<xsl:call-template name="populate-metadata-values">
+		<xsl:with-param name="path">/page/pageResponse/metadataList/metadata</xsl:with-param>
+		<xsl:with-param name="metadataListName">siteMetadata</xsl:with-param>
+	</xsl:call-template>
+	
+	<xsl:call-template name="populate-metadata-values">
+		<xsl:with-param name="path">/page/pageResponse/collection/metadataList/metadata</xsl:with-param>
+		<xsl:with-param name="metadataListName">collectionMetadata</xsl:with-param>
+	</xsl:call-template>
+	
+	<xsl:call-template name="populate-metadata-values">
+		<xsl:with-param name="path">/page/pageResponse/document/metadataList/metadata</xsl:with-param>
+		<xsl:with-param name="metadataListName">documentMetadata</xsl:with-param>
+	</xsl:call-template>
+	-->
+
+	<!-- NOT WORKING BUT IT WOULD BE TIDIER IF IT DID
+	<xsl:template name="populate-metadata-values">
+		<xsl:param name="path"/>
+		<xsl:param name="metadataListName"/>
+		
+		<xsl:for-each select="$path">
+			<script type="text/javascript">
+				<xsl:text disable-output-escaping="yes">var name = "</xsl:text><xsl:value-of select="@name"/><xsl:text disable-output-escaping="yes">";</xsl:text>
+				<xsl:text disable-output-escaping="yes">var value = "</xsl:text><xsl:value-of select="."/><xsl:text disable-output-escaping="yes">";</xsl:text>
+				<xsl:text disable-output-escaping="yes">var lang = "</xsl:text><xsl:value-of select="@lang"/><xsl:text disable-output-escaping="yes">";</xsl:text>
+				<xsl:text disable-output-escaping="yes">var metadataListName = "</xsl:text><xsl:value-of select="$metadataListName"/><xsl:text disable-output-escaping="yes">";</xsl:text>
+				var list = gs[metadataListName];
+				if(lang == "")
+				{
+					list[name] = value;
+				}
+				else
+				{
+					if (list[lang] == undefined)
+					{
+						list[lang] = new Array();
+					}
+					var langList = list[lang];
+					langList[name] = value;
+				}
+			</script>
+		</xsl:for-each>
+	</xsl:template>
+	-->
Index: main/trunk/greenstone3/web/interfaces/oran/transform/pages/document.xsl
===================================================================
--- main/trunk/greenstone3/web/interfaces/oran/transform/pages/document.xsl	(revision 24458)
+++ main/trunk/greenstone3/web/interfaces/oran/transform/pages/document.xsl	(revision 24467)
@@ -65,14 +65,17 @@
 			<div id="bookdiv" style="visibility:hidden; height:0px; display:inline;"><xsl:text> </xsl:text></div>
 		
+			<script type="text/javascript" src="interfaces/{$interface_name}/js/document_scripts.js"><xsl:text> </xsl:text></script>
+			
 			<!-- Adds the realistic books javascript if necessary ( *** in document-scripts.xsl *** ) -->
 			<xsl:if test="/page/pageResponse/collection[@name = $collName]/metadataList/metadata[@name = 'tidyoption'] = 'tidy'">
-				<xsl:call-template name="realisticBooksScript"/>
-			</xsl:if>
-			
-			<!-- Add the Javascript that adds and removes highlighting ( *** in document-scripts.xsl *** ) -->
-			<xsl:call-template name="highlightingScript"/>
-			
-			<!-- Add the Javascript that expands and collapses sections ( *** in document-scripts.xsl *** ) -->
-			<xsl:call-template name="expansionScript"/>
+				<script type="text/javascript">
+					<xsl:text disable-output-escaping="yes">
+						if(document.URL.indexOf("book=on") != -1)
+						{
+							loadBook();
+						}
+					</xsl:text>
+				</script>
+			</xsl:if>
 		
 			<!-- show the little berries for this document -->
@@ -130,5 +133,12 @@
 				<!-- *** in document-scripts.xsl *** -->
 				<div id="bookdiv" style="display:inline;"><xsl:text> </xsl:text></div>
-				<xsl:call-template name="realisticBooksScript"/>
+				<script type="text/javascript">
+					<xsl:text disable-output-escaping="yes">
+						if(document.URL.indexOf("book=on") != -1)
+						{
+							loadBook();
+						}
+					</xsl:text>
+				</script>
 			</xsl:when>
 			<xsl:otherwise>
