Index: /main/trunk/greenstone3/web/interfaces/default/js/debug_scripts.js
===================================================================
--- /main/trunk/greenstone3/web/interfaces/default/js/debug_scripts.js	(revision 27255)
+++ /main/trunk/greenstone3/web/interfaces/default/js/debug_scripts.js	(revision 27256)
@@ -527,58 +527,5 @@
 				}
 
-				var getURL = gs.xsltParams.library_name + "?a=g&rt=r&s=GetTemplateListFromFile&s1.fileName=" + selectedItem.data("fileItem").path + "&s1.locationName=" + selectedItem.data("fileItem").location + "&s1.interfaceName=" + gs.xsltParams.interface_name + "&s1.siteName=" + gs.xsltParams.site_name + "&s1.collectionName=" + gs.cgiParams.c;
-				$.ajax(getURL)
-				.success(function(templateResponse)
-				{
-					var templateListStart = templateResponse.indexOf("<templateList>") + "<templateList>".length;
-					var templateListEnd = templateResponse.indexOf("</templateList>");
-					var templateListString = templateResponse.substring(templateListStart, templateListEnd).replace(/&quot;/g, "\"");
-					var templateList = eval(templateListString);
-
-					_templateSelector.children("select").empty();
-					if(templateList.length == 0)
-					{
-						_templateSelector.children("select").append($("<option>-- No templates --</option>").data("index", -1));
-					}
-
-					for(var i = 0; i < templateList.length; i++)
-					{
-						var filename = selectedItem.data("fileItem").path;
-						var location = selectedItem.data("fileItem").location;
-						var namespace = templateList[i].namespace;
-						var nodename = "template";
-						var name = templateList[i].name;
-						var match = templateList[i].match;
-
-						if(name)
-						{
-							name = templateList[i].name.replace(/&apos;/g, "'").replace(/&quot;/g, "\"").replace(/&amp;/g, "&");
-						}
-						if(match)
-						{
-							match = templateList[i].match.replace(/&apos;/g, "'").replace(/&quot;/g, "\"").replace(/&amp;/g, "&");
-						}
-
-						var infoContainer = $("<option>");
-
-						_elements.push(infoContainer);
-
-						addChangeEventToInfoContainer(infoContainer, filename, location, nodename, namespace, name, match);
-
-						if(name && name.length > 0)
-						{
-							infoContainer.text(name);
-						}
-						if(match && match.length > 0)
-						{
-							infoContainer.text(match);
-						}
-
-						infoContainer.data("index", i);
-						_templateSelector.children("select").append(infoContainer);
-					}
-
-					_templateSelector.children("select").trigger("change");
-				});
+				_greenbug.populateTemplateSelectorFromFile(selectedItem.data("fileItem").path, selectedItem.data("fileItem").location, function(){_templateSelector.children("select").trigger("change")});
 			});
 		})
@@ -654,4 +601,63 @@
 		_elements.push(rightBorderDiv);
 	}
+	
+	this.populateTemplateSelectorFromFile = function(filename, location, callback)
+	{
+		var getURL = gs.xsltParams.library_name + "?a=g&rt=r&s=GetTemplateListFromFile&s1.fileName=" + filename + "&s1.locationName=" + location + "&s1.interfaceName=" + gs.xsltParams.interface_name + "&s1.siteName=" + gs.xsltParams.site_name + "&s1.collectionName=" + gs.cgiParams.c;
+		$.ajax(getURL)
+		.success(function(templateResponse)
+		{
+			var templateListStart = templateResponse.indexOf("<templateList>") + "<templateList>".length;
+			var templateListEnd = templateResponse.indexOf("</templateList>");
+			var templateListString = templateResponse.substring(templateListStart, templateListEnd).replace(/&quot;/g, "\"");
+			var templateList = eval(templateListString);
+
+			_templateSelector.children("select").empty();
+			if(templateList.length == 0)
+			{
+				_templateSelector.children("select").append($("<option>-- No templates --</option>").data("index", -1));
+			}
+
+			for(var i = 0; i < templateList.length; i++)
+			{
+				var namespace = templateList[i].namespace;
+				var nodename = "template";
+				var name = templateList[i].name;
+				var match = templateList[i].match;
+
+				if(name)
+				{
+					name = templateList[i].name.replace(/&apos;/g, "'").replace(/&quot;/g, "\"").replace(/&amp;/g, "&");
+				}
+				if(match)
+				{
+					match = templateList[i].match.replace(/&apos;/g, "'").replace(/&quot;/g, "\"").replace(/&amp;/g, "&");
+				}
+
+				var infoContainer = $("<option>");
+
+				_elements.push(infoContainer);
+
+				addChangeEventToInfoContainer(infoContainer, filename, location, nodename, namespace, name, match);
+
+				if(name && name.length > 0)
+				{
+					infoContainer.text(name);
+				}
+				if(match && match.length > 0)
+				{
+					infoContainer.text(match);
+				}
+
+				infoContainer.data("index", i);
+				_templateSelector.children("select").append(infoContainer);
+			}
+			
+			if(callback)
+			{
+				callback();
+			}
+		});
+	}
 
 	//Change the current template in the XML and Visual editor
@@ -750,4 +756,9 @@
 	}
 	
+	this.getTemplateTracker = function()
+	{
+		return _templateTracker;
+	}
+	
 	//Turns a filename into it's location (i.e. interface/site/collection) and name
 	this.fileNameToLocationAndName = function(filepath)
@@ -776,4 +787,6 @@
 			filename = filepath.replace(/.*[\/\\]sites[\/\\].*[\/\\]transform[\/\\]/, "");
 		}
+		
+		filename = filename.replace(/\\/g, "/");
 		
 		return {location:location, filename:filename};
Index: /main/trunk/greenstone3/web/interfaces/default/js/visual-xml-editor.js
===================================================================
--- /main/trunk/greenstone3/web/interfaces/default/js/visual-xml-editor.js	(revision 27255)
+++ /main/trunk/greenstone3/web/interfaces/default/js/visual-xml-editor.js	(revision 27256)
@@ -1146,4 +1146,30 @@
 		{
 			return _id;
+		}
+		
+		var visitCalledTemplate = function()
+		{
+			var url = gs.xsltParams.library_name + "?a=g&rt=r&s=ResolveCallTemplate&s1.interfaceName=" + gs.xsltParams.interface_name + "&s1.siteName=" + gs.xsltParams.site_name + "&s1.collectionName=" + gs.cgiParams.c + "&s1.fileName=" + _fileName + "&s1.templateName=" + _xmlNode.getAttribute("name");
+			$.ajax(url)
+			.success(function(response)
+			{
+				var startIndex = response.indexOf("<requestedTemplate>") + ("<requestedTemplate>").length;
+				var endIndex = response.indexOf("</requestedTemplate>");
+				
+				if(endIndex != -1)
+				{
+					var templateFileName = response.substring(startIndex, endIndex);
+					var file = _greenbug.fileNameToLocationAndName(templateFileName);
+					
+					var fileTemplateName = file.filename.replace(/\\/g, "/") + " (" + file.location + ")";
+					$("#veFileSelector").find("option").filter(function(){return $(this).text() == fileTemplateName}).prop("selected", true);
+					_greenbug.populateTemplateSelectorFromFile(file.filename, file.location);
+					_greenbug.changeCurrentTemplate(file.location, file.filename, "template", "xsl", _xmlNode.getAttribute("name"), null);
+				}
+				else
+				{
+					_greenbug.changeCurrentTemplate("interface", "gslib.xsl", "template", "xsl", _xmlNode.getAttribute("name"), null);
+				}
+			});
 		}
 
@@ -1249,25 +1275,5 @@
 					
 					visitTemplateOption.button();
-					visitTemplateOption.click(function()
-					{
-						var url = gs.xsltParams.library_name + "?a=g&rt=r&s=ResolveCallTemplate&s1.interfaceName=" + gs.xsltParams.interface_name + "&s1.siteName=" + gs.xsltParams.site_name + "&s1.collectionName=" + gs.cgiParams.c + "&s1.fileName=" + _fileName + "&s1.templateName=" + _xmlNode.getAttribute("name");
-						$.ajax(url)
-						.success(function(response)
-						{
-							var startIndex = response.indexOf("<requestedTemplate>") + ("<requestedTemplate>").length;
-							var endIndex = response.indexOf("</requestedTemplate>");
-							
-							if(endIndex != -1)
-							{
-								var templateFileName = response.substring(startIndex, endIndex);
-								var file = _greenbug.fileNameToLocationAndName(templateFileName);
-								_greenbug.changeCurrentTemplate(file.location, file.filename, "template", "xsl", _xmlNode.getAttribute("name"), null);
-							}
-							else
-							{
-								_greenbug.changeCurrentTemplate("interface", "gslib.xsl", "template", "xsl", _xmlNode.getAttribute("name"), null);
-							}
-						});
-					});
+					visitTemplateOption.click(visitCalledTemplate);
 				}
 			}
@@ -1286,5 +1292,9 @@
 			{
 				event.stopPropagation();
-				_div.css("border", "1px solid orange");
+				if(!_selectedElement || _id != _selectedElement.data("parentVEElement").getID())
+				{
+					_div.css("border", "1px solid orange");
+				}
+
 				var titleString = " ";
 				if(_xmlNode.nodeType == 1)
@@ -1307,12 +1317,20 @@
 			_div.mouseout(function(event)
 			{
-				_div.css("border", "1px solid black");
+				if(!_selectedElement || _id != _selectedElement.data("parentVEElement").getID())
+				{
+					_div.css("border", "1px solid black");
+				}
 				event.stopPropagation();
 			});
 			_div.click(function(event)
 			{
+				event.stopPropagation();
 				if(_selectedElement)
 				{
 					_selectedElement.css("border", _selectedElement.prevBorder);
+					if(_selectedElement.children("a").length)
+					{
+						_selectedElement.children("a").replaceWith(_selectedElement.children("a").children(".veTitleElement"));
+					}
 				}
 				_selectedElement = _div;
@@ -1322,6 +1340,13 @@
 				_div.data("parentVEElement").focus();
 				_div.data("parentVEElement").populateInformationDiv();
-
-				event.stopPropagation();
+				
+				if(_xmlNode.tagName == "xsl:call-template" && _xmlNode.getAttribute("name").length > 0)
+				{
+					var link = $("<a>");
+					link.attr("href", "javascript:;");
+					link.click(visitCalledTemplate);
+					link.append(_div.children(".veTitleElement"));
+					_div.append(link);
+				}
 			});
 		}
