Index: main/trunk/greenstone3/web/interfaces/default/js/document_scripts.js
===================================================================
--- main/trunk/greenstone3/web/interfaces/default/js/document_scripts.js	(revision 26396)
+++ main/trunk/greenstone3/web/interfaces/default/js/document_scripts.js	(revision 26397)
@@ -38,36 +38,31 @@
 	}
 	
-	var ajax = gs.functions.ajaxRequest();
-	ajax.open("GET", gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "/document/" + sectionID + "?hl=" + hl + "&p.s=TextQuery&ilt=" + template.replace(" ", "%20"), true);
-	ajax.onreadystatechange = function()
-	{
-		if(ajax.readyState == 4 && ajax.status == 200)
-		{
-			var response = ajax.responseText;
+	var url = gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "/document/" + sectionID + "?hl=" + hl + "&p.s=TextQuery&ilt=" + template.replace(" ", "%20");
+	
+	$.ajax(url)
+	.success(function(response)
+	{
+		if(response)
+		{
+			var textStart = response.indexOf(">", response.indexOf(">") + 1) + 1;
+			var textEnd = response.lastIndexOf("<");
 			
-			if(response)
-			{
-				var textStart = response.indexOf(">", response.indexOf(">") + 1) + 1;
-				var textEnd = response.lastIndexOf("<");
-				
-				if(textStart == 0 || textEnd == -1 || textEnd <= textStart)
-				{
-					callback("");
-				}
-				
-				var text = response.substring(textStart, textEnd);
-				callback(text);
-			}
-			else
-			{
-				callback(null);
-			}
-		}
-		else if(ajax.readyState == 4)
+			if(textStart == 0 || textEnd == -1 || textEnd <= textStart)
+			{
+				callback("");
+			}
+			
+			var text = response.substring(textStart, textEnd);
+			callback(text);
+		}
+		else
 		{
 			callback(null);
 		}
-	}
-	ajax.send();
+	})
+	.error(function()
+	{
+		callback(null);
+	});
 }
 
@@ -88,5 +83,4 @@
 	template += '</xsl:template>';
 
-	var ajax = gs.functions.ajaxRequest();
 	var url = gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "/document/" + sectionID + "?ilt=" + template.replace(" ", "%20");
 
@@ -95,59 +89,54 @@
 		url += "&dt=hierarchy";
 	}
-	ajax.open("GET", url, true);
-	ajax.onreadystatechange = function()
-	{
-		if(ajax.readyState == 4 && ajax.status == 200)
-		{
-			var response = ajax.responseText;
+	
+	$.ajax(url)
+	.success(function(response)
+	{
+		if(response)
+		{
+			var sectionsStart = response.indexOf(">", response.indexOf(">") + 1) + 1;
+			var sectionsEnd = response.lastIndexOf("<");
 			
-			if(response)
-			{
-				var sectionsStart = response.indexOf(">", response.indexOf(">") + 1) + 1;
-				var sectionsEnd = response.lastIndexOf("<");
-				
-				if(sectionsStart == 0 || sectionsEnd == -1 || sectionsEnd <= sectionsStart)
-				{
-					callback(" ");
-					return;
-				}
-				
-				var sections = response.substring(sectionsStart, sectionsEnd);
-				callback(sections);
-			}
-			else
-			{
-				callback(null);
-			}
-		}
-		else if(ajax.readyState == 4)
+			if(sectionsStart == 0 || sectionsEnd == -1 || sectionsEnd <= sectionsStart)
+			{
+				callback(" ");
+				return;
+			}
+			
+			var sections = response.substring(sectionsStart, sectionsEnd);
+			callback(sections);
+		}
+		else
 		{
 			callback(null);
 		}
-	}
-	ajax.send();
+	})
+	.error(function()
+	{
+		callback(null);
+	});
 }
 
 function toggleSection(sectionID, callback, tocDisabled)
 {
-	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")
-	{
-		if(tocToggleElem && !tocDisabled)
-		{
-			tocToggleElem.setAttribute("src", gs.imageURLs.collapse);
-		}
-		
-		if(tocElem && !tocDisabled)
-		{
-			tocElem.style.display = "block";
-		}
-		
-		if(gs.functions.hasClass(docElem, "noText"))
+	var docElem = gs.jqGet("doc" + sectionID);
+	var tocElem = gs.jqGet("toc" + sectionID);
+	
+	var tocToggleElem = gs.jqGet("ttoggle" + sectionID);
+	var docToggleElem = gs.jqGet("dtoggle" + sectionID);
+	
+	if(docElem.css("display") == "none")
+	{
+		if(tocToggleElem.length && !tocDisabled)
+		{
+			tocToggleElem.attr("src", gs.imageURLs.collapse);
+		}
+		
+		if(tocElem.length && !tocDisabled)
+		{
+			tocElem.css("display", "block");
+		}
+		
+		if(docElem.hasClass("noText"))
 		{
 			getTextForSection(sectionID, function(text)
@@ -158,6 +147,6 @@
 					if(text.search("wrap" + nodeID) != -1)
 					{
-						document.getElementById("zoomOptions").style.display = null;
-						document.getElementById("pagedImageOptions").style.display = null;
+						gs.jqGet("zoomOptions").css("display", null);
+						gs.jqGet("pagedImageOptions").css("display", null);
 					}
 					getSubSectionsForSection(sectionID, function(sections)
@@ -165,10 +154,10 @@
 						if(sections)
 						{
-							var textElem = document.getElementById("doc" + sectionID);
-							$(textElem).html(text + sections);
+							var textElem = gs.jqGet("doc" + sectionID);
+							textElem.html(text + sections);
 							
-							docElem.setAttribute("class", docElem.getAttribute("class").replace(/\bnoText\b/g, ""));
-							docElem.style.display = "block";
-							docToggleElem.setAttribute("src", gs.imageURLs.collapse);
+							docElem.removeClass("noText");
+							docElem.css("display", "block");
+							docToggleElem.attr("src", gs.imageURLs.collapse);
 							
 							if(callback)
@@ -177,5 +166,5 @@
 							}
 							
-							if(document.getElementById("viewSelection"))
+							if(gs.jqGet("viewSelection").length)
 							{
 								changeView();
@@ -184,5 +173,5 @@
 						else
 						{
-							docToggleElem.setAttribute("src", gs.imageURLs.expand);
+							docToggleElem.attr("src", gs.imageURLs.expand);
 							if(callback)
 							{
@@ -194,5 +183,5 @@
 				else
 				{
-					docToggleElem.setAttribute("src", gs.imageURLs.expand);
+					docToggleElem.attr("src", gs.imageURLs.expand);
 					if(callback)
 					{
@@ -202,10 +191,10 @@
 			});
 		
-			docToggleElem.setAttribute("src", gs.imageURLs.loading);
+			docToggleElem.attr("src", gs.imageURLs.loading);
 		}
 		else
 		{
-			docToggleElem.setAttribute("src", gs.imageURLs.collapse);
-			docElem.style.display = "block";
+			docToggleElem.attr("src", gs.imageURLs.collapse);
+			docElem.css("display", "block");
 			
 			if(callback)
@@ -217,17 +206,17 @@
 	else
 	{
-		docElem.style.display = "none";
+		docElem.css("display", "none");
 		
 		//Use the page image if this is a leaf node and the chapter image if it not
-		docToggleElem.setAttribute("src", gs.imageURLs.expand);
-		
-		if(tocToggleElem)
-		{
-			tocToggleElem.setAttribute("src", gs.imageURLs.expand);
-		}
-		
-		if(tocElem)
-		{
-			tocElem.style.display = "none";
+		docToggleElem.attr("src", gs.imageURLs.expand);
+		
+		if(tocToggleElem.length)
+		{
+			tocToggleElem.attr("src", gs.imageURLs.expand);
+		}
+		
+		if(tocElem.length)
+		{
+			tocElem.css("display", "none");
 		}
 		
@@ -288,5 +277,5 @@
 function expandOrCollapseAll(expand)
 {
-	var divs = document.getElementsByTagName("DIV");
+	var divs = $("div");
 	var startCounter = 0;
 	var endCounter = 0;
@@ -294,7 +283,7 @@
 	for(var i = 0; i < divs.length; i++)
 	{
-		if(divs[i].getAttribute("id") && divs[i].getAttribute("id").search(/^doc/) != -1)
-		{
-			var id = divs[i].getAttribute("id").replace(/^doc(.*)/, "$1");
+		if($(divs[i]).attr("id") && $(divs[i]).attr("id").search(/^doc/) != -1)
+		{
+			var id = $(divs[i]).attr("id").replace(/^doc(.*)/, "$1");
 			if(isExpanded(id) != expand)
 			{
@@ -344,58 +333,48 @@
 function loadTopLevelPage(callbackFunction, customURL)
 {
-	var ajax = gs.functions.ajaxRequest();
-
-	var url = gs.xsltParams.library_name + "?a=d&c=" + gs.cgiParams.c + "&excerptid=gs-document";
-	if(gs.cgiParams.d && gs.cgiParams.d.length > 0)
-	{
-		url += "&d=" + gs.cgiParams.d.replace(/([^.]*)\..*/, "$1");
-	}
-	else if(gs.cgiParams.href && gs.cgiParams.href.length > 0)
-	{
-		url += "&d=&alb=1&rl=1&href=" + gs.cgiParams.href;
-	}
-
-	if(customURL != null)
-	{
-		ajax.open("GET", customURL, true);
+	var url;
+	if(customURL)
+	{
+		url = customURL;
 	}
 	else
 	{
-		ajax.open("GET", url, true);
-	}
-
-	ajax.onreadystatechange = function()
-	{
-		if(ajax.readyState == 4 && ajax.status == 200)
-		{
-			var response = ajax.responseText;
+		url = gs.xsltParams.library_name + "?a=d&c=" + gs.cgiParams.c + "&excerptid=gs-document";
+		if(gs.cgiParams.d && gs.cgiParams.d.length > 0)
+		{
+			url += "&d=" + gs.cgiParams.d.replace(/([^.]*)\..*/, "$1");
+		}
+		else if(gs.cgiParams.href && gs.cgiParams.href.length > 0)
+		{
+			url += "&d=&alb=1&rl=1&href=" + gs.cgiParams.href;
+		}
+	}
+
+	$.ajax(url)
+	.success(function(response)
+	{
+		if(response)
+		{
+			var targetElem = gs.jqGet("gs-document");
+			var docStart = response.indexOf(">") + 1;
+			var docEnd = response.lastIndexOf("<");
+			var doc = response.substring(docStart, docEnd);
+
+			targetElem.html(doc);
 			
-			if(response)
-			{
-				var targetElem = document.getElementById("gs-document");
-				var docStart = response.indexOf(">") + 1;
-				var docEnd = response.lastIndexOf("<");
-				var doc = response.substring(docStart, docEnd);
-
-				targetElem.innerHTML = doc;
-				
-				if(callbackFunction)
-				{
-					callbackFunction();
-				}
-			}
-		}
-		else if(ajax.readyState == 4)
-		{
-			setTimeout(function(){loadTopLevelPage(callbackFunction, customURL);}, 1000);
-		}
-	};
-	ajax.send();
+			if(callbackFunction)
+			{
+				callbackFunction();
+			}
+		}
+	})
+	.error(function()
+	{
+		setTimeout(function(){loadTopLevelPage(callbackFunction, customURL);}, 1000);
+	});
 }
 
 function retrieveFullTableOfContents()
 {
-	var ajax = gs.functions.ajaxRequest();
-	
 	var url = gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "?excerptid=tableOfContents&ed=1";
 	if(gs.cgiParams.d && gs.cgiParams.d.length > 0)
@@ -407,41 +386,36 @@
 		url += "&a=d&d=&alb=1&rl=1&href=" + gs.cgiParams.href;
 	}
-	
-	ajax.open("GET", url, true);
-	ajax.onreadystatechange = function()
-	{
-		if(ajax.readyState == 4 && ajax.status == 200)
-		{
-			var newTOCElem = ajax.responseText;
-			var tocStart = newTOCElem.indexOf(">") + 1;
-			var tocEnd = newTOCElem.lastIndexOf("<");
-			
-			var newTOC = newTOCElem.substring(tocStart, tocEnd);
-			
-			//Add the "Expand document"/"Collapse document" links
-			newTOC = "<table style=\"width:100%; text-align:center;\"><tr><td><a href=\"javascript:expandOrCollapseAll(true);\">Expand document</a></td><td><a href=\"javascript:expandOrCollapseAll(false);\">Collapse document</a></td></tr></table>" + newTOC;
-			
-			//Collapse the TOC
-			newTOC = newTOC.replace(/display:block/g, "display:none");
-			newTOC = newTOC.replace(/display:none/, "display:block");
-			newTOC = newTOC.replace(/images\/collapse/g, "images/expand");
-			
-			var tocElem = document.getElementById("tableOfContents");
-			tocElem.innerHTML = newTOC;
-			
-			gs.variables.tocLoaded = true;
-		}
-		else if(ajax.readyState == 4)
-		{
-			setTimeout(retrieveFullTableOfContents, 1000);
-		}
-	}
-	ajax.send();
+
+	$.ajax(url)
+	.success(function(newTOCElem)
+	{
+		var tocStart = newTOCElem.indexOf(">") + 1;
+		var tocEnd = newTOCElem.lastIndexOf("<");
+		
+		var newTOC = newTOCElem.substring(tocStart, tocEnd);
+		
+		//Add the "Expand document"/"Collapse document" links
+		newTOC = "<table style=\"width:100%; text-align:center;\"><tr><td><a href=\"javascript:expandOrCollapseAll(true);\">Expand document</a></td><td><a href=\"javascript:expandOrCollapseAll(false);\">Collapse document</a></td></tr></table>" + newTOC;
+		
+		//Collapse the TOC
+		newTOC = newTOC.replace(/display:block/g, "display:none");
+		newTOC = newTOC.replace(/display:none/, "display:block");
+		newTOC = newTOC.replace(/images\/collapse/g, "images/expand");
+		
+		var tocElem = gs.jqGet("tableOfContents");
+		tocElem.html(newTOC);
+		
+		gs.variables.tocLoaded = true;
+	})
+	.error(function()
+	{
+		setTimeout(retrieveFullTableOfContents, 1000);
+	});
 }
 
 function isExpanded(sectionID)
 {
-	var docElem = document.getElementById("doc" + sectionID);
-	if(docElem.style.display == "block")
+	var docElem = gs.jqGet("doc" + sectionID);
+	if(docElem.css("display") == "block")
 	{
 		return true;
@@ -450,47 +424,38 @@
 }
 
-function isParentOf(parent, child)
-{
-	if(child.indexOf(parent) != -1 && child.length > parent.length && child[parent.length] == '.')
-	{
-		return true;
-	}
-	return false;
-}
-
 function minimizeSidebar()
 {
-	var toc = document.getElementById("contentsArea");
-	var maxLink = document.getElementById("sidebarMaximizeButton");
-	var minLink = document.getElementById("sidebarMinimizeButton");
-	
-	if(toc)
-	{
-		toc.style.display = "none";
-	}
-	
-	maxLink.style.display = "block";
-	minLink.style.display = "none";
+	var toc = gs.jqGet("contentsArea");
+	var maxLink = gs.jqGet("sidebarMaximizeButton");
+	var minLink = gs.jqGet("sidebarMinimizeButton");
+	
+	if(toc.length)
+	{
+		toc.css("display", "none");
+	}
+	
+	maxLink.css("display", "block");
+	minLink.css("display", "none");
 }
 
 function maximizeSidebar()
 {
-	var coverImage = document.getElementById("coverImage");
-	var toc = document.getElementById("contentsArea");
-	var maxLink = document.getElementById("sidebarMaximizeButton");
-	var minLink = document.getElementById("sidebarMinimizeButton");
-	
-	if(coverImage)
-	{
-		coverImage.style.display = "block";
-	}
-	
-	if(toc)
-	{
-		toc.style.display = "block";
-	}
-	
-	maxLink.style.display = "none";
-	minLink.style.display = "block";
+	var coverImage = gs.jqGet("coverImage");
+	var toc = gs.jqGet("contentsArea");
+	var maxLink = gs.jqGet("sidebarMaximizeButton");
+	var minLink = gs.jqGet("sidebarMinimizeButton");
+	
+	if(coverImage.length)
+	{
+		coverImage.css("display", "block");
+	}
+	
+	if(toc.length)
+	{
+		toc.css("display", "block");
+	}
+	
+	maxLink.css("display", "none");
+	minLink.css("display", "block");
 }
 
@@ -501,6 +466,6 @@
 function changeView()
 {
-	var viewList = document.getElementById("viewSelection");
-	var currentVal = viewList.value;
+	var viewList = gs.jqGet("viewSelection");
+	var currentVal = viewList.val();
 	
 	var view;
@@ -524,18 +489,17 @@
 	}
 	
-	var ajax = gs.functions.ajaxRequest();
-	ajax.open("GET", gs.xsltParams.library_name + "?a=d&view=" + view + "&c=" + gs.cgiParams.c);
-	ajax.send();
+	var url = gs.xsltParams.library_name + "?a=d&view=" + view + "&c=" + gs.cgiParams.c;
+	$.ajax(url);
 }
 
 function setImageVisible(visible)
 {
-	var divs = document.getElementsByTagName("DIV");
+	var divs = $("div");
 	var images = new Array();
 	for (var i = 0; i < divs.length; i++)
 	{
-		if(divs[i].id && divs[i].id.search(/^image/) != -1)
-		{
-			images.push(divs[i]);
+		if($(divs[i]).attr("id") && $(divs[i]).attr("id").search(/^image/) != -1)
+		{
+			images.push($(divs[i]));
 		}
 	}
@@ -546,9 +510,9 @@
 		if(visible)
 		{
-			image.style.display = "block";
+			image.css("display", "block");
 		}
 		else
 		{
-			image.style.display = "none";
+			image.css("display", "none");
 		}
 	}
@@ -557,11 +521,11 @@
 function setTextVisible(visible)
 {
-	var divs = document.getElementsByTagName("DIV");
+	var divs = $("div");
 	var textDivs = new Array();
 	for (var i = 0; i < divs.length; i++)
 	{
-		if(divs[i].id && divs[i].id.search(/^text/) != -1)
-		{
-			textDivs.push(divs[i]);
+		if($(divs[i]).attr("id") && $(divs[i]).attr("id").search(/^text/) != -1)
+		{
+			textDivs.push($(divs[i]));
 		}
 	}
@@ -572,9 +536,9 @@
 		if(visible)
 		{
-			text.style.display = "block";
+			text.css("display", "block");
 		}
 		else
 		{
-			text.style.display = "none";
+			text.css("display", "none");
 		}
 	}
@@ -589,33 +553,30 @@
 	ilt +=   '</xsl:for-each>';
 	ilt += '</xsl:template>';
-
-	var ajax = gs.functions.ajaxRequest();
-	ajax.open("GET", gs.xsltParams.library_name + "?a=d&ed=1&c=" + gs.cgiParams.c + "&d=" + gs.cgiParams.d + "&ilt=" + ilt.replace(/ /g, "%20"), true);
-	ajax.onreadystatechange = function()
-	{
-		if(ajax.readyState == 4 && ajax.status == 200)
-		{
-			document.getElementById("tableOfContents").innerHTML = ajax.responseText;
-			replaceLinksWithSlider();
-			var loading = document.getElementById("tocLoadingImage");
-			loading.parentNode.removeChild(loading);
-		}
-		else if(ajax.readyState == 4)
-		{
-			setTimeout(function(){retrieveTableOfContentsAndTitles();}, 1000);
-		}
-	}
-	ajax.send();
+	
+	var url = gs.xsltParams.library_name + "?a=d&ed=1&c=" + gs.cgiParams.c + "&d=" + gs.cgiParams.d + "&ilt=" + ilt.replace(/ /g, "%20");
+
+	$.ajax(url)
+	.success(function(response)
+	{
+		gs.jqGet("tableOfContents").html(response);
+		replaceLinksWithSlider();
+		var loading = gs.jqGet("tocLoadingImage");
+		loading.remove();
+	})
+	.error(function()
+	{
+		setTimeout(function(){retrieveTableOfContentsAndTitles();}, 1000);
+	});
 }
 
 function replaceLinksWithSlider()
 {
-	var tableOfContents = document.getElementById("tableOfContents");
-	var liElems = tableOfContents.getElementsByTagName("LI");
-	
+	var tableOfContents = gs.jqGet("tableOfContents");
+	var liElems = tableOfContents.find("li");
+
 	var leafSections = new Array();
 	for (var i = 0; i < liElems.length; i++)
 	{
-		var section = liElems[i];
+		var section = $(liElems[i]);
 		var add = true;
 		for(var j = 0; j < leafSections.length; j++)
@@ -623,16 +584,16 @@
 			if(leafSections[j] == undefined){continue;}
 			
-			var leaf = leafSections[j];
-			if(leaf.getAttribute("id").search(section.getAttribute("id")) != -1)
+			var leaf = $(leafSections[j]);
+			if(leaf.attr("id").search(section.attr("id")) != -1)
 			{
 				add = false;
 			}
 			
-			if(section.getAttribute("id").search(leaf.getAttribute("id")) != -1)
+			if(section.attr("id").search(leaf.attr("id")) != -1)
 			{
 				delete leafSections[j];
 			}
 		}
-		
+
 		if(add)
 		{
@@ -644,22 +605,24 @@
 	{
 		if(leafSections[i] == undefined){continue;}
-		leafSections[i].style.display = "none";
-		var links = leafSections[i].getElementsByTagName("A");
+
+		leafSections[i].css("display", "none");
+		var links = leafSections[i].find("a");
+
 		var widget = new SliderWidget(links);
-		leafSections[i].parentNode.insertBefore(widget.getElem(), leafSections[i]);
-	}
-	
+		leafSections[i].before(widget.getElem());
+	}
+
 	//Disable all TOC toggles
-	var imgs = document.getElementsByTagName("IMG");
+	var imgs = $("img");
 	for(var j = 0; j < imgs.length; j++)
 	{
-		var currentImage = imgs[j];
-		if(currentImage.getAttribute("id") && currentImage.getAttribute("id").search(/^ttoggle/) != -1)
-		{
-			currentImage.setAttribute("onclick", "");
-		}
-		else if(currentImage.getAttribute("id") && currentImage.getAttribute("id").search(/^dtoggle/) != -1)
-		{
-			currentImage.setAttribute("onclick", currentImage.getAttribute("onclick").replace(/\)/, ", null, true)"));
+		var currentImage = $(imgs[j]);
+		if(currentImage.attr("id") && currentImage.attr("id").search(/^ttoggle/) != -1)
+		{
+			currentImage.attr("onclick", "");
+		}
+		else if(currentImage.attr("id") && currentImage.attr("id").search(/^dtoggle/) != -1)
+		{
+			currentImage.attr("onclick", currentImage.attr("onclick").replace(/\)/, ", null, true)"));
 		}
 	}
@@ -673,17 +636,20 @@
 
 	//The container for the widget
-	var _mainDiv = document.createElement("DIV");
-	_mainDiv.setAttribute("class", "ui-widget-content pageSlider");
+	var _mainDiv = $("<div>");
+	_mainDiv.attr("class", "ui-widget-content pageSlider");
 	
 	//The table of images
-	var _linkTable = document.createElement("TABLE");
-	_mainDiv.appendChild(_linkTable);
+	var _linkTable = $("<table>");
+	_mainDiv.append(_linkTable);
 	
 	//The image row of the table
-	var _linkRow = document.createElement("TR");
-	_linkTable.appendChild(_linkRow);
+	var _linkRow = $("<tr>");
+	_linkTable.append(_linkRow);
 	
 	//The list of titles we can search through
 	var _titles = new Array();
+	
+	//Keep track of the slider position
+	var _prevScroll = 0;
 
 	//****************
@@ -741,10 +707,10 @@
 					for(var i = 0; i < _titles.length; i++)
 					{
-						_titles[i][1].cell.style.display = "none";
+						$(_titles[i][1].cell).css("display", "none");
 					}
 					
 					for(var i = 0; i < matchingTitles.length; i++)
 					{
-						matchingTitles[i][1].cell.style.display = "table-cell";
+						$(matchingTitles[i][1].cell).css("display", "table-cell");
 					}
 				}
@@ -757,9 +723,9 @@
 					if(currentTitle[0].search(currentValue.replace(/\./g, "\\.")) != -1)
 					{
-						currentTitle[1].cell.style.display = "table-cell";
+						$(currentTitle[1].cell).css("display", "table-cell");
 					}
 					else
 					{
-						currentTitle[1].cell.style.display = "none";
+						$(currentTitle[1].cell).css("display", "none");
 					}
 				}
@@ -770,6 +736,4 @@
 	var getImage = function(page, attemptNumber)
 	{
-		var ajax = gs.functions.ajaxRequest();
-
 		var href = page.getAttribute("href");
 		var startHREF = href.indexOf("'") + 1;
@@ -797,51 +761,29 @@
 		template += '</xsl:template>';
 
-		ajax.open("GET", href + "?ilt=" + template.replace(" ", "%20"));
-		ajax.onreadystatechange = function()
-		{
-			if(ajax.readyState == 4 && ajax.status == 200)
-			{
-				var text = ajax.responseText;
-				var hrefStart = text.indexOf("src=\"") + 5;
-				if(hrefStart == -1)
-				{
-					page.isLoading = false;
-					page.noImage = true;
-					page.image.setAttribute("src", gs.imageURLs.blank);
-					return;
-				}
-				var hrefEnd = text.indexOf("\"", hrefStart);
-				var href = text.substring(hrefStart, hrefEnd);
-
-				var image = document.createElement("IMG");
-				$(image).load(function()
-				{
-					page.link.innerHTML = "";
-					page.link.appendChild(image);
-					page.isLoading = false;
-					page.imageLoaded = true;
-				});
-				$(image).error(function()
-				{
-					if(!attemptNumber || attemptNumber < 3)
-					{
-						setTimeout(function(){getImage(page, ((!attemptNumber) ? 1 : attemptNumber + 1));}, 500);
-					}
-					else
-					{
-						page.isLoading = false;
-						page.noImage = true;
-						image.setAttribute("src", gs.imageURLs.blank);
-					}
-				});
-				image.setAttribute("src", href);
-				
-				var titleStart = text.indexOf("<p>") + 3;
-				var titleEnd = text.indexOf("</p>");
-				var title = text.substring(titleStart, titleEnd);
-			}
-			else if (ajax.readyState == 4)
-			{
-				page.failed = true;
+		var url = href + "?ilt=" + template.replace(" ", "%20");
+		$.ajax(url)
+		.success(function(text)
+		{
+			var hrefStart = text.indexOf("src=\"") + 5;
+			if(hrefStart == -1)
+			{
+				page.isLoading = false;
+				page.noImage = true;
+				$(page.image).attr("src", gs.imageURLs.blank);
+				return;
+			}
+			var hrefEnd = text.indexOf("\"", hrefStart);
+			var href = text.substring(hrefStart, hrefEnd);
+
+			var image = $("<img>");
+			image.load(function()
+			{
+				$(page.link).html("");
+				$(page.link).append(image);
+				page.isLoading = false;
+				page.imageLoaded = true;
+			});
+			image.error(function()
+			{
 				if(!attemptNumber || attemptNumber < 3)
 				{
@@ -850,50 +792,77 @@
 				else
 				{
-					var image = document.createElement("IMG");
-					image.setAttribute("src", gs.imageURLs.blank);
-					page.link.innerHTML = "";
-					page.link.appendChild(image);
 					page.isLoading = false;
 					page.noImage = true;
+					image.attr("src", gs.imageURLs.blank);
 				}
-			}
-		}
-		ajax.send();
+			});
+			image.attr("src", href);
+			
+			var titleStart = text.indexOf("<p>") + 3;
+			var titleEnd = text.indexOf("</p>");
+			var title = text.substring(titleStart, titleEnd);
+		})
+		.error(function()
+		{
+			page.failed = true;
+			if(!attemptNumber || attemptNumber < 3)
+			{
+				setTimeout(function(){getImage(page, ((!attemptNumber) ? 1 : attemptNumber + 1));}, 500);
+			}
+			else
+			{
+				var image = document.createElement("IMG");
+				image.setAttribute("src", gs.imageURLs.blank);
+				page.link.innerHTML = "";
+				page.link.appendChild(image);
+				page.isLoading = false;
+				page.noImage = true;
+			}
+		});
 	}
 	
 	var startCheckFunction = function()
 	{
-		var checkFunction = function()
-		{
-			var widgetLeft = _mainDiv.scrollLeft;
-			var widgetRight = _mainDiv.clientWidth + _mainDiv.scrollLeft;
-
-			var visiblePages = new Array();
-			for(var i = 0; i < _links.length; i++)
-			{
-				var current = _links[i].cell;
-				var currentLeft = current.offsetLeft;
-				var currentRight = currentLeft + current.clientWidth;
-				if(currentRight > widgetLeft && currentLeft < widgetRight)
-				{
-					visiblePages.push(_links[i]);
-				}
-			}
-
-			for(var i = 0; i < visiblePages.length; i++)
-			{
-				var page = visiblePages[i];
-				if(!page || page.imageLoaded || page.noImage || page.isLoading)
-				{
-					continue;
+		var checkFunction = function(forced)
+		{
+			//Don't bother checking if we haven't scrolled very far
+			if(Math.abs(_mainDiv.scrollLeft() - _prevScroll) > 100 || forced)
+			{
+				_prevScroll = _mainDiv.scrollLeft();
+				_checking = true;
+				var widgetLeft = _mainDiv.offset().left;
+				var widgetRight = widgetLeft + _mainDiv.width();
+				
+				var visiblePages = new Array();
+				for(var i = 0; i < _links.length; i++)
+				{
+					var current = _links[i].cell;
+					var currentLeft = current.offset().left;
+					var currentRight = currentLeft + current.width();
+
+					if(currentRight > widgetLeft && currentLeft < widgetRight)
+					{
+						visiblePages.push(_links[i]);
+					}
 				}
 				
-				page.isLoading = true;
-				getImage(page);
-			}
-		}
-		
-		checkFunction();
-		setInterval(checkFunction, 1000);
+				for(var i = 0; i < visiblePages.length; i++)
+				{
+					var page = visiblePages[i];
+					if(!page || page.imageLoaded || page.noImage || page.isLoading)
+					{
+						continue;
+					}
+					
+					page.isLoading = true;
+					getImage(page);
+				}
+				_checking = false;
+			}
+		}
+
+		setTimeout(checkFunction, 250);
+		setInterval(function(){checkFunction(true)}, 2000);
+		_mainDiv.scroll(checkFunction);
 	}
 	
@@ -904,14 +873,14 @@
 	for(var i = 0; i < _links.length; i++)
 	{
-		var col = document.createElement("TD");
-		_linkRow.appendChild(col);
-		col.setAttribute("class", "pageSliderCol");
+		var col = $("<td>");
+		_linkRow.append(col);
+		col.addClass("pageSliderCol");
 		_links[i].cell = col;
 		
-		var link = document.createElement("A");
-		col.appendChild(link);
+		var link = $("<a>");
+		col.append(link);
 		_links[i].link = link;
-		var href = _links[i].getAttribute("href");
-		link.setAttribute("href", href.replace(/\)/, ", 0, true)"));
+		var href = $(_links[i]).attr("href");
+		link.attr("href", href.replace(/\)/, ", 0, true)"));
 		
 		if(!_linkCellMap[href])
@@ -921,10 +890,13 @@
 		_linkCellMap[href].push(_links[i]);
 		
-		var image = document.createElement("IMG");
-		link.appendChild(image);
-		image.setAttribute("src", gs.imageURLs.loading);
+		var loadingText = $("<p>Loading image</p>");
+		link.append(loadingText);
+		
+		var image = $("<img>");
+		link.append(image);
+		image.attr("src", gs.imageURLs.loading);
 		_links[i].image = image;
 		
-		var title = _links[i].innerHTML;
+		var title = $(_links[i]).html();
 		if(title.search(/^[^ ]+ [^ ]+$/) != -1)
 		{
@@ -938,7 +910,6 @@
 		_titles.push([title, _links[i]]);
 		
-		var text = document.createTextNode(title);
-		col.appendChild(document.createElement("BR"));
-		col.appendChild(text);
+		col.append($("<br>"));
+		col.append(title);
 	}
 	
@@ -952,5 +923,5 @@
 function swapHighlight(imageClicked)
 {
-	var hlCheckbox = document.getElementById("highlightOption");
+	var hlCheckbox = $("#highlightOption");
 
 	if(imageClicked)
@@ -961,5 +932,5 @@
 	var from;
 	var to;
-	if(hlCheckbox.checked)
+	if(hlCheckbox.attr("checked"))
 	{
 		from = "noTermHighlight";
@@ -971,14 +942,13 @@
 		to = "noTermHighlight";
 	}
-	
-	var spans = document.getElementsByTagName("span");
-	for(var i = 0; i < spans.length; i++)
-	{
-		var currentSpan = spans[i];
-		if(currentSpan.getAttribute("class") == from)
-		{
-			currentSpan.setAttribute("class", to);
-		}
-	}
+
+	var spans = $("span").each(function()
+	{
+		if($(this).hasClass(from))
+		{
+			$(this).removeClass(from);
+			$(this).addClass(to);
+		}
+	});
 }
 
@@ -997,70 +967,39 @@
 function hideText()
 {
-	var textDiv = document.getElementById("gs-document-text");
-	textDiv.style.visibility = "hidden";
+	$("#gs-document-text").css("visibility", "hidden");
 }
 
 function showText()
 {
-	var textDiv = document.getElementById("gs-document-text");
-	textDiv.style.visibility = "visible";
+	$("#gs-document-text").css("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";
+	$("#bookDiv, #bookObject, #bookEmbed").css({"visibility": "hidden", "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";
+	$("#bookDiv, #bookObject, #bookEmbed").css({"visibility": "visible", "height": "600px"});
 }
 
 function swapLinkJavascript(rbOn)
 {
-	var option = document.getElementById("rbOption");
-	var optionImage = document.getElementById("rbOptionImage");
+	var option = $("#rbOption");
+	var optionImage = $("#rbOptionImage");
 	
 	if(rbOn)
 	{
-		option.setAttribute("onclick", "hideText(); showBook(); swapLinkJavascript(false);");
-		optionImage.setAttribute("onclick", "hideText(); showBook(); swapLinkJavascript(false);");
+		option.attr("onclick", "hideText(); showBook(); swapLinkJavascript(false);");
+		optionImage.attr("onclick", "hideText(); showBook(); swapLinkJavascript(false);");
 		$(option).attr("checked", false);
 	}
 	else
 	{
-		option.setAttribute("onclick", "hideBook(); showText(); swapLinkJavascript(true);");
-		optionImage.setAttribute("onclick", "hideBook(); showText(); swapLinkJavascript(true);");
+		option.attr("onclick", "hideBook(); showText(); swapLinkJavascript(true);");
+		optionImage.attr("onclick", "hideBook(); showText(); swapLinkJavascript(true);");
 		$(option).attr("checked", 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;
 }
 
@@ -1096,70 +1035,64 @@
 	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;
-}
+	$("#bookdiv").html(flash_plug_html);
+}
+
+/************************
+* METADATA EDIT SCRIPTS *
+************************/
 
 function addEditMetadataLink(cell)
 {
-	var id = cell.getAttribute("id").substring(6);
-	var metaTable = document.getElementById("meta" + id);
-
-	var row = cell.parentNode;
-	var newCell = document.createElement("TD");
-	newCell.setAttribute("style", "font-size:0.7em; padding:0px 10px");
-	newCell.setAttribute("class", "editMetadataButton");
-	
-	var linkSpan = document.createElement("SPAN");
-	linkSpan.setAttribute("class", "ui-state-default ui-corner-all");
-	linkSpan.setAttribute("style", "padding: 2px; float:left;");
-	
-	var linkLabel = document.createElement("SPAN");
-	linkLabel.innerHTML = "edit metadata";
+	cell = $(cell);
+	var id = cell.attr("id").substring(6);
+	var metaTable = gs.jqGet("meta" + id);
+
+	var row = cell.parent();
+	var newCell = $("<td>", {"style": "font-size:0.7em; padding:0px 10px", "class": "editMetadataButton"});
+	var linkSpan = $("<span>", {"class": "ui-state-default ui-corner-all", "style": "padding: 2px; float:left;"});
+	
+	var linkLabel = $("<span>edit metadata</span>");	
+	var linkIcon = $("<span>", {"class": "ui-icon ui-icon-folder-collapsed"});
+	newCell.linkIcon = linkIcon;
 	newCell.linkLabel = linkLabel;
-	var linkIcon = document.createElement("SPAN");
-	linkIcon.setAttribute("class", "ui-icon ui-icon-folder-collapsed");
-	newCell.linkIcon = linkIcon;
-	
-	var uList = document.createElement("UL");
-	var labelItem = document.createElement("LI");
-	var iconItem = document.createElement("LI");
-	uList.appendChild(iconItem);
-	uList.appendChild(labelItem);
-	labelItem.appendChild(linkLabel);
-	iconItem.appendChild(linkIcon);
-	
-	uList.setAttribute("style", "outline: 0 none; margin:0px; padding:0px;");
-	labelItem.setAttribute("style", "float:left; list-style:none outside none;");
-	iconItem.setAttribute("style", "float:left; list-style:none outside none;");
-	
-	var newLink = document.createElement("A");
-	newLink.setAttribute("href", "javascript:;");
-	newLink.onclick = function()
-	{
-		if(metaTable.style.display == "none")
-		{
-			linkLabel.innerHTML = "hide metadata";
-			linkIcon.setAttribute("class", "ui-icon ui-icon-folder-open");
-			metaTable.style.display = "block";
-			metaTable.metaNameField.style.display = "inline";
-			metaTable.addRowButton.style.display = "inline";
+	
+	var uList = $("<ul>", {"style": "outline: 0 none; margin:0px; padding:0px;"});
+	var labelItem = $("<li>", {"style": "float:left; list-style:none outside none;"});
+	var iconItem = $("<li>", {"style": "float:left; list-style:none outside none;"});
+
+	uList.append(iconItem);
+	uList.append(labelItem);
+	labelItem.append(linkLabel);
+	iconItem.append(linkIcon);
+	
+	var newLink = $("<a>", {"href": "javascript:;"});
+	newLink.click(function()
+	{
+		if(metaTable.css("display") == "none")
+		{
+			linkLabel.html("hide metadata");
+			linkIcon.attr("class", "ui-icon ui-icon-folder-open");
+			metaTable.css("display", "block");
+			metaTable.metaNameField.css("display", "inline");
+			metaTable.addRowButton.css("display", "inline");
 		}
 		else
 		{
-			linkLabel.innerHTML = "edit metadata";
-			linkIcon.setAttribute("class", "ui-icon ui-icon-folder-collapsed");
-			metaTable.style.display = "none";
-			metaTable.metaNameField.style.display = "none";
-			metaTable.addRowButton.style.display = "none";
-		}
-	}
-	newLink.appendChild(uList);
-	linkSpan.appendChild(newLink);
-	newCell.appendChild(linkSpan);
-	row.appendChild(newCell);
+			linkLabel.html("edit metadata");
+			linkIcon.attr("class", "ui-icon ui-icon-folder-collapsed");
+			metaTable.css("display", "none");
+			metaTable.metaNameField.css("display", "none");
+			metaTable.addRowButton.css("display", "none");
+		}
+	});
+
+	newLink.append(uList);
+	linkSpan.append(newLink);
+	newCell.append(linkSpan);
+	row.append(newCell);
 	
 	addFunctionalityToTable(metaTable);
-	metaTable.metaNameField.style.display = "none";
-	metaTable.addRowButton.style.display = "none";
+	metaTable.metaNameField.css("display", "none");
+	metaTable.addRowButton.css("display", "none");
 }
 
@@ -1168,48 +1101,38 @@
 	if(visible)
 	{
-		document.getElementById("editContentButton").innerHTML = "Hide editor";
+		$("#editContentButton").html("Hide editor");
 	}
 	else
 	{
-		document.getElementById("editContentButton").innerHTML = "Edit content";
-	}
-
-	var saveButton = document.getElementById("saveButton");
-	var metadataListLabel = document.getElementById("metadataListLabel");
-	var metadataList = document.getElementById("metadataSetList");
+		$("#editContentButton").html("Edit content");
+	}
 	
 	var visibility = (visible ? "" : "none");
-	saveButton.style.display = visibility;
-	metadataListLabel.style.display = visibility;
-	metadataList.style.display = visibility;
-	
-	var buttons = gs.functions.getElementsByClassName("editMetadataButton");
-	
-	for(var i = 0; i < buttons.length; i++)
-	{
-		buttons[i].style.display = visibility;
-		buttons[i].linkLabel.innerHTML = "edit metadata";
-		buttons[i].linkIcon.setAttribute("class", "ui-icon ui-icon-folder-collapsed");
-	}
-	
-	var tables = document.getElementsByTagName("TABLE");
-	for(var i = 0; i < tables.length; i++)
-	{
-		var currentTable = tables[i];
-		if(currentTable.getAttribute("id") && currentTable.getAttribute("id").search(/^meta/) != -1)
-		{
-			currentTable.style.display = "none";
-			currentTable.metaNameField.style.display = "none";
-			currentTable.addRowButton.style.display = "none";
-		}
-	}
+	$("#saveButton, #metadataListLabel, #metadataSetList").css("display", visibility);
+	
+	$(".editMetadataButton").each(function()
+	{
+		$(this).css("display", visibility);
+		$(this.linkLabel).html("edit metadata");
+		$(this.linkIcon).attr("class", "ui-icon ui-icon-folder-collapsed");
+	});
+	
+	$("table").each(function()
+	{
+		if($(this).attr("id") && $(this).attr("id").search(/^meta/) != -1)
+		{
+			$(this).css("display", "none");
+			$(this.metaNameField).css("display", "none");
+			$(this.addRowButton).css("display", "none");
+		}
+	});
 }
 
 function readyPageForEditing()
 {
-	if(document.getElementById("metadataSetList"))
-	{
-		var setList = document.getElementById("metadataSetList");
-		if(!setList.style.display || setList.style.display == "")
+	if($("#metadataSetList").length)
+	{
+		var setList = $("#metadataSetList");
+		if(!setList.css("display") || setList.css("display") == "")
 		{
 			setEditingFeaturesVisible(false);
@@ -1222,37 +1145,29 @@
 	}
 
-	document.getElementById("editContentButton").innerHTML = "Hide Editor";
-	
-	var textDivs = gs.functions.getElementsByClassName("sectionText");
-	for(var i = 0; i < textDivs.length; i++)
-	{
-		de.doc.registerEditSection(textDivs[i]);
-	}
-	
-	var editBar = document.getElementById("editBarLeft");
-	var saveButton = document.createElement("BUTTON");
-	saveButton.onclick = save;
-	saveButton.innerHTML = "Save changes";
-	saveButton.setAttribute("id", "saveButton");
-	editBar.appendChild(saveButton);
-	
-	var visibleMetadataList = document.createElement("SELECT");
-	var allOption = document.createElement("OPTION");
-	allOption.innerHTML = "All";
-	visibleMetadataList.appendChild(allOption);
-	visibleMetadataList.setAttribute("id", "metadataSetList");
-	var metadataListLabel = document.createElement("SPAN");
-	metadataListLabel.setAttribute("id", "metadataListLabel");
-	metadataListLabel.setAttribute("style", "margin-left:20px;");
-	metadataListLabel.innerHTML = "Visible metadata: ";
-	editBar.appendChild(metadataListLabel);
-	editBar.appendChild(visibleMetadataList);
-	visibleMetadataList.onchange = onVisibleMetadataSetChange;
-	
-	var statusBarDiv = document.createElement("DIV");
-	editBar.appendChild(statusBarDiv);
-	_statusBar = new StatusBar(statusBarDiv);
-	
-	var titleDivs = gs.functions.getElementsByClassName("sectionTitle");
+	$("#editContentButton").html("Hide Editor");
+	
+	var textDivs = $(".sectionText").each(function(){de.doc.registerEditSection(this);});
+	
+	var editBar = $("#editBarLeft");
+	var saveButton = $("<button>", {"id": "saveButton"});
+	saveButton.click(save);
+	saveButton.html("Save changes");
+	editBar.append(saveButton);
+	
+	var visibleMetadataList = $("<select>", {"id": "metadataSetList"});
+	var allOption = $("<option>All</option>");
+	visibleMetadataList.append(allOption);
+
+	var metadataListLabel = $("<span>", {"id": "metadataListLabel", "style": "margin-left:20px;"});
+	metadataListLabel.html("Visible metadata: ");
+	editBar.append(metadataListLabel);
+	editBar.append(visibleMetadataList);
+	visibleMetadataList.change(onVisibleMetadataSetChange);
+	
+	var statusBarDiv = $("<div>");
+	editBar.append(statusBarDiv);
+	_statusBar = new StatusBar(statusBarDiv[0]);
+	
+	var titleDivs = $(".sectionTitle");
 	for(var i = 0; i < titleDivs.length; i++)
 	{
@@ -1262,4 +1177,8 @@
 	_baseURL = gs.xsltParams.library_name;
 }
+
+/***************
+* MENU SCRIPTS *
+***************/
 
 function floatMenu(enabled)
@@ -1300,8 +1219,12 @@
 	}
 	
-	var ajax = gs.functions.ajaxRequest();
-	ajax.open("GET", gs.xsltParams.library_name + "?a=d&ftoc=" + (enabled ? "1" : "0") + "&c=" + gs.cgiParams.c);
-	ajax.send();
-}
+	var url = gs.xsltParams.library_name + "?a=d&ftoc=" + (enabled ? "1" : "0") + "&c=" + gs.cgiParams.c;
+	
+	$.ajax(url);
+}
+
+/********************
+* SLIDESHOW SCRIPTS *
+********************/
 
 function showSlideShow()
Index: main/trunk/greenstone3/web/interfaces/default/js/documentmaker_scripts_util.js
===================================================================
--- main/trunk/greenstone3/web/interfaces/default/js/documentmaker_scripts_util.js	(revision 26396)
+++ main/trunk/greenstone3/web/interfaces/default/js/documentmaker_scripts_util.js	(revision 26397)
@@ -631,9 +631,8 @@
 function addFunctionalityToTable(table)
 {
-	var rows = table.getElementsByTagName("TR");
-	for(var i = 0; i < rows.length; i++)
-	{
-		var cells = rows[i].getElementsByTagName("TD");
-		var metadataName = cells[0].innerHTML;
+	table.find("tr").each(function()
+	{
+		var cells = $(this).find("td");
+		var metadataName = $(cells[0]).html();
 		
 		if(metadataName.indexOf(".") != -1)
@@ -655,26 +654,24 @@
 				_metadataSetList.push(metadataSetName);
 				
-				var metadataSetList = document.getElementById("metadataSetList");
-				var newOption = document.createElement("OPTION");
-				newOption.innerHTML = metadataSetName;
-				metadataSetList.appendChild(newOption);
+				var metadataSetList = $("#metadataSetList");
+				var newOption = $("<option>");
+				newOption.html(metadataSetName);
+				metadataSetList.append(newOption);
 			}
 		}
 			
 		asyncRegisterEditSection(cells[1]);
-
-		addRemoveLinkToRow(rows[i]);
-	}
-
-	var metaNameField = document.createElement("INPUT");
-	metaNameField.setAttribute("type", "text");
-	insertAfter(metaNameField, table);
+		addRemoveLinkToRow(this);
+	});
+
+	var metaNameField = $("<input>", {"type": "text"});
+	table.after(metaNameField);
 	table.metaNameField = metaNameField;
 	
-	var addRowButton = document.createElement("BUTTON");
-	addRowButton.innerHTML = gs.text.dse.add_new_metadata;
-	addRowButton.onclick = function() 
+	var addRowButton = $("<button>");
+	addRowButton.html(gs.text.dse.add_new_metadata);
+	addRowButton.click(function() 
 	{ 
-		var name = metaNameField.value;
+		var name = metaNameField.val();
 		if(!name || name == "")
 		{
@@ -683,15 +680,13 @@
 		}
 		
-		var newRow = document.createElement("TR");
-		var nameCell = document.createElement("TD");
-		var valueCell = document.createElement("TD");
-		nameCell.setAttribute("class", "metaTableCellName");
-		nameCell.innerHTML = name;
-		valueCell.setAttribute("class", "metaTableCell");
-		
-		newRow.appendChild(nameCell);
-		newRow.appendChild(valueCell);
+		var newRow = $("<tr>");
+		var nameCell = $("<td>" + name + "</td>");
+		nameCell.attr("class", "metaTableCellName");
+		var valueCell = $("<td>", {"class": "metaTableCell"});
+		
+		newRow.append(nameCell);
+		newRow.append(valueCell);
 		addRemoveLinkToRow(newRow);
-		table.appendChild(newRow);
+		table.append(newRow);
 		
 		var undo = new Array();
@@ -702,17 +697,15 @@
 		
 		//Threading this function here probably isn't necessary like the other times it is called
-		de.doc.registerEditSection(valueCell);
-	};
+		de.doc.registerEditSection(valueCell[0]);
+	});
 	table.addRowButton = addRowButton;
-	insertAfter(addRowButton, metaNameField);
+	metaNameField.after(addRowButton);
 }
 
 function addRemoveLinkToRow(row)
 {
-	var newCell = document.createElement("TD");
-	var removeLink = document.createElement("A");
-	removeLink.innerHTML = "remove";
-	removeLink.setAttribute("href", "javascript:;");
-	removeLink.onclick = function()
+	var newCell = $("<td>");
+	var removeLink = $("<a>remove</a>", {"href": "javascript:;"});
+	removeLink.click(function()
 	{
 		var undo = new Array();
@@ -723,10 +716,9 @@
 		_undoOperations.push(undo);
 		_deletedMetadata.push(row);
-		row.style.display = "none";
-	}
-	newCell.appendChild(removeLink);
-	newCell.setAttribute("class", "metaTableCell");
-	newCell.setAttribute("style", "font-size:0.6em; padding-left: 3px; padding-right: 3px;");
-	row.appendChild(newCell);
+		row.css("display", "none");
+	});
+	newCell.append(removeLink);
+	newCell.attr({"class": "metaTableCell", "style": "font-size:0.6em; padding-left: 3px; padding-right: 3px;"});
+	$(row).append(newCell);
 }
 
