(function(){

	var positionStore = {};
	
	core.Module("unify.ui.core.Util", {
		getWidgetLocation : function(widget) {
			return lowland.bom.Element.getLocation(widget.getElement());
		},
		
		domElementToRootLevel : function(widget) {
			var hash = widget.getHash();
			var posOverride = positionStore[hash];
			
			var e = widget.getElement();
			
			if (!posOverride) {
				var pos = unify.ui.core.Util.getWidgetLocation(widget);
				var origPos = widget.getPosition();
	
				posOverride = positionStore[hash] = {
					originalPosition : {
						left: origPos[0],
						top: origPos[1],
						zIndex: lowland.bom.Style.get(e, "zIndex")
					},
					newPosition : {
						left: pos.left,
						top: pos.top,
						zIndex: 20000
					}
				};
			}
			
			var rootElement = unify.core.Init.getApplication().getRoot().getElement();
			
			if (rootElement === e.parentNode) {
				// Element is in root, so nothing to do
				return;
			}
			
			widget.setUserData("domElementPositionOverride", {left: posOverride.newPosition.left, top: posOverride.newPosition.top});
			
			lowland.bom.Style.set(e, {
				left: posOverride.newPosition.left + "px",
				top:  posOverride.newPosition.top + "px",
				zIndex: 20000
			});
			
			rootElement.appendChild(e);
		},
		
		domElementToTreeLevel : function(widget) {
			var hash = widget.getHash();
			var e = widget.getElement();
			
			var posOverride = positionStore[hash];
			
			if (!posOverride) {
				return;
			}
			
			var parentElement = widget.getParentBox().getContentElement();
			if (e.parentNode == parentElement) {
				// Element is in tree, so nothing to do
				return;
			}
			
			var origPos = posOverride.originalPosition;
			
			lowland.bom.Style.set(e, {
				left: origPos.left + "px",
				top: origPos.top + "px",
				zIndex: origPos.zIndex
			});
			parentElement.appendChild(e);
			
			widget.setUserData("domElementPositionOverride", null);
		}
	});


})();
@@ -32,16 +32,43 @@
 e = %7B%7D;%0A
+  var viewportRoot = null;%0A
 %09%0A%09core.
@@ -139,16 +139,146 @@
 dget) %7B%0A
+      if (!viewportRoot) %7B%0A        viewportRoot = unify.core.Init.getApplication().getRoot().getViewportElement();%0A      %7D%0A      %0A
 %09%09%09retur
@@ -330,16 +330,30 @@
 lement()
+, viewportRoot
 );%0A%09%09%7D,%0A

Make widget position detection relative to viewport element