Index: main/trunk/greenstone3/web/interfaces/default/js/visual-xml-editor.js
===================================================================
--- main/trunk/greenstone3/web/interfaces/default/js/visual-xml-editor.js	(revision 27071)
+++ main/trunk/greenstone3/web/interfaces/default/js/visual-xml-editor.js	(revision 27072)
@@ -340,4 +340,6 @@
 
 		_toolboxDiv.tabs();
+		
+		customCreateButton.button();
 	}
 
@@ -420,4 +422,9 @@
 	var addToOverList = function(veElement)
 	{
+		if(veElement.getDiv().data("toolbar"))
+		{
+			return;
+		}
+	
 		for(var i = 0; i < _overList.length; i++)
 		{
@@ -562,15 +569,15 @@
 	
 		var _textEditor = $("<div>");
-		var textTitle = $("<div>Text:</div>");
+		var _textTitle = $("<div>Text:</div>");
 		var _nodeText = $("<div>");
 		_nodeText.text(_xmlNode.nodeValue);
 
-		_textEditor.append(textTitle);
+		_textEditor.append(_textTitle);
 		_textEditor.append(_nodeText);
 		
-		var editButton = $("<button>edit text</button>");
-		editButton.click(function()
-		{
-			if(editButton.text() == "edit text")
+		var _editButton = $("<button>Edit text</button>");
+		_editButton.click(function()
+		{
+			if(_editButton.button("option", "label") == "Edit text")
 			{
 				_thisNode.editMode();
@@ -581,5 +588,5 @@
 			}
 		});
-		_textEditor.append(editButton);
+		_textEditor.append(_editButton);
 		
 		this.editMode = function()
@@ -591,5 +598,5 @@
 			_nodeText.text("");
 			_nodeText.append(textArea);
-			editButton.text("done");
+			_editButton.button("option", "label", "Done");
 		}
 
@@ -611,9 +618,11 @@
 			_nodeText.empty();
 			_nodeText.text(newValue);
-			editButton.text("edit text");
+			_editButton.button("option", "label", "Edit text");
 		}
 
 		this.getDiv = function()
 		{
+			//A hack to make sure the edit text button is styled correctly
+			setTimeout(function(){_editButton.button()}, 1);
 			return _textEditor;
 		}
@@ -964,7 +973,4 @@
 						_div.data("parentVEElement").setShortName(false);
 					}
-					
-					_div.data("dragging", false);
-					_div.data("toolbar", false);
 
 					_div.css("border", "1px solid black");
@@ -972,5 +978,5 @@
 					
 					//If the element was not dropped in a valid place then put it back
-					if(!_validDropSpot)
+					if(!_validDropSpot && !_div.data("toolbar"))
 					{
 						_div.detach();
@@ -1015,4 +1021,7 @@
 					}
 					
+					_div.data("dragging", false);
+					_div.data("toolbar", false);
+					
 					_overList = new Array();
 					_overList.freeSpaces = new Array();
@@ -1142,4 +1151,5 @@
 				_infoDiv.append(addSelect);
 				_infoDiv.append(addButton);
+				addButton.button();
 			}
 
@@ -1206,5 +1216,5 @@
 				_div.prevBorder = _div.css("border");
 				_div.css("border", "red solid 1px");
-				
+
 				_div.data("parentVEElement").focus();
 				_div.data("parentVEElement").populateInformationDiv();
@@ -1212,4 +1222,28 @@
 				event.stopPropagation();
 			});
+		}
+		
+		var checkResizeNecessary = function()
+		{
+			var elemsToCheck = _div.find(".veTitleElement");
+			for(var i = 0; i < elemsToCheck.length; i++)
+			{
+				var titleElem = elemsToCheck.eq(i);
+				titleElem.html("<span>" + titleElem.html() + "</span>");
+				var titleSpan = titleElem.children("span");
+
+				var resizeNecessary = false;
+				if(titleSpan.width() >= titleElem.parent().width())
+				{
+					resizeNecessary = true;
+				}
+				titleElem.html(titleSpan.text());
+				
+				if(resizeNecessary)
+				{
+					return true;
+				}
+			}
+			return false;
 		}
 
@@ -1244,11 +1278,14 @@
 		this.focus = function()
 		{
-			_div.data("parentVEElement").expand();
-			
-			var parents = _div.parents(".veElement");
-			parents.each(function()
-			{
-				$(this).data("parentVEElement").expand();
-			});
+			if(checkResizeNecessary())
+			{
+				_div.data("parentVEElement").expand();
+				
+				var parents = _div.parents(".veElement");
+				parents.each(function()
+				{
+					$(this).data("parentVEElement").expand();
+				});
+			}
 
 			_div.data("parentVEElement").evenlyDistributeChildren();
