diff --git a/indra/newview/llinventorypanel.cpp b/indra/newview/llinventorypanel.cpp
index 820520df9e2cbf40c2294d30903c6bfade102cf7..50adae09c0e81531dc3fb0463a5fedc9f0af29d9 100644
--- a/indra/newview/llinventorypanel.cpp
+++ b/indra/newview/llinventorypanel.cpp
@@ -916,6 +916,8 @@ BOOL is_inventorysp_active()
 // static
 LLInventoryPanel* LLInventoryPanel::getActiveInventoryPanel(BOOL auto_open)
 {
+	S32 z_min = S32_MAX;
+	LLInventoryPanel* res = NULL;
 	// A. If the inventory side panel is open, use that preferably.
 	if (is_inventorysp_active())
 	{
@@ -925,11 +927,26 @@ LLInventoryPanel* LLInventoryPanel::getActiveInventoryPanel(BOOL auto_open)
 			return inventorySP->getActivePanel();
 		}
 	}
+	// or if it is in floater undocked from sidetray get it and remember z order of floater to later compare it
+	// with other inventory floaters order.
+	else if (!LLSideTray::getInstance()->isTabAttached("sidebar_inventory"))
+	{
+		LLSidepanelInventory *inventorySP =
+			dynamic_cast<LLSidepanelInventory *>(LLSideTray::getInstance()->getPanel("sidepanel_inventory"));
+		LLFloater* inv_floater = LLFloaterReg::findInstance("side_bar_tab", LLSD("sidebar_inventory"));
+		if (inventorySP && inv_floater)
+		{
+			res = inventorySP->getActivePanel();
+			z_min = gFloaterView->getZOrder(inv_floater);
+		}
+		else
+		{
+			llwarns << "Inventory tab is detached from sidetray, but  either panel or floater were not found!" << llendl;
+		}
+	}
 	
 	// B. Iterate through the inventory floaters and return whichever is on top.
 	LLFloaterReg::const_instance_list_t& inst_list = LLFloaterReg::getFloaterList("inventory");
-	S32 z_min = S32_MAX;
-	LLInventoryPanel* res = NULL;
 	for (LLFloaterReg::const_instance_list_t::const_iterator iter = inst_list.begin(); iter != inst_list.end(); ++iter)
 	{
 		LLFloaterInventory* iv = dynamic_cast<LLFloaterInventory*>(*iter);
diff --git a/indra/newview/llsidetray.cpp b/indra/newview/llsidetray.cpp
index 342b73d9c075519edf85ab706166a66e55d9d92c..88e37b815f67556bc14e01c9ebf7cd02c9562843 100644
--- a/indra/newview/llsidetray.cpp
+++ b/indra/newview/llsidetray.cpp
@@ -314,6 +314,7 @@ void LLSideTrayTab::undock(LLFloater* floater_tab)
 
 	floater_tab->addChild(this);
 	floater_tab->setTitle(mTabTitle);
+	floater_tab->setName(getName());
 
 	// Reshape the floater if needed.
 	LLRect floater_rect;