From bde7d67066d189416a725da4527a02eb4f78ba4a Mon Sep 17 00:00:00 2001
From: Loren Shih <seraph@lindenlab.com>
Date: Mon, 2 Nov 2009 15:39:55 -0500
Subject: [PATCH] EXT-1866 : Inventory Side Panel svn merge -r137106:137808
 svn+ssh://svn.lindenlab.com/svn/linden/branches/avatar-pipeline/inventory-panel

Porting over changes from svn Inventory Panel work.
---
 indra/newview/CMakeLists.txt                  |  3543 ++---
 indra/newview/llagentwearables.cpp            |     1 +
 indra/newview/llassetuploadresponders.cpp     |     1 +
 indra/newview/llfloaterbuy.cpp                |     1 +
 indra/newview/llfloaterbuycontents.cpp        |     3 +-
 indra/newview/llfloatergesture.cpp            |     1 +
 indra/newview/llfloaterinventory.cpp          |  2108 +--
 indra/newview/llfloaterinventory.h            |   350 +-
 indra/newview/llfloateropenobject.cpp         |    11 +-
 indra/newview/llfloateropenobject.h           |     4 +-
 indra/newview/llfloatertools.cpp              |     2 +-
 indra/newview/llfolderview.cpp                |     1 +
 indra/newview/llimpanel.cpp                   |     1 +
 indra/newview/llinventorybridge.cpp           | 10288 +++++++-------
 indra/newview/llinventorybridge.h             |     7 +-
 indra/newview/llinventoryfunctions.cpp        |   344 +
 indra/newview/llinventoryfunctions.h          |   136 +
 indra/newview/llinventorymodel.cpp            |    10 +-
 indra/newview/llpanelcontents.cpp             |    10 +-
 indra/newview/llpanelcontents.h               |    11 +-
 indra/newview/llpanelgroupnotices.cpp         |     1 +
 indra/newview/llpanellandmarks.cpp            |  1909 +--
 indra/newview/llpanelmaininventory.cpp        |   818 ++
 indra/newview/llpanelmaininventory.h          |   125 +
 indra/newview/llpanelobject.h                 |     1 -
 indra/newview/llpanelobjectinventory.cpp      |  1905 +++
 indra/newview/llpanelobjectinventory.h        |   102 +
 indra/newview/llpanelvolume.cpp               |     1 -
 indra/newview/llpanelvolume.h                 |     1 -
 indra/newview/llplacesinventorybridge.cpp     |     5 +-
 indra/newview/llpreviewscript.cpp             |     1 -
 indra/newview/llsidepanelinventory.cpp        |   276 +
 indra/newview/llsidepanelinventory.h          |    85 +
 indra/newview/lltexturectrl.cpp               |     2 +
 indra/newview/lltoastgroupnotifypanel.cpp     |     1 +
 indra/newview/llviewerinventory.cpp           |     1 +
 indra/newview/llviewermenu.cpp                |     1 +
 indra/newview/llviewermessage.cpp             | 11445 ++++++++--------
 .../skins/default/textures/textures.xml       |     6 +-
 .../default/xui/en/floater_inventory.xml      |   423 +-
 .../default/xui/en/floater_openobject.xml     |     2 +-
 .../skins/default/xui/en/floater_tools.xml    |     2 +-
 .../default/xui/en/panel_main_inventory.xml   |   417 +
 .../skins/default/xui/en/panel_side_tray.xml  |   280 +-
 .../xui/en/panel_sidetray_home_tab.xml        |    63 +-
 .../default/xui/en/sidepanel_inventory.xml    |   122 +
 46 files changed, 18384 insertions(+), 16444 deletions(-)
 create mode 100644 indra/newview/llinventoryfunctions.cpp
 create mode 100644 indra/newview/llinventoryfunctions.h
 create mode 100644 indra/newview/llpanelmaininventory.cpp
 create mode 100644 indra/newview/llpanelmaininventory.h
 create mode 100644 indra/newview/llpanelobjectinventory.cpp
 create mode 100644 indra/newview/llpanelobjectinventory.h
 create mode 100644 indra/newview/llsidepanelinventory.cpp
 create mode 100644 indra/newview/llsidepanelinventory.h
 create mode 100644 indra/newview/skins/default/xui/en/panel_main_inventory.xml
 create mode 100644 indra/newview/skins/default/xui/en/sidepanel_inventory.xml

diff --git a/indra/newview/CMakeLists.txt b/indra/newview/CMakeLists.txt
index a7681e4a1d0..644ebfa3f44 100644
--- a/indra/newview/CMakeLists.txt
+++ b/indra/newview/CMakeLists.txt
@@ -1,1766 +1,1777 @@
-# -*- cmake -*-
-
-project(viewer)
-
-include(00-Common)
-include(Boost)
-include(BuildVersion)
-include(DBusGlib)
-include(DirectX)
-include(ELFIO)
-include(FMOD)
-include(OPENAL)
-include(FindOpenGL)
-include(LLAudio)
-include(LLCharacter)
-include(LLCommon)
-include(LLImage)
-include(LLImageJ2COJ)
-include(LLInventory)
-include(LLMath)
-include(LLMessage)
-include(LLPlugin)
-include(LLPrimitive)
-include(LLRender)
-include(LLUI)
-include(LLVFS)
-include(LLWindow)
-include(LLXML)
-include(LLXUIXML)
-include(LScript)
-include(Linking)
-include(NDOF)
-include(GooglePerfTools)
-include(TemplateCheck)
-include(UI)
-include(UnixInstall)
-include(LLKDU)
-include(ViewerMiscLibs)
-include(LLLogin)
-include(CMakeCopyIfDifferent)
-
-include_directories(
-    ${DBUSGLIB_INCLUDE_DIRS}
-    ${ELFIO_INCLUDE_DIR}
-    ${LLAUDIO_INCLUDE_DIRS}
-    ${LLCHARACTER_INCLUDE_DIRS}
-    ${LLCOMMON_INCLUDE_DIRS}
-    ${LLIMAGE_INCLUDE_DIRS}
-    ${LLINVENTORY_INCLUDE_DIRS}
-    ${LLMATH_INCLUDE_DIRS}
-    ${LLMESSAGE_INCLUDE_DIRS}
-    ${LLPLUGIN_INCLUDE_DIRS}
-    ${LLPRIMITIVE_INCLUDE_DIRS}
-    ${LLRENDER_INCLUDE_DIRS}
-    ${LLUI_INCLUDE_DIRS}
-    ${LLVFS_INCLUDE_DIRS}
-    ${LLWINDOW_INCLUDE_DIRS}
-    ${LLXML_INCLUDE_DIRS}
-    ${LLXUIXML_INCLUDE_DIRS}
-    ${LSCRIPT_INCLUDE_DIRS}
-    ${LSCRIPT_INCLUDE_DIRS}/lscript_compile
-    ${LLLOGIN_INCLUDE_DIRS}
-    )
-
-set(viewer_SOURCE_FILES
-    llaccordionctrl.cpp
-    llaccordionctrltab.cpp
-    llagent.cpp
-    llagentaccess.cpp
-    llagentdata.cpp
-    llagentlanguage.cpp
-    llagentlistener.cpp
-    llagentpicksinfo.cpp
-    llagentpilot.cpp
-    llagentui.cpp
-    llagentwearables.cpp
-    llanimstatelabels.cpp
-    llappearancemgr.cpp
-    llappviewer.cpp
-    llappviewerlistener.cpp
-    llassetuploadqueue.cpp
-    llassetuploadresponders.cpp
-    llaudiosourcevo.cpp
-    llavataractions.cpp
-    llavatariconctrl.cpp
-    llavatarlist.cpp
-    llavatarlistitem.cpp
-    llavatarpropertiesprocessor.cpp
-    llbottomtray.cpp
-    llbox.cpp
-    llbreadcrumbview.cpp
-    llcallbacklist.cpp
-    llcallingcard.cpp
-    llcapabilitylistener.cpp
-    llcaphttpsender.cpp
-    llchannelmanager.cpp
-    llchatbar.cpp
-    llchathistory.cpp
-    llchatitemscontainerctrl.cpp
-    llchatmsgbox.cpp
-    llchiclet.cpp
-    llclassifiedinfo.cpp
-    llclassifiedstatsresponder.cpp
-    llcloud.cpp
-    llcolorswatch.cpp
-    llcommandhandler.cpp
-    llcommandlineparser.cpp
-    llcompilequeue.cpp
-    llconfirmationmanager.cpp
-    llcurrencyuimanager.cpp
-    llcylinder.cpp
-    lldateutil.cpp
-    lldebugmessagebox.cpp
-    lldebugview.cpp
-    lldelayedgestureerror.cpp
-    lldirpicker.cpp
-    lldndbutton.cpp
-    lldrawable.cpp
-    lldrawpool.cpp
-    lldrawpoolalpha.cpp
-    lldrawpoolavatar.cpp
-    lldrawpoolbump.cpp
-    lldrawpoolground.cpp
-    lldrawpoolsimple.cpp
-    lldrawpoolsky.cpp
-    lldrawpoolterrain.cpp
-    lldrawpooltree.cpp
-    lldrawpoolwater.cpp
-    lldrawpoolwlsky.cpp
-    lldriverparam.cpp
-    lldynamictexture.cpp
-    llemote.cpp
-    lleventinfo.cpp
-    lleventnotifier.cpp
-    lleventpoll.cpp
-    llexpandabletextbox.cpp
-    llface.cpp
-    llfasttimerview.cpp
-    llfavoritesbar.cpp
-    llfeaturemanager.cpp
-    llfilepicker.cpp
-    llfirstuse.cpp
-    llflexibleobject.cpp
-    llfloaterabout.cpp
-    llfloateractivespeakers.cpp
-    llfloateranimpreview.cpp
-    llfloaterauction.cpp
-    llfloateravatarpicker.cpp
-    llfloateravatartextures.cpp
-    llfloaterbeacons.cpp
-    llfloaterbuildoptions.cpp
-    llfloaterbulkpermission.cpp
-    llfloaterbump.cpp
-    llfloaterbuy.cpp
-    llfloaterbuycontents.cpp
-    llfloaterbuycurrency.cpp
-    llfloaterbuyland.cpp
-    llfloatercall.cpp
-    llfloatercamera.cpp
-    llfloaterchat.cpp
-    llfloaterchatterbox.cpp
-    llfloatercolorpicker.cpp
-    llfloatercustomize.cpp
-    llfloaterdaycycle.cpp
-    llfloaterenvsettings.cpp
-    llfloaterfonttest.cpp
-    llfloaterfriends.cpp
-    llfloatergesture.cpp
-    llfloatergodtools.cpp
-    llfloatergroupinvite.cpp
-    llfloatergroups.cpp
-    llfloaterhandler.cpp
-    llfloaterhardwaresettings.cpp
-    llfloaterhelpbrowser.cpp
-    llfloaterhud.cpp
-    llfloaterimagepreview.cpp
-    llfloaterinspect.cpp
-    llfloaterinventory.cpp
-    llfloaterjoystick.cpp
-    llfloaterlagmeter.cpp
-    llfloaterland.cpp
-    llfloaterlandholdings.cpp
-    llfloatermap.cpp
-    llfloatermediabrowser.cpp
-    llfloatermediasettings.cpp
-    llfloatermemleak.cpp
-    llfloaternamedesc.cpp
-    llfloaternotificationsconsole.cpp
-    llfloateropenobject.cpp
-    llfloaterparcel.cpp
-    llfloaterpay.cpp
-    llfloaterperms.cpp
-    llfloaterpostcard.cpp
-    llfloaterpostprocess.cpp
-    llfloaterpreference.cpp
-    llfloaterproperties.cpp
-    llfloaterregioninfo.cpp
-    llfloaterreporter.cpp
-    llfloaterscriptdebug.cpp
-    llfloatersearch.cpp
-    llfloatersellland.cpp
-    llfloatersettingsdebug.cpp
-    llfloatersnapshot.cpp
-    llfloatertelehub.cpp
-    llfloatertestinspectors.cpp
-    llfloatertestlistview.cpp
-    llfloatertools.cpp
-    llfloatertopobjects.cpp
-    llfloatertos.cpp
-    llfloateruipreview.cpp
-    llfloaterurldisplay.cpp
-    llfloaterurlentry.cpp
-    llfloatervoicedevicesettings.cpp
-    llfloaterwater.cpp
-    llfloaterwhitelistentry.cpp
-    llfloaterwindlight.cpp
-    llfloaterworldmap.cpp
-    llfoldertype.cpp
-    llfolderview.cpp
-    llfolderviewitem.cpp
-    llfollowcam.cpp
-    llfriendcard.cpp
-    llgesturemgr.cpp
-    llglsandbox.cpp
-    llgroupactions.cpp
-    llgrouplist.cpp
-    llgroupmgr.cpp
-    llgroupnotify.cpp
-    llhomelocationresponder.cpp
-    llhudeffect.cpp
-    llhudeffectbeam.cpp
-    llhudeffectlookat.cpp
-    llhudeffectpointat.cpp
-    llhudeffecttrail.cpp
-    llhudicon.cpp
-    llhudmanager.cpp
-    llhudobject.cpp
-    llhudrender.cpp
-    llhudtext.cpp
-    llhudview.cpp
-    llimcontrolpanel.cpp
-    llimfloater.cpp
-    llimhandler.cpp
-    llimpanel.cpp
-    llimview.cpp
-    llinspect.cpp
-    llinspectavatar.cpp
-    llinspectgroup.cpp
-    llinspectobject.cpp
-    llinventorybridge.cpp
-    llinventoryclipboard.cpp
-    llinventoryfilter.cpp
-    llinventorymodel.cpp
-    llinventorysubtreepanel.cpp
-    lljoystickbutton.cpp
-    lllandmarkactions.cpp
-    lllandmarklist.cpp
-    lllistbrowser.cpp
-    lllistview.cpp
-    lllocaltextureobject.cpp
-    lllocationhistory.cpp
-    lllocationinputctrl.cpp
-    lllogchat.cpp
-    llloginhandler.cpp
-    lllogininstance.cpp
-    llmanip.cpp
-    llmaniprotate.cpp
-    llmanipscale.cpp
-    llmaniptranslate.cpp
-    llmapresponders.cpp
-    llmediactrl.cpp
-    llmediadataclient.cpp
-    llmediaremotectrl.cpp
-    llmemoryview.cpp
-    llmenucommands.cpp
-    llmetricperformancetester.cpp
-    llmimetypes.cpp
-    llmorphview.cpp
-    llmoveview.cpp
-    llmutelist.cpp
-    llnamebox.cpp
-    llnameeditor.cpp
-    llnamelistctrl.cpp
-    llnavigationbar.cpp
-    llnearbychat.cpp
-    llnearbychatbar.cpp
-    llnearbychathandler.cpp
-    llnetmap.cpp
-    llnotificationalerthandler.cpp
-    llnotificationgrouphandler.cpp
-    llnotificationmanager.cpp
-    llnotificationscripthandler.cpp
-    llnotificationtiphandler.cpp
-    llnotify.cpp
-    lloutputmonitorctrl.cpp
-    lloverlaybar.cpp
-    llpanelappearance.cpp
-    llpanelappearancetab.cpp
-    llpanelavatar.cpp
-    llpanelavatarrow.cpp
-    llpanelavatartag.cpp
-    llpanelblockedlist.cpp
-    llpanelclassified.cpp
-    llpanelcontents.cpp
-    llpaneleditwearable.cpp
-    llpanelevent.cpp
-    llpanelface.cpp
-    llpanelgroup.cpp
-    llpanelgroupgeneral.cpp
-    llpanelgroupinvite.cpp
-    llpanelgrouplandmoney.cpp
-    llpanelgroupnotices.cpp
-    llpanelgrouproles.cpp
-    llpanelimcontrolpanel.cpp
-    llpanelinventory.cpp
-    llpanelland.cpp
-    llpanellandaudio.cpp
-    llpanellandmarks.cpp
-    llpanellandmedia.cpp
-    llpanellogin.cpp
-    llpanellookinfo.cpp
-    llpanellooks.cpp
-    llpanelmedia.cpp
-    llpanelmediasettingsgeneral.cpp
-    llpanelmediasettingspermissions.cpp
-    llpanelmediasettingssecurity.cpp
-    llpanelmeprofile.cpp
-    llpanelobject.cpp
-    llpanelpeople.cpp
-    llpanelpeoplemenus.cpp
-    llpanelpermissions.cpp
-    llpanelpick.cpp
-    llpanelpicks.cpp
-    llpanelplace.cpp
-    llpanelplaceinfo.cpp
-    llpanelplaces.cpp
-    llpanelplacestab.cpp
-    llpanelprimmediacontrols.cpp
-    llpanelprofile.cpp
-    llpanelprofileview.cpp
-    llpanelshower.cpp
-    llpanelteleporthistory.cpp
-    llpanelvolume.cpp
-    llparcelselection.cpp
-    llparticipantlist.cpp
-    llpatchvertexarray.cpp
-    llplacesinventorybridge.cpp
-    llpolymesh.cpp
-    llpolymorph.cpp
-    llpreview.cpp
-    llpreviewanim.cpp
-    llpreviewgesture.cpp
-    llpreviewnotecard.cpp
-    llpreviewscript.cpp
-    llpreviewsound.cpp
-    llpreviewtexture.cpp
-    llproductinforequest.cpp
-    llprogressview.cpp
-    llrecentpeople.cpp
-    llregionposition.cpp
-    llremoteparcelrequest.cpp
-    llsavedsettingsglue.cpp
-    llscreenchannel.cpp
-    llscrollingpanelparam.cpp
-    llsearchcombobox.cpp
-    llsearchhistory.cpp
-    llselectmgr.cpp
-    llsidetray.cpp
-    llsidetraypanelcontainer.cpp
-    llsky.cpp
-    llslurl.cpp
-    llspatialpartition.cpp
-    llspeakers.cpp
-    llsplitbutton.cpp
-    llsprite.cpp
-    llstartup.cpp
-    llstatusbar.cpp
-    llstylemap.cpp
-    llsurface.cpp
-    llsurfacepatch.cpp
-    llsyswellitem.cpp
-    llsyswellwindow.cpp
-    llteleporthistory.cpp
-    llteleporthistorystorage.cpp
-    lltexglobalcolor.cpp
-    lltexlayer.cpp
-    lltexlayerparams.cpp
-    lltextureatlas.cpp
-    lltextureatlasmanager.cpp
-    lltexturecache.cpp
-    lltexturectrl.cpp
-    lltexturefetch.cpp
-    lltextureview.cpp
-    lltoast.cpp
-    lltoastalertpanel.cpp
-    lltoastgroupnotifypanel.cpp
-    lltoastimpanel.cpp
-    lltoastnotifypanel.cpp
-    lltoastpanel.cpp
-    lltool.cpp
-    lltoolbar.cpp
-    lltoolbrush.cpp
-    lltoolcomp.cpp
-    lltooldraganddrop.cpp
-    lltoolface.cpp
-    lltoolfocus.cpp
-    lltoolgrab.cpp
-    lltoolgun.cpp
-    lltoolindividual.cpp
-    lltoolmgr.cpp
-    lltoolmorph.cpp
-    lltoolobjpicker.cpp
-    lltoolpie.cpp
-    lltoolpipette.cpp
-    lltoolplacer.cpp
-    lltoolselect.cpp
-    lltoolselectland.cpp
-    lltoolselectrect.cpp
-    lltracker.cpp
-    lltransientdockablefloater.cpp
-    lltransientfloatermgr.cpp
-    lluilistener.cpp
-    lluploaddialog.cpp
-    llurl.cpp
-    llurldispatcher.cpp
-    llurlhistory.cpp
-    llurllineeditorctrl.cpp
-    llurlsimstring.cpp
-    llurlwhitelist.cpp
-    llvectorperfoptions.cpp
-    llviewchildren.cpp
-    llviewerassetstorage.cpp
-    llvieweraudio.cpp
-    llviewercamera.cpp
-    llviewercontrol.cpp
-    llviewercontrollistener.cpp
-    llviewerdisplay.cpp
-    llviewerfloaterreg.cpp
-    llviewergenericmessage.cpp
-    llviewergesture.cpp    
-    llviewerhelp.cpp
-    llviewerhelputil.cpp
-    llviewerinventory.cpp
-    llviewerjoint.cpp
-    llviewerjointattachment.cpp
-    llviewerjointmesh.cpp
-    llviewerjointmesh_sse.cpp
-    llviewerjointmesh_sse2.cpp
-    llviewerjointmesh_vec.cpp
-    llviewerjoystick.cpp
-    llviewerkeyboard.cpp
-    llviewerlayer.cpp
-    llviewermedia.cpp
-    llviewermedia_streamingaudio.cpp
-    llviewermediafocus.cpp
-    llviewermenu.cpp
-    llviewermenufile.cpp
-    llviewermessage.cpp
-    llviewernetwork.cpp
-    llviewerobject.cpp
-    llviewerobjectlist.cpp
-    llviewerparcelmedia.cpp
-    llviewerparcelmediaautoplay.cpp
-    llviewerparcelmgr.cpp
-    llviewerparceloverlay.cpp
-    llviewerpartsim.cpp
-    llviewerpartsource.cpp
-    llviewerregion.cpp
-    llviewershadermgr.cpp
-    llviewerstats.cpp
-    llviewertexteditor.cpp
-    llviewertexture.cpp
-    llviewertextureanim.cpp
-    llviewertexturelist.cpp
-    llviewerthrottle.cpp
-    llviewervisualparam.cpp
-    llviewerwindow.cpp
-    llviewerwindowlistener.cpp
-    llvlcomposition.cpp
-    llvlmanager.cpp
-    llvoavatar.cpp
-    llvoavatardefines.cpp
-    llvoavatarself.cpp
-    llvocache.cpp
-    llvoclouds.cpp
-    llvograss.cpp
-    llvoground.cpp
-    llvoicechannel.cpp
-    llvoiceclient.cpp
-    llvoicecontrolpanel.cpp
-    llvoiceremotectrl.cpp
-    llvoicevisualizer.cpp
-    llvoinventorylistener.cpp
-    llvopartgroup.cpp
-    llvosky.cpp
-    llvosurfacepatch.cpp
-    llvotextbubble.cpp
-    llvotree.cpp
-    llvovolume.cpp
-    llvowater.cpp
-    llvowlsky.cpp
-    llwatchdog.cpp
-    llwaterparammanager.cpp
-    llwaterparamset.cpp
-    llwearable.cpp
-    llwearabledictionary.cpp
-    llwearablelist.cpp
-    llweb.cpp
-    llwind.cpp
-    llwlanimator.cpp
-    llwldaycycle.cpp
-    llwlparammanager.cpp
-    llwlparamset.cpp
-    llworld.cpp
-    llworldmap.cpp
-    llworldmapview.cpp
-    llxmlrpclistener.cpp
-    llxmlrpctransaction.cpp
-    noise.cpp
-    pipeline.cpp
-    )
-
-set(VIEWER_BINARY_NAME "secondlife-bin" CACHE STRING
-    "The name of the viewer executable to create.")
-
-if (LINUX)
-  # We can't set these flags for Darwin, because they get passed to
-  # the PPC compiler.  Ugh.
-
-  set_source_files_properties(
-      llviewerjointmesh_sse.cpp
-      PROPERTIES COMPILE_FLAGS "-msse -mfpmath=sse"
-      )
-  set_source_files_properties(
-      llviewerjointmesh_sse2.cpp
-      PROPERTIES COMPILE_FLAGS "-msse2 -mfpmath=sse"
-      )
-endif (LINUX)
-
-set(viewer_HEADER_FILES
-    CMakeLists.txt
-    ViewerInstall.cmake
-    llaccordionctrl.h
-    llaccordionctrltab.h
-    llagent.h
-    llagentaccess.h
-    llagentdata.h
-    llagentlanguage.h
-    llagentlistener.h
-    llagentpicksinfo.h
-    llagentpilot.h
-    llagentui.h
-    llagentwearables.h
-    llanimstatelabels.h
-    llappearance.h
-    llappearancemgr.h
-    llappviewer.h
-    llappviewerlistener.h
-    llassetuploadqueue.h
-    llassetuploadresponders.h
-    llaudiosourcevo.h
-    llavataractions.h
-    llavatariconctrl.h
-    llavatarlist.h
-    llavatarlistitem.h
-    llavatarpropertiesprocessor.h
-    llbottomtray.h
-    llbox.h
-    llbreadcrumbview.h
-    llcallbacklist.h
-    llcallingcard.h
-    llcapabilitylistener.h
-    llcapabilityprovider.h
-    llcaphttpsender.h
-    llchannelmanager.h
-    llchatbar.h
-    llchathistory.h
-    llchatitemscontainerctrl.h
-    llchatmsgbox.h
-    llchiclet.h
-    llclassifiedinfo.h
-    llclassifiedstatsresponder.h
-    llcloud.h
-    llcolorswatch.h
-    llcommandhandler.h
-    llcommandlineparser.h
-    llcompilequeue.h
-    llconfirmationmanager.h
-    llcurrencyuimanager.h
-    llcylinder.h
-    lldateutil.h
-    lldebugmessagebox.h
-    lldebugview.h
-    lldelayedgestureerror.h
-    lldirpicker.h
-    lldndbutton.h
-    lldrawable.h
-    lldrawpool.h
-    lldrawpoolalpha.h
-    lldrawpoolavatar.h
-    lldrawpoolbump.h
-    lldrawpoolclouds.h
-    lldrawpoolground.h
-    lldrawpoolsimple.h
-    lldrawpoolsky.h
-    lldrawpoolterrain.h
-    lldrawpooltree.h
-    lldrawpoolwater.h
-    lldrawpoolwlsky.h
-    lldriverparam.h
-    lldynamictexture.h
-    llemote.h
-    lleventinfo.h
-    lleventnotifier.h
-    lleventpoll.h
-    llexpandabletextbox.h
-    llface.h
-    llfasttimerview.h
-    llfavoritesbar.h
-    llfeaturemanager.h
-    llfilepicker.h
-    llfirstuse.h
-    llflexibleobject.h
-    llfloaterabout.h
-    llfloateractivespeakers.h
-    llfloateranimpreview.h
-    llfloaterauction.h
-    llfloateravatarpicker.h
-    llfloateravatartextures.h
-    llfloaterbeacons.h
-    llfloaterbuildoptions.h
-    llfloaterbulkpermission.h
-    llfloaterbump.h
-    llfloaterbuy.h
-    llfloaterbuycontents.h
-    llfloaterbuycurrency.h
-    llfloaterbuyland.h
-    llfloatercall.h
-    llfloatercamera.h
-    llfloaterchat.h
-    llfloaterchatterbox.h
-    llfloatercolorpicker.h
-    llfloatercustomize.h
-    llfloaterdaycycle.h
-    llfloaterenvsettings.h
-    llfloaterfonttest.h
-    llfloaterfriends.h
-    llfloatergesture.h
-    llfloatergodtools.h
-    llfloatergroupinvite.h
-    llfloatergroups.h
-    llfloaterhandler.h
-    llfloaterhardwaresettings.h
-    llfloaterhelpbrowser.h
-    llfloaterhud.h
-    llfloaterimagepreview.h
-    llfloaterinspect.h
-    llfloaterinventory.h
-    llfloaterjoystick.h
-    llfloaterlagmeter.h
-    llfloaterland.h
-    llfloaterlandholdings.h
-    llfloatermap.h
-    llfloatermediabrowser.h
-    llfloatermediasettings.h
-    llfloatermemleak.h
-    llfloaternamedesc.h
-    llfloaternotificationsconsole.h
-    llfloateropenobject.h
-    llfloaterparcel.h
-    llfloaterpay.h
-    llfloaterperms.h
-    llfloaterpostcard.h
-    llfloaterpostprocess.h
-    llfloaterpreference.h
-    llfloaterproperties.h
-    llfloaterregioninfo.h
-    llfloaterreporter.h
-    llfloaterscriptdebug.h
-    llfloatersearch.h
-    llfloatersellland.h
-    llfloatersettingsdebug.h
-    llfloatersnapshot.h
-    llfloatertelehub.h
-    llfloatertestinspectors.h
-    llfloatertestlistview.h
-    llfloatertools.h
-    llfloatertopobjects.h
-    llfloatertos.h
-    llfloateruipreview.h
-    llfloaterurldisplay.h
-    llfloaterurlentry.h
-    llfloatervoicedevicesettings.h
-    llfloaterwater.h
-    llfloaterwhitelistentry.h
-    llfloaterwindlight.h
-    llfloaterworldmap.h
-    llfoldertype.h
-    llfolderview.h
-    llfoldervieweventlistener.h
-    llfolderviewitem.h
-    llfollowcam.h
-    llfriendcard.h
-    llgesturemgr.h
-    llgroupactions.h
-    llgrouplist.h
-    llgroupmgr.h
-    llgroupnotify.h
-    llhomelocationresponder.h
-    llhudeffect.h
-    llhudeffectbeam.h
-    llhudeffectlookat.h
-    llhudeffectpointat.h
-    llhudeffecttrail.h
-    llhudicon.h
-    llhudmanager.h
-    llhudobject.h
-    llhudrender.h
-    llhudtext.h
-    llhudview.h
-    llimcontrolpanel.h
-    llimfloater.h
-    llimpanel.h
-    llimview.h
-    llinspect.h
-    llinspectavatar.h
-    llinspectgroup.h
-    llinspectobject.h
-    llinventorybridge.h
-    llinventoryclipboard.h
-    llinventoryfilter.h
-    llinventorymodel.h
-    llinventorysubtreepanel.h
-    lljoystickbutton.h
-    lllandmarkactions.h
-    lllandmarklist.h
-    lllightconstants.h
-    lllistbrowser.h
-    lllistview.h
-    lllocaltextureobject.h
-    lllocationhistory.h
-    lllocationinputctrl.h
-    lllogchat.h
-    llloginhandler.h
-    lllogininstance.h
-    llmanip.h
-    llmaniprotate.h
-    llmanipscale.h
-    llmaniptranslate.h
-    llmapresponders.h
-    llmediactrl.h
-    llmediadataclient.h
-    llmediaremotectrl.h
-    llmemoryview.h
-    llmenucommands.h
-    llmetricperformancetester.h
-    llmimetypes.h
-    llmorphview.h
-    llmoveview.h
-    llmutelist.h
-    llnamebox.h
-    llnameeditor.h
-    llnamelistctrl.h
-    llnavigationbar.h
-    llnearbychat.h
-    llnearbychatbar.h
-    llnearbychathandler.h
-    llnetmap.h
-    llnotificationhandler.h
-    llnotificationmanager.h
-    llnotify.h
-    lloutputmonitorctrl.h
-    lloverlaybar.h
-    llpanelappearance.h
-    llpanelappearancetab.h
-    llpanelavatar.h
-    llpanelavatarrow.h
-    llpanelavatartag.h
-    llpanelblockedlist.h
-    llpanelclassified.h
-    llpanelcontents.h
-    llpaneleditwearable.h
-    llpanelevent.h
-    llpanelface.h
-    llpanelgroup.h
-    llpanelgroupgeneral.h
-    llpanelgroupinvite.h
-    llpanelgrouplandmoney.h
-    llpanelgroupnotices.h
-    llpanelgrouproles.h
-    llpanelimcontrolpanel.h
-    llpanelinventory.h
-    llpanelland.h
-    llpanellandaudio.h
-    llpanellandmarks.h
-    llpanellandmedia.h
-    llpanellogin.h
-    llpanellookinfo.h
-    llpanellooks.h
-    llpanelmedia.h
-    llpanelmediasettingsgeneral.h
-    llpanelmediasettingspermissions.h
-    llpanelmediasettingssecurity.h
-    llpanelmeprofile.h
-    llpanelobject.h
-    llpanelpeople.h
-    llpanelpeoplemenus.h
-    llpanelpermissions.h
-    llpanelpick.h
-    llpanelpicks.h
-    llpanelplace.h
-    llpanelplaceinfo.h
-    llpanelplaces.h
-    llpanelplacestab.h
-    llpanelprimmediacontrols.h
-    llpanelprofile.h
-    llpanelprofileview.h
-    llpanelshower.h
-    llpanelteleporthistory.h
-    llpanelvolume.h
-    llparcelselection.h
-    llparticipantlist.h
-    llpatchvertexarray.h
-    llplacesinventorybridge.h
-    llpolymesh.h
-    llpolymorph.h
-    llpreview.h
-    llpreviewanim.h
-    llpreviewgesture.h
-    llpreviewnotecard.h
-    llpreviewscript.h
-    llpreviewsound.h
-    llpreviewtexture.h
-    llproductinforequest.h
-    llprogressview.h
-    llrecentpeople.h
-    llregionposition.h
-    llremoteparcelrequest.h
-    llresourcedata.h
-    llrootview.h
-    llsavedsettingsglue.h
-    llscreenchannel.h
-    llscrollingpanelparam.h
-    llsearchcombobox.h
-    llsearchhistory.h
-    llselectmgr.h
-    llsidetray.h
-    llsidetraypanelcontainer.h
-    llsky.h
-    llslurl.h
-    llspatialpartition.h
-    llspeakers.h
-    llsplitbutton.h
-    llsprite.h
-    llstartup.h
-    llstatusbar.h
-    llstylemap.h
-    llsurface.h
-    llsurfacepatch.h
-    llsyswellitem.h
-    llsyswellwindow.h    
-    lltable.h
-    llteleporthistory.h
-    llteleporthistorystorage.h
-    lltexglobalcolor.h
-    lltexlayer.h
-    lltexlayerparams.h
-    lltextureatlas.h
-    lltextureatlasmanager.h
-    lltexturecache.h
-    lltexturectrl.h
-    lltexturefetch.h
-    lltextureview.h
-    lltoast.h
-    lltoastalertpanel.h
-    lltoastgroupnotifypanel.h
-    lltoastimpanel.h
-    lltoastnotifypanel.h
-    lltoastpanel.h
-    lltool.h
-    lltoolbar.h
-    lltoolbrush.h
-    lltoolcomp.h
-    lltooldraganddrop.h
-    lltoolface.h
-    lltoolfocus.h
-    lltoolgrab.h
-    lltoolgun.h
-    lltoolindividual.h
-    lltoolmgr.h
-    lltoolmorph.h
-    lltoolobjpicker.h
-    lltoolpie.h
-    lltoolpipette.h
-    lltoolplacer.h
-    lltoolselect.h
-    lltoolselectland.h
-    lltoolselectrect.h
-    lltracker.h
-    lltransientdockablefloater.h
-    lltransientfloatermgr.h
-    lluiconstants.h
-    lluilistener.h
-    lluploaddialog.h
-    llurl.h
-    llurldispatcher.h
-    llurlhistory.h
-    llurllineeditorctrl.h
-    llurlsimstring.h
-    llurlwhitelist.h
-    llvectorperfoptions.h
-    llviewchildren.h
-    llviewerassetstorage.h
-    llvieweraudio.h
-    llviewerbuild.h
-    llviewercamera.h
-    llviewercontrol.h
-    llviewercontrollistener.h
-    llviewerdisplay.h
-    llviewerfloaterreg.h
-    llviewergenericmessage.h
-    llviewergesture.h    
-    llviewerhelp.h
-    llviewerinventory.h
-    llviewerjoint.h
-    llviewerjointattachment.h
-    llviewerjointmesh.h
-    llviewerjoystick.h
-    llviewerkeyboard.h
-    llviewerlayer.h
-    llviewermedia.h
-    llviewermediafocus.h
-    llviewermediaobserver.h
-    llviewermenu.h
-    llviewermenufile.h
-    llviewermessage.h
-    llviewernetwork.h
-    llviewerobject.h
-    llviewerobjectlist.h
-    llviewerparcelmedia.h
-    llviewerparcelmediaautoplay.h
-    llviewerparcelmgr.h
-    llviewerparceloverlay.h
-    llviewerpartsim.h
-    llviewerpartsource.h
-    llviewerprecompiledheaders.h
-    llviewerregion.h
-    llviewershadermgr.h
-    llviewerstats.h
-    llviewertexteditor.h
-    llviewertexture.h
-    llviewertextureanim.h
-    llviewertexturelist.h
-    llviewerthrottle.h
-    llviewervisualparam.h
-    llviewerwindow.h
-    llviewerwindowlistener.h
-    llvlcomposition.h
-    llvlmanager.h
-    llvoavatar.h
-    llvoavatardefines.h
-    llvoavatarself.h
-    llvocache.h
-    llvoclouds.h
-    llvograss.h
-    llvoground.h
-    llvoicechannel.h
-    llvoiceclient.h
-    llvoicecontrolpanel.h
-    llvoiceremotectrl.h
-    llvoicevisualizer.h
-    llvoinventorylistener.h
-    llvopartgroup.h
-    llvosky.h
-    llvosurfacepatch.h
-    llvotextbubble.h
-    llvotree.h
-    llvotreenew.h
-    llvovolume.h
-    llvowater.h
-    llvowlsky.h
-    llwatchdog.h
-    llwaterparammanager.h
-    llwaterparamset.h
-    llwearable.h
-    llwearabledictionary.h
-    llwearablelist.h
-    llweb.h
-    llwind.h
-    llwindebug.h
-    llwlanimator.h
-    llwldaycycle.h
-    llwlparammanager.h
-    llwlparamset.h
-    llworld.h
-    llworldmap.h
-    llworldmapview.h
-    llxmlrpclistener.h
-    llxmlrpctransaction.h
-    macmain.h
-    noise.h
-    pipeline.h
-    randgauss.h
-    VertexCache.h
-    VorbisFramework.h
-    )
-
-source_group("CMake Rules" FILES ViewerInstall.cmake)
-
-if (DARWIN)
-  LIST(APPEND viewer_SOURCE_FILES llappviewermacosx.cpp)
-
-  find_library(AGL_LIBRARY AGL)
-  find_library(APPKIT_LIBRARY AppKit)
-  find_library(COCOA_LIBRARY Cocoa)
-  find_library(IOKIT_LIBRARY IOKit)
-
-  set(viewer_LIBRARIES
-    ${COCOA_LIBRARY}
-    ${AGL_LIBRARY}
-    ${IOKIT_LIBRARY}
-    )
-
-  # Add resource files to the project.
-  set(viewer_RESOURCE_FILES
-    secondlife.icns
-    macview.r
-    gpu_table.txt
-    Info-SecondLife.plist
-    SecondLife.nib/
-    # CMake doesn't seem to support Xcode language variants well just yet
-    English.lproj/InfoPlist.strings
-    English.lproj/language.txt
-    German.lproj/language.txt
-    Japanese.lproj/language.txt
-    Korean.lproj/language.txt
-    )
-  set_source_files_properties(
-    ${viewer_RESOURCE_FILES}
-    PROPERTIES
-    HEADER_FILE_ONLY TRUE
-    #MACOSX_PACKAGE_LOCATION Resources #don't do this! this tells cmake to copy the files.
-    )
-  SOURCE_GROUP("Resources" FILES ${viewer_RESOURCE_FILES})
-  list(APPEND viewer_SOURCE_FILES ${viewer_RESOURCE_FILES})
-endif (DARWIN)
-
-if (LINUX)
-    LIST(APPEND viewer_SOURCE_FILES llappviewerlinux.cpp)
-    LIST(APPEND viewer_SOURCE_FILES llappviewerlinux_api_dbus.cpp)
-    SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--as-needed")
-
-    set(viewer_LIBRARIES
-        Xinerama
-        )
-endif (LINUX)
-
-if (WINDOWS)
-    list(APPEND viewer_SOURCE_FILES
-         llappviewerwin32.cpp
-         llwindebug.cpp
-         )
-
-    list(APPEND viewer_HEADER_FILES
-         llappviewerwin32.h
-         llwindebug.h
-         )
-
-    # precompiled header configuration
-    # llviewerprecompiledheaders.cpp generates
-    # the .pch file.
-    # All sources added to viewer_SOURCE_FILES 
-    # at this point use it.
-    set_source_files_properties(llviewerprecompiledheaders.cpp
-        PROPERTIES
-        COMPILE_FLAGS "/Ycllviewerprecompiledheaders.h"
-        )        
-    foreach( src_file ${viewer_SOURCE_FILES} )
-        set_source_files_properties(
-            ${src_file}
-            PROPERTIES
-            COMPILE_FLAGS "/Yullviewerprecompiledheaders.h"
-            )        
-    endforeach( src_file ${viewer_SOURCE_FILES} )
-    list(APPEND viewer_SOURCE_FILES llviewerprecompiledheaders.cpp)
-    # llstartup.cpp needs special symbols for audio libraries, so it resets
-    # COMPILE_FLAGS below.  Make sure it maintains precompiled header settings.
-    set(LLSTARTUP_COMPILE_FLAGS 
-        "${LLSTARTUP_COMPILE_FLAGS} /Yullviewerprecompiledheaders.h")
-    
-    # Add resource files to the project.
-    # viewerRes.rc is the only buildable file, but
-    # the rest are all dependencies of it.
-    set(viewer_RESOURCE_FILES
-        res/arrow.cur
-        res/arrowcop.cur
-        res/arrowcopmulti.cur
-        res/arrowdrag.cur
-        res/circleandline.cur
-        res/icon1.ico
-        res/llarrow.cur
-        res/llarrowdrag.cur
-        res/llarrowdragmulti.cur
-        res/llarrowlocked.cur
-        res/llgrablocked.cur
-        res/llno.cur
-        res/llnolocked.cur
-        res/lltoolcamera.cur
-        res/lltoolcreate.cur
-        res/lltoolfocus.cur
-        res/lltoolgrab.cur
-        res/lltoolland.cur
-        res/lltoolpan.cur
-        res/lltoolpipette.cur
-        res/lltoolrotate.cur
-        res/lltoolscale.cur
-        res/lltooltranslate.cur
-        res/lltoolzoomin.cur
-        res/lltoolzoomout.cur
-        res/ll_icon.BMP
-        res/ll_icon.ico
-        res/resource.h
-        res/toolpickobject.cur
-        res/toolpickobject2.cur
-        res/toolpickobject3.cur
-        res/toolpipette.cur
-        )
-
-    set_source_files_properties(${viewer_RESOURCE_FILES}
-                                PROPERTIES HEADER_FILE_ONLY TRUE)
-
-    set(viewer_RESOURCE_FILES 
-        res/viewerRes.rc 
-        ${viewer_RESOURCE_FILES}
-        )
-
-    SOURCE_GROUP("Resource Files" FILES ${viewer_RESOURCE_FILES})
-
-    if (NOT STANDALONE)
-        list(APPEND viewer_SOURCE_FILES ${viewer_RESOURCE_FILES})
-    endif (NOT STANDALONE)	
-
-    find_library(DINPUT_LIBRARY dinput8 ${DIRECTX_LIBRARY_DIR})
-    find_library(DXGUID_LIBRARY dxguid ${DIRECTX_LIBRARY_DIR})
-    mark_as_advanced(
-        DINPUT_LIBRARY
-        DXGUID_LIBRARY
-        )
-
-    set(viewer_LIBRARIES
-        ${WINDOWS_LIBRARIES}
-        comdlg32
-        ${DINPUT_LIBRARY}
-        ${DXGUID_LIBRARY}
-        kernel32
-        odbc32
-        odbccp32
-        ole32
-        oleaut32
-        opengl32
-        shell32
-        Vfw32
-        winspool
-        )
-
-    find_library(INTEL_MEMOPS_LIBRARY
-                 NAMES ll_intel_memops
-                 PATHS
-                 optimized ${ARCH_PREBUILT_DIRS_RELEASE}
-                 debug ${ARCH_PREBUILT_DIRS_DEBUG}
-                 )
-    mark_as_advanced(INTEL_MEMOPS_LIBRARY)
-
-    if (INTEL_MEMOPS_LIBRARY)
-      list(APPEND viewer_LIBRARIES ${INTEL_MEMOPS_LIBRARY})
-    endif (INTEL_MEMOPS_LIBRARY)
-
-    use_prebuilt_binary(dbghelp)
-endif (WINDOWS)
-
-# Add the xui files. This is handy for searching for xui elements
-# from within the IDE.
-set(viewer_XUI_FILES
-    skins/default/colors.xml
-    skins/default/textures/textures.xml
-
-
-
-    )
-file(GLOB DEFAULT_XUI_FILE_GLOB_LIST
-     ${CMAKE_CURRENT_SOURCE_DIR}/skins/default/xui/en/*.xml)
-list(APPEND viewer_XUI_FILES ${DEFAULT_XUI_FILE_GLOB_LIST})
-
-file(GLOB DEFAULT_WIDGET_FILE_GLOB_LIST
-     ${CMAKE_CURRENT_SOURCE_DIR}/skins/default/xui/en/widgets/*.xml)
-list(APPEND viewer_XUI_FILES ${DEFAULT_WIDGET_FILE_GLOB_LIST})
-
-file(GLOB SILVER_XUI_FILE_GLOB_LIST
-     ${CMAKE_CURRENT_SOURCE_DIR}/skins/silver/xui/en-us/*.xml)
-list(APPEND viewer_XUI_FILES ${SILVER_XUI_FILE_GLOB_LIST})
-
-# Cannot append empty lists in CMake, wait until we have files here.
-#file(GLOB SILVER_WIDGET_FILE_GLOB_LIST
-#     ${CMAKE_CURRENT_SOURCE_DIR}/skins/silver/xui/en-us/widgets/*.xml)
-#list(APPEND viewer_XUI_FILES ${SILVER_WIDGET_FILE_GLOB_LIST})
-
-list(SORT viewer_XUI_FILES)
-
-source_group("XUI Files" FILES ${viewer_XUI_FILES})
-
-set_source_files_properties(${viewer_XUI_FILES}
-                            PROPERTIES HEADER_FILE_ONLY TRUE)
-
-list(APPEND viewer_SOURCE_FILES ${viewer_XUI_FILES})
-
-set(viewer_APPSETTINGS_FILES
-    app_settings/anim.ini
-    app_settings/cmd_line.xml
-    app_settings/grass.xml
-    app_settings/high_graphics.xml
-    app_settings/keys.ini
-    app_settings/keywords.ini
-    app_settings/logcontrol.xml
-    app_settings/low_graphics.xml
-    app_settings/mid_graphics.xml
-    app_settings/settings.xml
-    app_settings/settings_crash_behavior.xml
-    app_settings/settings_files.xml
-    app_settings/settings_per_account.xml
-    app_settings/std_bump.ini
-    app_settings/trees.xml
-    app_settings/ultra_graphics.xml
-    app_settings/viewerart.xml
-    ${CMAKE_SOURCE_DIR}/../etc/message.xml
-    ${CMAKE_SOURCE_DIR}/../scripts/messages/message_template.msg
-    )
-
-use_prebuilt_binary(artwork-common)
-
-source_group("App Settings" FILES ${viewer_APPSETTINGS_FILES})
-
-set_source_files_properties(${viewer_APPSETTINGS_FILES}
-                            PROPERTIES HEADER_FILE_ONLY TRUE)
-
-list(APPEND viewer_SOURCE_FILES ${viewer_APPSETTINGS_FILES})
-
-set(viewer_CHARACTER_FILES
-    character/attentions.xml
-    character/attentionsN.xml
-    character/avatar_lad.xml
-    character/avatar_skeleton.xml
-    character/genepool.xml
-    )
-
-source_group("Character File" FILES ${viewer_CHARACTER_FILES})
-
-set_source_files_properties(${viewer_CHARACTER_FILES}
-                            PROPERTIES HEADER_FILE_ONLY TRUE)
-if (NOT STANDALONE)
-    list(APPEND viewer_SOURCE_FILES ${viewer_CHARACTER_FILES})
-endif (NOT STANDALONE)
-
-if (WINDOWS)
-  file(GLOB viewer_INSTALLER_FILES installers/windows/*.nsi)
-
-  source_group("Installer Files" FILES ${viewer_INSTALLER_FILES})
-
-  set_source_files_properties(${viewer_INSTALLER_FILES}
-                              PROPERTIES HEADER_FILE_ONLY TRUE)
-
-  list(APPEND viewer_SOURCE_FILES ${viewer_INSTALLER_FILES})
-endif (WINDOWS)
-
-if (OPENAL)
-  set(LLSTARTUP_COMPILE_FLAGS "${LLSTARTUP_COMPILE_FLAGS} -DLL_OPENAL")
-endif (OPENAL)
-
-if (FMOD)
-  set(LLSTARTUP_COMPILE_FLAGS "${LLSTARTUP_COMPILE_FLAGS} -DLL_FMOD")
-
-  if (DARWIN)
-    set(fmodwrapper_SOURCE_FILES fmodwrapper.cpp)
-    add_library(fmodwrapper SHARED ${fmodwrapper_SOURCE_FILES})
-    set(fmodwrapper_needed_LIBRARIES ${FMOD_LIBRARY} ${CARBON_LIBRARY})
-    set_target_properties(
-      fmodwrapper
-      PROPERTIES
-      BUILD_WITH_INSTALL_RPATH 1
-      INSTALL_NAME_DIR "@executable_path/../Resources"
-      LINK_FLAGS "-unexported_symbols_list ${CMAKE_CURRENT_SOURCE_DIR}/fmod_hidden_symbols.exp"
-      )
-    set(FMODWRAPPER_LIBRARY fmodwrapper)
-    target_link_libraries(fmodwrapper ${fmodwrapper_needed_LIBRARIES})
-  else (DARWIN)
-    # fmodwrapper unnecessary on linux or windows
-    set(FMODWRAPPER_LIBRARY ${FMOD_LIBRARY})
-  endif (DARWIN)
-endif (FMOD)
-
-set_source_files_properties(llstartup.cpp PROPERTIES COMPILE_FLAGS "${LLSTARTUP_COMPILE_FLAGS}")
-
-list(APPEND viewer_SOURCE_FILES ${viewer_HEADER_FILES})
-
-set_source_files_properties(${viewer_HEADER_FILES}
-                            PROPERTIES HEADER_FILE_ONLY TRUE)
-
-add_executable(${VIEWER_BINARY_NAME}
-    WIN32
-    MACOSX_BUNDLE
-    ${viewer_SOURCE_FILES}
-    )
-check_message_template(${VIEWER_BINARY_NAME})
-
-if (LLKDU_LIBRARY)
-  add_dependencies(${VIEWER_BINARY_NAME} ${LLKDU_LIBRARY})
-endif (LLKDU_LIBRARY)
-
-# add package files
-file(GLOB EVENT_HOST_SCRIPT_GLOB_LIST
-     ${CMAKE_CURRENT_SOURCE_DIR}/../viewer_components/*.py)
-list(APPEND EVENT_HOST_SCRIPTS ${EVENT_HOST_SCRIPT_GLOB_LIST})
-
-set(PACKAGE OFF CACHE BOOL
-    "Add a package target that builds an installer package.")
-
-if (WINDOWS)
-    if(MSVC71)
-        set(release_flags "/MAP:Release/${VIEWER_BINARY_NAME}.map /MAPINFO:LINES")
-    else(MSVC71)
-        set(release_flags "/MAP:Release/${VIEWER_BINARY_NAME}.map")
-    endif(MSVC71)
-    
-    set_target_properties(${VIEWER_BINARY_NAME}
-        PROPERTIES
-        # *TODO -reenable this once we get server usage sorted out
-        #LINK_FLAGS "/debug /NODEFAULTLIB:LIBCMT /SUBSYSTEM:WINDOWS /INCLUDE:\"__tcmalloc\""
-        LINK_FLAGS "/debug /NODEFAULTLIB:LIBCMT /SUBSYSTEM:WINDOWS"
-        LINK_FLAGS_DEBUG "/NODEFAULTLIB:\"LIBCMT;LIBCMTD;MSVCRT\" /INCREMENTAL:NO"
-        LINK_FLAGS_RELEASE ${release_flags}
-        )
-
-    # sets the 'working directory' for debugging from visual studio.
-    if (NOT UNATTENDED)
-        add_custom_command(
-            TARGET ${VIEWER_BINARY_NAME} PRE_BUILD
-            COMMAND ${CMAKE_SOURCE_DIR}/tools/vstool/vstool.exe
-            ARGS
-              --solution 
-              ${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}.sln
-              --workingdir
-              ${VIEWER_BINARY_NAME}
-              ${CMAKE_CURRENT_SOURCE_DIR}
-            COMMENT "Setting the ${VIEWER_BINARY_NAME} working directory for debugging."
-            )
-    endif (NOT UNATTENDED)
-
-    add_custom_command(
-        TARGET ${VIEWER_BINARY_NAME} PRE_BUILD
-        COMMAND ${CMAKE_COMMAND}
-        ARGS
-          -E
-          copy_if_different
-          ${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/messages/message_template.msg
-          ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/app_settings/message_template.msg
-        COMMENT "Copying message_template.msg to the runtime folder."
-        )
-
-    add_custom_command(
-        TARGET ${VIEWER_BINARY_NAME} PRE_BUILD
-        COMMAND ${CMAKE_COMMAND}
-        ARGS
-          -E
-          copy_if_different
-          ${CMAKE_CURRENT_SOURCE_DIR}/../../etc/message.xml
-          ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/app_settings/message.xml
-        COMMENT "Copying message.xml to the runtime folder."
-        )
-       
-    if(WINDOWS)
-      # Copy Win Libs...
-      # This happens at build time, not config time. We can't glob files in this cmake.
-      # *FIX:Mani Write a sub script to glob the files...
-      # *FIX:Mani Use actually dependencies rather than bulk copy.
-      add_custom_command(
-        TARGET ${VIEWER_BINARY_NAME} PRE_BUILD
-        COMMAND ${CMAKE_COMMAND}
-        ARGS
-          -E
-          copy_directory
-          ${SHARED_LIB_STAGING_DIR}/${CMAKE_CFG_INTDIR}
-          ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}
-        COMMENT "Copying staged dlls."
-        )
-
-      add_dependencies(${VIEWER_BINARY_NAME} stage_third_party_libs llcommon)
-      if(LLKDU_LIBRARY)
-	# kdu may not exist!
-	add_dependencies(${VIEWER_BINARY_NAME} llkdu)
-      endif(LLKDU_LIBRARY)
-    endif(WINDOWS)    
-
-    if (EXISTS ${CMAKE_SOURCE_DIR}/copy_win_scripts)
-      add_dependencies(${VIEWER_BINARY_NAME} copy_win_scripts)
-    endif (EXISTS ${CMAKE_SOURCE_DIR}/copy_win_scripts)
-        
-    add_custom_command(
-        OUTPUT ${CMAKE_CFG_INTDIR}/touched.bat
-        COMMAND ${PYTHON_EXECUTABLE}
-        ARGS
-          ${CMAKE_CURRENT_SOURCE_DIR}/viewer_manifest.py
-          --configuration=${CMAKE_CFG_INTDIR}
-          --channel=${VIEWER_CHANNEL}
-          --login_channel=${VIEWER_LOGIN_CHANNEL}
-          --grid=${GRID}
-          --source=${CMAKE_CURRENT_SOURCE_DIR}
-              --artwork=${ARTWORK_DIR}
-              --build=${CMAKE_CURRENT_BINARY_DIR}
-              --dest=${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}
-              --touch=${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/touched.bat
-        DEPENDS ${VIEWER_BINARY_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/viewer_manifest.py
-        )
-
-    add_dependencies(${VIEWER_BINARY_NAME} SLPlugin media_plugin_quicktime media_plugin_webkit)
-
-    if (PACKAGE)
-      add_custom_command(
-          OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/event_host.tar.bz2
-          COMMAND ${PYTHON_EXECUTABLE}
-          ARGS
-            ${CMAKE_CURRENT_SOURCE_DIR}/event_host_manifest.py
-            ${CMAKE_CURRENT_SOURCE_DIR}/..
-            ${CMAKE_CURRENT_BINARY_DIR}
-            ${CMAKE_CFG_INTDIR}
-
-          DEPENDS 
-            lleventhost 
-            ${EVENT_HOST_SCRIPTS}
-            ${CMAKE_CURRENT_SOURCE_DIR}/event_host_manifest.py)
-
-      add_custom_target(package ALL 
-          DEPENDS 
-            ${CMAKE_CFG_INTDIR}/touched.bat)
-            # temporarily disable packaging of event_host until hg subrepos get
-            # sorted out on the parabuild cluster...
-            #${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/event_host.tar.bz2)
-      add_dependencies(package windows-updater windows-crash-logger)
-
-
-    endif (PACKAGE)
-endif (WINDOWS)
-
-target_link_libraries(${VIEWER_BINARY_NAME}
-    ${LLAUDIO_LIBRARIES}
-    ${LLCHARACTER_LIBRARIES}
-    ${LLIMAGE_LIBRARIES}
-    ${LLIMAGEJ2COJ_LIBRARIES}
-    ${LLINVENTORY_LIBRARIES}
-    ${LLMESSAGE_LIBRARIES}
-    ${LLPLUGIN_LIBRARIES}
-    ${LLPRIMITIVE_LIBRARIES}
-    ${LLRENDER_LIBRARIES}
-    ${FREETYPE_LIBRARIES}
-    ${LLUI_LIBRARIES}
-    ${LLVFS_LIBRARIES}
-    ${LLWINDOW_LIBRARIES}
-    ${LLXML_LIBRARIES}
-    ${LLXUIXML_LIBRARIES}
-    ${LSCRIPT_LIBRARIES}
-    ${LLMATH_LIBRARIES}
-    ${LLCOMMON_LIBRARIES}
-    ${NDOF_LIBRARY}
-    ${viewer_LIBRARIES}
-    ${BOOST_PROGRAM_OPTIONS_LIBRARY}
-    ${BOOST_REGEX_LIBRARY}
-    ${DBUSGLIB_LIBRARIES}
-    ${OPENGL_LIBRARIES}
-    ${FMODWRAPPER_LIBRARY}
-    ${OPENGL_LIBRARIES}
-    ${SDL_LIBRARY}
-    ${SMARTHEAP_LIBRARY}
-    ${UI_LIBRARIES}
-    ${WINDOWS_LIBRARIES}
-    ${XMLRPCEPI_LIBRARIES}
-    ${ELFIO_LIBRARIES}
-    ${LLLOGIN_LIBRARIES}
-    ${GOOGLE_PERFTOOLS_LIBRARIES}
-    )
-
-build_version(viewer)
-
-set(ARTWORK_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE PATH
-    "Path to artwork files.")
-
-
-if (LINUX)
-  add_custom_command(
-      OUTPUT secondlife-stripped
-      COMMAND strip
-      ARGS --strip-debug -o secondlife-stripped ${VIEWER_BINARY_NAME}
-      DEPENDS ${VIEWER_BINARY_NAME}
-      )
-
-  set(product SecondLife-${ARCH}-${viewer_VERSION})
-
-  add_custom_command(
-      OUTPUT ${product}.tar.bz2
-      COMMAND ${PYTHON_EXECUTABLE}
-      ARGS
-        ${CMAKE_CURRENT_SOURCE_DIR}/viewer_manifest.py
-        --grid=${GRID}
-        --channel=${VIEWER_CHANNEL}
-        --login_channel=${VIEWER_LOGIN_CHANNEL}
-        --installer_name=${product}
-        --arch=${ARCH}
-        --source=${CMAKE_CURRENT_SOURCE_DIR}
-        --artwork=${ARTWORK_DIR}
-        --build=${CMAKE_CURRENT_BINARY_DIR}
-        --dest=${CMAKE_CURRENT_BINARY_DIR}/packaged
-        --touch=${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/.${product}.touched
-      DEPENDS secondlife-stripped ${CMAKE_CURRENT_SOURCE_DIR}/viewer_manifest.py
-      )
-
-  add_dependencies(${VIEWER_BINARY_NAME} SLPlugin media_plugin_gstreamer010 media_plugin_webkit)
-
-  if (NOT INSTALL)
-    add_custom_target(package ALL DEPENDS ${product}.tar.bz2)
-    add_dependencies(package linux-crash-logger-strip-target)
-    add_dependencies(package linux-updater-strip-target)
-  endif (NOT INSTALL)
-endif (LINUX)
-
-if (DARWIN)
-  set(product "Second Life")
-  set_target_properties(
-    ${VIEWER_BINARY_NAME}
-    PROPERTIES
-    OUTPUT_NAME "${product}"
-    MACOSX_BUNDLE_INFO_STRING "info string - localize me"
-    MACOSX_BUNDLE_ICON_FILE "secondlife.icns"
-    MACOSX_BUNDLE_GUI_IDENTIFIER "Second Life"
-    MACOSX_BUNDLE_LONG_VERSION_STRING "ververver"
-    MACOSX_BUNDLE_BUNDLE_NAME "Second Life"
-    MACOSX_BUNDLE_SHORT_VERSION_STRING "asdf"
-    MACOSX_BUNDLE_BUNDLE_VERSION "asdf"
-    MACOSX_BUNDLE_COPYRIGHT "copyright linden lab 2007 - localize me and run me through a legal wringer"
-    )
-
-  add_custom_command(
-    TARGET ${VIEWER_BINARY_NAME} POST_BUILD
-    COMMAND ${PYTHON_EXECUTABLE}
-    ARGS
-      ${CMAKE_CURRENT_SOURCE_DIR}/viewer_manifest.py
-      --grid=${GRID}
-      --actions=copy
-      --configuration=${CMAKE_CFG_INTDIR}
-      --source=${CMAKE_CURRENT_SOURCE_DIR}
-      --artwork=${ARTWORK_DIR}
-      --build=${CMAKE_CURRENT_BINARY_DIR}
-      --dest=${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${product}.app
-    DEPENDS ${VIEWER_BINARY_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/viewer_manifest.py
-    )
-
-  add_dependencies(${VIEWER_BINARY_NAME} SLPlugin media_plugin_quicktime media_plugin_webkit)
-
-  if (PACKAGE)
-      add_custom_target(package ALL DEPENDS ${VIEWER_BINARY_NAME}) 
-      add_dependencies(package mac-updater mac-crash-logger)
-
-      add_custom_command(
-        TARGET package POST_BUILD
-        COMMAND ${PYTHON_EXECUTABLE}
-        ARGS
-          ${CMAKE_CURRENT_SOURCE_DIR}/viewer_manifest.py
-          --grid=${GRID}
-          --configuration=${CMAKE_CFG_INTDIR}
-          --channel=${VIEWER_CHANNEL}
-          --login_channel=${VIEWER_LOGIN_CHANNEL}
-          --source=${CMAKE_CURRENT_SOURCE_DIR}
-          --artwork=${ARTWORK_DIR}
-          --build=${CMAKE_CURRENT_BINARY_DIR}
-          --dest=${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${product}.app
-          --touch=${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/.${product}.touched
-        DEPENDS
-          ${CMAKE_CURRENT_SOURCE_DIR}/viewer_manifest.py
-      )
-
-
-      add_custom_command(
-        TARGET package POST_BUILD
-        COMMAND ${PYTHON_EXECUTABLE}
-        ARGS
-          ${CMAKE_CURRENT_SOURCE_DIR}/viewer_manifest.py
-          --grid=${GRID}
-          --configuration=${CMAKE_CFG_INTDIR}
-          --channel=${VIEWER_CHANNEL}
-          --login_channel=${VIEWER_LOGIN_CHANNEL}
-          --source=${CMAKE_CURRENT_SOURCE_DIR}
-          --artwork=${ARTWORK_DIR}
-          --build=${CMAKE_CURRENT_BINARY_DIR}
-          --dest=${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${product}.app
-          --touch=${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/.${product}.touched
-        DEPENDS
-          ${CMAKE_CURRENT_SOURCE_DIR}/viewer_manifest.py
-      )
-
-  endif (PACKAGE)
-endif (DARWIN)
-
-if (INSTALL)
-  include(${CMAKE_CURRENT_SOURCE_DIR}/ViewerInstall.cmake)
-endif (INSTALL)
-
-# To add a viewer unit test, just add the test .cpp file below
-# This creates a separate test project per file listed.
-include(LLAddBuildTest)
-SET(viewer_TEST_SOURCE_FILES
-  llagentaccess.cpp
-  lldateutil.cpp
-  llmediadataclient.cpp
-  llviewerhelputil.cpp
-  lllogininstance.cpp
-  )
-set_source_files_properties(
-  ${viewer_TEST_SOURCE_FILES}
-  PROPERTIES
-    LL_TEST_ADDITIONAL_SOURCE_FILES llviewerprecompiledheaders.cpp
-  )
-LL_ADD_PROJECT_UNIT_TESTS(${VIEWER_BINARY_NAME} "${viewer_TEST_SOURCE_FILES}")
-
-#set(TEST_DEBUG on)
-set(test_sources llcapabilitylistener.cpp llviewerprecompiledheaders.cpp)
-set(test_libs 
-  ${LLMESSAGE_LIBRARIES} 
-  ${WINDOWS_LIBRARIES} 
-  ${LLVFS_LIBRARIES}
-  ${LLMATH_LIBRARIES}
-  ${LLCOMMON_LIBRARIES} 
-  ${GOOGLEMOCK_LIBRARIES}
-  )
-
-LL_ADD_INTEGRATION_TEST(llcapabilitylistener 
-  "${test_sources}" 
-  "${test_libs}"
-  ${PYTHON_EXECUTABLE}
-  "${CMAKE_SOURCE_DIR}/llmessage/tests/test_llsdmessage_peer.py"
-  )
-
-#ADD_VIEWER_BUILD_TEST(llmemoryview viewer)
-
-
-# Don't do these for DARWIN or LINUX here -- they're taken care of by viewer_manifest.py
-if (WINDOWS)
-  add_custom_command(
-      TARGET ${VIEWER_BINARY_NAME} POST_BUILD
-      COMMAND ${CMAKE_COMMAND}
-      ARGS
-        -E
-        make_directory
-        ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/llplugin
-      COMMENT "Creating llplugin dir."
-      )
-
-  get_target_property(BUILT_SLPLUGIN SLPlugin LOCATION)
-  add_custom_command(
-      TARGET ${VIEWER_BINARY_NAME} POST_BUILD
-      COMMAND ${CMAKE_COMMAND}
-      ARGS
-        -E
-        copy_if_different
-        ${BUILT_SLPLUGIN}
-        ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}
-      COMMENT "Copying SLPlugin executable to the runtime folder."
-      )
-
-  get_target_property(BUILT_WEBKIT_PLUGIN media_plugin_webkit LOCATION)
-    add_custom_command(
-        TARGET ${VIEWER_BINARY_NAME} POST_BUILD
-        COMMAND ${CMAKE_COMMAND}
-        ARGS
-          -E
-          copy_if_different
-          ${BUILT_WEBKIT_PLUGIN}
-          ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/llplugin
-        COMMENT "Copying WebKit Plugin to the runtime folder."
-        )
-
-  get_target_property(BUILT_QUICKTIME_PLUGIN media_plugin_quicktime LOCATION)
-    add_custom_command(
-        TARGET ${VIEWER_BINARY_NAME} POST_BUILD
-        COMMAND ${CMAKE_COMMAND}
-        ARGS
-          -E
-          copy_if_different
-          ${BUILT_QUICKTIME_PLUGIN}
-          ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/llplugin
-        COMMENT "Copying Quicktime Plugin to the runtime folder."
-        )
-
-  #*******************************
-  # Copy media plugin support dlls
-  # Debug config runtime files required for the plugins
-  set(plugins_debug_src_dir "${CMAKE_SOURCE_DIR}/../libraries/i686-win32/lib/debug")
-  set(plugins_debug_files
-    libeay32.dll
-    qtcored4.dll
-    qtguid4.dll
-    qtnetworkd4.dll
-    qtopengld4.dll
-    qtwebkitd4.dll
-    ssleay32.dll
-    )
-  copy_if_different(
-    ${plugins_debug_src_dir}
-    "${CMAKE_CURRENT_BINARY_DIR}/Debug/llplugin"
-    out_targets
-    ${plugins_debug_files}
-    )
-  set(media_plugin_targets ${media_plugin_targets} ${out_targets})
-  
-  # Release & ReleaseDebInfo config runtime files required for the plugins
-  set(plugins_release_src_dir "${CMAKE_SOURCE_DIR}/../libraries/i686-win32/lib/release")
-  set(plugins_release_files
-    libeay32.dll
-    qtcore4.dll
-    qtgui4.dll
-    qtnetwork4.dll
-    qtopengl4.dll
-    qtwebkit4.dll
-    ssleay32.dll
-    )
-  copy_if_different(
-    ${plugins_release_src_dir}
-    "${CMAKE_CURRENT_BINARY_DIR}/Release/llplugin"
-    out_targets
-    ${plugins_release_files}
-    )
-  set(media_plugin_targets ${media_plugin_targets} ${out_targets})
-
-  copy_if_different(
-    ${plugins_release_src_dir}
-    "${CMAKE_CURRENT_BINARY_DIR}/RelWithDebInfo/llplugin"
-    out_targets
-    ${plugins_release_files}
-    )
-  set(media_plugin_targets ${media_plugin_targets} ${out_targets})
-  
-  add_custom_target(copy_media_plugin_libs ALL
-    DEPENDS 
-    ${media_plugin_targets}
-    )
-
-  add_custom_command(
-    TARGET ${VIEWER_BINARY_NAME} POST_BUILD
-    COMMAND ${CMAKE_COMMAND}
-    ARGS
-      -E
-      copy_directory
-      ${CMAKE_BINARY_DIR}/test_apps/llplugintest/${CMAKE_CFG_INTDIR}/imageformats
-      ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/llplugin/imageformats
-    COMMENT "Copying llpluging imageformat libs."
-    )
-
-  add_dependencies(${VIEWER_BINARY_NAME} llmediaplugintest copy_media_plugin_libs)
-
-endif (WINDOWS)
-
+# -*- cmake -*-
+
+project(viewer)
+
+include(00-Common)
+include(Boost)
+include(BuildVersion)
+include(DBusGlib)
+include(DirectX)
+include(ELFIO)
+include(FMOD)
+include(OPENAL)
+include(FindOpenGL)
+include(LLAudio)
+include(LLCharacter)
+include(LLCommon)
+include(LLImage)
+include(LLImageJ2COJ)
+include(LLInventory)
+include(LLMath)
+include(LLMessage)
+include(LLPlugin)
+include(LLPrimitive)
+include(LLRender)
+include(LLUI)
+include(LLVFS)
+include(LLWindow)
+include(LLXML)
+include(LLXUIXML)
+include(LScript)
+include(Linking)
+include(NDOF)
+include(GooglePerfTools)
+include(TemplateCheck)
+include(UI)
+include(UnixInstall)
+include(LLKDU)
+include(ViewerMiscLibs)
+include(LLLogin)
+include(CMakeCopyIfDifferent)
+
+include_directories(
+    ${DBUSGLIB_INCLUDE_DIRS}
+    ${ELFIO_INCLUDE_DIR}
+    ${LLAUDIO_INCLUDE_DIRS}
+    ${LLCHARACTER_INCLUDE_DIRS}
+    ${LLCOMMON_INCLUDE_DIRS}
+    ${LLIMAGE_INCLUDE_DIRS}
+    ${LLINVENTORY_INCLUDE_DIRS}
+    ${LLMATH_INCLUDE_DIRS}
+    ${LLMESSAGE_INCLUDE_DIRS}
+    ${LLPLUGIN_INCLUDE_DIRS}
+    ${LLPRIMITIVE_INCLUDE_DIRS}
+    ${LLRENDER_INCLUDE_DIRS}
+    ${LLUI_INCLUDE_DIRS}
+    ${LLVFS_INCLUDE_DIRS}
+    ${LLWINDOW_INCLUDE_DIRS}
+    ${LLXML_INCLUDE_DIRS}
+    ${LLXUIXML_INCLUDE_DIRS}
+    ${LSCRIPT_INCLUDE_DIRS}
+    ${LSCRIPT_INCLUDE_DIRS}/lscript_compile
+    ${LLLOGIN_INCLUDE_DIRS}
+    )
+
+set(viewer_SOURCE_FILES
+    llaccordionctrl.cpp
+    llaccordionctrltab.cpp
+    llagent.cpp
+    llagentaccess.cpp
+    llagentdata.cpp
+    llagentlanguage.cpp
+    llagentlistener.cpp
+    llagentpicksinfo.cpp
+    llagentpilot.cpp
+    llagentui.cpp
+    llagentwearables.cpp
+    llanimstatelabels.cpp
+    llappearancemgr.cpp
+    llappviewer.cpp
+    llappviewerlistener.cpp
+    llassetuploadqueue.cpp
+    llassetuploadresponders.cpp
+    llaudiosourcevo.cpp
+    llavataractions.cpp
+    llavatariconctrl.cpp
+    llavatarlist.cpp
+    llavatarlistitem.cpp
+    llavatarpropertiesprocessor.cpp
+    llbottomtray.cpp
+    llbox.cpp
+    llbreadcrumbview.cpp
+    llcallbacklist.cpp
+    llcallingcard.cpp
+    llcapabilitylistener.cpp
+    llcaphttpsender.cpp
+    llchannelmanager.cpp
+    llchatbar.cpp
+    llchathistory.cpp
+    llchatitemscontainerctrl.cpp
+    llchatmsgbox.cpp
+    llchiclet.cpp
+    llclassifiedinfo.cpp
+    llclassifiedstatsresponder.cpp
+    llcloud.cpp
+    llcolorswatch.cpp
+    llcommandhandler.cpp
+    llcommandlineparser.cpp
+    llcompilequeue.cpp
+    llconfirmationmanager.cpp
+    llcurrencyuimanager.cpp
+    llcylinder.cpp
+    lldateutil.cpp
+    lldebugmessagebox.cpp
+    lldebugview.cpp
+    lldelayedgestureerror.cpp
+    lldirpicker.cpp
+    lldndbutton.cpp
+    lldrawable.cpp
+    lldrawpool.cpp
+    lldrawpoolalpha.cpp
+    lldrawpoolavatar.cpp
+    lldrawpoolbump.cpp
+    lldrawpoolground.cpp
+    lldrawpoolsimple.cpp
+    lldrawpoolsky.cpp
+    lldrawpoolterrain.cpp
+    lldrawpooltree.cpp
+    lldrawpoolwater.cpp
+    lldrawpoolwlsky.cpp
+    lldriverparam.cpp
+    lldynamictexture.cpp
+    llemote.cpp
+    lleventinfo.cpp
+    lleventnotifier.cpp
+    lleventpoll.cpp
+    llexpandabletextbox.cpp
+    llface.cpp
+    llfasttimerview.cpp
+    llfavoritesbar.cpp
+    llfeaturemanager.cpp
+    llfilepicker.cpp
+    llfirstuse.cpp
+    llflexibleobject.cpp
+    llfloaterabout.cpp
+    llfloateractivespeakers.cpp
+    llfloateranimpreview.cpp
+    llfloaterauction.cpp
+    llfloateravatarpicker.cpp
+    llfloateravatartextures.cpp
+    llfloaterbeacons.cpp
+    llfloaterbuildoptions.cpp
+    llfloaterbulkpermission.cpp
+    llfloaterbump.cpp
+    llfloaterbuy.cpp
+    llfloaterbuycontents.cpp
+    llfloaterbuycurrency.cpp
+    llfloaterbuyland.cpp
+    llfloatercall.cpp
+    llfloatercamera.cpp
+    llfloaterchat.cpp
+    llfloaterchatterbox.cpp
+    llfloatercolorpicker.cpp
+    llfloatercustomize.cpp
+    llfloaterdaycycle.cpp
+    llfloaterenvsettings.cpp
+    llfloaterfonttest.cpp
+    llfloaterfriends.cpp
+    llfloatergesture.cpp
+    llfloatergodtools.cpp
+    llfloatergroupinvite.cpp
+    llfloatergroups.cpp
+    llfloaterhandler.cpp
+    llfloaterhardwaresettings.cpp
+    llfloaterhelpbrowser.cpp
+    llfloaterhud.cpp
+    llfloaterimagepreview.cpp
+    llfloaterinspect.cpp
+    llfloaterinventory.cpp
+    llfloaterjoystick.cpp
+    llfloaterlagmeter.cpp
+    llfloaterland.cpp
+    llfloaterlandholdings.cpp
+    llfloatermap.cpp
+    llfloatermediabrowser.cpp
+    llfloatermediasettings.cpp
+    llfloatermemleak.cpp
+    llfloaternamedesc.cpp
+    llfloaternotificationsconsole.cpp
+    llfloateropenobject.cpp
+    llfloaterparcel.cpp
+    llfloaterpay.cpp
+    llfloaterperms.cpp
+    llfloaterpostcard.cpp
+    llfloaterpostprocess.cpp
+    llfloaterpreference.cpp
+    llfloaterproperties.cpp
+    llfloaterregioninfo.cpp
+    llfloaterreporter.cpp
+    llfloaterscriptdebug.cpp
+    llfloatersearch.cpp
+    llfloatersellland.cpp
+    llfloatersettingsdebug.cpp
+    llfloatersnapshot.cpp
+    llfloatertelehub.cpp
+    llfloatertestinspectors.cpp
+    llfloatertestlistview.cpp
+    llfloatertools.cpp
+    llfloatertopobjects.cpp
+    llfloatertos.cpp
+    llfloateruipreview.cpp
+    llfloaterurldisplay.cpp
+    llfloaterurlentry.cpp
+    llfloatervoicedevicesettings.cpp
+    llfloaterwater.cpp
+    llfloaterwhitelistentry.cpp
+    llfloaterwindlight.cpp
+    llfloaterworldmap.cpp
+    llfoldertype.cpp
+    llfolderview.cpp
+    llfolderviewitem.cpp
+    llfollowcam.cpp
+    llfriendcard.cpp
+    llgesturemgr.cpp
+    llglsandbox.cpp
+    llgroupactions.cpp
+    llgrouplist.cpp
+    llgroupmgr.cpp
+    llgroupnotify.cpp
+    llhomelocationresponder.cpp
+    llhudeffect.cpp
+    llhudeffectbeam.cpp
+    llhudeffectlookat.cpp
+    llhudeffectpointat.cpp
+    llhudeffecttrail.cpp
+    llhudicon.cpp
+    llhudmanager.cpp
+    llhudobject.cpp
+    llhudrender.cpp
+    llhudtext.cpp
+    llhudview.cpp
+    llimcontrolpanel.cpp
+    llimfloater.cpp
+    llimhandler.cpp
+    llimpanel.cpp
+    llimview.cpp
+    llinspect.cpp
+    llinspectavatar.cpp
+    llinspectgroup.cpp
+    llinspectobject.cpp
+    llinventorybridge.cpp
+    llinventoryclipboard.cpp
+    llinventoryfilter.cpp
+    llinventoryfunctions.cpp
+    llinventorymodel.cpp
+    llinventorypanel.cpp
+    llinventorysubtreepanel.cpp
+    lljoystickbutton.cpp
+    lllandmarkactions.cpp
+    lllandmarklist.cpp
+    lllistbrowser.cpp
+    lllistview.cpp
+    lllocaltextureobject.cpp
+    lllocationhistory.cpp
+    lllocationinputctrl.cpp
+    lllogchat.cpp
+    llloginhandler.cpp
+    lllogininstance.cpp
+    llmanip.cpp
+    llmaniprotate.cpp
+    llmanipscale.cpp
+    llmaniptranslate.cpp
+    llmapresponders.cpp
+    llmediactrl.cpp
+    llmediadataclient.cpp
+    llmediaremotectrl.cpp
+    llmemoryview.cpp
+    llmenucommands.cpp
+    llmetricperformancetester.cpp
+    llmimetypes.cpp
+    llmorphview.cpp
+    llmoveview.cpp
+    llmutelist.cpp
+    llnamebox.cpp
+    llnameeditor.cpp
+    llnamelistctrl.cpp
+    llnavigationbar.cpp
+    llnearbychat.cpp
+    llnearbychatbar.cpp
+    llnearbychathandler.cpp
+    llnetmap.cpp
+    llnotificationalerthandler.cpp
+    llnotificationgrouphandler.cpp
+    llnotificationmanager.cpp
+    llnotificationscripthandler.cpp
+    llnotificationtiphandler.cpp
+    llnotify.cpp
+    lloutputmonitorctrl.cpp
+    lloverlaybar.cpp
+    llpanelappearance.cpp
+    llpanelappearancetab.cpp
+    llpanelavatar.cpp
+    llpanelavatarrow.cpp
+    llpanelavatartag.cpp
+    llpanelblockedlist.cpp
+    llpanelclassified.cpp
+    llpanelcontents.cpp
+    llpaneleditwearable.cpp
+    llpanelevent.cpp
+    llpanelface.cpp
+    llpanelgroup.cpp
+    llpanelgroupgeneral.cpp
+    llpanelgroupinvite.cpp
+    llpanelgrouplandmoney.cpp
+    llpanelgroupnotices.cpp
+    llpanelgrouproles.cpp
+    llpanelimcontrolpanel.cpp
+    llpanelland.cpp
+    llpanellandaudio.cpp
+    llpanellandmarks.cpp
+    llpanellandmedia.cpp
+    llpanellogin.cpp
+    llpanellookinfo.cpp
+    llpanellooks.cpp
+    llpanelmaininventory.cpp
+    llpanelmedia.cpp
+    llpanelmediasettingsgeneral.cpp
+    llpanelmediasettingspermissions.cpp
+    llpanelmediasettingssecurity.cpp
+    llpanelmeprofile.cpp
+    llpanelobject.cpp
+    llpanelobjectinventory.cpp
+    llpanelpeople.cpp
+    llpanelpeoplemenus.cpp
+    llpanelpermissions.cpp
+    llpanelpick.cpp
+    llpanelpicks.cpp
+    llpanelplace.cpp
+    llpanelplaceinfo.cpp
+    llpanelplaces.cpp
+    llpanelplacestab.cpp
+    llpanelprimmediacontrols.cpp
+    llpanelprofile.cpp
+    llpanelprofileview.cpp
+    llpanelshower.cpp
+    llpanelteleporthistory.cpp
+    llpanelvolume.cpp
+    llparcelselection.cpp
+    llparticipantlist.cpp
+    llpatchvertexarray.cpp
+    llplacesinventorybridge.cpp
+    llpolymesh.cpp
+    llpolymorph.cpp
+    llpreview.cpp
+    llpreviewanim.cpp
+    llpreviewgesture.cpp
+    llpreviewnotecard.cpp
+    llpreviewscript.cpp
+    llpreviewsound.cpp
+    llpreviewtexture.cpp
+    llproductinforequest.cpp
+    llprogressview.cpp
+    llrecentpeople.cpp
+    llregionposition.cpp
+    llremoteparcelrequest.cpp
+    llsavedsettingsglue.cpp
+    llscreenchannel.cpp
+    llscrollingpanelparam.cpp
+    llsearchcombobox.cpp
+    llsearchhistory.cpp
+    llselectmgr.cpp
+    llsidepanelinventory.cpp
+    llsidepanelobjectinfo.cpp
+    llsidetray.cpp
+    llsidetraypanelcontainer.cpp
+    llsky.cpp
+    llslurl.cpp
+    llspatialpartition.cpp
+    llspeakers.cpp
+    llsplitbutton.cpp
+    llsprite.cpp
+    llstartup.cpp
+    llstatusbar.cpp
+    llstylemap.cpp
+    llsurface.cpp
+    llsurfacepatch.cpp
+    llsyswellitem.cpp
+    llsyswellwindow.cpp
+    llteleporthistory.cpp
+    llteleporthistorystorage.cpp
+    lltexglobalcolor.cpp
+    lltexlayer.cpp
+    lltexlayerparams.cpp
+    lltextureatlas.cpp
+    lltextureatlasmanager.cpp
+    lltexturecache.cpp
+    lltexturectrl.cpp
+    lltexturefetch.cpp
+    lltextureview.cpp
+    lltoast.cpp
+    lltoastalertpanel.cpp
+    lltoastgroupnotifypanel.cpp
+    lltoastimpanel.cpp
+    lltoastnotifypanel.cpp
+    lltoastpanel.cpp
+    lltool.cpp
+    lltoolbar.cpp
+    lltoolbrush.cpp
+    lltoolcomp.cpp
+    lltooldraganddrop.cpp
+    lltoolface.cpp
+    lltoolfocus.cpp
+    lltoolgrab.cpp
+    lltoolgun.cpp
+    lltoolindividual.cpp
+    lltoolmgr.cpp
+    lltoolmorph.cpp
+    lltoolobjpicker.cpp
+    lltoolpie.cpp
+    lltoolpipette.cpp
+    lltoolplacer.cpp
+    lltoolselect.cpp
+    lltoolselectland.cpp
+    lltoolselectrect.cpp
+    lltracker.cpp
+    lltransientdockablefloater.cpp
+    lltransientfloatermgr.cpp
+    lluilistener.cpp
+    lluploaddialog.cpp
+    llurl.cpp
+    llurldispatcher.cpp
+    llurlhistory.cpp
+    llurllineeditorctrl.cpp
+    llurlsimstring.cpp
+    llurlwhitelist.cpp
+    llvectorperfoptions.cpp
+    llviewchildren.cpp
+    llviewerassetstorage.cpp
+    llvieweraudio.cpp
+    llviewercamera.cpp
+    llviewercontrol.cpp
+    llviewercontrollistener.cpp
+    llviewerdisplay.cpp
+    llviewerfloaterreg.cpp
+    llviewergenericmessage.cpp
+    llviewergesture.cpp    
+    llviewerhelp.cpp
+    llviewerhelputil.cpp
+    llviewerinventory.cpp
+    llviewerjoint.cpp
+    llviewerjointattachment.cpp
+    llviewerjointmesh.cpp
+    llviewerjointmesh_sse.cpp
+    llviewerjointmesh_sse2.cpp
+    llviewerjointmesh_vec.cpp
+    llviewerjoystick.cpp
+    llviewerkeyboard.cpp
+    llviewerlayer.cpp
+    llviewermedia.cpp
+    llviewermedia_streamingaudio.cpp
+    llviewermediafocus.cpp
+    llviewermenu.cpp
+    llviewermenufile.cpp
+    llviewermessage.cpp
+    llviewernetwork.cpp
+    llviewerobject.cpp
+    llviewerobjectlist.cpp
+    llviewerparcelmedia.cpp
+    llviewerparcelmediaautoplay.cpp
+    llviewerparcelmgr.cpp
+    llviewerparceloverlay.cpp
+    llviewerpartsim.cpp
+    llviewerpartsource.cpp
+    llviewerregion.cpp
+    llviewershadermgr.cpp
+    llviewerstats.cpp
+    llviewertexteditor.cpp
+    llviewertexture.cpp
+    llviewertextureanim.cpp
+    llviewertexturelist.cpp
+    llviewerthrottle.cpp
+    llviewervisualparam.cpp
+    llviewerwindow.cpp
+    llviewerwindowlistener.cpp
+    llvlcomposition.cpp
+    llvlmanager.cpp
+    llvoavatar.cpp
+    llvoavatardefines.cpp
+    llvoavatarself.cpp
+    llvocache.cpp
+    llvoclouds.cpp
+    llvograss.cpp
+    llvoground.cpp
+    llvoicechannel.cpp
+    llvoiceclient.cpp
+    llvoicecontrolpanel.cpp
+    llvoiceremotectrl.cpp
+    llvoicevisualizer.cpp
+    llvoinventorylistener.cpp
+    llvopartgroup.cpp
+    llvosky.cpp
+    llvosurfacepatch.cpp
+    llvotextbubble.cpp
+    llvotree.cpp
+    llvovolume.cpp
+    llvowater.cpp
+    llvowlsky.cpp
+    llwatchdog.cpp
+    llwaterparammanager.cpp
+    llwaterparamset.cpp
+    llwearable.cpp
+    llwearabledictionary.cpp
+    llwearablelist.cpp
+    llweb.cpp
+    llwind.cpp
+    llwlanimator.cpp
+    llwldaycycle.cpp
+    llwlparammanager.cpp
+    llwlparamset.cpp
+    llworld.cpp
+    llworldmap.cpp
+    llworldmapview.cpp
+    llxmlrpclistener.cpp
+    llxmlrpctransaction.cpp
+    noise.cpp
+    pipeline.cpp
+    )
+
+set(VIEWER_BINARY_NAME "secondlife-bin" CACHE STRING
+    "The name of the viewer executable to create.")
+
+if (LINUX)
+  # We can't set these flags for Darwin, because they get passed to
+  # the PPC compiler.  Ugh.
+
+  set_source_files_properties(
+      llviewerjointmesh_sse.cpp
+      PROPERTIES COMPILE_FLAGS "-msse -mfpmath=sse"
+      )
+  set_source_files_properties(
+      llviewerjointmesh_sse2.cpp
+      PROPERTIES COMPILE_FLAGS "-msse2 -mfpmath=sse"
+      )
+endif (LINUX)
+
+set(viewer_HEADER_FILES
+    CMakeLists.txt
+    ViewerInstall.cmake
+    llaccordionctrl.h
+    llaccordionctrltab.h
+    llagent.h
+    llagentaccess.h
+    llagentdata.h
+    llagentlanguage.h
+    llagentlistener.h
+    llagentpicksinfo.h
+    llagentpilot.h
+    llagentui.h
+    llagentwearables.h
+    llanimstatelabels.h
+    llappearance.h
+    llappearancemgr.h
+    llappviewer.h
+    llappviewerlistener.h
+    llassetuploadqueue.h
+    llassetuploadresponders.h
+    llaudiosourcevo.h
+    llavataractions.h
+    llavatariconctrl.h
+    llavatarlist.h
+    llavatarlistitem.h
+    llavatarpropertiesprocessor.h
+    llbottomtray.h
+    llbox.h
+    llbreadcrumbview.h
+    llcallbacklist.h
+    llcallingcard.h
+    llcapabilitylistener.h
+    llcapabilityprovider.h
+    llcaphttpsender.h
+    llchannelmanager.h
+    llchatbar.h
+    llchathistory.h
+    llchatitemscontainerctrl.h
+    llchatmsgbox.h
+    llchiclet.h
+    llclassifiedinfo.h
+    llclassifiedstatsresponder.h
+    llcloud.h
+    llcolorswatch.h
+    llcommandhandler.h
+    llcommandlineparser.h
+    llcompilequeue.h
+    llconfirmationmanager.h
+    llcurrencyuimanager.h
+    llcylinder.h
+    lldateutil.h
+    lldebugmessagebox.h
+    lldebugview.h
+    lldelayedgestureerror.h
+    lldirpicker.h
+    lldndbutton.h
+    lldrawable.h
+    lldrawpool.h
+    lldrawpoolalpha.h
+    lldrawpoolavatar.h
+    lldrawpoolbump.h
+    lldrawpoolclouds.h
+    lldrawpoolground.h
+    lldrawpoolsimple.h
+    lldrawpoolsky.h
+    lldrawpoolterrain.h
+    lldrawpooltree.h
+    lldrawpoolwater.h
+    lldrawpoolwlsky.h
+    lldriverparam.h
+    lldynamictexture.h
+    llemote.h
+    lleventinfo.h
+    lleventnotifier.h
+    lleventpoll.h
+    llexpandabletextbox.h
+    llface.h
+    llfasttimerview.h
+    llfavoritesbar.h
+    llfeaturemanager.h
+    llfilepicker.h
+    llfirstuse.h
+    llflexibleobject.h
+    llfloaterabout.h
+    llfloateractivespeakers.h
+    llfloateranimpreview.h
+    llfloaterauction.h
+    llfloateravatarpicker.h
+    llfloateravatartextures.h
+    llfloaterbeacons.h
+    llfloaterbuildoptions.h
+    llfloaterbulkpermission.h
+    llfloaterbump.h
+    llfloaterbuy.h
+    llfloaterbuycontents.h
+    llfloaterbuycurrency.h
+    llfloaterbuyland.h
+    llfloatercall.h
+    llfloatercamera.h
+    llfloaterchat.h
+    llfloaterchatterbox.h
+    llfloatercolorpicker.h
+    llfloatercustomize.h
+    llfloaterdaycycle.h
+    llfloaterenvsettings.h
+    llfloaterfonttest.h
+    llfloaterfriends.h
+    llfloatergesture.h
+    llfloatergodtools.h
+    llfloatergroupinvite.h
+    llfloatergroups.h
+    llfloaterhandler.h
+    llfloaterhardwaresettings.h
+    llfloaterhelpbrowser.h
+    llfloaterhud.h
+    llfloaterimagepreview.h
+    llfloaterinspect.h
+    llfloaterinventory.h
+    llfloaterjoystick.h
+    llfloaterlagmeter.h
+    llfloaterland.h
+    llfloaterlandholdings.h
+    llfloatermap.h
+    llfloatermediabrowser.h
+    llfloatermediasettings.h
+    llfloatermemleak.h
+    llfloaternamedesc.h
+    llfloaternotificationsconsole.h
+    llfloateropenobject.h
+    llfloaterparcel.h
+    llfloaterpay.h
+    llfloaterperms.h
+    llfloaterpostcard.h
+    llfloaterpostprocess.h
+    llfloaterpreference.h
+    llfloaterproperties.h
+    llfloaterregioninfo.h
+    llfloaterreporter.h
+    llfloaterscriptdebug.h
+    llfloatersearch.h
+    llfloatersellland.h
+    llfloatersettingsdebug.h
+    llfloatersnapshot.h
+    llfloatertelehub.h
+    llfloatertestinspectors.h
+    llfloatertestlistview.h
+    llfloatertools.h
+    llfloatertopobjects.h
+    llfloatertos.h
+    llfloateruipreview.h
+    llfloaterurldisplay.h
+    llfloaterurlentry.h
+    llfloatervoicedevicesettings.h
+    llfloaterwater.h
+    llfloaterwhitelistentry.h
+    llfloaterwindlight.h
+    llfloaterworldmap.h
+    llfoldertype.h
+    llfolderview.h
+    llfoldervieweventlistener.h
+    llfolderviewitem.h
+    llfollowcam.h
+    llfriendcard.h
+    llgesturemgr.h
+    llgroupactions.h
+    llgrouplist.h
+    llgroupmgr.h
+    llgroupnotify.h
+    llhomelocationresponder.h
+    llhudeffect.h
+    llhudeffectbeam.h
+    llhudeffectlookat.h
+    llhudeffectpointat.h
+    llhudeffecttrail.h
+    llhudicon.h
+    llhudmanager.h
+    llhudobject.h
+    llhudrender.h
+    llhudtext.h
+    llhudview.h
+    llimcontrolpanel.h
+    llimfloater.h
+    llimpanel.h
+    llimview.h
+    llinspect.h
+    llinspectavatar.h
+    llinspectgroup.h
+    llinspectobject.h
+    llinventorybridge.h
+    llinventoryclipboard.h
+    llinventoryfilter.h
+    llinventoryfunctions.h
+    llinventorymodel.h
+    llinventorypanel.h
+    llinventorysubtreepanel.h
+    lljoystickbutton.h
+    lllandmarkactions.h
+    lllandmarklist.h
+    lllightconstants.h
+    lllistbrowser.h
+    lllistview.h
+    lllocaltextureobject.h
+    lllocationhistory.h
+    lllocationinputctrl.h
+    lllogchat.h
+    llloginhandler.h
+    lllogininstance.h
+    llmanip.h
+    llmaniprotate.h
+    llmanipscale.h
+    llmaniptranslate.h
+    llmapresponders.h
+    llmediactrl.h
+    llmediadataclient.h
+    llmediaremotectrl.h
+    llmemoryview.h
+    llmenucommands.h
+    llmetricperformancetester.h
+    llmimetypes.h
+    llmorphview.h
+    llmoveview.h
+    llmutelist.h
+    llnamebox.h
+    llnameeditor.h
+    llnamelistctrl.h
+    llnavigationbar.h
+    llnearbychat.h
+    llnearbychatbar.h
+    llnearbychathandler.h
+    llnetmap.h
+    llnotificationhandler.h
+    llnotificationmanager.h
+    llnotify.h
+    lloutputmonitorctrl.h
+    lloverlaybar.h
+    llpanelappearance.h
+    llpanelappearancetab.h
+    llpanelavatar.h
+    llpanelavatarrow.h
+    llpanelavatartag.h
+    llpanelblockedlist.h
+    llpanelclassified.h
+    llpanelcontents.h
+    llpaneleditwearable.h
+    llpanelevent.h
+    llpanelface.h
+    llpanelgroup.h
+    llpanelgroupgeneral.h
+    llpanelgroupinvite.h
+    llpanelgrouplandmoney.h
+    llpanelgroupnotices.h
+    llpanelgrouproles.h
+    llpanelimcontrolpanel.h
+    llpanelinventory.h
+    llpanelland.h
+    llpanellandaudio.h
+    llpanellandmarks.h
+    llpanellandmedia.h
+    llpanellogin.h
+    llpanellookinfo.h
+    llpanellooks.h
+    llpanelmaininventory.h
+    llpanelmedia.h
+    llpanelmediasettingsgeneral.h
+    llpanelmediasettingspermissions.h
+    llpanelmediasettingssecurity.h
+    llpanelmeprofile.h
+    llpanelobject.h
+    llpanelobjectinventory.h
+    llpanelpeople.h
+    llpanelpeoplemenus.h
+    llpanelpermissions.h
+    llpanelpick.h
+    llpanelpicks.h
+    llpanelplace.h
+    llpanelplaceinfo.h
+    llpanelplaces.h
+    llpanelplacestab.h
+    llpanelprimmediacontrols.h
+    llpanelprofile.h
+    llpanelprofileview.h
+    llpanelshower.h
+    llpanelteleporthistory.h
+    llpanelvolume.h
+    llparcelselection.h
+    llparticipantlist.h
+    llpatchvertexarray.h
+    llplacesinventorybridge.h
+    llpolymesh.h
+    llpolymorph.h
+    llpreview.h
+    llpreviewanim.h
+    llpreviewgesture.h
+    llpreviewnotecard.h
+    llpreviewscript.h
+    llpreviewsound.h
+    llpreviewtexture.h
+    llproductinforequest.h
+    llprogressview.h
+    llrecentpeople.h
+    llregionposition.h
+    llremoteparcelrequest.h
+    llresourcedata.h
+    llrootview.h
+    llsavedsettingsglue.h
+    llscreenchannel.h
+    llscrollingpanelparam.h
+    llsearchcombobox.h
+    llsearchhistory.h
+    llselectmgr.h
+    llsidepanelinventory.h
+    llsidepanelobjectinfo.h
+    llsidetray.h
+    llsidetraypanelcontainer.h
+    llsky.h
+    llslurl.h
+    llspatialpartition.h
+    llspeakers.h
+    llsplitbutton.h
+    llsprite.h
+    llstartup.h
+    llstatusbar.h
+    llstylemap.h
+    llsurface.h
+    llsurfacepatch.h
+    llsyswellitem.h
+    llsyswellwindow.h    
+    lltable.h
+    llteleporthistory.h
+    llteleporthistorystorage.h
+    lltexglobalcolor.h
+    lltexlayer.h
+    lltexlayerparams.h
+    lltextureatlas.h
+    lltextureatlasmanager.h
+    lltexturecache.h
+    lltexturectrl.h
+    lltexturefetch.h
+    lltextureview.h
+    lltoast.h
+    lltoastalertpanel.h
+    lltoastgroupnotifypanel.h
+    lltoastimpanel.h
+    lltoastnotifypanel.h
+    lltoastpanel.h
+    lltool.h
+    lltoolbar.h
+    lltoolbrush.h
+    lltoolcomp.h
+    lltooldraganddrop.h
+    lltoolface.h
+    lltoolfocus.h
+    lltoolgrab.h
+    lltoolgun.h
+    lltoolindividual.h
+    lltoolmgr.h
+    lltoolmorph.h
+    lltoolobjpicker.h
+    lltoolpie.h
+    lltoolpipette.h
+    lltoolplacer.h
+    lltoolselect.h
+    lltoolselectland.h
+    lltoolselectrect.h
+    lltracker.h
+    lltransientdockablefloater.h
+    lltransientfloatermgr.h
+    lluiconstants.h
+    lluilistener.h
+    lluploaddialog.h
+    llurl.h
+    llurldispatcher.h
+    llurlhistory.h
+    llurllineeditorctrl.h
+    llurlsimstring.h
+    llurlwhitelist.h
+    llvectorperfoptions.h
+    llviewchildren.h
+    llviewerassetstorage.h
+    llvieweraudio.h
+    llviewerbuild.h
+    llviewercamera.h
+    llviewercontrol.h
+    llviewercontrollistener.h
+    llviewerdisplay.h
+    llviewerfloaterreg.h
+    llviewergenericmessage.h
+    llviewergesture.h    
+    llviewerhelp.h
+    llviewerinventory.h
+    llviewerjoint.h
+    llviewerjointattachment.h
+    llviewerjointmesh.h
+    llviewerjoystick.h
+    llviewerkeyboard.h
+    llviewerlayer.h
+    llviewermedia.h
+    llviewermediafocus.h
+    llviewermediaobserver.h
+    llviewermenu.h
+    llviewermenufile.h
+    llviewermessage.h
+    llviewernetwork.h
+    llviewerobject.h
+    llviewerobjectlist.h
+    llviewerparcelmedia.h
+    llviewerparcelmediaautoplay.h
+    llviewerparcelmgr.h
+    llviewerparceloverlay.h
+    llviewerpartsim.h
+    llviewerpartsource.h
+    llviewerprecompiledheaders.h
+    llviewerregion.h
+    llviewershadermgr.h
+    llviewerstats.h
+    llviewertexteditor.h
+    llviewertexture.h
+    llviewertextureanim.h
+    llviewertexturelist.h
+    llviewerthrottle.h
+    llviewervisualparam.h
+    llviewerwindow.h
+    llviewerwindowlistener.h
+    llvlcomposition.h
+    llvlmanager.h
+    llvoavatar.h
+    llvoavatardefines.h
+    llvoavatarself.h
+    llvocache.h
+    llvoclouds.h
+    llvograss.h
+    llvoground.h
+    llvoicechannel.h
+    llvoiceclient.h
+    llvoicecontrolpanel.h
+    llvoiceremotectrl.h
+    llvoicevisualizer.h
+    llvoinventorylistener.h
+    llvopartgroup.h
+    llvosky.h
+    llvosurfacepatch.h
+    llvotextbubble.h
+    llvotree.h
+    llvotreenew.h
+    llvovolume.h
+    llvowater.h
+    llvowlsky.h
+    llwatchdog.h
+    llwaterparammanager.h
+    llwaterparamset.h
+    llwearable.h
+    llwearabledictionary.h
+    llwearablelist.h
+    llweb.h
+    llwind.h
+    llwindebug.h
+    llwlanimator.h
+    llwldaycycle.h
+    llwlparammanager.h
+    llwlparamset.h
+    llworld.h
+    llworldmap.h
+    llworldmapview.h
+    llxmlrpclistener.h
+    llxmlrpctransaction.h
+    macmain.h
+    noise.h
+    pipeline.h
+    randgauss.h
+    VertexCache.h
+    VorbisFramework.h
+    )
+
+source_group("CMake Rules" FILES ViewerInstall.cmake)
+
+if (DARWIN)
+  LIST(APPEND viewer_SOURCE_FILES llappviewermacosx.cpp)
+
+  find_library(AGL_LIBRARY AGL)
+  find_library(APPKIT_LIBRARY AppKit)
+  find_library(COCOA_LIBRARY Cocoa)
+  find_library(IOKIT_LIBRARY IOKit)
+
+  set(viewer_LIBRARIES
+    ${COCOA_LIBRARY}
+    ${AGL_LIBRARY}
+    ${IOKIT_LIBRARY}
+    )
+
+  # Add resource files to the project.
+  set(viewer_RESOURCE_FILES
+    secondlife.icns
+    macview.r
+    gpu_table.txt
+    Info-SecondLife.plist
+    SecondLife.nib/
+    # CMake doesn't seem to support Xcode language variants well just yet
+    English.lproj/InfoPlist.strings
+    English.lproj/language.txt
+    German.lproj/language.txt
+    Japanese.lproj/language.txt
+    Korean.lproj/language.txt
+    )
+  set_source_files_properties(
+    ${viewer_RESOURCE_FILES}
+    PROPERTIES
+    HEADER_FILE_ONLY TRUE
+    #MACOSX_PACKAGE_LOCATION Resources #don't do this! this tells cmake to copy the files.
+    )
+  SOURCE_GROUP("Resources" FILES ${viewer_RESOURCE_FILES})
+  list(APPEND viewer_SOURCE_FILES ${viewer_RESOURCE_FILES})
+endif (DARWIN)
+
+if (LINUX)
+    LIST(APPEND viewer_SOURCE_FILES llappviewerlinux.cpp)
+    LIST(APPEND viewer_SOURCE_FILES llappviewerlinux_api_dbus.cpp)
+    SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--as-needed")
+
+    set(viewer_LIBRARIES
+        Xinerama
+        )
+endif (LINUX)
+
+if (WINDOWS)
+    list(APPEND viewer_SOURCE_FILES
+         llappviewerwin32.cpp
+         llwindebug.cpp
+         )
+
+    list(APPEND viewer_HEADER_FILES
+         llappviewerwin32.h
+         llwindebug.h
+         )
+
+    # precompiled header configuration
+    # llviewerprecompiledheaders.cpp generates
+    # the .pch file.
+    # All sources added to viewer_SOURCE_FILES 
+    # at this point use it.
+    set_source_files_properties(llviewerprecompiledheaders.cpp
+        PROPERTIES
+        COMPILE_FLAGS "/Ycllviewerprecompiledheaders.h"
+        )        
+    foreach( src_file ${viewer_SOURCE_FILES} )
+        set_source_files_properties(
+            ${src_file}
+            PROPERTIES
+            COMPILE_FLAGS "/Yullviewerprecompiledheaders.h"
+            )        
+    endforeach( src_file ${viewer_SOURCE_FILES} )
+    list(APPEND viewer_SOURCE_FILES llviewerprecompiledheaders.cpp)
+    # llstartup.cpp needs special symbols for audio libraries, so it resets
+    # COMPILE_FLAGS below.  Make sure it maintains precompiled header settings.
+    set(LLSTARTUP_COMPILE_FLAGS 
+        "${LLSTARTUP_COMPILE_FLAGS} /Yullviewerprecompiledheaders.h")
+    
+    # Add resource files to the project.
+    # viewerRes.rc is the only buildable file, but
+    # the rest are all dependencies of it.
+    set(viewer_RESOURCE_FILES
+        res/arrow.cur
+        res/arrowcop.cur
+        res/arrowcopmulti.cur
+        res/arrowdrag.cur
+        res/circleandline.cur
+        res/icon1.ico
+        res/llarrow.cur
+        res/llarrowdrag.cur
+        res/llarrowdragmulti.cur
+        res/llarrowlocked.cur
+        res/llgrablocked.cur
+        res/llno.cur
+        res/llnolocked.cur
+        res/lltoolcamera.cur
+        res/lltoolcreate.cur
+        res/lltoolfocus.cur
+        res/lltoolgrab.cur
+        res/lltoolland.cur
+        res/lltoolpan.cur
+        res/lltoolpipette.cur
+        res/lltoolrotate.cur
+        res/lltoolscale.cur
+        res/lltooltranslate.cur
+        res/lltoolzoomin.cur
+        res/lltoolzoomout.cur
+        res/ll_icon.BMP
+        res/ll_icon.ico
+        res/resource.h
+        res/toolpickobject.cur
+        res/toolpickobject2.cur
+        res/toolpickobject3.cur
+        res/toolpipette.cur
+        )
+
+    set_source_files_properties(${viewer_RESOURCE_FILES}
+                                PROPERTIES HEADER_FILE_ONLY TRUE)
+
+    set(viewer_RESOURCE_FILES 
+        res/viewerRes.rc 
+        ${viewer_RESOURCE_FILES}
+        )
+
+    SOURCE_GROUP("Resource Files" FILES ${viewer_RESOURCE_FILES})
+
+    if (NOT STANDALONE)
+        list(APPEND viewer_SOURCE_FILES ${viewer_RESOURCE_FILES})
+    endif (NOT STANDALONE)	
+
+    find_library(DINPUT_LIBRARY dinput8 ${DIRECTX_LIBRARY_DIR})
+    find_library(DXGUID_LIBRARY dxguid ${DIRECTX_LIBRARY_DIR})
+    mark_as_advanced(
+        DINPUT_LIBRARY
+        DXGUID_LIBRARY
+        )
+
+    set(viewer_LIBRARIES
+        ${WINDOWS_LIBRARIES}
+        comdlg32
+        ${DINPUT_LIBRARY}
+        ${DXGUID_LIBRARY}
+        kernel32
+        odbc32
+        odbccp32
+        ole32
+        oleaut32
+        opengl32
+        shell32
+        Vfw32
+        winspool
+        )
+
+    find_library(INTEL_MEMOPS_LIBRARY
+                 NAMES ll_intel_memops
+                 PATHS
+                 optimized ${ARCH_PREBUILT_DIRS_RELEASE}
+                 debug ${ARCH_PREBUILT_DIRS_DEBUG}
+                 )
+    mark_as_advanced(INTEL_MEMOPS_LIBRARY)
+
+    if (INTEL_MEMOPS_LIBRARY)
+      list(APPEND viewer_LIBRARIES ${INTEL_MEMOPS_LIBRARY})
+    endif (INTEL_MEMOPS_LIBRARY)
+
+    use_prebuilt_binary(dbghelp)
+endif (WINDOWS)
+
+# Add the xui files. This is handy for searching for xui elements
+# from within the IDE.
+set(viewer_XUI_FILES
+    skins/default/colors.xml
+    skins/default/textures/textures.xml
+
+
+
+    )
+file(GLOB DEFAULT_XUI_FILE_GLOB_LIST
+     ${CMAKE_CURRENT_SOURCE_DIR}/skins/default/xui/en/*.xml)
+list(APPEND viewer_XUI_FILES ${DEFAULT_XUI_FILE_GLOB_LIST})
+
+file(GLOB DEFAULT_WIDGET_FILE_GLOB_LIST
+     ${CMAKE_CURRENT_SOURCE_DIR}/skins/default/xui/en/widgets/*.xml)
+list(APPEND viewer_XUI_FILES ${DEFAULT_WIDGET_FILE_GLOB_LIST})
+
+file(GLOB SILVER_XUI_FILE_GLOB_LIST
+     ${CMAKE_CURRENT_SOURCE_DIR}/skins/silver/xui/en-us/*.xml)
+list(APPEND viewer_XUI_FILES ${SILVER_XUI_FILE_GLOB_LIST})
+
+# Cannot append empty lists in CMake, wait until we have files here.
+#file(GLOB SILVER_WIDGET_FILE_GLOB_LIST
+#     ${CMAKE_CURRENT_SOURCE_DIR}/skins/silver/xui/en-us/widgets/*.xml)
+#list(APPEND viewer_XUI_FILES ${SILVER_WIDGET_FILE_GLOB_LIST})
+
+list(SORT viewer_XUI_FILES)
+
+source_group("XUI Files" FILES ${viewer_XUI_FILES})
+
+set_source_files_properties(${viewer_XUI_FILES}
+                            PROPERTIES HEADER_FILE_ONLY TRUE)
+
+list(APPEND viewer_SOURCE_FILES ${viewer_XUI_FILES})
+
+set(viewer_APPSETTINGS_FILES
+    app_settings/anim.ini
+    app_settings/cmd_line.xml
+    app_settings/grass.xml
+    app_settings/high_graphics.xml
+    app_settings/keys.ini
+    app_settings/keywords.ini
+    app_settings/logcontrol.xml
+    app_settings/low_graphics.xml
+    app_settings/mid_graphics.xml
+    app_settings/settings.xml
+    app_settings/settings_crash_behavior.xml
+    app_settings/settings_files.xml
+    app_settings/settings_per_account.xml
+    app_settings/std_bump.ini
+    app_settings/trees.xml
+    app_settings/ultra_graphics.xml
+    app_settings/viewerart.xml
+    ${CMAKE_SOURCE_DIR}/../etc/message.xml
+    ${CMAKE_SOURCE_DIR}/../scripts/messages/message_template.msg
+    )
+
+use_prebuilt_binary(artwork-common)
+
+source_group("App Settings" FILES ${viewer_APPSETTINGS_FILES})
+
+set_source_files_properties(${viewer_APPSETTINGS_FILES}
+                            PROPERTIES HEADER_FILE_ONLY TRUE)
+
+list(APPEND viewer_SOURCE_FILES ${viewer_APPSETTINGS_FILES})
+
+set(viewer_CHARACTER_FILES
+    character/attentions.xml
+    character/attentionsN.xml
+    character/avatar_lad.xml
+    character/avatar_skeleton.xml
+    character/genepool.xml
+    )
+
+source_group("Character File" FILES ${viewer_CHARACTER_FILES})
+
+set_source_files_properties(${viewer_CHARACTER_FILES}
+                            PROPERTIES HEADER_FILE_ONLY TRUE)
+if (NOT STANDALONE)
+    list(APPEND viewer_SOURCE_FILES ${viewer_CHARACTER_FILES})
+endif (NOT STANDALONE)
+
+if (WINDOWS)
+  file(GLOB viewer_INSTALLER_FILES installers/windows/*.nsi)
+
+  source_group("Installer Files" FILES ${viewer_INSTALLER_FILES})
+
+  set_source_files_properties(${viewer_INSTALLER_FILES}
+                              PROPERTIES HEADER_FILE_ONLY TRUE)
+
+  list(APPEND viewer_SOURCE_FILES ${viewer_INSTALLER_FILES})
+endif (WINDOWS)
+
+if (OPENAL)
+  set(LLSTARTUP_COMPILE_FLAGS "${LLSTARTUP_COMPILE_FLAGS} -DLL_OPENAL")
+endif (OPENAL)
+
+if (FMOD)
+  set(LLSTARTUP_COMPILE_FLAGS "${LLSTARTUP_COMPILE_FLAGS} -DLL_FMOD")
+
+  if (DARWIN)
+    set(fmodwrapper_SOURCE_FILES fmodwrapper.cpp)
+    add_library(fmodwrapper SHARED ${fmodwrapper_SOURCE_FILES})
+    set(fmodwrapper_needed_LIBRARIES ${FMOD_LIBRARY} ${CARBON_LIBRARY})
+    set_target_properties(
+      fmodwrapper
+      PROPERTIES
+      BUILD_WITH_INSTALL_RPATH 1
+      INSTALL_NAME_DIR "@executable_path/../Resources"
+      LINK_FLAGS "-unexported_symbols_list ${CMAKE_CURRENT_SOURCE_DIR}/fmod_hidden_symbols.exp"
+      )
+    set(FMODWRAPPER_LIBRARY fmodwrapper)
+    target_link_libraries(fmodwrapper ${fmodwrapper_needed_LIBRARIES})
+  else (DARWIN)
+    # fmodwrapper unnecessary on linux or windows
+    set(FMODWRAPPER_LIBRARY ${FMOD_LIBRARY})
+  endif (DARWIN)
+endif (FMOD)
+
+set_source_files_properties(llstartup.cpp PROPERTIES COMPILE_FLAGS "${LLSTARTUP_COMPILE_FLAGS}")
+
+list(APPEND viewer_SOURCE_FILES ${viewer_HEADER_FILES})
+
+set_source_files_properties(${viewer_HEADER_FILES}
+                            PROPERTIES HEADER_FILE_ONLY TRUE)
+
+add_executable(${VIEWER_BINARY_NAME}
+    WIN32
+    MACOSX_BUNDLE
+    ${viewer_SOURCE_FILES}
+    )
+check_message_template(${VIEWER_BINARY_NAME})
+
+if (LLKDU_LIBRARY)
+  add_dependencies(${VIEWER_BINARY_NAME} ${LLKDU_LIBRARY})
+endif (LLKDU_LIBRARY)
+
+# add package files
+file(GLOB EVENT_HOST_SCRIPT_GLOB_LIST
+     ${CMAKE_CURRENT_SOURCE_DIR}/../viewer_components/*.py)
+list(APPEND EVENT_HOST_SCRIPTS ${EVENT_HOST_SCRIPT_GLOB_LIST})
+
+set(PACKAGE OFF CACHE BOOL
+    "Add a package target that builds an installer package.")
+
+if (WINDOWS)
+    if(MSVC71)
+        set(release_flags "/MAP:Release/${VIEWER_BINARY_NAME}.map /MAPINFO:LINES")
+    else(MSVC71)
+        set(release_flags "/MAP:Release/${VIEWER_BINARY_NAME}.map")
+    endif(MSVC71)
+    
+    set_target_properties(${VIEWER_BINARY_NAME}
+        PROPERTIES
+        # *TODO -reenable this once we get server usage sorted out
+        #LINK_FLAGS "/debug /NODEFAULTLIB:LIBCMT /SUBSYSTEM:WINDOWS /INCLUDE:\"__tcmalloc\""
+        LINK_FLAGS "/debug /NODEFAULTLIB:LIBCMT /SUBSYSTEM:WINDOWS"
+        LINK_FLAGS_DEBUG "/NODEFAULTLIB:\"LIBCMT;LIBCMTD;MSVCRT\" /INCREMENTAL:NO"
+        LINK_FLAGS_RELEASE ${release_flags}
+        )
+
+    # sets the 'working directory' for debugging from visual studio.
+    if (NOT UNATTENDED)
+        add_custom_command(
+            TARGET ${VIEWER_BINARY_NAME} PRE_BUILD
+            COMMAND ${CMAKE_SOURCE_DIR}/tools/vstool/vstool.exe
+            ARGS
+              --solution 
+              ${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}.sln
+              --workingdir
+              ${VIEWER_BINARY_NAME}
+              ${CMAKE_CURRENT_SOURCE_DIR}
+            COMMENT "Setting the ${VIEWER_BINARY_NAME} working directory for debugging."
+            )
+    endif (NOT UNATTENDED)
+
+    add_custom_command(
+        TARGET ${VIEWER_BINARY_NAME} PRE_BUILD
+        COMMAND ${CMAKE_COMMAND}
+        ARGS
+          -E
+          copy_if_different
+          ${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/messages/message_template.msg
+          ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/app_settings/message_template.msg
+        COMMENT "Copying message_template.msg to the runtime folder."
+        )
+
+    add_custom_command(
+        TARGET ${VIEWER_BINARY_NAME} PRE_BUILD
+        COMMAND ${CMAKE_COMMAND}
+        ARGS
+          -E
+          copy_if_different
+          ${CMAKE_CURRENT_SOURCE_DIR}/../../etc/message.xml
+          ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/app_settings/message.xml
+        COMMENT "Copying message.xml to the runtime folder."
+        )
+       
+    if(WINDOWS)
+      # Copy Win Libs...
+      # This happens at build time, not config time. We can't glob files in this cmake.
+      # *FIX:Mani Write a sub script to glob the files...
+      # *FIX:Mani Use actually dependencies rather than bulk copy.
+      add_custom_command(
+        TARGET ${VIEWER_BINARY_NAME} PRE_BUILD
+        COMMAND ${CMAKE_COMMAND}
+        ARGS
+          -E
+          copy_directory
+          ${SHARED_LIB_STAGING_DIR}/${CMAKE_CFG_INTDIR}
+          ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}
+        COMMENT "Copying staged dlls."
+        )
+
+      add_dependencies(${VIEWER_BINARY_NAME} stage_third_party_libs llcommon)
+      if(LLKDU_LIBRARY)
+	# kdu may not exist!
+	add_dependencies(${VIEWER_BINARY_NAME} llkdu)
+      endif(LLKDU_LIBRARY)
+    endif(WINDOWS)    
+
+    if (EXISTS ${CMAKE_SOURCE_DIR}/copy_win_scripts)
+      add_dependencies(${VIEWER_BINARY_NAME} copy_win_scripts)
+    endif (EXISTS ${CMAKE_SOURCE_DIR}/copy_win_scripts)
+        
+    add_custom_command(
+        OUTPUT ${CMAKE_CFG_INTDIR}/touched.bat
+        COMMAND ${PYTHON_EXECUTABLE}
+        ARGS
+          ${CMAKE_CURRENT_SOURCE_DIR}/viewer_manifest.py
+          --configuration=${CMAKE_CFG_INTDIR}
+          --channel=${VIEWER_CHANNEL}
+          --login_channel=${VIEWER_LOGIN_CHANNEL}
+          --grid=${GRID}
+          --source=${CMAKE_CURRENT_SOURCE_DIR}
+              --artwork=${ARTWORK_DIR}
+              --build=${CMAKE_CURRENT_BINARY_DIR}
+              --dest=${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}
+              --touch=${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/touched.bat
+        DEPENDS ${VIEWER_BINARY_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/viewer_manifest.py
+        )
+
+    add_dependencies(${VIEWER_BINARY_NAME} SLPlugin media_plugin_quicktime media_plugin_webkit)
+
+    if (PACKAGE)
+      add_custom_command(
+          OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/event_host.tar.bz2
+          COMMAND ${PYTHON_EXECUTABLE}
+          ARGS
+            ${CMAKE_CURRENT_SOURCE_DIR}/event_host_manifest.py
+            ${CMAKE_CURRENT_SOURCE_DIR}/..
+            ${CMAKE_CURRENT_BINARY_DIR}
+            ${CMAKE_CFG_INTDIR}
+
+          DEPENDS 
+            lleventhost 
+            ${EVENT_HOST_SCRIPTS}
+            ${CMAKE_CURRENT_SOURCE_DIR}/event_host_manifest.py)
+
+      add_custom_target(package ALL 
+          DEPENDS 
+            ${CMAKE_CFG_INTDIR}/touched.bat)
+            # temporarily disable packaging of event_host until hg subrepos get
+            # sorted out on the parabuild cluster...
+            #${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/event_host.tar.bz2)
+      add_dependencies(package windows-updater windows-crash-logger)
+
+
+    endif (PACKAGE)
+endif (WINDOWS)
+
+target_link_libraries(${VIEWER_BINARY_NAME}
+    ${LLAUDIO_LIBRARIES}
+    ${LLCHARACTER_LIBRARIES}
+    ${LLIMAGE_LIBRARIES}
+    ${LLIMAGEJ2COJ_LIBRARIES}
+    ${LLINVENTORY_LIBRARIES}
+    ${LLMESSAGE_LIBRARIES}
+    ${LLPLUGIN_LIBRARIES}
+    ${LLPRIMITIVE_LIBRARIES}
+    ${LLRENDER_LIBRARIES}
+    ${FREETYPE_LIBRARIES}
+    ${LLUI_LIBRARIES}
+    ${LLVFS_LIBRARIES}
+    ${LLWINDOW_LIBRARIES}
+    ${LLXML_LIBRARIES}
+    ${LLXUIXML_LIBRARIES}
+    ${LSCRIPT_LIBRARIES}
+    ${LLMATH_LIBRARIES}
+    ${LLCOMMON_LIBRARIES}
+    ${NDOF_LIBRARY}
+    ${viewer_LIBRARIES}
+    ${BOOST_PROGRAM_OPTIONS_LIBRARY}
+    ${BOOST_REGEX_LIBRARY}
+    ${DBUSGLIB_LIBRARIES}
+    ${OPENGL_LIBRARIES}
+    ${FMODWRAPPER_LIBRARY}
+    ${OPENGL_LIBRARIES}
+    ${SDL_LIBRARY}
+    ${SMARTHEAP_LIBRARY}
+    ${UI_LIBRARIES}
+    ${WINDOWS_LIBRARIES}
+    ${XMLRPCEPI_LIBRARIES}
+    ${ELFIO_LIBRARIES}
+    ${LLLOGIN_LIBRARIES}
+    ${GOOGLE_PERFTOOLS_LIBRARIES}
+    )
+
+build_version(viewer)
+
+set(ARTWORK_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE PATH
+    "Path to artwork files.")
+
+
+if (LINUX)
+  add_custom_command(
+      OUTPUT secondlife-stripped
+      COMMAND strip
+      ARGS --strip-debug -o secondlife-stripped ${VIEWER_BINARY_NAME}
+      DEPENDS ${VIEWER_BINARY_NAME}
+      )
+
+  set(product SecondLife-${ARCH}-${viewer_VERSION})
+
+  add_custom_command(
+      OUTPUT ${product}.tar.bz2
+      COMMAND ${PYTHON_EXECUTABLE}
+      ARGS
+        ${CMAKE_CURRENT_SOURCE_DIR}/viewer_manifest.py
+        --grid=${GRID}
+        --channel=${VIEWER_CHANNEL}
+        --login_channel=${VIEWER_LOGIN_CHANNEL}
+        --installer_name=${product}
+        --arch=${ARCH}
+        --source=${CMAKE_CURRENT_SOURCE_DIR}
+        --artwork=${ARTWORK_DIR}
+        --build=${CMAKE_CURRENT_BINARY_DIR}
+        --dest=${CMAKE_CURRENT_BINARY_DIR}/packaged
+        --touch=${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/.${product}.touched
+      DEPENDS secondlife-stripped ${CMAKE_CURRENT_SOURCE_DIR}/viewer_manifest.py
+      )
+
+  add_dependencies(${VIEWER_BINARY_NAME} SLPlugin media_plugin_gstreamer010 media_plugin_webkit)
+
+  if (NOT INSTALL)
+    add_custom_target(package ALL DEPENDS ${product}.tar.bz2)
+    add_dependencies(package linux-crash-logger-strip-target)
+    add_dependencies(package linux-updater-strip-target)
+  endif (NOT INSTALL)
+endif (LINUX)
+
+if (DARWIN)
+  set(product "Second Life")
+  set_target_properties(
+    ${VIEWER_BINARY_NAME}
+    PROPERTIES
+    OUTPUT_NAME "${product}"
+    MACOSX_BUNDLE_INFO_STRING "info string - localize me"
+    MACOSX_BUNDLE_ICON_FILE "secondlife.icns"
+    MACOSX_BUNDLE_GUI_IDENTIFIER "Second Life"
+    MACOSX_BUNDLE_LONG_VERSION_STRING "ververver"
+    MACOSX_BUNDLE_BUNDLE_NAME "Second Life"
+    MACOSX_BUNDLE_SHORT_VERSION_STRING "asdf"
+    MACOSX_BUNDLE_BUNDLE_VERSION "asdf"
+    MACOSX_BUNDLE_COPYRIGHT "copyright linden lab 2007 - localize me and run me through a legal wringer"
+    )
+
+  add_custom_command(
+    TARGET ${VIEWER_BINARY_NAME} POST_BUILD
+    COMMAND ${PYTHON_EXECUTABLE}
+    ARGS
+      ${CMAKE_CURRENT_SOURCE_DIR}/viewer_manifest.py
+      --grid=${GRID}
+      --actions=copy
+      --configuration=${CMAKE_CFG_INTDIR}
+      --source=${CMAKE_CURRENT_SOURCE_DIR}
+      --artwork=${ARTWORK_DIR}
+      --build=${CMAKE_CURRENT_BINARY_DIR}
+      --dest=${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${product}.app
+    DEPENDS ${VIEWER_BINARY_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/viewer_manifest.py
+    )
+
+  add_dependencies(${VIEWER_BINARY_NAME} SLPlugin media_plugin_quicktime media_plugin_webkit)
+
+  if (PACKAGE)
+      add_custom_target(package ALL DEPENDS ${VIEWER_BINARY_NAME}) 
+      add_dependencies(package mac-updater mac-crash-logger)
+
+      add_custom_command(
+        TARGET package POST_BUILD
+        COMMAND ${PYTHON_EXECUTABLE}
+        ARGS
+          ${CMAKE_CURRENT_SOURCE_DIR}/viewer_manifest.py
+          --grid=${GRID}
+          --configuration=${CMAKE_CFG_INTDIR}
+          --channel=${VIEWER_CHANNEL}
+          --login_channel=${VIEWER_LOGIN_CHANNEL}
+          --source=${CMAKE_CURRENT_SOURCE_DIR}
+          --artwork=${ARTWORK_DIR}
+          --build=${CMAKE_CURRENT_BINARY_DIR}
+          --dest=${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${product}.app
+          --touch=${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/.${product}.touched
+        DEPENDS
+          ${CMAKE_CURRENT_SOURCE_DIR}/viewer_manifest.py
+      )
+
+
+      add_custom_command(
+        TARGET package POST_BUILD
+        COMMAND ${PYTHON_EXECUTABLE}
+        ARGS
+          ${CMAKE_CURRENT_SOURCE_DIR}/viewer_manifest.py
+          --grid=${GRID}
+          --configuration=${CMAKE_CFG_INTDIR}
+          --channel=${VIEWER_CHANNEL}
+          --login_channel=${VIEWER_LOGIN_CHANNEL}
+          --source=${CMAKE_CURRENT_SOURCE_DIR}
+          --artwork=${ARTWORK_DIR}
+          --build=${CMAKE_CURRENT_BINARY_DIR}
+          --dest=${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${product}.app
+          --touch=${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/.${product}.touched
+        DEPENDS
+          ${CMAKE_CURRENT_SOURCE_DIR}/viewer_manifest.py
+      )
+
+  endif (PACKAGE)
+endif (DARWIN)
+
+if (INSTALL)
+  include(${CMAKE_CURRENT_SOURCE_DIR}/ViewerInstall.cmake)
+endif (INSTALL)
+
+# To add a viewer unit test, just add the test .cpp file below
+# This creates a separate test project per file listed.
+include(LLAddBuildTest)
+SET(viewer_TEST_SOURCE_FILES
+  llagentaccess.cpp
+  lldateutil.cpp
+  llmediadataclient.cpp
+  llviewerhelputil.cpp
+  lllogininstance.cpp
+  )
+set_source_files_properties(
+  ${viewer_TEST_SOURCE_FILES}
+  PROPERTIES
+    LL_TEST_ADDITIONAL_SOURCE_FILES llviewerprecompiledheaders.cpp
+  )
+LL_ADD_PROJECT_UNIT_TESTS(${VIEWER_BINARY_NAME} "${viewer_TEST_SOURCE_FILES}")
+
+#set(TEST_DEBUG on)
+set(test_sources llcapabilitylistener.cpp llviewerprecompiledheaders.cpp)
+set(test_libs 
+  ${LLMESSAGE_LIBRARIES} 
+  ${WINDOWS_LIBRARIES} 
+  ${LLVFS_LIBRARIES}
+  ${LLMATH_LIBRARIES}
+  ${LLCOMMON_LIBRARIES} 
+  ${GOOGLEMOCK_LIBRARIES}
+  )
+
+LL_ADD_INTEGRATION_TEST(llcapabilitylistener 
+  "${test_sources}" 
+  "${test_libs}"
+  ${PYTHON_EXECUTABLE}
+  "${CMAKE_SOURCE_DIR}/llmessage/tests/test_llsdmessage_peer.py"
+  )
+
+#ADD_VIEWER_BUILD_TEST(llmemoryview viewer)
+
+
+# Don't do these for DARWIN or LINUX here -- they're taken care of by viewer_manifest.py
+if (WINDOWS)
+  add_custom_command(
+      TARGET ${VIEWER_BINARY_NAME} POST_BUILD
+      COMMAND ${CMAKE_COMMAND}
+      ARGS
+        -E
+        make_directory
+        ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/llplugin
+      COMMENT "Creating llplugin dir."
+      )
+
+  get_target_property(BUILT_SLPLUGIN SLPlugin LOCATION)
+  add_custom_command(
+      TARGET ${VIEWER_BINARY_NAME} POST_BUILD
+      COMMAND ${CMAKE_COMMAND}
+      ARGS
+        -E
+        copy_if_different
+        ${BUILT_SLPLUGIN}
+        ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}
+      COMMENT "Copying SLPlugin executable to the runtime folder."
+      )
+
+  get_target_property(BUILT_WEBKIT_PLUGIN media_plugin_webkit LOCATION)
+    add_custom_command(
+        TARGET ${VIEWER_BINARY_NAME} POST_BUILD
+        COMMAND ${CMAKE_COMMAND}
+        ARGS
+          -E
+          copy_if_different
+          ${BUILT_WEBKIT_PLUGIN}
+          ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/llplugin
+        COMMENT "Copying WebKit Plugin to the runtime folder."
+        )
+
+  get_target_property(BUILT_QUICKTIME_PLUGIN media_plugin_quicktime LOCATION)
+    add_custom_command(
+        TARGET ${VIEWER_BINARY_NAME} POST_BUILD
+        COMMAND ${CMAKE_COMMAND}
+        ARGS
+          -E
+          copy_if_different
+          ${BUILT_QUICKTIME_PLUGIN}
+          ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/llplugin
+        COMMENT "Copying Quicktime Plugin to the runtime folder."
+        )
+
+  #*******************************
+  # Copy media plugin support dlls
+  # Debug config runtime files required for the plugins
+  set(plugins_debug_src_dir "${CMAKE_SOURCE_DIR}/../libraries/i686-win32/lib/debug")
+  set(plugins_debug_files
+    libeay32.dll
+    qtcored4.dll
+    qtguid4.dll
+    qtnetworkd4.dll
+    qtopengld4.dll
+    qtwebkitd4.dll
+    ssleay32.dll
+    )
+  copy_if_different(
+    ${plugins_debug_src_dir}
+    "${CMAKE_CURRENT_BINARY_DIR}/Debug/llplugin"
+    out_targets
+    ${plugins_debug_files}
+    )
+  set(media_plugin_targets ${media_plugin_targets} ${out_targets})
+  
+  # Release & ReleaseDebInfo config runtime files required for the plugins
+  set(plugins_release_src_dir "${CMAKE_SOURCE_DIR}/../libraries/i686-win32/lib/release")
+  set(plugins_release_files
+    libeay32.dll
+    qtcore4.dll
+    qtgui4.dll
+    qtnetwork4.dll
+    qtopengl4.dll
+    qtwebkit4.dll
+    ssleay32.dll
+    )
+  copy_if_different(
+    ${plugins_release_src_dir}
+    "${CMAKE_CURRENT_BINARY_DIR}/Release/llplugin"
+    out_targets
+    ${plugins_release_files}
+    )
+  set(media_plugin_targets ${media_plugin_targets} ${out_targets})
+
+  copy_if_different(
+    ${plugins_release_src_dir}
+    "${CMAKE_CURRENT_BINARY_DIR}/RelWithDebInfo/llplugin"
+    out_targets
+    ${plugins_release_files}
+    )
+  set(media_plugin_targets ${media_plugin_targets} ${out_targets})
+  
+  add_custom_target(copy_media_plugin_libs ALL
+    DEPENDS 
+    ${media_plugin_targets}
+    )
+
+  add_custom_command(
+    TARGET ${VIEWER_BINARY_NAME} POST_BUILD
+    COMMAND ${CMAKE_COMMAND}
+    ARGS
+      -E
+      copy_directory
+      ${CMAKE_BINARY_DIR}/test_apps/llplugintest/${CMAKE_CFG_INTDIR}/imageformats
+      ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/llplugin/imageformats
+    COMMENT "Copying llpluging imageformat libs."
+    )
+
+  add_dependencies(${VIEWER_BINARY_NAME} llmediaplugintest copy_media_plugin_libs)
+
+endif (WINDOWS)
+
diff --git a/indra/newview/llagentwearables.cpp b/indra/newview/llagentwearables.cpp
index b9a0b4293dd..1d4a78f0258 100644
--- a/indra/newview/llagentwearables.cpp
+++ b/indra/newview/llagentwearables.cpp
@@ -39,6 +39,7 @@
 #include "llfloaterinventory.h"
 #include "llinventorybridge.h"
 #include "llinventorymodel.h"
+#include "llinventorypanel.h"
 #include "llnotify.h"
 #include "llviewerregion.h"
 #include "llvoavatarself.h"
diff --git a/indra/newview/llassetuploadresponders.cpp b/indra/newview/llassetuploadresponders.cpp
index cd3963050f6..5dbf57c9bef 100644
--- a/indra/newview/llassetuploadresponders.cpp
+++ b/indra/newview/llassetuploadresponders.cpp
@@ -41,6 +41,7 @@
 #include "llfilepicker.h"
 #include "llnotify.h"
 #include "llinventorymodel.h"
+#include "llinventorypanel.h"
 #include "llfloaterinventory.h"
 #include "llpermissionsflags.h"
 #include "llpreviewnotecard.h"
diff --git a/indra/newview/llfloaterbuy.cpp b/indra/newview/llfloaterbuy.cpp
index 9d07362edc8..3da06fa7b32 100644
--- a/indra/newview/llfloaterbuy.cpp
+++ b/indra/newview/llfloaterbuy.cpp
@@ -45,6 +45,7 @@
 #include "llinventorymodel.h"	// for gInventory
 #include "llfloaterreg.h"
 #include "llfloaterinventory.h"	// for get_item_icon
+#include "llinventoryfunctions.h"
 #include "llselectmgr.h"
 #include "llscrolllistctrl.h"
 #include "llviewerobject.h"
diff --git a/indra/newview/llfloaterbuycontents.cpp b/indra/newview/llfloaterbuycontents.cpp
index 3a4171c6bee..f3eaa0c9163 100644
--- a/indra/newview/llfloaterbuycontents.cpp
+++ b/indra/newview/llfloaterbuycontents.cpp
@@ -45,6 +45,7 @@
 #include "llagent.h"			// for agent id
 #include "llalertdialog.h"
 #include "llcheckboxctrl.h"
+#include "llinventoryfunctions.h"
 #include "llinventorymodel.h"	// for gInventory
 #include "llfloaterreg.h"
 #include "llfloaterinventory.h"	// for get_item_icon
@@ -280,7 +281,7 @@ void LLFloaterBuyContents::onClickBuy()
 	// We may want to wear this item
 	if (childGetValue("wear_check"))
 	{
-		LLFloaterInventory::sWearNewClothing = TRUE;
+		LLInventoryState::sWearNewClothing = TRUE;
 	}
 
 	// Put the items where we put new folders.
diff --git a/indra/newview/llfloatergesture.cpp b/indra/newview/llfloatergesture.cpp
index 1300103423c..c114eed4a24 100644
--- a/indra/newview/llfloatergesture.cpp
+++ b/indra/newview/llfloatergesture.cpp
@@ -44,6 +44,7 @@
 #include "llcombobox.h"
 #include "llgesturemgr.h"
 #include "llinventorymodel.h"
+#include "llinventorypanel.h"
 #include "llfloaterinventory.h"
 #include "llkeyboard.h"
 #include "lllineeditor.h"
diff --git a/indra/newview/llfloaterinventory.cpp b/indra/newview/llfloaterinventory.cpp
index a47916b7d7b..89a9a317c27 100644
--- a/indra/newview/llfloaterinventory.cpp
+++ b/indra/newview/llfloaterinventory.cpp
@@ -1,1953 +1,155 @@
-/** 
- * @file llfloaterinventory.cpp
- * @brief Implementation of the inventory view and associated stuff.
- *
- * $LicenseInfo:firstyear=2001&license=viewergpl$
- * 
- * Copyright (c) 2001-2009, Linden Research, Inc.
- * 
- * Second Life Viewer Source Code
- * The source code in this file ("Source Code") is provided by Linden Lab
- * to you under the terms of the GNU General Public License, version 2.0
- * ("GPL"), unless you have obtained a separate licensing agreement
- * ("Other License"), formally executed by you and Linden Lab.  Terms of
- * the GPL can be found in doc/GPL-license.txt in this distribution, or
- * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
- * 
- * There are special exceptions to the terms and conditions of the GPL as
- * it is applied to this Source Code. View the full text of the exception
- * in the file doc/FLOSS-exception.txt in this software distribution, or
- * online at
- * http://secondlifegrid.net/programs/open_source/licensing/flossexception
- * 
- * By copying, modifying or distributing this software, you acknowledge
- * that you have read and understood your obligations described above,
- * and agree to abide by those obligations.
- * 
- * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
- * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
- * COMPLETENESS OR PERFORMANCE.
- * $/LicenseInfo$
- */
-
-#include "llviewerprecompiledheaders.h"
-
-#include <utility> // for std::pair<>
-
-#include "llfloaterinventory.h"
-
-// library includes
-#include "llagent.h"
-#include "llagentwearables.h"
-#include "llcallingcard.h"
-#include "llfloaterreg.h"
-#include "llsdserialize.h"
-#include "llfiltereditor.h"
-#include "llspinctrl.h"
-#include "llui.h"
-#include "message.h"
-
-// newview includes
-#include "llappearancemgr.h"
-#include "llappviewer.h"
-#include "llfirstuse.h"
-#include "llfloaterchat.h"
-#include "llfloatercustomize.h"
-#include "llfocusmgr.h"
-#include "llfolderview.h"
-#include "llgesturemgr.h"
-#include "lliconctrl.h"
-#include "llimview.h"
-#include "llinventorybridge.h"
-#include "llinventoryclipboard.h"
-#include "llinventorymodel.h"
-#include "lllineeditor.h"
-#include "llmenugl.h"
-#include "llpreviewanim.h"
-#include "llpreviewgesture.h"
-#include "llpreviewnotecard.h"
-#include "llpreviewscript.h"
-#include "llpreviewsound.h"
-#include "llpreviewtexture.h"
-#include "llresmgr.h"
-#include "llscrollbar.h"
-#include "llscrollcontainer.h"
-#include "llselectmgr.h"
-#include "lltabcontainer.h"
-#include "lltooldraganddrop.h"
-#include "lluictrlfactory.h"
-#include "llviewerinventory.h"
-#include "llviewermessage.h"
-#include "llviewerobjectlist.h"
-#include "llviewerregion.h"
-#include "llviewerwindow.h"
-#include "llvoavatarself.h"
-#include "llwearablelist.h"
-
-static LLDefaultChildRegistry::Register<LLInventoryPanel> r("inventory_panel");
-
-//BOOL LLFloaterInventory::sOpenNextNewItem = FALSE;
-BOOL LLFloaterInventory::sWearNewClothing = FALSE;
-LLUUID LLFloaterInventory::sWearNewClothingTransactionID;
-
-///----------------------------------------------------------------------------
-/// LLFloaterInventoryFinder
-///----------------------------------------------------------------------------
-
-LLFloaterInventoryFinder::LLFloaterInventoryFinder(LLFloaterInventory* inventory_view)
-:	LLFloater(LLSD()),
-	mFloaterInventory(inventory_view),
-	mFilter(inventory_view->mActivePanel->getFilter())
-{
-	LLUICtrlFactory::getInstance()->buildFloater(this, "floater_inventory_view_finder.xml", NULL);
-	updateElementsFromFilter();
-}
-
-
-void LLFloaterInventoryFinder::onCheckSinceLogoff(LLUICtrl *ctrl, void *user_data)
-{
-	LLFloaterInventoryFinder *self = (LLFloaterInventoryFinder *)user_data;
-	if (!self) return;
-
-	bool since_logoff= self->childGetValue("check_since_logoff");
-	
-	if (!since_logoff && 
-	    !(  self->mSpinSinceDays->get() ||  self->mSpinSinceHours->get() ) )
-	{
-		self->mSpinSinceHours->set(1.0f);
-	}	
-}
-BOOL LLFloaterInventoryFinder::postBuild()
-{
-	const LLRect& viewrect = mFloaterInventory->getRect();
-	setRect(LLRect(viewrect.mLeft - getRect().getWidth(), viewrect.mTop, viewrect.mLeft, viewrect.mTop - getRect().getHeight()));
-
-	childSetAction("All", selectAllTypes, this);
-	childSetAction("None", selectNoTypes, this);
-
-	mSpinSinceHours = getChild<LLSpinCtrl>("spin_hours_ago");
-	childSetCommitCallback("spin_hours_ago", onTimeAgo, this);
-
-	mSpinSinceDays = getChild<LLSpinCtrl>("spin_days_ago");
-	childSetCommitCallback("spin_days_ago", onTimeAgo, this);
-
-	//	mCheckSinceLogoff   = getChild<LLSpinCtrl>("check_since_logoff");
-	childSetCommitCallback("check_since_logoff", onCheckSinceLogoff, this);
-
-	childSetAction("Close", onCloseBtn, this);
-
-	updateElementsFromFilter();
-	return TRUE;
-}
-void LLFloaterInventoryFinder::onTimeAgo(LLUICtrl *ctrl, void *user_data)
-{
-	LLFloaterInventoryFinder *self = (LLFloaterInventoryFinder *)user_data;
-	if (!self) return;
-	
-	bool since_logoff=true;
-	if ( self->mSpinSinceDays->get() ||  self->mSpinSinceHours->get() )
-	{
-		since_logoff = false;
-	}
-	self->childSetValue("check_since_logoff", since_logoff);
-}
-
-void LLFloaterInventoryFinder::changeFilter(LLInventoryFilter* filter)
-{
-	mFilter = filter;
-	updateElementsFromFilter();
-}
-
-void LLFloaterInventoryFinder::updateElementsFromFilter()
-{
-	if (!mFilter)
-		return;
-
-	// Get data needed for filter display
-	U32 filter_types = mFilter->getFilterTypes();
-	std::string filter_string = mFilter->getFilterSubString();
-	LLInventoryFilter::EFolderShow show_folders = mFilter->getShowFolderState();
-	U32 hours = mFilter->getHoursAgo();
-
-	// update the ui elements
-	LLFloater::setTitle(mFilter->getName());
-	childSetValue("check_animation", (S32) (filter_types & 0x1 << LLInventoryType::IT_ANIMATION));
-
-	childSetValue("check_calling_card", (S32) (filter_types & 0x1 << LLInventoryType::IT_CALLINGCARD));
-	childSetValue("check_clothing", (S32) (filter_types & 0x1 << LLInventoryType::IT_WEARABLE));
-	childSetValue("check_gesture", (S32) (filter_types & 0x1 << LLInventoryType::IT_GESTURE));
-	childSetValue("check_landmark", (S32) (filter_types & 0x1 << LLInventoryType::IT_LANDMARK));
-	childSetValue("check_notecard", (S32) (filter_types & 0x1 << LLInventoryType::IT_NOTECARD));
-	childSetValue("check_object", (S32) (filter_types & 0x1 << LLInventoryType::IT_OBJECT));
-	childSetValue("check_script", (S32) (filter_types & 0x1 << LLInventoryType::IT_LSL));
-	childSetValue("check_sound", (S32) (filter_types & 0x1 << LLInventoryType::IT_SOUND));
-	childSetValue("check_texture", (S32) (filter_types & 0x1 << LLInventoryType::IT_TEXTURE));
-	childSetValue("check_snapshot", (S32) (filter_types & 0x1 << LLInventoryType::IT_SNAPSHOT));
-	childSetValue("check_show_empty", show_folders == LLInventoryFilter::SHOW_ALL_FOLDERS);
-	childSetValue("check_since_logoff", mFilter->isSinceLogoff());
-	mSpinSinceHours->set((F32)(hours % 24));
-	mSpinSinceDays->set((F32)(hours / 24));
-}
-
-void LLFloaterInventoryFinder::draw()
-{
-	LLMemType mt(LLMemType::MTYPE_INVENTORY_DRAW);
-	U32 filter = 0xffffffff;
-	BOOL filtered_by_all_types = TRUE;
-
-	if (!childGetValue("check_animation"))
-	{
-		filter &= ~(0x1 << LLInventoryType::IT_ANIMATION);
-		filtered_by_all_types = FALSE;
-	}
-
-
-	if (!childGetValue("check_calling_card"))
-	{
-		filter &= ~(0x1 << LLInventoryType::IT_CALLINGCARD);
-		filtered_by_all_types = FALSE;
-	}
-
-	if (!childGetValue("check_clothing"))
-	{
-		filter &= ~(0x1 << LLInventoryType::IT_WEARABLE);
-		filtered_by_all_types = FALSE;
-	}
-
-	if (!childGetValue("check_gesture"))
-	{
-		filter &= ~(0x1 << LLInventoryType::IT_GESTURE);
-		filtered_by_all_types = FALSE;
-	}
-
-	if (!childGetValue("check_landmark"))
-
-
-	{
-		filter &= ~(0x1 << LLInventoryType::IT_LANDMARK);
-		filtered_by_all_types = FALSE;
-	}
-
-	if (!childGetValue("check_notecard"))
-	{
-		filter &= ~(0x1 << LLInventoryType::IT_NOTECARD);
-		filtered_by_all_types = FALSE;
-	}
-
-	if (!childGetValue("check_object"))
-	{
-		filter &= ~(0x1 << LLInventoryType::IT_OBJECT);
-		filter &= ~(0x1 << LLInventoryType::IT_ATTACHMENT);
-		filtered_by_all_types = FALSE;
-	}
-
-	if (!childGetValue("check_script"))
-	{
-		filter &= ~(0x1 << LLInventoryType::IT_LSL);
-		filtered_by_all_types = FALSE;
-	}
-
-	if (!childGetValue("check_sound"))
-	{
-		filter &= ~(0x1 << LLInventoryType::IT_SOUND);
-		filtered_by_all_types = FALSE;
-	}
-
-	if (!childGetValue("check_texture"))
-	{
-		filter &= ~(0x1 << LLInventoryType::IT_TEXTURE);
-		filtered_by_all_types = FALSE;
-	}
-
-	if (!childGetValue("check_snapshot"))
-	{
-		filter &= ~(0x1 << LLInventoryType::IT_SNAPSHOT);
-		filtered_by_all_types = FALSE;
-	}
-
-	if (!filtered_by_all_types)
-	{
-		// don't include folders in filter, unless I've selected everything
-		filter &= ~(0x1 << LLInventoryType::IT_CATEGORY);
-	}
-
-	// update the panel, panel will update the filter
-	mFloaterInventory->mActivePanel->setShowFolderState(getCheckShowEmpty() ?
-		LLInventoryFilter::SHOW_ALL_FOLDERS : LLInventoryFilter::SHOW_NON_EMPTY_FOLDERS);
-	mFloaterInventory->mActivePanel->setFilterTypes(filter);
-	if (getCheckSinceLogoff())
-	{
-		mSpinSinceDays->set(0);
-		mSpinSinceHours->set(0);
-	}
-	U32 days = (U32)mSpinSinceDays->get();
-	U32 hours = (U32)mSpinSinceHours->get();
-	if (hours > 24)
-	{
-		days += hours / 24;
-		hours = (U32)hours % 24;
-		mSpinSinceDays->set((F32)days);
-		mSpinSinceHours->set((F32)hours);
-	}
-	hours += days * 24;
-	mFloaterInventory->mActivePanel->setHoursAgo(hours);
-	mFloaterInventory->mActivePanel->setSinceLogoff(getCheckSinceLogoff());
-	mFloaterInventory->setFilterTextFromFilter();
-
-	LLFloater::draw();
-}
-
-BOOL LLFloaterInventoryFinder::getCheckShowEmpty()
-{
-	return childGetValue("check_show_empty");
-}
-
-BOOL LLFloaterInventoryFinder::getCheckSinceLogoff()
-{
-	return childGetValue("check_since_logoff");
-}
-
-void LLFloaterInventoryFinder::onCloseBtn(void* user_data)
-{
-	LLFloaterInventoryFinder* finderp = (LLFloaterInventoryFinder*)user_data;
-	finderp->closeFloater();
-}
-
-// static
-void LLFloaterInventoryFinder::selectAllTypes(void* user_data)
-{
-	LLFloaterInventoryFinder* self = (LLFloaterInventoryFinder*)user_data;
-	if(!self) return;
-
-	self->childSetValue("check_animation", TRUE);
-	self->childSetValue("check_calling_card", TRUE);
-	self->childSetValue("check_clothing", TRUE);
-	self->childSetValue("check_gesture", TRUE);
-	self->childSetValue("check_landmark", TRUE);
-	self->childSetValue("check_notecard", TRUE);
-	self->childSetValue("check_object", TRUE);
-	self->childSetValue("check_script", TRUE);
-	self->childSetValue("check_sound", TRUE);
-	self->childSetValue("check_texture", TRUE);
-	self->childSetValue("check_snapshot", TRUE);
-
-/*
-	self->mCheckCallingCard->set(TRUE);
-	self->mCheckClothing->set(TRUE);
-	self->mCheckGesture->set(TRUE);
-	self->mCheckLandmark->set(TRUE);
-	self->mCheckNotecard->set(TRUE);
-	self->mCheckObject->set(TRUE);
-	self->mCheckScript->set(TRUE);
-	self->mCheckSound->set(TRUE);
-	self->mCheckTexture->set(TRUE);
-	self->mCheckSnapshot->set(TRUE);*/
-}
-
-//static
-void LLFloaterInventoryFinder::selectNoTypes(void* user_data)
-{
-	LLFloaterInventoryFinder* self = (LLFloaterInventoryFinder*)user_data;
-	if(!self) return;
-
-	/*
-	self->childSetValue("check_animation", FALSE);
-	self->mCheckCallingCard->set(FALSE);
-	self->mCheckClothing->set(FALSE);
-	self->mCheckGesture->set(FALSE);
-	self->mCheckLandmark->set(FALSE);
-	self->mCheckNotecard->set(FALSE);
-	self->mCheckObject->set(FALSE);
-	self->mCheckScript->set(FALSE);
-	self->mCheckSound->set(FALSE);
-	self->mCheckTexture->set(FALSE);
-	self->mCheckSnapshot->set(FALSE);*/
-
-
-	self->childSetValue("check_animation", FALSE);
-	self->childSetValue("check_calling_card", FALSE);
-	self->childSetValue("check_clothing", FALSE);
-	self->childSetValue("check_gesture", FALSE);
-	self->childSetValue("check_landmark", FALSE);
-	self->childSetValue("check_notecard", FALSE);
-	self->childSetValue("check_object", FALSE);
-	self->childSetValue("check_script", FALSE);
-	self->childSetValue("check_sound", FALSE);
-	self->childSetValue("check_texture", FALSE);
-	self->childSetValue("check_snapshot", FALSE);
-}
-
-
-///----------------------------------------------------------------------------
-/// LLFloaterInventory
-///----------------------------------------------------------------------------
-void LLSaveFolderState::setApply(BOOL apply)
-{
-	mApply = apply; 
-	// before generating new list of open folders, clear the old one
-	if(!apply) 
-	{
-		clearOpenFolders(); 
-	}
-}
-
-void LLSaveFolderState::doFolder(LLFolderViewFolder* folder)
-{
-	LLMemType mt(LLMemType::MTYPE_INVENTORY_DO_FOLDER);
-	if(mApply)
-	{
-		// we're applying the open state
-		LLInvFVBridge* bridge = (LLInvFVBridge*)folder->getListener();
-		if(!bridge) return;
-		LLUUID id(bridge->getUUID());
-		if(mOpenFolders.find(id) != mOpenFolders.end())
-		{
-			folder->setOpen(TRUE);
-		}
-		else
-		{
-			// keep selected filter in its current state, this is less jarring to user
-			if (!folder->isSelected())
-			{
-				folder->setOpen(FALSE);
-			}
-		}
-	}
-	else
-	{
-		// we're recording state at this point
-		if(folder->isOpen())
-		{
-			LLInvFVBridge* bridge = (LLInvFVBridge*)folder->getListener();
-			if(!bridge) return;
-			mOpenFolders.insert(bridge->getUUID());
-		}
-	}
-}
-
-LLFloaterInventory::LLFloaterInventory(const LLSD& key)
-	: LLFloater(key)
-{
-	LLMemType mt(LLMemType::MTYPE_INVENTORY_VIEW_INIT);
-	// Menu Callbacks (non contex menus)
-	mCommitCallbackRegistrar.add("Inventory.DoToSelected", boost::bind(&LLFloaterInventory::doToSelected, this, _2));
-	mCommitCallbackRegistrar.add("Inventory.CloseAllFolders", boost::bind(&LLFloaterInventory::closeAllFolders, this));
-	mCommitCallbackRegistrar.add("Inventory.EmptyTrash", boost::bind(&LLInventoryModel::emptyFolderType, &gInventory, "ConfirmEmptyTrash", LLAssetType::AT_TRASH));
-	mCommitCallbackRegistrar.add("Inventory.EmptyLostAndFound", boost::bind(&LLInventoryModel::emptyFolderType, &gInventory, "ConfirmEmptyLostAndFound", LLAssetType::AT_LOST_AND_FOUND));
-	mCommitCallbackRegistrar.add("Inventory.DoCreate", boost::bind(&LLFloaterInventory::doCreate, this, _2));
-// 	mCommitCallbackRegistrar.add("Inventory.NewWindow", boost::bind(&LLFloaterInventory::newWindow, this));
-	mCommitCallbackRegistrar.add("Inventory.ShowFilters", boost::bind(&LLFloaterInventory::toggleFindOptions, this));
-	mCommitCallbackRegistrar.add("Inventory.ResetFilters", boost::bind(&LLFloaterInventory::resetFilters, this));
-	mCommitCallbackRegistrar.add("Inventory.SetSortBy", boost::bind(&LLFloaterInventory::setSortBy, this, _2));
-
-	// Controls
-	// *TODO: Just use persistant settings for each of these
-	U32 sort_order = gSavedSettings.getU32("InventorySortOrder");
-	BOOL sort_by_name = ! ( sort_order & LLInventoryFilter::SO_DATE );
-	BOOL sort_folders_by_name = ( sort_order & LLInventoryFilter::SO_FOLDERS_BY_NAME );
-	BOOL sort_system_folders_to_top = ( sort_order & LLInventoryFilter::SO_SYSTEM_FOLDERS_TO_TOP );
-	
-	gSavedSettings.declareBOOL("Inventory.SortByName", sort_by_name, "Declared in code", FALSE);
-	gSavedSettings.declareBOOL("Inventory.SortByDate", !sort_by_name, "Declared in code", FALSE);
-	gSavedSettings.declareBOOL("Inventory.FoldersAlwaysByName", sort_folders_by_name, "Declared in code", FALSE);
-	gSavedSettings.declareBOOL("Inventory.SystemFoldersToTop", sort_system_folders_to_top, "Declared in code", FALSE);
-	
-	mSavedFolderState = new LLSaveFolderState();
-	mSavedFolderState->setApply(FALSE);
-
-	//Called from floater reg: LLUICtrlFactory::getInstance()->buildFloater(this, "floater_inventory.xml");
-}
-
-BOOL LLFloaterInventory::postBuild()
-{
-	gInventory.addObserver(this);
-	
-	mFilterTabs = getChild<LLTabContainer>("inventory filter tabs");
-	mFilterTabs->setCommitCallback(boost::bind(&LLFloaterInventory::onFilterSelected, this));
-	
-	//panel->getFilter()->markDefault();
-
-	// Set up the default inv. panel/filter settings.
-	mActivePanel = getChild<LLInventoryPanel>("All Items");
-	if (mActivePanel)
-	{
-		// "All Items" is the previous only view, so it gets the InventorySortOrder
-		mActivePanel->setSortOrder(gSavedSettings.getU32("InventorySortOrder"));
-		mActivePanel->getFilter()->markDefault();
-		mActivePanel->getRootFolder()->applyFunctorRecursively(*mSavedFolderState);
-		mActivePanel->setSelectCallback(boost::bind(&LLInventoryPanel::onSelectionChange, mActivePanel, _1, _2));
-	}
-	LLInventoryPanel* recent_items_panel = getChild<LLInventoryPanel>("Recent Items");
-	if (recent_items_panel)
-	{
-		recent_items_panel->setSinceLogoff(TRUE);
-		recent_items_panel->setSortOrder(LLInventoryFilter::SO_DATE);
-		recent_items_panel->setShowFolderState(LLInventoryFilter::SHOW_NON_EMPTY_FOLDERS);
-		recent_items_panel->getFilter()->markDefault();
-		recent_items_panel->setSelectCallback(boost::bind(&LLInventoryPanel::onSelectionChange, recent_items_panel, _1, _2));
-	}
-
-	// Now load the stored settings from disk, if available.
-	std::ostringstream filterSaveName;
-	filterSaveName << gDirUtilp->getExpandedFilename(LL_PATH_PER_SL_ACCOUNT, "filters.xml");
-	llinfos << "LLFloaterInventory::init: reading from " << filterSaveName << llendl;
-	llifstream file(filterSaveName.str());
-	LLSD savedFilterState;
-	if (file.is_open())
-	{
-		LLSDSerialize::fromXML(savedFilterState, file);
-		file.close();
-
-		// Load the persistent "Recent Items" settings.
-		// Note that the "All Items" settings do not persist.
-		if(recent_items_panel)
-		{
-			if(savedFilterState.has(recent_items_panel->getFilter()->getName()))
-			{
-				LLSD recent_items = savedFilterState.get(
-					recent_items_panel->getFilter()->getName());
-				recent_items_panel->getFilter()->fromLLSD(recent_items);
-			}
-		}
-
-	}
-
-
-	mFilterEditor = getChild<LLFilterEditor>("inventory search editor");
-	if (mFilterEditor)
-	{
-		mFilterEditor->setCommitCallback(boost::bind(&LLFloaterInventory::onFilterEdit, this, _2));
-	}
-
-	// *TODO:Get the cost info from the server
-	const std::string upload_cost("10");
-	childSetLabelArg("Upload Image", "[COST]", upload_cost);
-	childSetLabelArg("Upload Sound", "[COST]", upload_cost);
-	childSetLabelArg("Upload Animation", "[COST]", upload_cost);
-	childSetLabelArg("Bulk Upload", "[COST]", upload_cost);
-	
-	return TRUE;
-}
-
-// Destroys the object
-LLFloaterInventory::~LLFloaterInventory( void )
-{
-	// Save the filters state.
-	LLSD filterRoot;
-	LLInventoryPanel* all_items_panel = getChild<LLInventoryPanel>("All Items");
-	if (all_items_panel)
-	{
-		LLInventoryFilter* filter = all_items_panel->getFilter();
-		LLSD filterState;
-		filter->toLLSD(filterState);
-		filterRoot[filter->getName()] = filterState;
-	}
-
-	LLInventoryPanel* recent_items_panel = getChild<LLInventoryPanel>("Recent Items");
-	if (recent_items_panel)
-	{
-		LLInventoryFilter* filter = recent_items_panel->getFilter();
-		LLSD filterState;
-		filter->toLLSD(filterState);
-		filterRoot[filter->getName()] = filterState;
-	}
-
-	std::ostringstream filterSaveName;
-	filterSaveName << gDirUtilp->getExpandedFilename(LL_PATH_PER_SL_ACCOUNT, "filters.xml");
-	llofstream filtersFile(filterSaveName.str());
-	if(!LLSDSerialize::toPrettyXML(filterRoot, filtersFile))
-	{
-		llwarns << "Could not write to filters save file " << filterSaveName << llendl;
-	}
-	else
-		filtersFile.close();
-
-	gInventory.removeObserver(this);
-	delete mSavedFolderState;
-}
-
-void LLFloaterInventory::draw()
-{
- 	if (LLInventoryModel::isEverythingFetched())
-	{
-		updateTitle();
-	}
-	LLFloater::draw();
-}
-
-void LLOpenFilteredFolders::doItem(LLFolderViewItem *item)
-{
-	if (item->getFiltered())
-	{
-		item->getParentFolder()->setOpenArrangeRecursively(TRUE, LLFolderViewFolder::RECURSE_UP);
-	}
-}
-
-void LLOpenFilteredFolders::doFolder(LLFolderViewFolder* folder)
-{
-	if (folder->getFiltered() && folder->getParentFolder())
-	{
-		folder->getParentFolder()->setOpenArrangeRecursively(TRUE, LLFolderViewFolder::RECURSE_UP);
-	}
-	// if this folder didn't pass the filter, and none of its descendants did
-	else if (!folder->getFiltered() && !folder->hasFilteredDescendants())
-	{
-		folder->setOpenArrangeRecursively(FALSE, LLFolderViewFolder::RECURSE_NO);
-	}
-}
-
-void LLSelectFirstFilteredItem::doItem(LLFolderViewItem *item)
-{
-	if (item->getFiltered() && !mItemSelected)
-	{
-		item->getRoot()->setSelection(item, FALSE, FALSE);
-		if (item->getParentFolder())
-		{
-			item->getParentFolder()->setOpenArrangeRecursively(TRUE, LLFolderViewFolder::RECURSE_UP);
-		}
-		item->getRoot()->scrollToShowSelection();
-		mItemSelected = TRUE;
-	}
-}
-
-void LLSelectFirstFilteredItem::doFolder(LLFolderViewFolder* folder)
-{
-	if (folder->getFiltered() && !mItemSelected)
-	{
-		folder->getRoot()->setSelection(folder, FALSE, FALSE);
-		if (folder->getParentFolder())
-		{
-			folder->getParentFolder()->setOpenArrangeRecursively(TRUE, LLFolderViewFolder::RECURSE_UP);
-		}
-		folder->getRoot()->scrollToShowSelection();
-		mItemSelected = TRUE;
-	}
-}
-
-void LLOpenFoldersWithSelection::doItem(LLFolderViewItem *item)
-{
-	if (item->getParentFolder() && item->isSelected())
-	{
-		item->getParentFolder()->setOpenArrangeRecursively(TRUE, LLFolderViewFolder::RECURSE_UP);
-	}
-}
-
-void LLOpenFoldersWithSelection::doFolder(LLFolderViewFolder* folder)
-{
-	if (folder->getParentFolder() && folder->isSelected())
-	{
-		folder->getParentFolder()->setOpenArrangeRecursively(TRUE, LLFolderViewFolder::RECURSE_UP);
-	}
-}
-
-void LLFloaterInventory::startSearch()
-{
-	// this forces focus to line editor portion of search editor
-	if (mFilterEditor)
-	{
-		mFilterEditor->focusFirstItem(TRUE);
-	}
-}
-
-void LLFloaterInventory::onOpen(const LLSD& key)
-{
-	LLFirstUse::useInventory();
-}
-
-BOOL LLFloaterInventory::handleKeyHere(KEY key, MASK mask)
-{
-	LLFolderView* root_folder = mActivePanel ? mActivePanel->getRootFolder() : NULL;
-	if (root_folder)
-	{
-		// first check for user accepting current search results
-		if (mFilterEditor 
-			&& mFilterEditor->hasFocus()
-		    && (key == KEY_RETURN 
-		    	|| key == KEY_DOWN)
-		    && mask == MASK_NONE)
-		{
-			// move focus to inventory proper
-			mActivePanel->setFocus(TRUE);
-			root_folder->scrollToShowSelection();
-			return TRUE;
-		}
-
-		if (mActivePanel->hasFocus() && key == KEY_UP)
-		{
-			startSearch();
-		}
-	}
-
-	return LLFloater::handleKeyHere(key, mask);
-
-}
-
-void LLFloaterInventory::updateTitle()
-{
-	LLLocale locale(LLLocale::USER_LOCALE);
-	std::string item_count_string;
-	LLResMgr::getInstance()->getIntegerString(item_count_string, gInventory.getItemCount());
-
-	LLStringUtil::format_map_t string_args;
-	string_args["[ITEM_COUNT]"] = item_count_string;
-	string_args["[FILTER]"] = mFilterText;
-
-	if (LLInventoryModel::backgroundFetchActive())
-	{
-		setTitle(getString("TitleFetching", string_args));
-	}
-	else
-	{
-		setTitle(getString("TitleCompleted", string_args));
-	}	
-}
-
-
-void LLFloaterInventory::changed(U32 mask)
-{
-	updateTitle();
-}
-
-//----------------------------------------------------------------------------
-// menu callbacks
-
-void LLFloaterInventory::doToSelected(const LLSD& userdata)
-{
-	getPanel()->getRootFolder()->doToSelected(&gInventory, userdata);
-}
-
-void LLFloaterInventory::closeAllFolders()
-{
-	getPanel()->getRootFolder()->closeAllFolders();
-}
-
-void LLFloaterInventory::doCreate(const LLSD& userdata)
-{
-	menu_create_inventory_item(getPanel()->getRootFolder(), NULL, userdata);
-}
-
-void LLFloaterInventory::resetFilters()
-{
-	LLFloaterInventoryFinder *finder = getFinder();
-	getActivePanel()->getFilter()->resetDefault();
-	if (finder)
-	{
-		finder->updateElementsFromFilter();
-	}
-
-	setFilterTextFromFilter();
-}
-
-void LLFloaterInventory::setSortBy(const LLSD& userdata)
-{
-	std::string sort_field = userdata.asString();
-	if (sort_field == "name")
-	{
-		U32 order = getActivePanel()->getSortOrder();
-		getActivePanel()->setSortOrder( order & ~LLInventoryFilter::SO_DATE );
-			
-		gSavedSettings.setBOOL("Inventory.SortByName", TRUE );
-		gSavedSettings.setBOOL("Inventory.SortByDate", FALSE );
-	}
-	else if (sort_field == "date")
-	{
-		U32 order = getActivePanel()->getSortOrder();
-		getActivePanel()->setSortOrder( order | LLInventoryFilter::SO_DATE );
-
-		gSavedSettings.setBOOL("Inventory.SortByName", FALSE );
-		gSavedSettings.setBOOL("Inventory.SortByDate", TRUE );
-	}
-	else if (sort_field == "foldersalwaysbyname")
-	{
-		U32 order = getActivePanel()->getSortOrder();
-		if ( order & LLInventoryFilter::SO_FOLDERS_BY_NAME )
-		{
-			order &= ~LLInventoryFilter::SO_FOLDERS_BY_NAME;
-
-			gSavedSettings.setBOOL("Inventory.FoldersAlwaysByName", FALSE );
-		}
-		else
-		{
-			order |= LLInventoryFilter::SO_FOLDERS_BY_NAME;
-
-			gSavedSettings.setBOOL("Inventory.FoldersAlwaysByName", TRUE );
-		}
-		getActivePanel()->setSortOrder( order );
-	}
-	else if (sort_field == "systemfolderstotop")
-	{
-		U32 order = getActivePanel()->getSortOrder();
-		if ( order & LLInventoryFilter::SO_SYSTEM_FOLDERS_TO_TOP )
-		{
-			order &= ~LLInventoryFilter::SO_SYSTEM_FOLDERS_TO_TOP;
-
-			gSavedSettings.setBOOL("Inventory.SystemFoldersToTop", FALSE );
-		}
-		else
-		{
-			order |= LLInventoryFilter::SO_SYSTEM_FOLDERS_TO_TOP;
-
-			gSavedSettings.setBOOL("Inventory.SystemFoldersToTop", TRUE );
-		}
-		getActivePanel()->setSortOrder( order );
-	}
-}
-
-//----------------------------------------------------------------------------
-
-// static
-LLFloaterInventory* LLFloaterInventory::showAgentInventory()
-{
-	LLFloaterInventory* iv = NULL;
-	if (!gAgent.cameraMouselook())
-	{
-		iv = LLFloaterReg::showTypedInstance<LLFloaterInventory>("inventory", LLSD());
-	}
-	return iv;
-}
-
-// static
-LLFloaterInventory* LLFloaterInventory::getActiveInventory()
-{
-	LLFloaterInventory* res = NULL;
-	LLFloaterReg::const_instance_list_t& inst_list = LLFloaterReg::getFloaterList("inventory");
-	S32 z_min = S32_MAX;
-	for (LLFloaterReg::const_instance_list_t::const_iterator iter = inst_list.begin(); iter != inst_list.end(); ++iter)
-	{
-		LLFloaterInventory* iv = dynamic_cast<LLFloaterInventory*>(*iter);
-		if (iv)
-		{
-			S32 z_order = gFloaterView->getZOrder(iv);
-			if (z_order < z_min)
-			{
-				res = iv;
-				z_min = z_order;
-			}
-		}
-	}
-	return res;
-}
-
-// static
-void LLFloaterInventory::cleanup()
-{
-	LLFloaterReg::const_instance_list_t& inst_list = LLFloaterReg::getFloaterList("inventory");
-	for (LLFloaterReg::const_instance_list_t::const_iterator iter = inst_list.begin(); iter != inst_list.end();)
-	{
-		LLFloaterInventory* iv = dynamic_cast<LLFloaterInventory*>(*iter++);
-		if (iv)
-		{
-			iv->destroy();
-		}
-	}
-}
-
-void LLFloaterInventory::toggleFindOptions()
-{
-	LLMemType mt(LLMemType::MTYPE_INVENTORY_VIEW_TOGGLE);
-	LLFloater *floater = getFinder();
-	if (!floater)
-	{
-		LLFloaterInventoryFinder * finder = new LLFloaterInventoryFinder(this);
-		mFinderHandle = finder->getHandle();
-		finder->openFloater();
-		addDependentFloater(mFinderHandle);
-
-		// start background fetch of folders
-		gInventory.startBackgroundFetch();
-	}
-	else
-	{
-		floater->closeFloater();
-	}
-}
-
-// static
-BOOL LLFloaterInventory::filtersVisible(void* user_data)
-{
-	LLFloaterInventory* self = (LLFloaterInventory*)user_data;
-	if(!self) return FALSE;
-
-	return self->getFinder() != NULL;
-}
-
-void LLFloaterInventory::onClearSearch()
-{
-	LLFloater *finder = getFinder();
-	if (mActivePanel)
-	{
-		mActivePanel->setFilterSubString(LLStringUtil::null);
-		mActivePanel->setFilterTypes(0xffffffff);
-	}
-
-	if (finder)
-	{
-		LLFloaterInventoryFinder::selectAllTypes(finder);
-	}
-
-	// re-open folders that were initially open
-	if (mActivePanel)
-	{
-		mSavedFolderState->setApply(TRUE);
-		mActivePanel->getRootFolder()->applyFunctorRecursively(*mSavedFolderState);
-		LLOpenFoldersWithSelection opener;
-		mActivePanel->getRootFolder()->applyFunctorRecursively(opener);
-		mActivePanel->getRootFolder()->scrollToShowSelection();
-	}
-}
-
-void LLFloaterInventory::onFilterEdit(const std::string& search_string )
-{
-	if (search_string == "")
-	{
-		onClearSearch();
-	}
-	if (!mActivePanel)
-	{
-		return;
-	}
-
-	gInventory.startBackgroundFetch();
-
-	std::string uppercase_search_string = search_string;
-	LLStringUtil::toUpper(uppercase_search_string);
-	if (mActivePanel->getFilterSubString().empty() && uppercase_search_string.empty())
-	{
-			// current filter and new filter empty, do nothing
-			return;
-	}
-
-	// save current folder open state if no filter currently applied
-	if (!mActivePanel->getRootFolder()->isFilterModified())
-	{
-		mSavedFolderState->setApply(FALSE);
-		mActivePanel->getRootFolder()->applyFunctorRecursively(*mSavedFolderState);
-	}
-
-	// set new filter string
-	mActivePanel->setFilterSubString(uppercase_search_string);
-}
-
-
- //static
- BOOL LLFloaterInventory::incrementalFind(LLFolderViewItem* first_item, const char *find_text, BOOL backward)
- {
- 	LLFloaterInventory* active_view = NULL;
-	
-	LLFloaterReg::const_instance_list_t& inst_list = LLFloaterReg::getFloaterList("inventory");
-	for (LLFloaterReg::const_instance_list_t::const_iterator iter = inst_list.begin(); iter != inst_list.end(); ++iter)
-	{
-		LLFloaterInventory* iv = dynamic_cast<LLFloaterInventory*>(*iter);
-		if (iv)
-		{
-			if (gFocusMgr.childHasKeyboardFocus(iv))
-			{
-				active_view = iv;
-				break;
-			}
- 		}
- 	}
-
- 	if (!active_view)
- 	{
- 		return FALSE;
- 	}
-
- 	std::string search_string(find_text);
-
- 	if (search_string.empty())
- 	{
- 		return FALSE;
- 	}
-
- 	if (active_view->mActivePanel &&
- 		active_view->mActivePanel->getRootFolder()->search(first_item, search_string, backward))
- 	{
- 		return TRUE;
- 	}
-
- 	return FALSE;
- }
-
-void LLFloaterInventory::onFilterSelected()
-{
-	// Find my index
-	mActivePanel = (LLInventoryPanel*)childGetVisibleTab("inventory filter tabs");
-
-	if (!mActivePanel)
-	{
-		return;
-	}
-	LLInventoryFilter* filter = mActivePanel->getFilter();
-	LLFloaterInventoryFinder *finder = getFinder();
-	if (finder)
-	{
-		finder->changeFilter(filter);
-	}
-	if (filter->isActive())
-	{
-		// If our filter is active we may be the first thing requiring a fetch so we better start it here.
-		gInventory.startBackgroundFetch();
-	}
-	setFilterTextFromFilter();
-}
-
-BOOL LLFloaterInventory::handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop,
-										 EDragAndDropType cargo_type,
-										 void* cargo_data,
-										 EAcceptance* accept,
-										 std::string& tooltip_msg)
-{
-	// Check to see if we are auto scrolling from the last frame
-	LLInventoryPanel* panel = (LLInventoryPanel*)this->getActivePanel();
-	BOOL needsToScroll = panel->getScrollableContainer()->autoScroll(x, y);
-	if(mFilterTabs)
-	{
-		if(needsToScroll)
-		{
-			mFilterTabs->startDragAndDropDelayTimer();
-		}
-	}
-	
-	BOOL handled = LLFloater::handleDragAndDrop(x, y, mask, drop, cargo_type, cargo_data, accept, tooltip_msg);
-
-	return handled;
-}
-const std::string& get_item_icon_name(LLAssetType::EType asset_type,
-							 LLInventoryType::EType inventory_type,
-							 U32 attachment_point,
-							 BOOL item_is_multi )
-{
-	EInventoryIcon idx = OBJECT_ICON_NAME;
-	if ( item_is_multi )
-	{
-		idx = OBJECT_MULTI_ICON_NAME;
-	}
-	
-	switch(asset_type)
-	{
-	case LLAssetType::AT_TEXTURE:
-		if(LLInventoryType::IT_SNAPSHOT == inventory_type)
-		{
-			idx = SNAPSHOT_ICON_NAME;
-		}
-		else
-		{
-			idx = TEXTURE_ICON_NAME;
-		}
-		break;
-
-	case LLAssetType::AT_SOUND:
-		idx = SOUND_ICON_NAME;
-		break;
-	case LLAssetType::AT_CALLINGCARD:
-		if(attachment_point!= 0)
-		{
-			idx = CALLINGCARD_ONLINE_ICON_NAME;
-		}
-		else
-		{
-			idx = CALLINGCARD_OFFLINE_ICON_NAME;
-		}
-		break;
-	case LLAssetType::AT_LANDMARK:
-		if(attachment_point!= 0)
-		{
-			idx = LANDMARK_VISITED_ICON_NAME;
-		}
-		else
-		{
-			idx = LANDMARK_ICON_NAME;
-		}
-		break;
-	case LLAssetType::AT_SCRIPT:
-	case LLAssetType::AT_LSL_TEXT:
-	case LLAssetType::AT_LSL_BYTECODE:
-		idx = SCRIPT_ICON_NAME;
-		break;
-	case LLAssetType::AT_CLOTHING:
-		idx = CLOTHING_ICON_NAME;
-	case LLAssetType::AT_BODYPART :
-		if(LLAssetType::AT_BODYPART == asset_type)
-		{
-			idx = BODYPART_ICON_NAME;
-		}
-		switch(LLInventoryItem::II_FLAGS_WEARABLES_MASK & attachment_point)
-		{
-		case WT_SHAPE:
-			idx = BODYPART_SHAPE_ICON_NAME;
-			break;
-		case WT_SKIN:
-			idx = BODYPART_SKIN_ICON_NAME;
-			break;
-		case WT_HAIR:
-			idx = BODYPART_HAIR_ICON_NAME;
-			break;
-		case WT_EYES:
-			idx = BODYPART_EYES_ICON_NAME;
-			break;
-		case WT_SHIRT:
-			idx = CLOTHING_SHIRT_ICON_NAME;
-			break;
-		case WT_PANTS:
-			idx = CLOTHING_PANTS_ICON_NAME;
-			break;
-		case WT_SHOES:
-			idx = CLOTHING_SHOES_ICON_NAME;
-			break;
-		case WT_SOCKS:
-			idx = CLOTHING_SOCKS_ICON_NAME;
-			break;
-		case WT_JACKET:
-			idx = CLOTHING_JACKET_ICON_NAME;
-			break;
-		case WT_GLOVES:
-			idx = CLOTHING_GLOVES_ICON_NAME;
-			break;
-		case WT_UNDERSHIRT:
-			idx = CLOTHING_UNDERSHIRT_ICON_NAME;
-			break;
-		case WT_UNDERPANTS:
-			idx = CLOTHING_UNDERPANTS_ICON_NAME;
-			break;
-		case WT_SKIRT:
-			idx = CLOTHING_SKIRT_ICON_NAME;
-			break;
-		case WT_ALPHA:
-			idx = CLOTHING_ALPHA_ICON_NAME;
-			break;
-		case WT_TATTOO:
-			idx = CLOTHING_TATTOO_ICON_NAME;
-			break;
-		default:
-			// no-op, go with choice above
-			break;
-		}
-		break;
-	case LLAssetType::AT_NOTECARD:
-		idx = NOTECARD_ICON_NAME;
-		break;
-	case LLAssetType::AT_ANIMATION:
-		idx = ANIMATION_ICON_NAME;
-		break;
-	case LLAssetType::AT_GESTURE:
-		idx = GESTURE_ICON_NAME;
-		break;
-	case LLAssetType::AT_FAVORITE:
-		//TODO - need bette idx
-		idx = LANDMARK_ICON_NAME;
-		break;
-	case LLAssetType::AT_LINK:
-		idx = LINKITEM_ICON_NAME;
-		break;
-	case LLAssetType::AT_LINK_FOLDER:
-		idx = LINKFOLDER_ICON_NAME;
-		break;
-	default:
-		break;
-	}
-	
-	return ICON_NAME[idx];
-}
-
-LLUIImagePtr get_item_icon(LLAssetType::EType asset_type,
-							 LLInventoryType::EType inventory_type,
-							 U32 attachment_point,
-							 BOOL item_is_multi)
-{
-	const std::string& icon_name = get_item_icon_name(asset_type, inventory_type, attachment_point, item_is_multi );
-	return LLUI::getUIImage(icon_name);
-}
-
-const std::string LLInventoryPanel::DEFAULT_SORT_ORDER = std::string("InventorySortOrder");
-const std::string LLInventoryPanel::RECENTITEMS_SORT_ORDER = std::string("RecentItemsSortOrder");
-const std::string LLInventoryPanel::INHERIT_SORT_ORDER = std::string("");
-static const LLInventoryFVBridgeBuilder INVENTORY_BRIDGE_BUILDER;
-
-LLInventoryPanel::LLInventoryPanel(const LLInventoryPanel::Params& p)
-:	LLPanel(p),
-	mInventoryObserver(NULL),
-	mFolders(NULL),
-	mScroller(NULL),
-	mSortOrderSetting(p.sort_order_setting),
-	mInventory(p.inventory),
-	mAllowMultiSelect(p.allow_multi_select),
-	mHasInventoryConnection(false),
-	mStartFolderString(p.start_folder)
-,	mBuildDefaultHierarchy(true)
-,	mInvFVBridgeBuilder(NULL)
-{
-	mInvFVBridgeBuilder = &INVENTORY_BRIDGE_BUILDER;
-
-	// contex menu callbacks
-	mCommitCallbackRegistrar.add("Inventory.DoToSelected", boost::bind(&LLInventoryPanel::doToSelected, this, _2));
-	mCommitCallbackRegistrar.add("Inventory.EmptyTrash", boost::bind(&LLInventoryModel::emptyFolderType, &gInventory, "ConfirmEmptyTrash", LLAssetType::AT_TRASH));
-	mCommitCallbackRegistrar.add("Inventory.EmptyLostAndFound", boost::bind(&LLInventoryModel::emptyFolderType, &gInventory, "ConfirmEmptyLostAndFound", LLAssetType::AT_LOST_AND_FOUND));
-	mCommitCallbackRegistrar.add("Inventory.DoCreate", boost::bind(&LLInventoryPanel::doCreate, this, _2));
-	mCommitCallbackRegistrar.add("Inventory.AttachObject", boost::bind(&LLInventoryPanel::attachObject, this, _2));
-	mCommitCallbackRegistrar.add("Inventory.BeginIMSession", boost::bind(&LLInventoryPanel::beginIMSession, this));
-	
-	setBackgroundColor(LLUIColorTable::instance().getColor("InventoryBackgroundColor"));
-	setBackgroundVisible(TRUE);
-	setBackgroundOpaque(TRUE);
-}
-
-BOOL LLInventoryPanel::postBuild()
-{
-	LLMemType mt(LLMemType::MTYPE_INVENTORY_POST_BUILD);
-
-	mCommitCallbackRegistrar.pushScope(); // registered as a widget; need to push callback scope ourselves
-	
-	// create root folder
-	{
-		LLRect folder_rect(0,
-						   0,
-						   getRect().getWidth(),
-						   0);
-		LLFolderView::Params p;
-		p.name = getName();
-		p.rect = folder_rect;
-		p.parent_panel = this;
-		mFolders = LLUICtrlFactory::create<LLFolderView>(p);
-		mFolders->setAllowMultiSelect(mAllowMultiSelect);
-	}
-
-	mCommitCallbackRegistrar.popScope();
-	
-	mFolders->setCallbackRegistrar(&mCommitCallbackRegistrar);
-	
-	// scroller
-	{
-		LLRect scroller_view_rect = getRect();
-		scroller_view_rect.translate(-scroller_view_rect.mLeft, -scroller_view_rect.mBottom);
-		LLScrollContainer::Params p;
-		p.name("Inventory Scroller");
-		p.rect(scroller_view_rect);
-		p.follows.flags(FOLLOWS_ALL);
-		p.reserve_scroll_corner(true);
-		p.tab_stop(true);
-		mScroller = LLUICtrlFactory::create<LLScrollContainer>(p);
-	}
-	addChild(mScroller);
-	mScroller->addChild(mFolders);
-	
-	mFolders->setScrollContainer(mScroller);
-
-	// set up the callbacks from the inventory we're viewing, and then
-	// build everything.
-	mInventoryObserver = new LLInventoryPanelObserver(this);
-	mInventory->addObserver(mInventoryObserver);
-
-	// determine the root folder, if any, so inventory contents show just the children
-	// of that folder (i.e. not including the folder itself).
-	const LLAssetType::EType preferred_type = LLAssetType::lookupHumanReadable(mStartFolderString);
-
-	if ("inventory" == mStartFolderString)
-	{
-		mStartFolderID = gInventory.getRootFolderID();
-	}
-	else if ("library" == mStartFolderString)
-	{
-		mStartFolderID = gInventory.getLibraryRootFolderID();
-	}
-	else
-	{
-		mStartFolderID = (preferred_type != LLAssetType::AT_NONE ? gInventory.findCategoryUUIDForType(preferred_type) : LLUUID::null);
-	}
-
-	// build view of inventory if we need default full hierarchy and inventory ready, otherwise wait for modelChanged() callback
-	if (mBuildDefaultHierarchy && mInventory->isInventoryUsable() && !mHasInventoryConnection)
-	{
-		rebuildViewsFor(mStartFolderID);
-		mHasInventoryConnection = true;
-	}
-
-	// bit of a hack to make sure the inventory is open.
-	mFolders->openFolder(preferred_type != LLAssetType::AT_NONE ? LLAssetType::lookupCategoryName(preferred_type) : "My Inventory");
-
-	if (mSortOrderSetting != INHERIT_SORT_ORDER)
-	{
-		setSortOrder(gSavedSettings.getU32(mSortOrderSetting));
-	}
-	else
-	{
-		setSortOrder(gSavedSettings.getU32(DEFAULT_SORT_ORDER));
-	}
-	mFolders->setSortOrder(mFolders->getFilter()->getSortOrder());
-
-	return TRUE;
-}
-
-LLInventoryPanel::~LLInventoryPanel()
-{
-	// should this be a global setting?
-	if (mFolders)
-	{
-		U32 sort_order = mFolders->getSortOrder();
-		if (mSortOrderSetting != INHERIT_SORT_ORDER)
-		{
-			gSavedSettings.setU32(mSortOrderSetting, sort_order);
-		}
-	}
-
-	// LLView destructor will take care of the sub-views.
-	mInventory->removeObserver(mInventoryObserver);
-	delete mInventoryObserver;
-	mScroller = NULL;
-}
-
-LLMemType mt(LLMemType::MTYPE_INVENTORY_FROM_XML); // ! BUG ! Should this be removed?
-void LLInventoryPanel::draw()
-{
-	// select the desired item (in case it wasn't loaded when the selection was requested)
-	mFolders->updateSelection();
-	LLPanel::draw();
-}
-
-void LLInventoryPanel::setFilterTypes(U64 filter_types, BOOL filter_for_categories)
-{
-	mFolders->getFilter()->setFilterTypes(filter_types, filter_for_categories);
-}	
-
-void LLInventoryPanel::setFilterPermMask(PermissionMask filter_perm_mask)
-{
-	mFolders->getFilter()->setFilterPermissions(filter_perm_mask);
-}
-
-void LLInventoryPanel::setFilterSubString(const std::string& string)
-{
-	mFolders->getFilter()->setFilterSubString(string);
-}
-
-void LLInventoryPanel::setSortOrder(U32 order)
-{
-	mFolders->getFilter()->setSortOrder(order);
-	if (mFolders->getFilter()->isModified())
-	{
-		mFolders->setSortOrder(order);
-		// try to keep selection onscreen, even if it wasn't to start with
-		mFolders->scrollToShowSelection();
-	}
-}
-
-void LLInventoryPanel::setSinceLogoff(BOOL sl)
-{
-	mFolders->getFilter()->setDateRangeLastLogoff(sl);
-}
-
-void LLInventoryPanel::setHoursAgo(U32 hours)
-{
-	mFolders->getFilter()->setHoursAgo(hours);
-}
-
-void LLInventoryPanel::setShowFolderState(LLInventoryFilter::EFolderShow show)
-{
-	mFolders->getFilter()->setShowFolderState(show);
-}
-
-LLInventoryFilter::EFolderShow LLInventoryPanel::getShowFolderState()
-{
-	return mFolders->getFilter()->getShowFolderState();
-}
-
-static LLFastTimer::DeclareTimer FTM_REFRESH("Inventory Refresh");
-
-void LLInventoryPanel::modelChanged(U32 mask)
-{
-	LLFastTimer t2(FTM_REFRESH);
-
-	bool handled = false;
-
-	// inventory just initialized, do complete build
-	if ((mask & LLInventoryObserver::ADD) && gInventory.getChangedIDs().empty() && !mHasInventoryConnection)
-	{
-		rebuildViewsFor(mStartFolderID);
-		mHasInventoryConnection = true;
-		return;
-	}
-
-	if(mask & LLInventoryObserver::LABEL)
-	{
-		handled = true;
-		// label change - empty out the display name for each object
-		// in this change set.
-		const std::set<LLUUID>& changed_items = gInventory.getChangedIDs();
-		std::set<LLUUID>::const_iterator id_it = changed_items.begin();
-		std::set<LLUUID>::const_iterator id_end = changed_items.end();
-		LLFolderViewItem* view = NULL;
-		LLInvFVBridge* bridge = NULL;
-		for (;id_it != id_end; ++id_it)
-		{
-			view = mFolders->getItemByID(*id_it);
-			if(view)
-			{
-				// request refresh on this item (also flags for filtering)
-				bridge = (LLInvFVBridge*)view->getListener();
-				if(bridge)
-				{	// Clear the display name first, so it gets properly re-built during refresh()
-					bridge->clearDisplayName();
-				}
-				view->refresh();
-			}
-		}
-	}
-	if((mask & (LLInventoryObserver::STRUCTURE
-				| LLInventoryObserver::ADD
-				| LLInventoryObserver::REMOVE)) != 0)
-	{
-		handled = true;
-		// Record which folders are open by uuid.
-		LLInventoryModel* model = getModel();
-		if (model)
-		{
-			const std::set<LLUUID>& changed_items = gInventory.getChangedIDs();
-
-			std::set<LLUUID>::const_iterator id_it = changed_items.begin();
-			std::set<LLUUID>::const_iterator id_end = changed_items.end();
-			for (;id_it != id_end; ++id_it)
-			{
-				// sync view with model
-				LLInventoryObject* model_item = model->getObject(*id_it);
-				LLFolderViewItem* view_item = mFolders->getItemByID(*id_it);
-
-				if (model_item)
-				{
-					if (!view_item)
-					{
-						// this object was just created, need to build a view for it
-						if ((mask & LLInventoryObserver::ADD) != LLInventoryObserver::ADD)
-						{
-							llwarns << *id_it << " is in model but not in view, but ADD flag not set" << llendl;
-						}
-						buildNewViews(*id_it);
-						
-						// select any newly created object
-						// that has the auto rename at top of folder
-						// root set
-						if(mFolders->getRoot()->needsAutoRename())
-						{
-							setSelection(*id_it, FALSE);
-						}
-					}
-					else
-					{
-						// this object was probably moved, check its parent
-						if ((mask & LLInventoryObserver::STRUCTURE) != LLInventoryObserver::STRUCTURE)
-						{
-							llwarns << *id_it << " is in model and in view, but STRUCTURE flag not set" << llendl;
-						}
-
-						LLFolderViewFolder* new_parent = (LLFolderViewFolder*)mFolders->getItemByID(model_item->getParentUUID());
-
-						// added check against NULL for cases when Inventory panel contains startFolder.
-						// in this case parent is LLFolderView (LLInventoryPanel::mFolders) itself.
-						// this check is a fix for bug EXT-1859.
-						if (NULL != new_parent && view_item->getParentFolder() != new_parent)
-						{
-							view_item->getParentFolder()->extractItem(view_item);
-							view_item->addToFolder(new_parent, mFolders);
-						}
-					}
-				}
-				else
-				{
-					if (view_item)
-					{
-						if ((mask & LLInventoryObserver::REMOVE) != LLInventoryObserver::REMOVE)
-						{
-							llwarns << *id_it << " is not in model but in view, but REMOVE flag not set" << llendl;
-						}
-						// item in view but not model, need to delete view
-						view_item->destroyView();
-					}
-					else
-					{
-						llwarns << *id_it << "Item does not exist in either view or model, but notification triggered" << llendl;
-					}
-				}
-			}
-		}
-	}
-
-	if (!handled)
-	{
-		// it's a small change that only requires a refresh.
-		// *TODO: figure out a more efficient way to do the refresh
-		// since it is expensive on large inventories
-		mFolders->refresh();
-	}
-}
-
-
-void LLInventoryPanel::rebuildViewsFor(const LLUUID& id)
-{
-	LLFolderViewItem* old_view = NULL;
-
-	// get old LLFolderViewItem
-	old_view = mFolders->getItemByID(id);
-	if (old_view && id.notNull())
-	{
-		old_view->destroyView();
-	}
-
-	buildNewViews(id);
-}
-
-void LLInventoryPanel::buildNewViews(const LLUUID& id)
-{
-	LLMemType mt(LLMemType::MTYPE_INVENTORY_BUILD_NEW_VIEWS);
-	LLFolderViewItem* itemp = NULL;
-	LLInventoryObject* objectp = NULL;
-
-	// Don't add the start folder (the inventory panel will show contents
-	// beginning with the children of the starting folder, excluding the starting folder itself).
-	if (id != mStartFolderID)
-	{
-		objectp = gInventory.getObject(id);
-		if (objectp)
-		{		
-			const LLUUID &parent_id = objectp->getParentUUID();
-			// If this item's parent is the starting folder, then just add it to the top level (recall that 
-			// the starting folder isn't actually represented in the view, parent_folder would be NULL in
-			// this case otherwise).
-			LLFolderViewFolder* parent_folder = (parent_id == mStartFolderID ?
-				mFolders : (LLFolderViewFolder*)mFolders->getItemByID(parent_id));
-
-			// This item exists outside the inventory's hierarchy, so don't add it.
-			if (!parent_folder)
-			{
-				return;
-			}
-
-			if (objectp->getType() <= LLAssetType::AT_NONE ||
-				objectp->getType() >= LLAssetType::AT_COUNT)
-			{
-				llwarns << "LLInventoryPanel::buildNewViews called with invalid objectp->mType : " << 
-					((S32) objectp->getType()) << llendl;
-				return;
-			}
-			
-			if (objectp->getType() == LLAssetType::AT_CATEGORY &&
-					 objectp->getActualType() != LLAssetType::AT_LINK_FOLDER) 
-			{
-				LLInvFVBridge* new_listener = mInvFVBridgeBuilder->createBridge(objectp->getType(),
-																				objectp->getType(),
-																				LLInventoryType::IT_CATEGORY,
-																				this,
-																				objectp->getUUID());
-
-				if (new_listener)
-				{
-					LLFolderViewFolder::Params p;
-					p.name = new_listener->getDisplayName();
-					p.icon = new_listener->getIcon();
-					p.root = mFolders;
-					p.listener = new_listener;
-					LLFolderViewFolder* folderp = LLUICtrlFactory::create<LLFolderViewFolder>(p);
-				
-					folderp->setItemSortOrder(mFolders->getSortOrder());
-					itemp = folderp;
-				}
-			}
-			else 
-			{
-				// Build new view for item
-				LLInventoryItem* item = (LLInventoryItem*)objectp;
-				LLInvFVBridge* new_listener = mInvFVBridgeBuilder->createBridge(item->getType(),
-																				item->getActualType(),
-																				item->getInventoryType(),
-																				this,
-																				item->getUUID(),
-																				item->getFlags());
-
-				if (new_listener)
-				{
-					LLFolderViewItem::Params params;
-					params.name(new_listener->getDisplayName());
-					params.icon(new_listener->getIcon());
-					params.creation_date(new_listener->getCreationDate());
-					params.root(mFolders);
-					params.listener(new_listener);
-					params.rect(LLRect (0, 0, 0, 0));
-					itemp = LLUICtrlFactory::create<LLFolderViewItem> (params);
-				}
-			}
-
-			if (itemp)
-			{
-				itemp->addToFolder(parent_folder, mFolders);
-			}
-		}
-	}
-
-	// If this is a folder, add the children of the folder and recursively add any 
-	// child folders.
-	if ((id == mStartFolderID) ||
-		(objectp && objectp->getType() == LLAssetType::AT_CATEGORY))
-	{
-		LLViewerInventoryCategory::cat_array_t* categories;
-		LLViewerInventoryItem::item_array_t* items;
-
-		mInventory->lockDirectDescendentArrays(id, categories, items);
-		if(categories)
-		{
-			S32 count = categories->count();
-			for(S32 i = 0; i < count; ++i)
-			{
-				LLInventoryCategory* cat = categories->get(i);
-				buildNewViews(cat->getUUID());
-			}
-		}
-		if(items)
-		{
-			S32 count = items->count();
-			for(S32 i = 0; i < count; ++i)
-			{
-				LLInventoryItem* item = items->get(i);
-				buildNewViews(item->getUUID());
-			}
-		}
-		mInventory->unlockDirectDescendentArrays(id);
-	}
-}
-
-struct LLConfirmPurgeData
-{
-	LLUUID mID;
-	LLInventoryModel* mModel;
-};
-
-class LLIsNotWorn : public LLInventoryCollectFunctor
-{
-public:
-	LLIsNotWorn() {}
-	virtual ~LLIsNotWorn() {}
-	virtual bool operator()(LLInventoryCategory* cat,
-							LLInventoryItem* item)
-	{
-		return !gAgentWearables.isWearingItem(item->getUUID());
-	}
-};
-
-class LLOpenFolderByID : public LLFolderViewFunctor
-{
-public:
-	LLOpenFolderByID(const LLUUID& id) : mID(id) {}
-	virtual ~LLOpenFolderByID() {}
-	virtual void doFolder(LLFolderViewFolder* folder)
-		{
-			if (folder->getListener() && folder->getListener()->getUUID() == mID) folder->setOpenArrangeRecursively(TRUE, LLFolderViewFolder::RECURSE_UP);
-		}
-	virtual void doItem(LLFolderViewItem* item) {}
-protected:
-	const LLUUID& mID;
-};
-
-
-void LLInventoryPanel::openSelected()
-{
-	LLFolderViewItem* folder_item = mFolders->getCurSelectedItem();
-	if(!folder_item) return;
-	LLInvFVBridge* bridge = (LLInvFVBridge*)folder_item->getListener();
-	if(!bridge) return;
-	bridge->openItem();
-}
-
-BOOL LLInventoryPanel::handleHover(S32 x, S32 y, MASK mask)
-{
-	BOOL handled = LLView::handleHover(x, y, mask);
-	if(handled)
-	{
-		ECursorType cursor = getWindow()->getCursor();
-		if (LLInventoryModel::backgroundFetchActive() && cursor == UI_CURSOR_ARROW)
-		{
-			// replace arrow cursor with arrow and hourglass cursor
-			getWindow()->setCursor(UI_CURSOR_WORKING);
-		}
-	}
-	else
-	{
-		getWindow()->setCursor(UI_CURSOR_ARROW);
-	}
-	return TRUE;
-}
-
-BOOL LLInventoryPanel::handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop,
-								   EDragAndDropType cargo_type,
-								   void* cargo_data,
-								   EAcceptance* accept,
-								   std::string& tooltip_msg)
-{
-
-	BOOL handled = LLPanel::handleDragAndDrop(x, y, mask, drop, cargo_type, cargo_data, accept, tooltip_msg);
-
-	if (handled)
-	{
-		mFolders->setDragAndDropThisFrame();
-	}
-
-	return handled;
-}
-
-void LLInventoryPanel::onFocusLost()
-{
-	// inventory no longer handles cut/copy/paste/delete
-	if (LLEditMenuHandler::gEditMenuHandler == mFolders)
-	{
-		LLEditMenuHandler::gEditMenuHandler = NULL;
-	}
-
-	LLPanel::onFocusLost();
-}
-
-void LLInventoryPanel::onFocusReceived()
-{
-	// inventory now handles cut/copy/paste/delete
-	LLEditMenuHandler::gEditMenuHandler = mFolders;
-
-	LLPanel::onFocusReceived();
-}
-
-
-void LLInventoryPanel::openAllFolders()
-{
-	mFolders->setOpenArrangeRecursively(TRUE, LLFolderViewFolder::RECURSE_DOWN);
-	mFolders->arrangeAll();
-}
-
-void LLInventoryPanel::openDefaultFolderForType(LLAssetType::EType type)
-{
-	LLUUID category_id = mInventory->findCategoryUUIDForType(type);
-	LLOpenFolderByID opener(category_id);
-	mFolders->applyFunctorRecursively(opener);
-}
-
-void LLInventoryPanel::setSelection(const LLUUID& obj_id, BOOL take_keyboard_focus)
-{
-	// Don't select objects in COF (e.g. to prevent refocus when items are worn).
-	const LLInventoryObject *obj = gInventory.getObject(obj_id);
-	if (obj && obj->getParentUUID() == LLAppearanceManager::getCOF())
-	{
-		return;
-	}
-	mFolders->setSelectionByID(obj_id, take_keyboard_focus);
-}
-
-void LLInventoryPanel::clearSelection()
-{
-	mFolders->clearSelection();
-}
-
-void LLInventoryPanel::onSelectionChange(const std::deque<LLFolderViewItem*>& items, BOOL user_action)
-{
-	LLFolderView* fv = getRootFolder();
-	if (fv->needsAutoRename()) // auto-selecting a new user-created asset and preparing to rename
-	{
-		fv->setNeedsAutoRename(FALSE);
-		if (items.size()) // new asset is visible and selected
-		{
-			fv->startRenamingSelectedItem();
-		}
-	}
-	// Seraph - Put determineFolderType in here for ensemble typing?
-}
-
-//----------------------------------------------------------------------------
-
-void LLInventoryPanel::doToSelected(const LLSD& userdata)
-{
-	mFolders->doToSelected(&gInventory, userdata);
-}
-
-void LLInventoryPanel::doCreate(const LLSD& userdata)
-{
-	menu_create_inventory_item(mFolders, LLFolderBridge::sSelf, userdata);
-}
-
-bool LLInventoryPanel::beginIMSession()
-{
-	std::set<LLUUID> selected_items;
-	mFolders->getSelectionList(selected_items);
-
-	std::string name;
-	static int session_num = 1;
-
-	LLDynamicArray<LLUUID> members;
-	EInstantMessage type = IM_SESSION_CONFERENCE_START;
-
-	std::set<LLUUID>::const_iterator iter;
-	for (iter = selected_items.begin(); iter != selected_items.end(); iter++)
-	{
-
-		LLUUID item = *iter;
-		LLFolderViewItem* folder_item = mFolders->getItemByID(item);
-			
-		if(folder_item) 
-		{
-			LLFolderViewEventListener* fve_listener = folder_item->getListener();
-			if (fve_listener && (fve_listener->getInventoryType() == LLInventoryType::IT_CATEGORY))
-			{
-
-				LLFolderBridge* bridge = (LLFolderBridge*)folder_item->getListener();
-				if(!bridge) return true;
-				LLViewerInventoryCategory* cat = bridge->getCategory();
-				if(!cat) return true;
-				name = cat->getName();
-				LLUniqueBuddyCollector is_buddy;
-				LLInventoryModel::cat_array_t cat_array;
-				LLInventoryModel::item_array_t item_array;
-				gInventory.collectDescendentsIf(bridge->getUUID(),
-												cat_array,
-												item_array,
-												LLInventoryModel::EXCLUDE_TRASH,
-												is_buddy);
-				S32 count = item_array.count();
-				if(count > 0)
-				{
-					LLFloaterReg::showInstance("communicate");
-					// create the session
-					LLAvatarTracker& at = LLAvatarTracker::instance();
-					LLUUID id;
-					for(S32 i = 0; i < count; ++i)
-					{
-						id = item_array.get(i)->getCreatorUUID();
-						if(at.isBuddyOnline(id))
-						{
-							members.put(id);
-						}
-					}
-				}
-			}
-			else
-			{
-				LLFolderViewItem* folder_item = mFolders->getItemByID(item);
-				if(!folder_item) return true;
-				LLInvFVBridge* listenerp = (LLInvFVBridge*)folder_item->getListener();
-
-				if (listenerp->getInventoryType() == LLInventoryType::IT_CALLINGCARD)
-				{
-					LLInventoryItem* inv_item = gInventory.getItem(listenerp->getUUID());
-
-					if (inv_item)
-					{
-						LLAvatarTracker& at = LLAvatarTracker::instance();
-						LLUUID id = inv_item->getCreatorUUID();
-
-						if(at.isBuddyOnline(id))
-						{
-							members.put(id);
-						}
-					}
-				} //if IT_CALLINGCARD
-			} //if !IT_CATEGORY
-		}
-	} //for selected_items	
-
-	// the session_id is randomly generated UUID which will be replaced later
-	// with a server side generated number
-
-	if (name.empty())
-	{
-		name = llformat("Session %d", session_num++);
-	}
-
-	gIMMgr->addSession(name, type, members[0], members);
-		
-	return true;
-}
-
-bool LLInventoryPanel::attachObject(const LLSD& userdata)
-{
-	std::set<LLUUID> selected_items;
-	mFolders->getSelectionList(selected_items);
-
-	std::string joint_name = userdata.asString();
-	LLVOAvatar *avatarp = static_cast<LLVOAvatar*>(gAgent.getAvatarObject());
-	LLViewerJointAttachment* attachmentp = NULL;
-	for (LLVOAvatar::attachment_map_t::iterator iter = avatarp->mAttachmentPoints.begin(); 
-		 iter != avatarp->mAttachmentPoints.end(); )
-	{
-		LLVOAvatar::attachment_map_t::iterator curiter = iter++;
-		LLViewerJointAttachment* attachment = curiter->second;
-		if (attachment->getName() == joint_name)
-		{
-			attachmentp = attachment;
-			break;
-		}
-	}
-	if (attachmentp == NULL)
-	{
-		return true;
-	}
-
-	for (std::set<LLUUID>::const_iterator set_iter = selected_items.begin(); 
-		 set_iter != selected_items.end(); 
-		 ++set_iter)
-	{
-		const LLUUID &id = *set_iter;
-		LLViewerInventoryItem* item = (LLViewerInventoryItem*)gInventory.getItem(id);
-		if(item && gInventory.isObjectDescendentOf(id, gInventory.getRootFolderID()))
-		{
-			rez_attachment(item, attachmentp);
-		}
-		else if(item && item->isComplete())
-		{
-			// must be in library. copy it to our inventory and put it on.
-			LLPointer<LLInventoryCallback> cb = new RezAttachmentCallback(attachmentp);
-			copy_inventory_item(gAgent.getID(),
-								item->getPermissions().getOwner(),
-								item->getUUID(),
-								LLUUID::null,
-								std::string(),
-								cb);
-		}
-	}
-	gFocusMgr.setKeyboardFocus(NULL);
-
-	return true;
-}
-
-
-//----------------------------------------------------------------------------
-
-// static DEBUG ONLY:
-void LLInventoryPanel::dumpSelectionInformation(void* user_data)
-{
-	LLInventoryPanel* iv = (LLInventoryPanel*)user_data;
-	iv->mFolders->dumpSelectionInformation();
-}
-
-BOOL LLInventoryPanel::getSinceLogoff()
-{
-	return mFolders->getFilter()->isSinceLogoff();
-}
-
-void example_param_block_usage()
-{
-	LLInventoryPanel::Params param_block;
-	param_block.name(std::string("inventory"));
-
-	param_block.sort_order_setting(LLInventoryPanel::RECENTITEMS_SORT_ORDER);
-	param_block.allow_multi_select(true);
-	param_block.filter(LLInventoryPanel::Filter()
-			.sort_order(1)
-			.types(0xffff0000));
-	param_block.inventory(&gInventory);
-	param_block.has_border(true);
-
-	LLUICtrlFactory::create<LLInventoryPanel>(param_block);
-
-	param_block = LLInventoryPanel::Params();
-	param_block.name(std::string("inventory"));
-
-	//LLSD param_block_sd;
-	//param_block_sd["sort_order_setting"] = LLInventoryPanel::RECENTITEMS_SORT_ORDER;
-	//param_block_sd["allow_multi_select"] = true;
-	//param_block_sd["filter"]["sort_order"] = 1;
-	//param_block_sd["filter"]["types"] = (S32)0xffff0000;
-	//param_block_sd["has_border"] = true;
-
-	//LLInitParam::LLSDParser(param_block_sd).parse(param_block);
-
-	LLUICtrlFactory::create<LLInventoryPanel>(param_block);
-}
+/** 
+ * @file llfloaterinventory.cpp
+ * @brief Implementation of the inventory view and associated stuff.
+ *
+ * $LicenseInfo:firstyear=2001&license=viewergpl$
+ * 
+ * Copyright (c) 2001-2009, Linden Research, Inc.
+ * 
+ * Second Life Viewer Source Code
+ * The source code in this file ("Source Code") is provided by Linden Lab
+ * to you under the terms of the GNU General Public License, version 2.0
+ * ("GPL"), unless you have obtained a separate licensing agreement
+ * ("Other License"), formally executed by you and Linden Lab.  Terms of
+ * the GPL can be found in doc/GPL-license.txt in this distribution, or
+ * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
+ * 
+ * There are special exceptions to the terms and conditions of the GPL as
+ * it is applied to this Source Code. View the full text of the exception
+ * in the file doc/FLOSS-exception.txt in this software distribution, or
+ * online at
+ * http://secondlifegrid.net/programs/open_source/licensing/flossexception
+ * 
+ * By copying, modifying or distributing this software, you acknowledge
+ * that you have read and understood your obligations described above,
+ * and agree to abide by those obligations.
+ * 
+ * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
+ * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
+ * COMPLETENESS OR PERFORMANCE.
+ * $/LicenseInfo$
+ */
+
+#include "llviewerprecompiledheaders.h"
+
+#include "llfloaterinventory.h"
+
+#include "llagent.h"
+#include "llfirstuse.h"
+#include "llfloaterreg.h"
+#include "llinventorymodel.h"
+#include "llpanelmaininventory.h"
+#include "llresmgr.h"
+
+///----------------------------------------------------------------------------
+/// LLFloaterInventory
+///----------------------------------------------------------------------------
+
+LLFloaterInventory::LLFloaterInventory(const LLSD& key)
+	: LLFloater(key)
+{
+}
+
+LLFloaterInventory::~LLFloaterInventory()
+{
+}
+
+BOOL LLFloaterInventory::postBuild()
+{
+	mPanelMainInventory = getChild<LLPanelMainInventory>("Inventory Panel");
+	return TRUE;
+}
+
+
+void LLFloaterInventory::draw()
+{
+ 	if (LLInventoryModel::isEverythingFetched())
+	{
+		updateTitle();
+	}
+	LLFloater::draw();
+}
+
+void LLFloaterInventory::updateTitle()
+{
+	LLLocale locale(LLLocale::USER_LOCALE);
+	std::string item_count_string;
+	LLResMgr::getInstance()->getIntegerString(item_count_string, gInventory.getItemCount());
+
+	LLStringUtil::format_map_t string_args;
+	string_args["[ITEM_COUNT]"] = item_count_string;
+	string_args["[FILTER]"] = mPanelMainInventory->getFilterText();
+
+	if (LLInventoryModel::backgroundFetchActive())
+	{
+		setTitle(getString("TitleFetching", string_args));
+	}
+	else
+	{
+		setTitle(getString("TitleCompleted", string_args));
+	}
+}
+
+void LLFloaterInventory::changed(U32 mask)
+{
+	updateTitle();
+}
+
+LLInventoryPanel* LLFloaterInventory::getPanel()
+{
+	if (mPanelMainInventory)
+		return mPanelMainInventory->getPanel();
+	return NULL;
+}
+
+// static
+LLFloaterInventory* LLFloaterInventory::showAgentInventory()
+{
+	LLFloaterInventory* iv = NULL;
+	if (!gAgent.cameraMouselook())
+	{
+		iv = LLFloaterReg::showTypedInstance<LLFloaterInventory>("inventory", LLSD());
+	}
+	return iv;
+}
+
+// static
+LLFloaterInventory* LLFloaterInventory::getActiveInventory()
+{
+	LLFloaterInventory* res = NULL;
+	LLFloaterReg::const_instance_list_t& inst_list = LLFloaterReg::getFloaterList("inventory");
+	S32 z_min = S32_MAX;
+	for (LLFloaterReg::const_instance_list_t::const_iterator iter = inst_list.begin(); iter != inst_list.end(); ++iter)
+	{
+		LLFloaterInventory* iv = dynamic_cast<LLFloaterInventory*>(*iter);
+		if (iv)
+		{
+			S32 z_order = gFloaterView->getZOrder(iv);
+			if (z_order < z_min)
+			{
+				res = iv;
+				z_min = z_order;
+			}
+		}
+	}
+	return res;
+}
+
+// static
+void LLFloaterInventory::cleanup()
+{
+	LLFloaterReg::const_instance_list_t& inst_list = LLFloaterReg::getFloaterList("inventory");
+	for (LLFloaterReg::const_instance_list_t::const_iterator iter = inst_list.begin(); iter != inst_list.end();)
+	{
+		LLFloaterInventory* iv = dynamic_cast<LLFloaterInventory*>(*iter++);
+		if (iv)
+		{
+			iv->destroy();
+		}
+	}
+}
+
+void LLFloaterInventory::onOpen(const LLSD& key)
+{
+	LLFirstUse::useInventory();
+}
diff --git a/indra/newview/llfloaterinventory.h b/indra/newview/llfloaterinventory.h
index 4c9ac5d4c68..f2f2963a333 100644
--- a/indra/newview/llfloaterinventory.h
+++ b/indra/newview/llfloaterinventory.h
@@ -31,366 +31,54 @@
  * $/LicenseInfo$
  */
 
-#ifndef LL_LLINVENTORYVIEW_H
-#define LL_LLINVENTORYVIEW_H
+#ifndef LL_LLFLOATERINVENTORY_H
+#define LL_LLFLOATERINVENTORY_H
 
-#include "llassetstorage.h"
-#include "lldarray.h"
 #include "llfloater.h"
-#include "llinventory.h"
-#include "llinventoryfilter.h"
-#include "llfolderview.h"
-#include "llinventorymodel.h"
-#include "lluictrlfactory.h"
-#include <set>
 
+class LLInventoryPanel;
+class LLPanelMainInventory;
 
 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 // Class LLFloaterInventory
 //
-// This is the agent inventory _floater_.
-// It deals with the buttons and views used to navigate as
-// well as controls the behavior of the overall object.
+// This deals with the buttons and views used to navigate as
+// well as controlling the behavior of the overall object.
 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-class LLFolderViewItem;
-class LLInventoryFilter;
-class LLInventoryModel;
-class LLInvFVBridge;
-class LLInventoryFVBridgeBuilder;
-class LLMenuBarGL;
-class LLCheckBoxCtrl;
-class LLSpinCtrl;
-class LLScrollContainer;
-class LLTextBox;
-class LLIconCtrl;
-class LLSaveFolderState;
-class LLFilterEditor;
-class LLTabContainer;
-
-class LLInventoryPanel : public LLPanel
+class LLFloaterInventory : public LLFloater
 {
-public:
-	static const std::string DEFAULT_SORT_ORDER;
-	static const std::string RECENTITEMS_SORT_ORDER;
-	static const std::string INHERIT_SORT_ORDER;
-
-	struct Filter : public LLInitParam::Block<Filter>
-	{
-		Optional<U32>			sort_order;
-		Optional<U32>			types;
-		Optional<std::string>	search_string;
-
-		Filter()
-		:	sort_order("sort_order"),
-			types("types", 0xffffffff),
-			search_string("search_string")
-		{}
-	};
-
-	struct Params 
-	:	public LLInitParam::Block<Params, LLPanel::Params>
-	{
-		Optional<std::string>				sort_order_setting;
-		Optional<LLInventoryModel*>			inventory;
-		Optional<bool>						allow_multi_select;
-		Optional<Filter>					filter;
-		Optional<std::string>               start_folder;
-
-		Params()
-		:	sort_order_setting("sort_order_setting"),
-			inventory("", &gInventory),
-			allow_multi_select("allow_multi_select", true),
-			filter("filter"),
-			start_folder("start_folder")
-		{}
-	};
-
-protected:
-	LLInventoryPanel(const Params&);
-	friend class LLUICtrlFactory;
-
-public:
-	virtual ~LLInventoryPanel();
-
-	LLInventoryModel* getModel() { return mInventory; }
-
-	BOOL postBuild();
-
-	// LLView methods
-	void draw();
-	BOOL handleHover(S32 x, S32 y, MASK mask);
-	BOOL handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop,
-								   EDragAndDropType cargo_type,
-								   void* cargo_data,
-								   EAcceptance* accept,
-								   std::string& tooltip_msg);
-	// LLUICtrl methods
-	 /*virtual*/ void onFocusLost();
-	 /*virtual*/ void onFocusReceived();
-
-	// Call this method to set the selection.
-	void openAllFolders();
-	void openDefaultFolderForType(LLAssetType::EType);
-	void setSelection(const LLUUID& obj_id, BOOL take_keyboard_focus);
-	void setSelectCallback(const LLFolderView::signal_t::slot_type& cb) { if (mFolders) mFolders->setSelectCallback(cb); }
-	void clearSelection();
-	LLInventoryFilter* getFilter() { return mFolders->getFilter(); }
-	void setFilterTypes(U64 filter, BOOL filter_for_categories = FALSE); // if filter_for_categories is true, operate on folder preferred asset type
-	U32 getFilterTypes() const { return mFolders->getFilterTypes(); }
-	void setFilterPermMask(PermissionMask filter_perm_mask);
-	U32 getFilterPermMask() const { return mFolders->getFilterPermissions(); }
-	void setFilterSubString(const std::string& string);
-	const std::string getFilterSubString() { return mFolders->getFilterSubString(); }
-	void setSortOrder(U32 order);
-	U32 getSortOrder() { return mFolders->getSortOrder(); }
-	void setSinceLogoff(BOOL sl);
-	void setHoursAgo(U32 hours);
-	BOOL getSinceLogoff();
-	
-	void setShowFolderState(LLInventoryFilter::EFolderShow show);
-	LLInventoryFilter::EFolderShow getShowFolderState();
-	void setAllowMultiSelect(BOOL allow) { mFolders->setAllowMultiSelect(allow); }
-	// This method is called when something has changed about the inventory.
-	void modelChanged(U32 mask);
-	LLFolderView* getRootFolder() { return mFolders; }
-	LLScrollContainer* getScrollableContainer() { return mScroller; }
-	
-	void onSelectionChange(const std::deque<LLFolderViewItem*> &items, BOOL user_action);
-	
-	// Callbacks
-	void doToSelected(const LLSD& userdata);
-	void doCreate(const LLSD& userdata);
-	bool beginIMSession();
-	bool attachObject(const LLSD& userdata);
-	
-	// DEBUG ONLY:
-	static void dumpSelectionInformation(void* user_data);
-
-	void openSelected();
-	void unSelectAll()	{ mFolders->setSelection(NULL, FALSE, FALSE); }
-	
-protected:
-	// Given the id and the parent, build all of the folder views.
-	void rebuildViewsFor(const LLUUID& id);
-	virtual void buildNewViews(const LLUUID& id); // made virtual to support derived classes. EXT-719
-
-protected:
-	LLInventoryModel*			mInventory;
-	LLInventoryObserver*		mInventoryObserver;
-	BOOL 						mAllowMultiSelect;
-	std::string					mSortOrderSetting;
-
-//private: // Can not make these private - needed by llinventorysubtreepanel
-	LLFolderView*				mFolders;
-	std::string                 mStartFolderString;
-
-	/**
-	 * Contains UUID of Inventory item from which hierarchy should be built.
-	 * Can be set with the "start_folder" xml property.
-	 * Default is LLUUID::null that means total Inventory hierarchy.
-	 */
-	LLUUID						mStartFolderID;
-	LLScrollContainer*			mScroller;
-	bool						mHasInventoryConnection;
-
-	/**
-	 * Flag specified if default inventory hierarchy should be created in postBuild()
-	 */
-	bool						mBuildDefaultHierarchy;
-
-	LLUUID						mRootInventoryItemUUID;
-
-	/**
-	 * Pointer to LLInventoryFVBridgeBuilder.
-	 *
-	 * It is set in LLInventoryPanel's constructor and can be overridden in derived classes with 
-	 * another implementation.
-	 * Take into account it will not be deleted by LLInventoryPanel itself.
-	 */
-	const LLInventoryFVBridgeBuilder* mInvFVBridgeBuilder;
-
-};
-
-class LLFloaterInventory;
-
-class LLFloaterInventoryFinder : public LLFloater
-{
-public:
-	LLFloaterInventoryFinder( LLFloaterInventory* inventory_view);
-	virtual void draw();
-	/*virtual*/	BOOL	postBuild();
-	void changeFilter(LLInventoryFilter* filter);
-	void updateElementsFromFilter();
-	BOOL getCheckShowEmpty();
-	BOOL getCheckSinceLogoff();
-
-	static void onTimeAgo(LLUICtrl*, void *);
-	static void onCheckSinceLogoff(LLUICtrl*, void *);
-	static void onCloseBtn(void* user_data);
-	static void selectAllTypes(void* user_data);
-	static void selectNoTypes(void* user_data);
-
-protected:
-	LLFloaterInventory*	mFloaterInventory;
-	LLSpinCtrl*			mSpinSinceDays;
-	LLSpinCtrl*			mSpinSinceHours;
-	LLInventoryFilter*	mFilter;
-};
-
-class LLFloaterInventory : public LLFloater, LLInventoryObserver
-{
-friend class LLFloaterInventoryFinder;
-
 public:
 	LLFloaterInventory(const LLSD& key);
 	~LLFloaterInventory();
 
-	/*virtual*/ void changed(U32 mask);
-
-	 BOOL postBuild();
-
-	//
-	// Misc functions
-	//
-	void setFilterTextFromFilter() { mFilterText = mActivePanel->getFilter()->getFilterText(); }
-	void startSearch();
-	
-	// This method makes sure that an inventory view exists, is
-	// visible, and has focus. The view chosen is returned.
-	static LLFloaterInventory* showAgentInventory();
+	BOOL postBuild();
 
 	// Return the active inventory view if there is one. Active is
 	// defined as the inventory that is the closest to the front, and
 	// is visible.
 	static LLFloaterInventory* getActiveInventory();
 
-	// This method calls showAgentInventory() if no views are visible,
-	// or hides/destroyes them all if any are visible.
-	static void toggleVisibility();
-	static void toggleVisibility(void*) { toggleVisibility(); }
+	// This method makes sure that an inventory view exists, is
+	// visible, and has focus. The view chosen is returned.
+	static LLFloaterInventory* showAgentInventory();
 
 	// Final cleanup, destroy all open inventory views.
 	static void cleanup();
 
-	// LLView & LLFloater functionality
-	virtual void onOpen(const LLSD& key);
-	virtual void draw();
-	virtual BOOL handleKeyHere(KEY key, MASK mask);
-
-	BOOL handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop,
-		EDragAndDropType cargo_type,
-		void* cargo_data,
-		EAcceptance* accept,
-		std::string& tooltip_msg);
-
-
-	LLInventoryPanel* getPanel() { return mActivePanel; }
-	LLInventoryPanel* getActivePanel() { return mActivePanel; }
-
-	static BOOL filtersVisible(void* user_data);
-	void onClearSearch();
-	static void onFoldersByName(void *user_data);
-	static BOOL checkFoldersByName(void *user_data);
-	void onFilterEdit(const std::string& search_string );
-	static BOOL incrementalFind(LLFolderViewItem* first_item, const char *find_text, BOOL backward);
-	void onFilterSelected();
-
-	const std::string getFilterSubString() { return mActivePanel->getFilterSubString(); }
-	void setFilterSubString(const std::string& string) { mActivePanel->setFilterSubString(string); }
-	
-	// menu callbacks
-	void doToSelected(const LLSD& userdata);
-	void closeAllFolders();
-	void doCreate(const LLSD& userdata);
-	void resetFilters();
-	void setSortBy(const LLSD& userdata);
-	
-	// HACK: Until we can route this info through the instant message hierarchy
-	static BOOL sWearNewClothing;
-	static LLUUID sWearNewClothingTransactionID;	// wear all clothing in this transaction
-
-	void toggleFindOptions();
-
-	LLFloaterInventoryFinder* getFinder() { return (LLFloaterInventoryFinder*)mFinderHandle.get(); }
+	// Inherited functionality
+	/*virtual*/ void changed(U32 mask);
+	/*virtual*/ void draw();
+	/*virtual*/ void onOpen(const LLSD& key);
 
+	LLInventoryPanel* getPanel();
 protected:
-	LLFilterEditor*				mFilterEditor;
-	LLTabContainer*				mFilterTabs;
-	LLHandle<LLFloater>			mFinderHandle;
-	LLInventoryPanel*			mActivePanel;
-	LLSaveFolderState*			mSavedFolderState;
-
-	std::string					mFilterText;
-
-private:
 	void updateTitle();
+private:
+	LLPanelMainInventory* mPanelMainInventory;
 };
 
-class LLSelectFirstFilteredItem : public LLFolderViewFunctor
-{
-public:
-	LLSelectFirstFilteredItem() : mItemSelected(FALSE) {}
-	virtual ~LLSelectFirstFilteredItem() {}
-	virtual void doFolder(LLFolderViewFolder* folder);
-	virtual void doItem(LLFolderViewItem* item);
-	BOOL wasItemSelected() { return mItemSelected; }
-protected:
-	BOOL	mItemSelected;
-};
-
-class LLOpenFilteredFolders : public LLFolderViewFunctor
-{
-public:
-	LLOpenFilteredFolders()  {}
-	virtual ~LLOpenFilteredFolders() {}
-	virtual void doFolder(LLFolderViewFolder* folder);
-	virtual void doItem(LLFolderViewItem* item);
-};
-
-class LLSaveFolderState : public LLFolderViewFunctor
-{
-public:
-	LLSaveFolderState() : mApply(FALSE) {}
-	virtual ~LLSaveFolderState() {}
-	virtual void doFolder(LLFolderViewFolder* folder);
-	virtual void doItem(LLFolderViewItem* item) {}
-	void setApply(BOOL apply);
-	void clearOpenFolders() { mOpenFolders.clear(); }
-protected:
-	std::set<LLUUID> mOpenFolders;
-	BOOL mApply;
-};
-
-class LLOpenFoldersWithSelection : public LLFolderViewFunctor
-{
-public:
-	LLOpenFoldersWithSelection() {}
-	virtual ~LLOpenFoldersWithSelection() {}
-	virtual void doFolder(LLFolderViewFolder* folder);
-	virtual void doItem(LLFolderViewItem* item);
-};
-
-///----------------------------------------------------------------------------
-/// Function declarations, constants, enums, and typedefs
-///----------------------------------------------------------------------------
-
-// useful functions with the inventory view
-
-class LLInventoryCategory;
-class LLInventoryItem;
-
-const std::string& get_item_icon_name(LLAssetType::EType asset_type,
-							 LLInventoryType::EType inventory_type,
-							 U32 attachment_point, 
-							 BOOL item_is_multi );
-
-LLUIImagePtr get_item_icon(LLAssetType::EType asset_type,
-							 LLInventoryType::EType inventory_type,
-							 U32 attachment_point, 
-							 BOOL item_is_multi );
-
-#endif // LL_LLINVENTORYVIEW_H
+#endif // LL_LLFLOATERINVENTORY_H
 
 
 
diff --git a/indra/newview/llfloateropenobject.cpp b/indra/newview/llfloateropenobject.cpp
index aa82dc34b74..b6ec0868cfd 100644
--- a/indra/newview/llfloateropenobject.cpp
+++ b/indra/newview/llfloateropenobject.cpp
@@ -32,7 +32,7 @@
 
 /*
  * Shows the contents of an object.
- * A floater wrapper for llpanelinventory
+ * A floater wrapper for LLPanelObjectInventory
  */
 
 #include "llviewerprecompiledheaders.h"
@@ -47,7 +47,8 @@
 #include "llinventorybridge.h"
 #include "llfloaterinventory.h"
 #include "llinventorymodel.h"
-#include "llpanelinventory.h"
+#include "llinventorypanel.h"
+#include "llpanelobjectinventory.h"
 #include "llfloaterreg.h"
 #include "llselectmgr.h"
 #include "lluiconstants.h"
@@ -58,7 +59,7 @@
 
 LLFloaterOpenObject::LLFloaterOpenObject(const LLSD& key)
 :	LLFloater(key),
-	mPanelInventory(NULL),
+	mPanelInventoryObject(NULL),
 	mDirty(TRUE)
 {
 //	LLUICtrlFactory::getInstance()->buildFloater(this,"floater_openobject.xml");
@@ -74,7 +75,7 @@ LLFloaterOpenObject::~LLFloaterOpenObject()
 BOOL LLFloaterOpenObject::postBuild()
 {
 	childSetTextArg("object_name", "[DESC]", std::string("Object") ); // *Note: probably do not want to translate this
-	mPanelInventory = getChild<LLPanelInventory>("object_contents");
+	mPanelInventoryObject = getChild<LLPanelObjectInventory>("object_contents");
 	return TRUE;
 }
 
@@ -96,7 +97,7 @@ void LLFloaterOpenObject::onOpen(const LLSD& key)
 }
 void LLFloaterOpenObject::refresh()
 {
-	mPanelInventory->refresh();
+	mPanelInventoryObject->refresh();
 
 	std::string name;
 	BOOL enabled;
diff --git a/indra/newview/llfloateropenobject.h b/indra/newview/llfloateropenobject.h
index a61cc04941f..10d96b7ea3a 100644
--- a/indra/newview/llfloateropenobject.h
+++ b/indra/newview/llfloateropenobject.h
@@ -41,7 +41,7 @@
 #include "llfloater.h"
 
 class LLObjectSelection;
-class LLPanelInventory;
+class LLPanelObjectInventory;
 
 class LLFloaterOpenObject
 : public LLFloater
@@ -77,7 +77,7 @@ class LLFloaterOpenObject
 	
 protected:
 
-	LLPanelInventory*	mPanelInventory;
+	LLPanelObjectInventory*	mPanelInventoryObject;
 	LLSafeHandle<LLObjectSelection> mObjectSelection;
 	BOOL mDirty;
 };
diff --git a/indra/newview/llfloatertools.cpp b/indra/newview/llfloatertools.cpp
index 3bec6f9e734..9c13e90d2cb 100644
--- a/indra/newview/llfloatertools.cpp
+++ b/indra/newview/llfloatertools.cpp
@@ -53,7 +53,7 @@
 #include "llpanelcontents.h"
 #include "llpanelface.h"
 #include "llpanelland.h"
-#include "llpanelinventory.h"
+#include "llpanelobjectinventory.h"
 #include "llpanelobject.h"
 #include "llpanelvolume.h"
 #include "llpanelpermissions.h"
diff --git a/indra/newview/llfolderview.cpp b/indra/newview/llfolderview.cpp
index de18e747528..a963c96da43 100644
--- a/indra/newview/llfolderview.cpp
+++ b/indra/newview/llfolderview.cpp
@@ -38,6 +38,7 @@
 #include "llinventorybridge.h"
 #include "llinventoryclipboard.h" // *TODO: remove this once hack below gone.
 #include "llinventoryfilter.h"
+#include "llinventoryfunctions.h"
 #include "llfoldertype.h"
 #include "llfloaterinventory.h"// hacked in for the bonus context menu items.
 #include "llkeyboard.h"
diff --git a/indra/newview/llimpanel.cpp b/indra/newview/llimpanel.cpp
index 77ee90f6812..fdbbf2f189f 100644
--- a/indra/newview/llimpanel.cpp
+++ b/indra/newview/llimpanel.cpp
@@ -70,6 +70,7 @@
 #include "llpanelimcontrolpanel.h"
 #include "llrecentpeople.h"
 #include "llresmgr.h"
+#include "lltooldraganddrop.h"
 #include "lltrans.h"
 #include "lltabcontainer.h"
 #include "llviewertexteditor.h"
diff --git a/indra/newview/llinventorybridge.cpp b/indra/newview/llinventorybridge.cpp
index 3aa35d98f83..55e102b8f34 100644
--- a/indra/newview/llinventorybridge.cpp
+++ b/indra/newview/llinventorybridge.cpp
@@ -1,5139 +1,5149 @@
-/** 
- * @file llinventorybridge.cpp
- * @brief Implementation of the Inventory-Folder-View-Bridge classes.
- *
- * $LicenseInfo:firstyear=2001&license=viewergpl$
- * 
- * Copyright (c) 2001-2009, Linden Research, Inc.
- * 
- * Second Life Viewer Source Code
- * The source code in this file ("Source Code") is provided by Linden Lab
- * to you under the terms of the GNU General Public License, version 2.0
- * ("GPL"), unless you have obtained a separate licensing agreement
- * ("Other License"), formally executed by you and Linden Lab.  Terms of
- * the GPL can be found in doc/GPL-license.txt in this distribution, or
- * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
- * 
- * There are special exceptions to the terms and conditions of the GPL as
- * it is applied to this Source Code. View the full text of the exception
- * in the file doc/FLOSS-exception.txt in this software distribution, or
- * online at
- * http://secondlifegrid.net/programs/open_source/licensing/flossexception
- * 
- * By copying, modifying or distributing this software, you acknowledge
- * that you have read and understood your obligations described above,
- * and agree to abide by those obligations.
- * 
- * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
- * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
- * COMPLETENESS OR PERFORMANCE.
- * $/LicenseInfo$
- */
-
-#include "llviewerprecompiledheaders.h"
-
-#include <utility> // for std::pair<>
-
-#include "llfloaterinventory.h"
-#include "llinventorybridge.h"
-
-#include "message.h"
-
-#include "llagent.h"
-#include "llagentwearables.h"
-#include "llcallingcard.h"
-#include "llcheckboxctrl.h"		// for radio buttons
-#include "llfloaterreg.h"
-#include "llradiogroup.h"
-#include "llspinctrl.h"
-#include "lltextbox.h"
-#include "llui.h"
-
-#include "llviewercontrol.h"
-#include "llfirstuse.h"
-#include "llfoldertype.h"
-#include "llfloaterchat.h"
-#include "llfloatercustomize.h"
-#include "llfloaterproperties.h"
-#include "llfloaterworldmap.h"
-#include "llfocusmgr.h"
-#include "llfolderview.h"
-#include "llfriendcard.h"
-#include "llavataractions.h"
-#include "llgesturemgr.h"
-#include "lliconctrl.h"
-#include "llinventorymodel.h"
-#include "llinventoryclipboard.h"
-#include "lllineeditor.h"
-#include "llmenugl.h"
-#include "llpreviewanim.h"
-#include "llpreviewgesture.h"
-#include "llpreviewnotecard.h"
-#include "llpreviewscript.h"
-#include "llpreviewsound.h"
-#include "llpreviewtexture.h"
-#include "llresmgr.h"
-#include "llscrollcontainer.h"
-#include "llimview.h"
-#include "lltooldraganddrop.h"
-#include "llviewertexturelist.h"
-#include "llviewerinventory.h"
-#include "llviewerobjectlist.h"
-#include "llviewerwindow.h"
-#include "llvoavatar.h"
-#include "llwearable.h"
-#include "llwearablelist.h"
-#include "llviewermessage.h" 
-#include "llviewerregion.h"
-#include "llvoavatarself.h"
-#include "lltabcontainer.h"
-#include "lluictrlfactory.h"
-#include "llselectmgr.h"
-#include "llsidetray.h"
-#include "llfloateropenobject.h"
-#include "lltrans.h"
-#include "llappearancemgr.h"
-
-using namespace LLOldEvents;
-
-// Helpers
-// bug in busy count inc/dec right now, logic is complex... do we really need it?
-void inc_busy_count()
-{
-// 	gViewerWindow->getWindow()->incBusyCount();
-//  check balance of these calls if this code is changed to ever actually
-//  *do* something!
-}
-void dec_busy_count()
-{
-// 	gViewerWindow->getWindow()->decBusyCount();
-//  check balance of these calls if this code is changed to ever actually
-//  *do* something!
-}
-
-// Function declarations
-void wear_add_inventory_item_on_avatar(LLInventoryItem* item);
-void remove_inventory_category_from_avatar(LLInventoryCategory* category);
-void remove_inventory_category_from_avatar_step2( BOOL proceed, LLUUID category_id);
-bool move_task_inventory_callback(const LLSD& notification, const LLSD& response, LLMoveInv*);
-bool confirm_replace_attachment_rez(const LLSD& notification, const LLSD& response);
-
-std::string ICON_NAME[ICON_NAME_COUNT] =
-{
-	"Inv_Texture",
-	"Inv_Sound",
-	"Inv_CallingCard",
-	"Inv_CallingCard",
-	"Inv_Landmark",
-	"Inv_Landmark",
-	"Inv_Script",
-	"Inv_Clothing",
-	"Inv_Object",
-	"Inv_Object",
-	"Inv_Notecard",
-	"Inv_Skin",
-	"Inv_Snapshot",
-
-	"Inv_BodyShape",
-	"Inv_Skin",
-	"Inv_Hair",
-	"Inv_Eye",
-	"Inv_Shirt",
-	"Inv_Pants",
-	"Inv_Shoe",
-	"Inv_Socks",
-	"Inv_Jacket",
-	"Inv_Gloves",
-	"Inv_Undershirt",
-	"Inv_Underpants",
-	"Inv_Skirt",
-	"inv_item_alpha.tga",
-	"inv_item_tattoo.tga",
-
-	"Inv_Animation",
-	"Inv_Gesture",
-
-	"inv_item_linkitem.tga",
-	"inv_item_linkfolder.tga"
-};
-
-
-// +=================================================+
-// |        LLInventoryPanelObserver                 |
-// +=================================================+
-void LLInventoryPanelObserver::changed(U32 mask)
-{
-	mIP->modelChanged(mask);
-}
-
-
-// +=================================================+
-// |        LLInvFVBridge                            |
-// +=================================================+
-
-LLInvFVBridge::LLInvFVBridge(LLInventoryPanel* inventory, const LLUUID& uuid) :
-mUUID(uuid), mInvType(LLInventoryType::IT_NONE)
-{
-	mInventoryPanel = inventory->getHandle();
-}
-
-const std::string& LLInvFVBridge::getName() const
-{
-	LLInventoryObject* obj = getInventoryObject();
-	if(obj)
-	{
-		return obj->getName();
-	}
-	return LLStringUtil::null;
-}
-
-const std::string& LLInvFVBridge::getDisplayName() const
-{
-	return getName();
-}
-
-// Folders have full perms
-PermissionMask LLInvFVBridge::getPermissionMask() const
-{
-
-	return PERM_ALL;
-}
-
-// virtual
-LLAssetType::EType LLInvFVBridge::getPreferredType() const
-{
-	return LLAssetType::AT_NONE;
-}
-
-
-// Folders don't have creation dates.
-time_t LLInvFVBridge::getCreationDate() const
-{
-	return 0;
-}
-
-// Can be destoryed (or moved to trash)
-BOOL LLInvFVBridge::isItemRemovable()
-{
-	LLInventoryModel* model = getInventoryModel();
-	if(!model) return FALSE;
-	if(model->isObjectDescendentOf(mUUID, gInventory.getRootFolderID()))
-	{
-		return TRUE;
-	}
-	return FALSE;
-}
-
-// Sends an update to all link items that point to the base item.
-void LLInvFVBridge::renameLinkedItems(const LLUUID &item_id, const std::string& new_name)
-{
-	LLInventoryModel* model = getInventoryModel();
-	if(!model) return;
-
-	LLInventoryItem* itemp = model->getItem(mUUID);
-	if (!itemp) return;
-
-	if (itemp->getIsLinkType())
-	{
-		return;
-	}
-	
-	LLInventoryModel::item_array_t item_array = model->collectLinkedItems(item_id);
-	for (LLInventoryModel::item_array_t::iterator iter = item_array.begin();
-		 iter != item_array.end();
-		 iter++)
-	{
-		LLViewerInventoryItem *linked_item = (*iter);
-		if (linked_item->getUUID() == item_id) continue;
-		
-		LLPointer<LLViewerInventoryItem> new_item = new LLViewerInventoryItem(linked_item);
-		new_item->rename(new_name);
-		new_item->updateServer(FALSE);
-		model->updateItem(new_item);
-		// model->addChangedMask(LLInventoryObserver::LABEL, linked_item->getUUID());
-	}
-	model->notifyObservers();
-}
-
-// Can be moved to another folder
-BOOL LLInvFVBridge::isItemMovable() const
-{
-	return TRUE;
-}
-
-/*virtual*/
-/**
- * @brief Adds this item into clipboard storage
- */
-void LLInvFVBridge::cutToClipboard()
-{
-	if(isItemMovable())
-	{
-		LLInventoryClipboard::instance().cut(mUUID);
-	}
-}
-// *TODO: make sure this does the right thing
-void LLInvFVBridge::showProperties()
-{
-	LLFloaterReg::showInstance("properties", mUUID);
-}
-
-void LLInvFVBridge::removeBatch(LLDynamicArray<LLFolderViewEventListener*>& batch)
-{
-	// Deactivate gestures when moving them into Trash
-	LLInvFVBridge* bridge;
-	LLInventoryModel* model = getInventoryModel();
-	LLViewerInventoryItem* item = NULL;
-	LLViewerInventoryCategory* cat = NULL;
-	LLInventoryModel::cat_array_t	descendent_categories;
-	LLInventoryModel::item_array_t	descendent_items;
-	S32 count = batch.count();
-	S32 i,j;
-	for(i = 0; i < count; ++i)
-	{	
-		bridge = (LLInvFVBridge*)(batch.get(i));
-		if(!bridge || !bridge->isItemRemovable()) continue;
-		item = (LLViewerInventoryItem*)model->getItem(bridge->getUUID());
-		if (item)
-		{
-			if(LLAssetType::AT_GESTURE == item->getType())
-			{
-				LLGestureManager::instance().deactivateGesture(item->getUUID());
-			}
-		}
-	}
-	for(i = 0; i < count; ++i)
-	{		
-		bridge = (LLInvFVBridge*)(batch.get(i));
-		if(!bridge || !bridge->isItemRemovable()) continue;
-		cat = (LLViewerInventoryCategory*)model->getCategory(bridge->getUUID());
-		if (cat)
-		{
-			gInventory.collectDescendents( cat->getUUID(), descendent_categories, descendent_items, FALSE );
-			for (j=0; j<descendent_items.count(); j++)
-			{
-				if(LLAssetType::AT_GESTURE == descendent_items[j]->getType())
-				{
-					LLGestureManager::instance().deactivateGesture(descendent_items[j]->getUUID());
-				}
-			}
-		}
-	}
-	removeBatchNoCheck(batch);
-}
-
-void LLInvFVBridge::removeBatchNoCheck(LLDynamicArray<LLFolderViewEventListener*>& batch)
-{
-	// this method moves a bunch of items and folders to the trash. As
-	// per design guidelines for the inventory model, the message is
-	// built and the accounting is performed first. After all of that,
-	// we call LLInventoryModel::moveObject() to move everything
-	// around.
-	LLInvFVBridge* bridge;
-	LLInventoryModel* model = getInventoryModel();
-	if(!model) return;
-	LLMessageSystem* msg = gMessageSystem;
-	LLUUID trash_id = model->findCategoryUUIDForType(LLAssetType::AT_TRASH);
-	LLViewerInventoryItem* item = NULL;
-	LLViewerInventoryCategory* cat = NULL;
-	std::vector<LLUUID> move_ids;
-	LLInventoryModel::update_map_t update;
-	bool start_new_message = true;
-	S32 count = batch.count();
-	S32 i;
-	for(i = 0; i < count; ++i)
-	{
-		bridge = (LLInvFVBridge*)(batch.get(i));
-		if(!bridge || !bridge->isItemRemovable()) continue;
-		item = (LLViewerInventoryItem*)model->getItem(bridge->getUUID());
-		if(item)
-		{
-			if(item->getParentUUID() == trash_id) continue;
-			move_ids.push_back(item->getUUID());
-			LLPreview::hide(item->getUUID());
-			--update[item->getParentUUID()];
-			++update[trash_id];
-			if(start_new_message)
-			{
-				start_new_message = false;
-				msg->newMessageFast(_PREHASH_MoveInventoryItem);
-				msg->nextBlockFast(_PREHASH_AgentData);
-				msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-				msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-				msg->addBOOLFast(_PREHASH_Stamp, TRUE);
-			}
-			msg->nextBlockFast(_PREHASH_InventoryData);
-			msg->addUUIDFast(_PREHASH_ItemID, item->getUUID());
-			msg->addUUIDFast(_PREHASH_FolderID, trash_id);
-			msg->addString("NewName", NULL);
-			if(msg->isSendFullFast(_PREHASH_InventoryData))
-			{
-				start_new_message = true;
-				gAgent.sendReliableMessage();
-				gInventory.accountForUpdate(update);
-				update.clear();
-			}
-		}
-	}
-	if(!start_new_message)
-	{
-		start_new_message = true;
-		gAgent.sendReliableMessage();
-		gInventory.accountForUpdate(update);
-		update.clear();
-	}
-	for(i = 0; i < count; ++i)
-	{
-		bridge = (LLInvFVBridge*)(batch.get(i));
-		if(!bridge || !bridge->isItemRemovable()) continue;
-		cat = (LLViewerInventoryCategory*)model->getCategory(bridge->getUUID());
-		if(cat)
-		{
-			if(cat->getParentUUID() == trash_id) continue;
-			move_ids.push_back(cat->getUUID());
-			--update[cat->getParentUUID()];
-			++update[trash_id];
-			if(start_new_message)
-			{
-				start_new_message = false;
-				msg->newMessageFast(_PREHASH_MoveInventoryFolder);
-				msg->nextBlockFast(_PREHASH_AgentData);
-				msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-				msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-				msg->addBOOL("Stamp", TRUE);
-			}
-			msg->nextBlockFast(_PREHASH_InventoryData);
-			msg->addUUIDFast(_PREHASH_FolderID, cat->getUUID());
-			msg->addUUIDFast(_PREHASH_ParentID, trash_id);
-			if(msg->isSendFullFast(_PREHASH_InventoryData))
-			{
-				start_new_message = true;
-				gAgent.sendReliableMessage();
-				gInventory.accountForUpdate(update);
-				update.clear();
-			}
-		}
-	}
-	if(!start_new_message)
-	{
-		gAgent.sendReliableMessage();
-		gInventory.accountForUpdate(update);
-	}
-
-	// move everything.
-	std::vector<LLUUID>::iterator it = move_ids.begin();
-	std::vector<LLUUID>::iterator end = move_ids.end();
-	for(; it != end; ++it)
-	{
-		gInventory.moveObject((*it), trash_id);
-	}
-
-	// notify inventory observers.
-	model->notifyObservers();
-}
-
-BOOL LLInvFVBridge::isClipboardPasteable() const
-{
-	if (!LLInventoryClipboard::instance().hasContents() || !isAgentInventory())
-	{
-		return FALSE;
-	}
-	LLInventoryModel* model = getInventoryModel();
-	if (!model)
-	{
-		return FALSE;
-	}
-
-	const LLUUID &agent_id = gAgent.getID();
-
-	LLDynamicArray<LLUUID> objects;
-	LLInventoryClipboard::instance().retrieve(objects);
-	S32 count = objects.count();
-	for(S32 i = 0; i < count; i++)
-	{
-		const LLUUID &item_id = objects.get(i);
-
-		// Can't paste folders
-		const LLInventoryCategory *cat = model->getCategory(item_id);
-		if (cat)
-		{
-			return FALSE;
-		}
-
-		const LLInventoryItem *item = model->getItem(item_id);
-		if (item)
-		{
-			if (!item->getPermissions().allowCopyBy(agent_id))
-			{
-				return FALSE;
-			}
-		}
-	}
-	return TRUE;
-}
-
-BOOL LLInvFVBridge::isClipboardPasteableAsLink() const
-{
-	if (!LLInventoryClipboard::instance().hasContents() || !isAgentInventory())
-	{
-		return FALSE;
-	}
-	const LLInventoryModel* model = getInventoryModel();
-	if (!model)
-	{
-		return FALSE;
-	}
-
-	LLDynamicArray<LLUUID> objects;
-	LLInventoryClipboard::instance().retrieve(objects);
-	S32 count = objects.count();
-	for(S32 i = 0; i < count; i++)
-	{
-		const LLInventoryItem *item = model->getItem(objects.get(i));
-		if (item)
-		{
-			if (!LLAssetType::lookupCanLink(item->getActualType()))
-			{
-				return FALSE;
-			}
-		}
-		const LLViewerInventoryCategory *cat = model->getCategory(objects.get(i));
-		if (cat && !LLAssetType::lookupCanLink(cat->getPreferredType()))
-		{
-			return FALSE;
-		}
-	}
-	return TRUE;
-}
-
-void hideContextEntries(LLMenuGL& menu, 
-						const std::vector<std::string> &entries_to_show,
-						const std::vector<std::string> &disabled_entries)
-{
-	const LLView::child_list_t *list = menu.getChildList();
-
-	LLView::child_list_t::const_iterator itor;
-	for (itor = list->begin(); itor != list->end(); ++itor)
-	{
-		std::string name = (*itor)->getName();
-
-		// descend into split menus:
-		LLMenuItemBranchGL* branchp = dynamic_cast<LLMenuItemBranchGL*>(*itor);
-		if ((name == "More") && branchp)
-		{
-			hideContextEntries(*branchp->getBranch(), entries_to_show, disabled_entries);
-		}
-		
-		
-		bool found = false;
-		std::vector<std::string>::const_iterator itor2;
-		for (itor2 = entries_to_show.begin(); itor2 != entries_to_show.end(); ++itor2)
-		{
-			if (*itor2 == name)
-			{
-				found = true;
-			}
-		}
-		if (!found)
-		{
-			(*itor)->setVisible(FALSE);
-		}
-		else
-		{
-			for (itor2 = disabled_entries.begin(); itor2 != disabled_entries.end(); ++itor2)
-			{
-				if (*itor2 == name)
-				{
-					(*itor)->setEnabled(FALSE);
-				}
-			}
-		}
-	}
-}
-
-// Helper for commonly-used entries
-void LLInvFVBridge::getClipboardEntries(bool show_asset_id, 
-										std::vector<std::string> &items, 
-										std::vector<std::string> &disabled_items, U32 flags)
-{
-	items.push_back(std::string("Rename"));
-	if (!isItemRenameable() || (flags & FIRST_SELECTED_ITEM) == 0)
-	{
-		disabled_items.push_back(std::string("Rename"));
-	}
-
-	if (show_asset_id)
-	{
-		items.push_back(std::string("Copy Asset UUID"));
-		if ( (! ( isItemPermissive() || gAgent.isGodlike() ) ) 
-			  || (flags & FIRST_SELECTED_ITEM) == 0)
-		{
-			disabled_items.push_back(std::string("Copy Asset UUID"));
-		}
-	}
-
-	items.push_back(std::string("Copy Separator"));
-
-	items.push_back(std::string("Copy"));
-	if (!isItemCopyable())
-	{
-		disabled_items.push_back(std::string("Copy"));
-	}
-
-	items.push_back(std::string("Paste"));
-	if (!isClipboardPasteable() || (flags & FIRST_SELECTED_ITEM) == 0)
-	{
-		disabled_items.push_back(std::string("Paste"));
-	}
-
-	items.push_back(std::string("Paste As Link"));
-	if (!isClipboardPasteableAsLink() || (flags & FIRST_SELECTED_ITEM) == 0)
-	{
-		disabled_items.push_back(std::string("Paste As Link"));
-	}
-	items.push_back(std::string("Paste Separator"));
-
-	items.push_back(std::string("Delete"));
-	if (!isItemRemovable())
-	{
-		disabled_items.push_back(std::string("Delete"));
-	}
-}
-
-void LLInvFVBridge::buildContextMenu(LLMenuGL& menu, U32 flags)
-{
-	lldebugs << "LLInvFVBridge::buildContextMenu()" << llendl;
-	std::vector<std::string> items;
-	std::vector<std::string> disabled_items;
-	if(isInTrash())
-	{
-		items.push_back(std::string("PurgeItem"));
-		if (!isItemRemovable())
-		{
-			disabled_items.push_back(std::string("PurgeItem"));
-		}
-		items.push_back(std::string("RestoreItem"));
-	}
-	else
-	{
-		items.push_back(std::string("Open"));
-		items.push_back(std::string("Properties"));
-
-		getClipboardEntries(true, items, disabled_items, flags);
-	}
-	hideContextEntries(menu, items, disabled_items);
-}
-
-// *TODO: remove this
-BOOL LLInvFVBridge::startDrag(EDragAndDropType* type, LLUUID* id) const
-{
-	BOOL rv = FALSE;
-
-	const LLInventoryObject* obj = getInventoryObject();
-
-	if(obj)
-	{
-		*type = LLAssetType::lookupDragAndDropType(obj->getActualType());
-		if(*type == DAD_NONE)
-		{
-			return FALSE;
-		}
-		
-		*id = obj->getUUID();
-		//object_ids.put(obj->getUUID());
-
-		if (*type == DAD_CATEGORY)
-		{
-			gInventory.startBackgroundFetch(obj->getUUID());
-		}
-
-		rv = TRUE;
-	}
-
-	return rv;
-}
-
-LLInventoryObject* LLInvFVBridge::getInventoryObject() const
-{
-	LLInventoryObject* obj = NULL;
-	LLInventoryModel* model = getInventoryModel();
-	if(model)
-	{
-		obj = (LLInventoryObject*)model->getObject(mUUID);
-	}
-	return obj;
-}
-
-LLInventoryModel* LLInvFVBridge::getInventoryModel() const
-{
-	LLInventoryPanel* panel = dynamic_cast<LLInventoryPanel*>(mInventoryPanel.get());
-	return panel ? panel->getModel() : NULL;
-}
-
-BOOL LLInvFVBridge::isInTrash() const
-{
-	LLInventoryModel* model = getInventoryModel();
-	if(!model) return FALSE;
-	const LLUUID trash_id = model->findCategoryUUIDForType(LLAssetType::AT_TRASH);
-	return model->isObjectDescendentOf(mUUID, trash_id);
-}
-
-BOOL LLInvFVBridge::isLinkedObjectInTrash() const
-{
-	if (isInTrash()) return TRUE;
-
-	const LLInventoryObject *obj = getInventoryObject();
-	if (obj && obj->getIsLinkType())
-	{
-		LLInventoryModel* model = getInventoryModel();
-		if(!model) return FALSE;
-		const LLUUID trash_id = model->findCategoryUUIDForType(LLAssetType::AT_TRASH);
-		return model->isObjectDescendentOf(obj->getLinkedUUID(), trash_id);
-	}
-	return FALSE;
-}
-
-BOOL LLInvFVBridge::isAgentInventory() const
-{
-	const LLInventoryModel* model = getInventoryModel();
-	if(!model) return FALSE;
-	if(gInventory.getRootFolderID() == mUUID) return TRUE;
-	return model->isObjectDescendentOf(mUUID, gInventory.getRootFolderID());
-}
-
-BOOL LLInvFVBridge::isCOFFolder() const
-{
-	const LLInventoryModel* model = getInventoryModel();
-	if(!model) return TRUE;
-	const LLUUID cof_id = gInventory.findCategoryUUIDForType(LLAssetType::AT_CURRENT_OUTFIT);
-	if (mUUID == cof_id || model->isObjectDescendentOf(mUUID, cof_id))
-	{
-		return TRUE;
-	}
-	return FALSE;
-}
-
-BOOL LLInvFVBridge::isItemPermissive() const
-{
-	return FALSE;
-}
-
-// static
-void LLInvFVBridge::changeItemParent(LLInventoryModel* model,
-									 LLViewerInventoryItem* item,
-									 const LLUUID& new_parent,
-									 BOOL restamp)
-{
-	if(item->getParentUUID() != new_parent)
-	{
-		LLInventoryModel::update_list_t update;
-		LLInventoryModel::LLCategoryUpdate old_folder(item->getParentUUID(),-1);
-		update.push_back(old_folder);
-		LLInventoryModel::LLCategoryUpdate new_folder(new_parent, 1);
-		update.push_back(new_folder);
-		gInventory.accountForUpdate(update);
-
-		LLPointer<LLViewerInventoryItem> new_item = new LLViewerInventoryItem(item);
-		new_item->setParent(new_parent);
-		new_item->updateParentOnServer(restamp);
-		model->updateItem(new_item);
-		model->notifyObservers();
-	}
-}
-
-// static
-void LLInvFVBridge::changeCategoryParent(LLInventoryModel* model,
-										 LLViewerInventoryCategory* cat,
-										 const LLUUID& new_parent,
-										 BOOL restamp)
-{
-	if(cat->getParentUUID() != new_parent)
-	{
-		LLInventoryModel::update_list_t update;
-		LLInventoryModel::LLCategoryUpdate old_folder(cat->getParentUUID(), -1);
-		update.push_back(old_folder);
-		LLInventoryModel::LLCategoryUpdate new_folder(new_parent, 1);
-		update.push_back(new_folder);
-		gInventory.accountForUpdate(update);
-
-		LLPointer<LLViewerInventoryCategory> new_cat = new LLViewerInventoryCategory(cat);
-		new_cat->setParent(new_parent);
-		new_cat->updateParentOnServer(restamp);
-		model->updateCategory(new_cat);
-		model->notifyObservers();
-	}
-}
-
-
-const std::string safe_inv_type_lookup(LLInventoryType::EType inv_type)
-{
-	const std::string rv= LLInventoryType::lookup(inv_type);
-	if(rv.empty())
-	{
-		return std::string("<invalid>");
-	}
-	return rv;
-}
-
-LLInvFVBridge* LLInvFVBridge::createBridge(LLAssetType::EType asset_type,
-										   LLAssetType::EType actual_asset_type,
-										   LLInventoryType::EType inv_type,
-										   LLInventoryPanel* inventory,
-										   const LLUUID& uuid,
-										   U32 flags)
-{
-	LLInvFVBridge* new_listener = NULL;
-	switch(asset_type)
-	{
-		case LLAssetType::AT_TEXTURE:
-			if(!(inv_type == LLInventoryType::IT_TEXTURE || inv_type == LLInventoryType::IT_SNAPSHOT))
-			{
-				llwarns << LLAssetType::lookup(asset_type) << " asset has inventory type " << safe_inv_type_lookup(inv_type) << " on uuid " << uuid << llendl;
-			}
-			new_listener = new LLTextureBridge(inventory, uuid, inv_type);
-			break;
-
-		case LLAssetType::AT_SOUND:
-			if(!(inv_type == LLInventoryType::IT_SOUND))
-			{
-				llwarns << LLAssetType::lookup(asset_type) << " asset has inventory type " << safe_inv_type_lookup(inv_type) << " on uuid " << uuid << llendl;
-			}
-			new_listener = new LLSoundBridge(inventory, uuid);
-			break;
-
-		case LLAssetType::AT_LANDMARK:
-			if(!(inv_type == LLInventoryType::IT_LANDMARK))
-			{
-				llwarns << LLAssetType::lookup(asset_type) << " asset has inventory type " << safe_inv_type_lookup(inv_type) << " on uuid " << uuid << llendl;
-			}
-			new_listener = new LLLandmarkBridge(inventory, uuid, flags);
-			break;
-		
-		case LLAssetType::AT_CALLINGCARD:
-			if(!(inv_type == LLInventoryType::IT_CALLINGCARD))
-			{
-				llwarns << LLAssetType::lookup(asset_type) << " asset has inventory type " << safe_inv_type_lookup(inv_type) << " on uuid " << uuid << llendl;
-			}
-			new_listener = new LLCallingCardBridge(inventory, uuid);
-			break;
-
-		case LLAssetType::AT_SCRIPT:
-			if(!(inv_type == LLInventoryType::IT_LSL))
-			{
-				llwarns << LLAssetType::lookup(asset_type) << " asset has inventory type " << safe_inv_type_lookup(inv_type) << " on uuid " << uuid << llendl;
-			}
-			new_listener = new LLScriptBridge(inventory, uuid);
-			break;
-
-		case LLAssetType::AT_OBJECT:
-			if(!(inv_type == LLInventoryType::IT_OBJECT || inv_type == LLInventoryType::IT_ATTACHMENT))
-			{
-				llwarns << LLAssetType::lookup(asset_type) << " asset has inventory type " << safe_inv_type_lookup(inv_type) << " on uuid " << uuid << llendl;
-			}
-			new_listener = new LLObjectBridge(inventory, uuid, inv_type, flags);
-			break;
-
-		case LLAssetType::AT_NOTECARD:
-			if(!(inv_type == LLInventoryType::IT_NOTECARD))
-			{
-				llwarns << LLAssetType::lookup(asset_type) << " asset has inventory type " << safe_inv_type_lookup(inv_type) << " on uuid " << uuid << llendl;
-			}
-			new_listener = new LLNotecardBridge(inventory, uuid);
-			break;
-
-		case LLAssetType::AT_ANIMATION:
-			if(!(inv_type == LLInventoryType::IT_ANIMATION))
-			{
-				llwarns << LLAssetType::lookup(asset_type) << " asset has inventory type " << safe_inv_type_lookup(inv_type) << " on uuid " << uuid << llendl;
-			}
-			new_listener = new LLAnimationBridge(inventory, uuid);
-			break;
-
-		case LLAssetType::AT_GESTURE:
-			if(!(inv_type == LLInventoryType::IT_GESTURE))
-			{
-				llwarns << LLAssetType::lookup(asset_type) << " asset has inventory type " << safe_inv_type_lookup(inv_type) << " on uuid " << uuid << llendl;
-			}
-			new_listener = new LLGestureBridge(inventory, uuid);
-			break;
-
-		case LLAssetType::AT_LSL_TEXT:
-			if(!(inv_type == LLInventoryType::IT_LSL))
-			{
-				llwarns << LLAssetType::lookup(asset_type) << " asset has inventory type " << safe_inv_type_lookup(inv_type) << " on uuid " << uuid << llendl;
-			}
-			new_listener = new LLLSLTextBridge(inventory, uuid);
-			break;
-
-		case LLAssetType::AT_CLOTHING:
-		case LLAssetType::AT_BODYPART:
-			if(!(inv_type == LLInventoryType::IT_WEARABLE))
-			{
-				llwarns << LLAssetType::lookup(asset_type) << " asset has inventory type " << safe_inv_type_lookup(inv_type) << " on uuid " << uuid << llendl;
-			}
-			new_listener = new LLWearableBridge(inventory, uuid, asset_type, inv_type, (EWearableType)flags);
-			break;
-		case LLAssetType::AT_CATEGORY:
-		case LLAssetType::AT_ROOT_CATEGORY:
-			if (actual_asset_type == LLAssetType::AT_LINK_FOLDER)
-			{
-				// Create a link folder handler instead.
-				new_listener = new LLLinkFolderBridge(inventory, uuid);
-				break;
-			}
-			new_listener = new LLFolderBridge(inventory, uuid);
-			break;
-		case LLAssetType::AT_LINK:
-			// Only should happen for broken links.
-			new_listener = new LLLinkItemBridge(inventory, uuid);
-			break;
-		case LLAssetType::AT_LINK_FOLDER:
-			// Only should happen for broken links.
-			new_listener = new LLLinkItemBridge(inventory, uuid);
-			break;
-		default:
-			llinfos << "Unhandled asset type (llassetstorage.h): "
-					<< (S32)asset_type << llendl;
-			break;
-	}
-
-	if (new_listener)
-	{
-		new_listener->mInvType = inv_type;
-	}
-
-	return new_listener;
-}
-
-void LLInvFVBridge::purgeItem(LLInventoryModel *model, const LLUUID &uuid)
-{
-	LLInventoryCategory* cat = model->getCategory(uuid);
-	if (cat)
-	{
-		model->purgeDescendentsOf(uuid);
-		model->notifyObservers();
-	}
-	LLInventoryObject* obj = model->getObject(uuid);
-	if (obj)
-	{
-		model->purgeObject(uuid);
-		model->notifyObservers();
-	}
-}
-
-// +=================================================+
-// |        InventoryFVBridgeBuilder                 |
-// +=================================================+
-LLInvFVBridge* LLInventoryFVBridgeBuilder::createBridge(LLAssetType::EType asset_type,
-														LLAssetType::EType actual_asset_type,
-														LLInventoryType::EType inv_type,
-														LLInventoryPanel* inventory,
-														const LLUUID& uuid,
-														U32 flags /* = 0x00 */) const
-{
-	return LLInvFVBridge::createBridge(asset_type,
-		actual_asset_type,
-		inv_type,
-		inventory,
-		uuid,
-		flags);
-}
-
-// +=================================================+
-// |        LLItemBridge                             |
-// +=================================================+
-
-void LLItemBridge::performAction(LLFolderView* folder, LLInventoryModel* model, std::string action)
-{
-	if ("goto" == action)
-	{
-		gotoItem(folder);
-	}
-	if ("open" == action)
-	{
-		openItem();
-		return;
-	}
-	else if ("properties" == action)
-	{
-		showProperties();
-		return;
-	}
-	else if ("purge" == action)
-	{
-		purgeItem(model, mUUID);
-		return;
-	}
-	else if ("restoreToWorld" == action)
-	{
-		restoreToWorld();
-		return;
-	}
-	else if ("restore" == action)
-	{
-		restoreItem();
-		return;
-	}
-	else if ("copy_uuid" == action)
-	{
-		// Single item only
-		LLInventoryItem* item = model->getItem(mUUID);
-		if(!item) return;
-		LLUUID asset_id = item->getAssetUUID();
-		std::string buffer;
-		asset_id.toString(buffer);
-
-		gViewerWindow->mWindow->copyTextToClipboard(utf8str_to_wstring(buffer));
-		return;
-	}
-	else if ("copy" == action)
-	{
-		copyToClipboard();
-		return;
-	}
-	else if ("paste" == action)
-	{
-		// Single item only
-		LLInventoryItem* itemp = model->getItem(mUUID);
-		if (!itemp) return;
-
-		LLFolderViewItem* folder_view_itemp = folder->getItemByID(itemp->getParentUUID());
-		if (!folder_view_itemp) return;
-
-		folder_view_itemp->getListener()->pasteFromClipboard();
-		return;
-	}
-	else if ("paste_link" == action)
-	{
-		// Single item only
-		LLInventoryItem* itemp = model->getItem(mUUID);
-		if (!itemp) return;
-
-		LLFolderViewItem* folder_view_itemp = folder->getItemByID(itemp->getParentUUID());
-		if (!folder_view_itemp) return;
-
-		folder_view_itemp->getListener()->pasteLinkFromClipboard();
-		return;
-	}
-}
-
-void LLItemBridge::selectItem()
-{
-	LLViewerInventoryItem* item = (LLViewerInventoryItem*)getItem();
-	if(item && !item->isComplete())
-	{
-		item->fetchFromServer();
-	}
-}
-
-void LLItemBridge::restoreItem()
-{
-	LLViewerInventoryItem* item = (LLViewerInventoryItem*)getItem();
-	if(item)
-	{
-		LLInventoryModel* model = getInventoryModel();
-		const LLUUID new_parent = model->findCategoryUUIDForType(item->getType());
-		// do not restamp on restore.
-		LLInvFVBridge::changeItemParent(model, item, new_parent, FALSE);
-	}
-}
-
-void LLItemBridge::restoreToWorld()
-{
-	LLViewerInventoryItem* itemp = (LLViewerInventoryItem*)getItem();
-	if (itemp)
-	{
-		LLMessageSystem* msg = gMessageSystem;
-		msg->newMessage("RezRestoreToWorld");
-		msg->nextBlockFast(_PREHASH_AgentData);
-		msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-		msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-
-		msg->nextBlockFast(_PREHASH_InventoryData);
-		itemp->packMessage(msg);
-		msg->sendReliable(gAgent.getRegion()->getHost());
-	}
-
-	//Similar functionality to the drag and drop rez logic
-	BOOL remove_from_inventory = FALSE;
-
-	//remove local inventory copy, sim will deal with permissions and removing the item
-	//from the actual inventory if its a no-copy etc
-	if(!itemp->getPermissions().allowCopyBy(gAgent.getID()))
-	{
-		remove_from_inventory = TRUE;
-	}
-
-	// Check if it's in the trash. (again similar to the normal rez logic)
-	const LLUUID trash_id = gInventory.findCategoryUUIDForType(LLAssetType::AT_TRASH);
-	if(gInventory.isObjectDescendentOf(itemp->getUUID(), trash_id))
-	{
-		remove_from_inventory = TRUE;
-	}
-
-	if(remove_from_inventory)
-	{
-		gInventory.deleteObject(itemp->getUUID());
-		gInventory.notifyObservers();
-	}
-}
-
-void LLItemBridge::gotoItem(LLFolderView *folder)
-{
-	LLInventoryObject *obj = getInventoryObject();
-	if (obj && obj->getIsLinkType())
-	{
-		LLInventoryPanel* active_panel = LLFloaterInventory::getActiveInventory()->getPanel();
-		if (active_panel)
-		{
-			active_panel->setSelection(obj->getLinkedUUID(), TAKE_FOCUS_NO);
-		}
-	}
-}
-
-LLUIImagePtr LLItemBridge::getIcon() const
-{
-	return LLUI::getUIImage(ICON_NAME[OBJECT_ICON_NAME]);
-}
-
-PermissionMask LLItemBridge::getPermissionMask() const
-{
-	LLViewerInventoryItem* item = getItem();
-	PermissionMask perm_mask = 0;
-	if(item) 
-	{
-		BOOL copy = item->getPermissions().allowCopyBy(gAgent.getID());
-		BOOL mod = item->getPermissions().allowModifyBy(gAgent.getID());
-		BOOL xfer = item->getPermissions().allowOperationBy(PERM_TRANSFER,
-															gAgent.getID());
-
-		if (copy) perm_mask |= PERM_COPY;
-		if (mod)  perm_mask |= PERM_MODIFY;
-		if (xfer) perm_mask |= PERM_TRANSFER;
-
-	}
-	return perm_mask;
-}
-
-const std::string& LLItemBridge::getDisplayName() const
-{
-	if(mDisplayName.empty())
-	{
-		buildDisplayName(getItem(), mDisplayName);
-	}
-	return mDisplayName;
-}
-
-void LLItemBridge::buildDisplayName(LLInventoryItem* item, std::string& name)
-{
-	if(item) 
-	{
-		name.assign(item->getName());			
-	}
-	else
-	{
-		name.assign(LLStringUtil::null);
-	}
-}
-
-LLFontGL::StyleFlags LLItemBridge::getLabelStyle() const
-{ 
-	U8 font = LLFontGL::NORMAL;
-	
-	if( gAgentWearables.isWearingItem( mUUID ) )
-	{
-		// llinfos << "BOLD" << llendl;
-		font |= LLFontGL::BOLD;
-	}
-
-	const LLViewerInventoryItem* item = getItem();
-	if (item && item->getIsLinkType())
-	{
-		font |= LLFontGL::ITALIC;
-	}
-	return (LLFontGL::StyleFlags)font;
-}
-
-std::string LLItemBridge::getLabelSuffix() const
-{
-	// String table is loaded before login screen and inventory items are
-	// loaded after login, so LLTrans should be ready.
-	static std::string NO_COPY =LLTrans::getString("no_copy");
-	static std::string NO_MOD = LLTrans::getString("no_modify");
-	static std::string NO_XFER = LLTrans::getString("no_transfer");
-	static std::string LINK = LLTrans::getString("link");
-	static std::string BROKEN_LINK = LLTrans::getString("broken_link");
-	std::string suffix;
-	LLInventoryItem* item = getItem();
-	if(item) 
-	{
-		// it's a bit confusing to put nocopy/nomod/etc on calling cards.
-		if(LLAssetType::AT_CALLINGCARD != item->getType()
-		   && item->getPermissions().getOwner() == gAgent.getID())
-		{
-			BOOL broken_link = LLAssetType::lookupIsLinkType(item->getType());
-			if (broken_link) return BROKEN_LINK;
-
-			BOOL link = item->getIsLinkType();
-			if (link) return LINK;
-
-			BOOL copy = item->getPermissions().allowCopyBy(gAgent.getID());
-			if (!copy)
-			{
-				suffix += NO_COPY;
-			}
-			BOOL mod = item->getPermissions().allowModifyBy(gAgent.getID());
-			if (!mod)
-			{
-				suffix += NO_MOD;
-			}
-			BOOL xfer = item->getPermissions().allowOperationBy(PERM_TRANSFER,
-																gAgent.getID());
-			if (!xfer)
-			{
-				suffix += NO_XFER;
-			}
-		}
-	}
-	return suffix;
-}
-
-time_t LLItemBridge::getCreationDate() const
-{
-	LLViewerInventoryItem* item = getItem();
-	if (item)
-	{
-		return item->getCreationDate();
-	}
-	return 0;
-}
-
-
-BOOL LLItemBridge::isItemRenameable() const
-{
-	LLViewerInventoryItem* item = getItem();
-	if(item)
-	{
-		// (For now) Don't allow calling card rename since that may confuse users as to
-		// what the calling card points to.
-		if (item->getInventoryType() == LLInventoryType::IT_CALLINGCARD)
-		{
-			return FALSE;
-		}
-		return (item->getPermissions().allowModifyBy(gAgent.getID()));
-	}
-	return FALSE;
-}
-
-BOOL LLItemBridge::renameItem(const std::string& new_name)
-{
-	if(!isItemRenameable())
-		return FALSE;
-	LLPreview::dirty(mUUID);
-	LLInventoryModel* model = getInventoryModel();
-	if(!model)
-		return FALSE;
-	LLViewerInventoryItem* item = getItem();
-	if(item && (item->getName() != new_name))
-	{
-		LLPointer<LLViewerInventoryItem> new_item = new LLViewerInventoryItem(item);
-		new_item->rename(new_name);
-		buildDisplayName(new_item, mDisplayName);
-		new_item->updateServer(FALSE);
-		model->updateItem(new_item);
-
-		model->notifyObservers();
-	}
-	// return FALSE because we either notified observers (& therefore
-	// rebuilt) or we didn't update.
-	return FALSE;
-}
-
-
-BOOL LLItemBridge::removeItem()
-{
-	if(!isItemRemovable())
-	{
-		return FALSE;
-	}
-	// move it to the trash
-	LLPreview::hide(mUUID, TRUE);
-	LLInventoryModel* model = getInventoryModel();
-	if(!model) return FALSE;
-	LLUUID trash_id = model->findCategoryUUIDForType(LLAssetType::AT_TRASH);
-	LLViewerInventoryItem* item = getItem();
-
-	// if item is not already in trash
-	if(item && !model->isObjectDescendentOf(mUUID, trash_id))
-	{
-		// move to trash, and restamp
-		LLInvFVBridge::changeItemParent(model, item, trash_id, TRUE);
-		// delete was successful
-		return TRUE;
-	}
-	else
-	{
-		// tried to delete already item in trash (should purge?)
-		return FALSE;
-	}
-}
-
-BOOL LLItemBridge::isItemCopyable() const
-{
-	LLViewerInventoryItem* item = getItem();
-	if (item)
-	{
-		// can't copy worn objects. DEV-15183
-		LLVOAvatarSelf *avatarp = gAgent.getAvatarObject();
-		if( !avatarp )
-		{
-			return FALSE;
-		}
-
-		if(avatarp->isWearingAttachment(mUUID))
-		{
-			return FALSE;
-		}
-		
-		// All items can be copied, not all can be pasted.
-		// The only time an item can't be copied is if it's a link 
-		// return (item->getPermissions().allowCopyBy(gAgent.getID()));
-		if (item->getIsLinkType())
-		{
-			return FALSE;
-		}
-		return TRUE;
-	}
-	return FALSE;
-}
-BOOL LLItemBridge::copyToClipboard() const
-{
-	if(isItemCopyable())
-	{
-		LLInventoryClipboard::instance().add(mUUID);
-		return TRUE;
-	}
-	return FALSE;
-}
-
-LLViewerInventoryItem* LLItemBridge::getItem() const
-{
-	LLViewerInventoryItem* item = NULL;
-	LLInventoryModel* model = getInventoryModel();
-	if(model)
-	{
-		item = (LLViewerInventoryItem*)model->getItem(mUUID);
-	}
-	return item;
-}
-
-BOOL LLItemBridge::isItemPermissive() const
-{
-	LLViewerInventoryItem* item = getItem();
-	if(item)
-	{
-		U32 mask = item->getPermissions().getMaskBase();
-		if((mask & PERM_ITEM_UNRESTRICTED) == PERM_ITEM_UNRESTRICTED)
-		{
-			return TRUE;
-		}
-	}
-	return FALSE;
-}
-
-// +=================================================+
-// |        LLFolderBridge                           |
-// +=================================================+
-
-LLFolderBridge* LLFolderBridge::sSelf=NULL;
-
-// Can be moved to another folder
-BOOL LLFolderBridge::isItemMovable() const 
-{
-	LLInventoryObject* obj = getInventoryObject();
-	if(obj)
-	{
-		return (!LLAssetType::lookupIsProtectedCategoryType(((LLInventoryCategory*)obj)->getPreferredType()));
-	}
-	return FALSE;
-}
-
-void LLFolderBridge::selectItem()
-{
-}
-
-
-// Can be destroyed (or moved to trash)
-BOOL LLFolderBridge::isItemRemovable()
-{
-	LLInventoryModel* model = getInventoryModel();
-	if(!model) 
-	{
-		return FALSE;
-	}
-
-	if(!model->isObjectDescendentOf(mUUID, gInventory.getRootFolderID()))
-	{
-		return FALSE;
-	}
-
-	LLVOAvatarSelf* avatar = gAgent.getAvatarObject();
-	if( !avatar )
-	{
-		return FALSE;
-	}
-
-	LLInventoryCategory* category = model->getCategory(mUUID);
-	if( !category )
-	{
-		return FALSE;
-	}
-
-	if(LLAssetType::lookupIsProtectedCategoryType(category->getPreferredType()))
-	{
-		return FALSE;
-	}
-
-	LLInventoryModel::cat_array_t	descendent_categories;
-	LLInventoryModel::item_array_t	descendent_items;
-	gInventory.collectDescendents( mUUID, descendent_categories, descendent_items, FALSE );
-
-	S32 i;
-	for( i = 0; i < descendent_categories.count(); i++ )
-	{
-		LLInventoryCategory* category = descendent_categories[i];
-		if(LLAssetType::lookupIsProtectedCategoryType(category->getPreferredType()))
-		{
-			return FALSE;
-		}
-	}
-
-	for( i = 0; i < descendent_items.count(); i++ )
-	{
-		LLInventoryItem* item = descendent_items[i];
-		if( (item->getType() == LLAssetType::AT_CLOTHING) ||
-			(item->getType() == LLAssetType::AT_BODYPART) )
-		{
-			if(gAgentWearables.isWearingItem(item->getUUID()))
-			{
-				return FALSE;
-			}
-		}
-		else
-		if( item->getType() == LLAssetType::AT_OBJECT )
-		{
-			if(avatar->isWearingAttachment(item->getUUID()))
-			{
-				return FALSE;
-			}
-		}
-	}
-
-	return TRUE;
-}
-
-BOOL LLFolderBridge::isUpToDate() const
-{
-	LLInventoryModel* model = getInventoryModel();
-	if(!model) return FALSE;
-	LLViewerInventoryCategory* category = (LLViewerInventoryCategory*)model->getCategory(mUUID);
-	if( !category )
-	{
-		return FALSE;
-	}
-
-	return category->getVersion() != LLViewerInventoryCategory::VERSION_UNKNOWN;
-}
-
-BOOL LLFolderBridge::isItemCopyable() const
-{
-	return TRUE;
-}
-
-BOOL LLFolderBridge::copyToClipboard() const
-{
-	if(isItemCopyable())
-	{
-		LLInventoryClipboard::instance().add(mUUID);
-		return TRUE;
-	}
-	return FALSE;
-}
-
-BOOL LLFolderBridge::isClipboardPasteable() const
-{
-	if ( ! LLInvFVBridge::isClipboardPasteable() )
-		return FALSE;
-
-	// Don't allow pasting duplicates to the Calling Card/Friends subfolders, see bug EXT-1599
-	if ( LLFriendCardsManager::instance().isCategoryInFriendFolder( getCategory() ) )
-	{
-		LLInventoryModel* model = getInventoryModel();
-		if ( !model )
-		{
-			return FALSE;
-		}
-
-		LLDynamicArray<LLUUID> objects;
-		LLInventoryClipboard::instance().retrieve(objects);
-		const LLViewerInventoryCategory *current_cat = getCategory();
-
-		// Search for the direct descendent of current Friends subfolder among all pasted items, 
-		// and return false if is found.
-		for(S32 i = objects.count() - 1; i >= 0; --i)
-		{
-			const LLUUID &obj_id = objects.get(i);
-			if ( LLFriendCardsManager::instance().isObjDirectDescendentOfCategory(model->getObject(obj_id), current_cat) )
-			{
-				return FALSE;
-			}
-		}
-
-	}
-	return TRUE;
-}
-
-BOOL LLFolderBridge::isClipboardPasteableAsLink() const
-{
-	// Check normal paste-as-link permissions
-	if (!LLInvFVBridge::isClipboardPasteableAsLink())
-	{
-		return FALSE;
-	}
-	
-	const LLInventoryModel* model = getInventoryModel();
-	if (!model)
-	{
-		return FALSE;
-	}
-
-	const LLViewerInventoryCategory *current_cat = getCategory();
-	if (current_cat)
-	{
-		const BOOL is_in_friend_folder = LLFriendCardsManager::instance().isCategoryInFriendFolder( current_cat );
-		const LLUUID &current_cat_id = current_cat->getUUID();
-		LLDynamicArray<LLUUID> objects;
-		LLInventoryClipboard::instance().retrieve(objects);
-		S32 count = objects.count();
-		for(S32 i = 0; i < count; i++)
-		{
-			const LLUUID &obj_id = objects.get(i);
-			const LLInventoryCategory *cat = model->getCategory(obj_id);
-			if (cat)
-			{
-				const LLUUID &cat_id = cat->getUUID();
-				// Don't allow recursive pasting
-				if ((cat_id == current_cat_id) || 
-					model->isObjectDescendentOf(current_cat_id, cat_id))
-				{
-					return FALSE;
-				}
-			}
-			// Don't allow pasting duplicates to the Calling Card/Friends subfolders, see bug EXT-1599
-			if ( is_in_friend_folder )
-			{
-				// If object is direct descendent of current Friends subfolder than return false.
-				// Note: We can't use 'const LLInventoryCategory *cat', because it may be null
-				// in case type of obj_id is LLInventoryItem.
-				if ( LLFriendCardsManager::instance().isObjDirectDescendentOfCategory(model->getObject(obj_id), current_cat) )
-				{
-					return FALSE;
-				}
-			}
-		}
-	}
-	return TRUE;
-
-}
-
-BOOL LLFolderBridge::dragCategoryIntoFolder(LLInventoryCategory* inv_cat,
-											BOOL drop)
-{
-	// This should never happen, but if an inventory item is incorrectly parented, 
-	// the UI will get confused and pass in a NULL.
-	if(!inv_cat) return FALSE;
-
-	LLInventoryModel* model = getInventoryModel();
-	if(!model) return FALSE;
-
-	LLVOAvatarSelf* avatar = gAgent.getAvatarObject();
-	if(!avatar) return FALSE;
-
-	// cannot drag categories into library
-	if(!isAgentInventory())
-	{
-		return FALSE;
-	}
-
-	// check to make sure source is agent inventory, and is represented there.
-	LLToolDragAndDrop::ESource source = LLToolDragAndDrop::getInstance()->getSource();
-	BOOL is_agent_inventory = (model->getCategory(inv_cat->getUUID()) != NULL)
-		&& (LLToolDragAndDrop::SOURCE_AGENT == source);
-
-	BOOL accept = FALSE;
-	S32 i;
-	LLInventoryModel::cat_array_t	descendent_categories;
-	LLInventoryModel::item_array_t	descendent_items;
-	if(is_agent_inventory)
-	{
-		const LLUUID& cat_id = inv_cat->getUUID();
-
-		// Is the destination the trash?
-		const LLUUID trash_id = model->findCategoryUUIDForType(LLAssetType::AT_TRASH);
-		BOOL move_is_into_trash = (mUUID == trash_id)
-				|| model->isObjectDescendentOf(mUUID, trash_id);
-		BOOL is_movable = (!LLAssetType::lookupIsProtectedCategoryType(inv_cat->getPreferredType()));
-		LLUUID current_outfit_id = model->findCategoryUUIDForType(LLAssetType::AT_CURRENT_OUTFIT);
-		BOOL move_is_into_current_outfit = (mUUID == current_outfit_id);
-		BOOL move_is_into_outfit = (getCategory() && getCategory()->getPreferredType()==LLAssetType::AT_OUTFIT);
-		if (move_is_into_current_outfit || move_is_into_outfit)
-		{
-			// BAP - restrictions?
-			is_movable = true;
-		}
-
-		if (mUUID == gInventory.findCategoryUUIDForType(LLAssetType::AT_FAVORITE))
-		{
-			is_movable = FALSE; // It's generally movable but not into Favorites folder. EXT-1604
-		}
-
-		if( is_movable )
-		{
-			gInventory.collectDescendents( cat_id, descendent_categories, descendent_items, FALSE );
-
-			for( i = 0; i < descendent_categories.count(); i++ )
-			{
-				LLInventoryCategory* category = descendent_categories[i];
-				if(LLAssetType::lookupIsProtectedCategoryType(category->getPreferredType()))
-				{
-					// ...can't move "special folders" like Textures
-					is_movable = FALSE;
-					break;
-				}
-			}
-			
-			if( is_movable )
-			{
-				if( move_is_into_trash )
-				{
-					for( i = 0; i < descendent_items.count(); i++ )
-					{
-						LLInventoryItem* item = descendent_items[i];
-						if( (item->getType() == LLAssetType::AT_CLOTHING) ||
-							(item->getType() == LLAssetType::AT_BODYPART) )
-						{
-							if( gAgentWearables.isWearingItem( item->getUUID() ) )
-							{
-								is_movable = FALSE;  // It's generally movable, but not into the trash!
-								break;
-							}
-						}
-						else
-						if( item->getType() == LLAssetType::AT_OBJECT )
-						{
-							if( avatar->isWearingAttachment( item->getUUID() ) )
-							{
-								is_movable = FALSE;  // It's generally movable, but not into the trash!
-								break;
-							}
-						}
-					}
-				}
-			}
-		}
-
-		
-		accept =	is_movable
-					&& (mUUID != cat_id)								// Can't move a folder into itself
-					&& (mUUID != inv_cat->getParentUUID())				// Avoid moves that would change nothing
-					&& !(model->isObjectDescendentOf(mUUID, cat_id));	// Avoid circularity
-		if(accept && drop)
-		{
-			// Look for any gestures and deactivate them
-			if (move_is_into_trash)
-			{
-				for (i = 0; i < descendent_items.count(); i++)
-				{
-					LLInventoryItem* item = descendent_items[i];
-					if (item->getType() == LLAssetType::AT_GESTURE
-						&& LLGestureManager::instance().isGestureActive(item->getUUID()))
-					{
-						LLGestureManager::instance().deactivateGesture(item->getUUID());
-					}
-				}
-			}
-			// if target is an outfit or current outfit folder we use link
-			if (move_is_into_current_outfit || move_is_into_outfit) 
-			{
-#if SUPPORT_ENSEMBLES
-				// BAP - should skip if dup.
-				if (move_is_into_current_outfit)
-				{
-					LLAppearanceManager::wearEnsemble(inv_cat);
-				}
-				else
-				{
-					LLPointer<LLInventoryCallback> cb = NULL;
-					link_inventory_item(
-						gAgent.getID(),
-						inv_cat->getUUID(),
-						mUUID,
-						inv_cat->getName(),
-						LLAssetType::AT_LINK_FOLDER,
-						cb);
-				}
-#endif
-			}
-			else
-			{
-				
-				// Reparent the folder and restamp children if it's moving
-				// into trash.
-				LLInvFVBridge::changeCategoryParent(
-					model,
-					(LLViewerInventoryCategory*)inv_cat,
-					mUUID,
-					move_is_into_trash);
-			}
-		}
-	}
-	else if(LLToolDragAndDrop::SOURCE_WORLD == source)
-	{
-		// content category has same ID as object itself
-		LLUUID object_id = inv_cat->getUUID();
-		LLUUID category_id = mUUID;
-		accept = move_inv_category_world_to_agent(object_id, category_id, drop);
-	}
-	return accept;
-}
-
-void warn_move_inventory(LLViewerObject* object, LLMoveInv* move_inv)
-{
-	const char* dialog = NULL;
-	if (object->flagScripted())
-	{
-		dialog = "MoveInventoryFromScriptedObject";
-	}
-	else
-	{
-		dialog = "MoveInventoryFromObject";
-	}
-	LLNotifications::instance().add(dialog, LLSD(), LLSD(), boost::bind(move_task_inventory_callback, _1, _2, move_inv));
-}
-
-// Move/copy all inventory items from the Contents folder of an in-world
-// object to the agent's inventory, inside a given category.
-BOOL move_inv_category_world_to_agent(const LLUUID& object_id, 
-									  const LLUUID& category_id,
-									  BOOL drop,
-									  void (*callback)(S32, void*),
-									  void* user_data)
-{
-	// Make sure the object exists. If we allowed dragging from
-	// anonymous objects, it would be possible to bypass
-	// permissions.
-	// content category has same ID as object itself
-	LLViewerObject* object = gObjectList.findObject(object_id);
-	if(!object)
-	{
-		llinfos << "Object not found for drop." << llendl;
-		return FALSE;
-	}
-
-	// this folder is coming from an object, as there is only one folder in an object, the root,
-	// we need to collect the entire contents and handle them as a group
-	InventoryObjectList inventory_objects;
-	object->getInventoryContents(inventory_objects);
-
-	if (inventory_objects.empty())
-	{
-		llinfos << "Object contents not found for drop." << llendl;
-		return FALSE;
-	}
-	
-	BOOL accept = TRUE;
-	BOOL is_move = FALSE;
-
-	// coming from a task. Need to figure out if the person can
-	// move/copy this item.
-	InventoryObjectList::iterator it = inventory_objects.begin();
-	InventoryObjectList::iterator end = inventory_objects.end();
-	for ( ; it != end; ++it)
-	{
-		// coming from a task. Need to figure out if the person can
-		// move/copy this item.
-		LLPermissions perm(((LLInventoryItem*)((LLInventoryObject*)(*it)))->getPermissions());
-		if((perm.allowCopyBy(gAgent.getID(), gAgent.getGroupID())
-			&& perm.allowTransferTo(gAgent.getID())))
-//			|| gAgent.isGodlike())
-		{
-			accept = TRUE;
-		}
-		else if(object->permYouOwner())
-		{
-			// If the object cannot be copied, but the object the
-			// inventory is owned by the agent, then the item can be
-			// moved from the task to agent inventory.
-			is_move = TRUE;
-			accept = TRUE;
-		}
-		else
-		{
-			accept = FALSE;
-			break;
-		}
-	}
-
-	if(drop && accept)
-	{
-		it = inventory_objects.begin();
-		InventoryObjectList::iterator first_it = inventory_objects.begin();
-		LLMoveInv* move_inv = new LLMoveInv;
-		move_inv->mObjectID = object_id;
-		move_inv->mCategoryID = category_id;
-		move_inv->mCallback = callback;
-		move_inv->mUserData = user_data;
-
-		for ( ; it != end; ++it)
-		{
-			two_uuids_t two(category_id, (*it)->getUUID());
-			move_inv->mMoveList.push_back(two);
-		}
-
-		if(is_move)
-		{
-			// Callback called from within here.
-			warn_move_inventory(object, move_inv);
-		}
-		else
-		{
-			LLNotification::Params params("MoveInventoryFromObject");
-			params.functor.function(boost::bind(move_task_inventory_callback, _1, _2, move_inv));
-			LLNotifications::instance().forceResponse(params, 0);
-		}
-	}
-	return accept;
-}
-
-bool LLFindCOFValidItems::operator()(LLInventoryCategory* cat,
-									 LLInventoryItem* item)
-{
-	// Valid COF items are:
-	// - links to wearables (body parts or clothing)
-	// - links to attachments
-	// - links to gestures
-	// - links to ensemble folders
-	LLViewerInventoryItem *linked_item = ((LLViewerInventoryItem*)item)->getLinkedItem(); // BAP - safe?
-	if (linked_item)
-	{
-		LLAssetType::EType type = linked_item->getType();
-		return (type == LLAssetType::AT_CLOTHING ||
-				type == LLAssetType::AT_BODYPART ||
-				type == LLAssetType::AT_GESTURE ||
-				type == LLAssetType::AT_OBJECT);
-	}
-	else
-	{
-		LLViewerInventoryCategory *linked_category = ((LLViewerInventoryItem*)item)->getLinkedCategory(); // BAP - safe?
-		// BAP remove AT_NONE support after ensembles are fully working?
-		return (linked_category && 
-				((linked_category->getPreferredType() == LLAssetType::AT_NONE) ||
-				 (LLAssetType::lookupIsEnsembleCategoryType(linked_category->getPreferredType()))));
-	}
-}
-
-
-bool LLFindWearables::operator()(LLInventoryCategory* cat,
-								 LLInventoryItem* item)
-{
-	if(item)
-	{
-		if((item->getType() == LLAssetType::AT_CLOTHING)
-		   || (item->getType() == LLAssetType::AT_BODYPART))
-		{
-			return TRUE;
-		}
-	}
-	return FALSE;
-}
-
-
-
-//Used by LLFolderBridge as callback for directory recursion.
-class LLRightClickInventoryFetchObserver : public LLInventoryFetchObserver
-{
-public:
-	LLRightClickInventoryFetchObserver() :
-		mCopyItems(false)
-	{ };
-	LLRightClickInventoryFetchObserver(const LLUUID& cat_id, bool copy_items) :
-		mCatID(cat_id),
-		mCopyItems(copy_items)
-		{ };
-	virtual void done()
-	{
-		// we've downloaded all the items, so repaint the dialog
-		LLFolderBridge::staticFolderOptionsMenu();
-
-		gInventory.removeObserver(this);
-		delete this;
-	}
-	
-
-protected:
-	LLUUID mCatID;
-	bool mCopyItems;
-
-};
-
-//Used by LLFolderBridge as callback for directory recursion.
-class LLRightClickInventoryFetchDescendentsObserver : public LLInventoryFetchDescendentsObserver
-{
-public:
-	LLRightClickInventoryFetchDescendentsObserver(bool copy_items) : mCopyItems(copy_items) {}
-	~LLRightClickInventoryFetchDescendentsObserver() {}
-	virtual void done();
-protected:
-	bool mCopyItems;
-};
-
-void LLRightClickInventoryFetchDescendentsObserver::done()
-{
-	// Avoid passing a NULL-ref as mCompleteFolders.front() down to
-	// gInventory.collectDescendents()
-	if( mCompleteFolders.empty() )
-	{
-		llwarns << "LLRightClickInventoryFetchDescendentsObserver::done with empty mCompleteFolders" << llendl;
-		dec_busy_count();
-		gInventory.removeObserver(this);
-		delete this;
-		return;
-	}
-
-	// What we do here is get the complete information on the items in
-	// the library, and set up an observer that will wait for that to
-	// happen.
-	LLInventoryModel::cat_array_t cat_array;
-	LLInventoryModel::item_array_t item_array;
-	gInventory.collectDescendents(mCompleteFolders.front(),
-								  cat_array,
-								  item_array,
-								  LLInventoryModel::EXCLUDE_TRASH);
-	S32 count = item_array.count();
-#if 0 // HACK/TODO: Why?
-	// This early causes a giant menu to get produced, and doesn't seem to be needed.
-	if(!count)
-	{
-		llwarns << "Nothing fetched in category " << mCompleteFolders.front()
-				<< llendl;
-		dec_busy_count();
-		gInventory.removeObserver(this);
-		delete this;
-		return;
-	}
-#endif
-
-	LLRightClickInventoryFetchObserver* outfit;
-	outfit = new LLRightClickInventoryFetchObserver(mCompleteFolders.front(), mCopyItems);
-	LLInventoryFetchObserver::item_ref_t ids;
-	for(S32 i = 0; i < count; ++i)
-	{
-		ids.push_back(item_array.get(i)->getUUID());
-	}
-
-	// clean up, and remove this as an observer since the call to the
-	// outfit could notify observers and throw us into an infinite
-	// loop.
-	dec_busy_count();
-	gInventory.removeObserver(this);
-	delete this;
-
-	// increment busy count and either tell the inventory to check &
-	// call done, or add this object to the inventory for observation.
-	inc_busy_count();
-
-	// do the fetch
-	outfit->fetchItems(ids);
-	outfit->done();				//Not interested in waiting and this will be right 99% of the time.
-//Uncomment the following code for laggy Inventory UI.
-/*	if(outfit->isEverythingComplete())
-	{
-		// everything is already here - call done.
-		outfit->done();
-	}
-	else
-	{
-		// it's all on it's way - add an observer, and the inventory
-		// will call done for us when everything is here.
-		gInventory.addObserver(outfit);
-	}*/
-}
-
-
-//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-// Class LLInventoryWearObserver
-//
-// Observer for "copy and wear" operation to support knowing 
-// when the all of the contents have been added to inventory.
-//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-class LLInventoryCopyAndWearObserver : public LLInventoryObserver
-{
-public:
-	LLInventoryCopyAndWearObserver(const LLUUID& cat_id, int count) :mCatID(cat_id), mContentsCount(count), mFolderAdded(FALSE) {}
-	virtual ~LLInventoryCopyAndWearObserver() {}
-	virtual void changed(U32 mask);
-
-protected:
-	LLUUID mCatID;
-	int    mContentsCount;
-	BOOL   mFolderAdded;
-};
-
-
-
-void LLInventoryCopyAndWearObserver::changed(U32 mask)
-{
-	if((mask & (LLInventoryObserver::ADD)) != 0)
-	{
-		if (!mFolderAdded) 
-		{
-			const std::set<LLUUID>& changed_items = gInventory.getChangedIDs();
-
-			std::set<LLUUID>::const_iterator id_it = changed_items.begin();
-			std::set<LLUUID>::const_iterator id_end = changed_items.end();
-			for (;id_it != id_end; ++id_it)
-			{
-				if ((*id_it) == mCatID) 
-				{
-					mFolderAdded = TRUE;
-					break;
-				}
-			}
-		}
-
-		if (mFolderAdded) 
-		{
-			LLViewerInventoryCategory* category = gInventory.getCategory(mCatID);
-
-			if (NULL == category)
-			{
-				llwarns << "gInventory.getCategory(" << mCatID
-					<< ") was NULL" << llendl;
-			}
-			else
-			{
-				if (category->getDescendentCount() ==
-				    mContentsCount)
-				{
-					gInventory.removeObserver(this);
-					LLAppearanceManager::wearInventoryCategory(category, FALSE, TRUE);
-					delete this;
-				}
-			}		
-		}
-
-	}
-}
-
-
-
-void LLFolderBridge::performAction(LLFolderView* folder, LLInventoryModel* model, std::string action)
-{
-	if ("open" == action)
-	{
-		openItem();
-		return;
-	}
-	else if ("paste" == action)
-	{
-		pasteFromClipboard();
-		return;
-	}
-	else if ("paste_link" == action)
-	{
-		pasteLinkFromClipboard();
-		return;
-	}
-	else if ("properties" == action)
-	{
-		showProperties();
-		return;
-	}
-	else if ("replaceoutfit" == action)
-	{
-		modifyOutfit(FALSE);
-		return;
-	}
-#if SUPPORT_ENSEMBLES
-	else if ("wearasensemble" == action)
-	{
-		LLInventoryModel* model = getInventoryModel();
-		if(!model) return;
-		LLViewerInventoryCategory* cat = getCategory();
-		if(!cat) return;
-		LLAppearanceManager::wearEnsemble(cat,true);
-		return;
-	}
-#endif
-	else if ("addtooutfit" == action)
-	{
-		modifyOutfit(TRUE);
-		return;
-	}
-	else if ("copy" == action)
-	{
-		copyToClipboard();
-		return;
-	}
-	else if ("removefromoutfit" == action)
-	{
-		LLInventoryModel* model = getInventoryModel();
-		if(!model) return;
-		LLViewerInventoryCategory* cat = getCategory();
-		if(!cat) return;
-		
-		remove_inventory_category_from_avatar ( cat );
-		return;
-	}	
-	else if ("purge" == action)
-	{		
-		purgeItem(model, mUUID);
-		return;
-	}
-	else if ("restore" == action)
-	{
-		restoreItem();
-		return;
-	}
-}
-
-void LLFolderBridge::openItem()
-{
-	lldebugs << "LLFolderBridge::openItem()" << llendl;
-	LLInventoryModel* model = getInventoryModel();
-	if(!model) return;
-	bool fetching_inventory = model->fetchDescendentsOf(mUUID);
-	// Only change folder type if we have the folder contents.
-	if (!fetching_inventory)
-	{
-		// Disabling this for now, it's causing crash when new items are added to folders
-		// since folder type may change before new item item has finished processing.
-		// determineFolderType();
-	}
-}
-
-void LLFolderBridge::closeItem()
-{
-	determineFolderType();
-}
-
-void LLFolderBridge::determineFolderType()
-{
-	if (isUpToDate())
-	{
-		LLInventoryModel* model = getInventoryModel();
-		LLViewerInventoryCategory* category = model->getCategory(mUUID);
-		category->determineFolderType();
-	}
-}
-
-BOOL LLFolderBridge::isItemRenameable() const
-{
-	LLViewerInventoryCategory* cat = (LLViewerInventoryCategory*)getCategory();
-	if(cat && !LLAssetType::lookupIsProtectedCategoryType(cat->getPreferredType())
-	   && (cat->getOwnerID() == gAgent.getID()))
-	{
-		return TRUE;
-	}
-	return FALSE;
-}
-
-void LLFolderBridge::restoreItem()
-{
-	LLViewerInventoryCategory* cat;
-	cat = (LLViewerInventoryCategory*)getCategory();
-	if(cat)
-	{
-		LLInventoryModel* model = getInventoryModel();
-		LLUUID new_parent = model->findCategoryUUIDForType(cat->getType());
-		// do not restamp children on restore
-		LLInvFVBridge::changeCategoryParent(model, cat, new_parent, FALSE);
-	}
-}
-
-LLAssetType::EType LLFolderBridge::getPreferredType() const
-{
-	LLAssetType::EType preferred_type = LLAssetType::AT_NONE;
-	LLViewerInventoryCategory* cat = getCategory();
-	if(cat)
-	{
-		preferred_type = cat->getPreferredType();
-	}
-
-	return preferred_type;
-}
-
-// Icons for folders are based on the preferred type
-LLUIImagePtr LLFolderBridge::getIcon() const
-{
-	LLAssetType::EType preferred_type = LLAssetType::AT_NONE;
-	LLViewerInventoryCategory* cat = getCategory();
-	if(cat)
-	{
-		preferred_type = cat->getPreferredType();
-	}
-	return getIcon(preferred_type);
-}
-
-LLUIImagePtr LLFolderBridge::getIcon(LLAssetType::EType preferred_type)
-{
-	// we only have one folder image now
-	return LLUI::getUIImage("Inv_FolderClosed");
-}
-
-BOOL LLFolderBridge::renameItem(const std::string& new_name)
-{
-	if(!isItemRenameable())
-		return FALSE;
-	LLInventoryModel* model = getInventoryModel();
-	if(!model)
-		return FALSE;
-	LLViewerInventoryCategory* cat = getCategory();
-	if(cat && (cat->getName() != new_name))
-	{
-		LLPointer<LLViewerInventoryCategory> new_cat = new LLViewerInventoryCategory(cat);
-		new_cat->rename(new_name);
-		new_cat->updateServer(FALSE);
-		model->updateCategory(new_cat);
-
-		model->notifyObservers();
-	}
-	// return FALSE because we either notified observers (& therefore
-	// rebuilt) or we didn't update.
-	return FALSE;
-}
-
-BOOL LLFolderBridge::removeItem()
-{
-	if(!isItemRemovable())
-	{
-		return FALSE;
-	}
-	// move it to the trash
-	LLPreview::hide(mUUID);
-	LLInventoryModel* model = getInventoryModel();
-	if(!model) return FALSE;
-
-	LLUUID trash_id = model->findCategoryUUIDForType(LLAssetType::AT_TRASH);
-
-	// Look for any gestures and deactivate them
-	LLInventoryModel::cat_array_t	descendent_categories;
-	LLInventoryModel::item_array_t	descendent_items;
-	gInventory.collectDescendents( mUUID, descendent_categories, descendent_items, FALSE );
-
-	S32 i;
-	for (i = 0; i < descendent_items.count(); i++)
-	{
-		LLInventoryItem* item = descendent_items[i];
-		if (item->getType() == LLAssetType::AT_GESTURE
-			&& LLGestureManager::instance().isGestureActive(item->getUUID()))
-		{
-			LLGestureManager::instance().deactivateGesture(item->getUUID());
-		}
-	}
-
-	// go ahead and do the normal remove if no 'last calling
-	// cards' are being removed.
-	LLViewerInventoryCategory* cat = getCategory();
-	if(cat)
-	{
-		LLInvFVBridge::changeCategoryParent(model, cat, trash_id, TRUE);
-	}
-
-	return TRUE;
-}
-
-void LLFolderBridge::pasteFromClipboard()
-{
-	LLInventoryModel* model = getInventoryModel();
-	if(model && isClipboardPasteable())
-	{
-		LLInventoryItem* item = NULL;
-		LLDynamicArray<LLUUID> objects;
-		LLInventoryClipboard::instance().retrieve(objects);
-		S32 count = objects.count();
-		const LLUUID parent_id(mUUID);
-		for(S32 i = 0; i < count; i++)
-		{
-			item = model->getItem(objects.get(i));
-			if (item)
-			{
-				if(LLInventoryClipboard::instance().isCutMode())
-				{
-					// move_inventory_item() is not enough, 
-					//we have to update inventory locally too
-					changeItemParent(model, dynamic_cast<LLViewerInventoryItem*>(item), parent_id, FALSE);
-				}
-				else
-				{
-					copy_inventory_item(
-						gAgent.getID(),
-						item->getPermissions().getOwner(),
-						item->getUUID(),
-						parent_id,
-						std::string(),
-						LLPointer<LLInventoryCallback>(NULL));
-				}
-			}
-		}
-	}
-}
-
-void LLFolderBridge::pasteLinkFromClipboard()
-{
-	const LLInventoryModel* model = getInventoryModel();
-	if(model)
-	{
-		LLDynamicArray<LLUUID> objects;
-		LLInventoryClipboard::instance().retrieve(objects);
-		S32 count = objects.count();
-		LLUUID parent_id(mUUID);
-		for(S32 i = 0; i < count; i++)
-		{
-			const LLUUID &object_id = objects.get(i);
-#if SUPPORT_ENSEMBLES
-			if (LLInventoryCategory *cat = model->getCategory(object_id))
-			{
-				link_inventory_item(
-					gAgent.getID(),
-					cat->getUUID(),
-					parent_id,
-					cat->getName(),
-					LLAssetType::AT_LINK_FOLDER,
-					LLPointer<LLInventoryCallback>(NULL));
-			}
-			else
-#endif
-			if (LLInventoryItem *item = model->getItem(object_id))
-			{
-				link_inventory_item(
-					gAgent.getID(),
-					item->getUUID(),
-					parent_id,
-					item->getName(),
-					LLAssetType::AT_LINK,
-					LLPointer<LLInventoryCallback>(NULL));
-			}
-		}
-	}
-}
-
-void LLFolderBridge::staticFolderOptionsMenu()
-{
-	if (!sSelf) return;
-	sSelf->folderOptionsMenu();
-}
-
-void LLFolderBridge::folderOptionsMenu()
-{
-	std::vector<std::string> disabled_items;
-
-	LLInventoryModel* model = getInventoryModel();
-	if(!model) return;
-
-	const LLInventoryCategory* category = model->getCategory(mUUID);
-	LLAssetType::EType type = category->getPreferredType();
-	const bool is_default_folder = category && LLAssetType::lookupIsProtectedCategoryType(type);
-	// BAP change once we're no longer treating regular categories as ensembles.
-	const bool is_ensemble = category && (type == LLAssetType::AT_NONE ||
-										  LLAssetType::lookupIsEnsembleCategoryType(type));
-	
-	// calling card related functionality for folders.
-
-	// Only enable calling-card related options for non-default folders.
-	if (!is_default_folder)
-	{
-		LLIsType is_callingcard(LLAssetType::AT_CALLINGCARD);
-		if (mCallingCards || checkFolderForContentsOfType(model, is_callingcard))
-		{
-			mItems.push_back(std::string("Calling Card Separator"));
-			mItems.push_back(std::string("Conference Chat Folder"));
-			mItems.push_back(std::string("IM All Contacts In Folder"));
-		}
-	}
-	
-	// wearables related functionality for folders.
-	//is_wearable
-	LLFindWearables is_wearable;
-	LLIsType is_object( LLAssetType::AT_OBJECT );
-	LLIsType is_gesture( LLAssetType::AT_GESTURE );
-
-	if (mWearables ||
-		checkFolderForContentsOfType(model, is_wearable)  ||
-		checkFolderForContentsOfType(model, is_object) ||
-		checkFolderForContentsOfType(model, is_gesture) )
-	{
-		mItems.push_back(std::string("Folder Wearables Separator"));
-
-		// Only enable add/replace outfit for non-default folders.
-		if (!is_default_folder)
-		{
-			mItems.push_back(std::string("Add To Outfit"));
-			mItems.push_back(std::string("Replace Outfit"));
-		}
-		if (is_ensemble)
-		{
-			mItems.push_back(std::string("Wear As Ensemble"));
-		}
-		mItems.push_back(std::string("Take Off Items"));
-	}
-	hideContextEntries(*mMenu, mItems, disabled_items);
-}
-
-BOOL LLFolderBridge::checkFolderForContentsOfType(LLInventoryModel* model, LLInventoryCollectFunctor& is_type)
-{
-	LLInventoryModel::cat_array_t cat_array;
-	LLInventoryModel::item_array_t item_array;
-	model->collectDescendentsIf(mUUID,
-								cat_array,
-								item_array,
-								LLInventoryModel::EXCLUDE_TRASH,
-								is_type);
-	return ((item_array.count() > 0) ? TRUE : FALSE );
-}
-
-// Flags unused
-void LLFolderBridge::buildContextMenu(LLMenuGL& menu, U32 flags)
-{
-	mItems.clear();
-	mDisabledItems.clear();
-
-	lldebugs << "LLFolderBridge::buildContextMenu()" << llendl;
-//	std::vector<std::string> disabled_items;
-	LLInventoryModel* model = getInventoryModel();
-	if(!model) return;
-	LLUUID trash_id = model->findCategoryUUIDForType(LLAssetType::AT_TRASH);
-	LLUUID lost_and_found_id = model->findCategoryUUIDForType(LLAssetType::AT_LOST_AND_FOUND);
-
-	mItems.clear(); //adding code to clear out member Items (which means Items should not have other data here at this point)
-	mDisabledItems.clear(); //adding code to clear out disabled members from previous 
-	if (lost_and_found_id == mUUID)
-	  {
-		// This is the lost+found folder.
-		  mItems.push_back(std::string("Empty Lost And Found"));
-	  }
-
-	if(trash_id == mUUID)
-	{
-		// This is the trash.
-		mItems.push_back(std::string("Empty Trash"));
-	}
-	else if(model->isObjectDescendentOf(mUUID, trash_id))
-	{
-		// This is a folder in the trash.
-		mItems.clear(); // clear any items that used to exist
-		mItems.push_back(std::string("Purge Item"));
-		if (!isItemRemovable())
-		{
-			mDisabledItems.push_back(std::string("Purge Item"));
-		}
-
-		mItems.push_back(std::string("Restore Item"));
-	}
-	else if(isAgentInventory()) // do not allow creating in library
-	{
-		LLViewerInventoryCategory *cat =  getCategory();
-
-		// BAP removed protected check to re-enable standard ops in untyped folders.
-		// Not sure what the right thing is to do here.
-		if (!isCOFFolder() && cat /*&&
-			LLAssetType::lookupIsProtectedCategoryType(cat->getPreferredType())*/)
-		{
-			// Do not allow to create 2-level subfolder in the Calling Card/Friends folder. EXT-694.
-			if (!LLFriendCardsManager::instance().isCategoryInFriendFolder(cat))
-				mItems.push_back(std::string("New Folder"));
-			mItems.push_back(std::string("New Script"));
-			mItems.push_back(std::string("New Note"));
-			mItems.push_back(std::string("New Gesture"));
-			mItems.push_back(std::string("New Clothes"));
-			mItems.push_back(std::string("New Body Parts"));
-			mItems.push_back(std::string("Change Type"));
-			
-			LLViewerInventoryCategory *cat = getCategory();
-			if (cat && LLAssetType::lookupIsProtectedCategoryType(cat->getPreferredType()))
-			{
-				mDisabledItems.push_back(std::string("Change Type"));
-			}
-			
-			getClipboardEntries(false, mItems, mDisabledItems, flags);
-		}
-		else
-		{
-			// Want some but not all of the items from getClipboardEntries for outfits.
-			if (cat && cat->getPreferredType()==LLAssetType::AT_OUTFIT)
-			{
-				mItems.push_back(std::string("Rename"));
-				mItems.push_back(std::string("Delete"));
-			}
-		}
-
-		//Added by spatters to force inventory pull on right-click to display folder options correctly. 07-17-06
-		mCallingCards = mWearables = FALSE;
-		
-		LLIsType is_callingcard(LLAssetType::AT_CALLINGCARD);
-		if (checkFolderForContentsOfType(model, is_callingcard))
-		{
-			mCallingCards=TRUE;
-		}
-		
-		LLFindWearables is_wearable;
-		LLIsType is_object( LLAssetType::AT_OBJECT );
-		LLIsType is_gesture( LLAssetType::AT_GESTURE );
-		
-		if (checkFolderForContentsOfType(model, is_wearable)  ||
-			checkFolderForContentsOfType(model, is_object) ||
-			checkFolderForContentsOfType(model, is_gesture) )
-		{
-			mWearables=TRUE;
-		}
-		
-		mMenu = &menu;
-		sSelf = this;
-		LLRightClickInventoryFetchDescendentsObserver* fetch = new LLRightClickInventoryFetchDescendentsObserver(FALSE);
-
-		LLInventoryFetchDescendentsObserver::folder_ref_t folders;
-		LLViewerInventoryCategory* category = (LLViewerInventoryCategory*)model->getCategory(mUUID);
-		if (category)
-		{
-			folders.push_back(category->getUUID());
-		}
-		fetch->fetchDescendents(folders);
-		inc_busy_count();
-		if(fetch->isEverythingComplete())
-		{
-			// everything is already here - call done.
-			fetch->done();
-		}
-		else
-		{
-			// it's all on it's way - add an observer, and the inventory
-			// will call done for us when everything is here.
-			gInventory.addObserver(fetch);
-		}
-	}
-	else
-	{
-		mItems.push_back(std::string("--no options--"));
-		mDisabledItems.push_back(std::string("--no options--"));
-	}
-	hideContextEntries(menu, mItems, mDisabledItems);
-}
-
-BOOL LLFolderBridge::hasChildren() const
-{
-	LLInventoryModel* model = getInventoryModel();
-	if(!model) return FALSE;
-	LLInventoryModel::EHasChildren has_children;
-	has_children = gInventory.categoryHasChildren(mUUID);
-	return has_children != LLInventoryModel::CHILDREN_NO;
-}
-
-BOOL LLFolderBridge::dragOrDrop(MASK mask, BOOL drop,
-								EDragAndDropType cargo_type,
-								void* cargo_data)
-{
-	//llinfos << "LLFolderBridge::dragOrDrop()" << llendl;
-	BOOL accept = FALSE;
-	switch(cargo_type)
-	{
-		case DAD_TEXTURE:
-		case DAD_SOUND:
-		case DAD_CALLINGCARD:
-		case DAD_LANDMARK:
-		case DAD_SCRIPT:
-		case DAD_OBJECT:
-		case DAD_NOTECARD:
-		case DAD_CLOTHING:
-		case DAD_BODYPART:
-		case DAD_ANIMATION:
-		case DAD_GESTURE:
-		case DAD_LINK:
-			accept = dragItemIntoFolder((LLInventoryItem*)cargo_data,
-										drop);
-			break;
-		case DAD_CATEGORY:
-			if (LLFriendCardsManager::instance().isAnyFriendCategory(mUUID))
-			{
-				accept = FALSE;
-			}
-			else
-			{
-				accept = dragCategoryIntoFolder((LLInventoryCategory*)cargo_data, drop);
-			}
-			break;
-		default:
-			break;
-	}
-	return accept;
-}
-
-LLViewerInventoryCategory* LLFolderBridge::getCategory() const
-{
-	LLViewerInventoryCategory* cat = NULL;
-	LLInventoryModel* model = getInventoryModel();
-	if(model)
-	{
-		cat = (LLViewerInventoryCategory*)model->getCategory(mUUID);
-	}
-	return cat;
-}
-
-
-// static
-void LLFolderBridge::pasteClipboard(void* user_data)
-{
-	LLFolderBridge* self = (LLFolderBridge*)user_data;
-	if(self) self->pasteFromClipboard();
-}
-
-void LLFolderBridge::createNewCategory(void* user_data)
-{
-	LLFolderBridge* bridge = (LLFolderBridge*)user_data;
-	if(!bridge) return;
-	LLInventoryPanel* panel = dynamic_cast<LLInventoryPanel*>(bridge->mInventoryPanel.get());
-	if (!panel) return;
-	LLInventoryModel* model = panel->getModel();
-	if(!model) return;
-	LLUUID id;
-	id = model->createNewCategory(bridge->getUUID(),
-								  LLAssetType::AT_NONE,
-								  LLStringUtil::null);
-	model->notifyObservers();
-
-	// At this point, the bridge has probably been deleted, but the
-	// view is still there.
-	panel->setSelection(id, TAKE_FOCUS_YES);
-}
-
-void LLFolderBridge::createNewShirt(void* user_data)
-{
-	LLFolderBridge::createWearable((LLFolderBridge*)user_data, WT_SHIRT);
-}
-
-void LLFolderBridge::createNewPants(void* user_data)
-{
-	LLFolderBridge::createWearable((LLFolderBridge*)user_data, WT_PANTS);
-}
-
-void LLFolderBridge::createNewShoes(void* user_data)
-{
-	LLFolderBridge::createWearable((LLFolderBridge*)user_data, WT_SHOES);
-}
-
-void LLFolderBridge::createNewSocks(void* user_data)
-{
-	LLFolderBridge::createWearable((LLFolderBridge*)user_data, WT_SOCKS);
-}
-
-void LLFolderBridge::createNewJacket(void* user_data)
-{
-	LLFolderBridge::createWearable((LLFolderBridge*)user_data, WT_JACKET);
-}
-
-void LLFolderBridge::createNewSkirt(void* user_data)
-{
-	LLFolderBridge::createWearable((LLFolderBridge*)user_data, WT_SKIRT);
-}
-
-void LLFolderBridge::createNewGloves(void* user_data)
-{
-	LLFolderBridge::createWearable((LLFolderBridge*)user_data, WT_GLOVES);
-}
-
-void LLFolderBridge::createNewUndershirt(void* user_data)
-{
-	LLFolderBridge::createWearable((LLFolderBridge*)user_data, WT_UNDERSHIRT);
-}
-
-void LLFolderBridge::createNewUnderpants(void* user_data)
-{
-	LLFolderBridge::createWearable((LLFolderBridge*)user_data, WT_UNDERPANTS);
-}
-
-void LLFolderBridge::createNewShape(void* user_data)
-{
-	LLFolderBridge::createWearable((LLFolderBridge*)user_data, WT_SHAPE);
-}
-
-void LLFolderBridge::createNewSkin(void* user_data)
-{
-	LLFolderBridge::createWearable((LLFolderBridge*)user_data, WT_SKIN);
-}
-
-void LLFolderBridge::createNewHair(void* user_data)
-{
-	LLFolderBridge::createWearable((LLFolderBridge*)user_data, WT_HAIR);
-}
-
-void LLFolderBridge::createNewEyes(void* user_data)
-{
-	LLFolderBridge::createWearable((LLFolderBridge*)user_data, WT_EYES);
-}
-
-// static
-void LLFolderBridge::createWearable(LLFolderBridge* bridge, EWearableType type)
-{
-	if(!bridge) return;
-	LLUUID parent_id = bridge->getUUID();
-	createWearable(parent_id, type);
-}
-
-// Separate function so can be called by global menu as well as right-click
-// menu.
-// static
-void LLFolderBridge::createWearable(LLUUID parent_id, EWearableType type)
-{
-	LLWearable* wearable = LLWearableList::instance().createNewWearable(type);
-	LLAssetType::EType asset_type = wearable->getAssetType();
-	LLInventoryType::EType inv_type = LLInventoryType::IT_WEARABLE;
-	create_inventory_item(gAgent.getID(), gAgent.getSessionID(),
-		parent_id, wearable->getTransactionID(), wearable->getName(),
-		wearable->getDescription(), asset_type, inv_type, wearable->getType(),
-		wearable->getPermissions().getMaskNextOwner(),
-		LLPointer<LLInventoryCallback>(NULL));
-}
-
-void LLFolderBridge::modifyOutfit(BOOL append)
-{
-	LLInventoryModel* model = getInventoryModel();
-	if(!model) return;
-	LLViewerInventoryCategory* cat = getCategory();
-	if(!cat) return;
-	
-	// BAP - was:
-	// wear_inventory_category_on_avatar( cat, append );
-	LLAppearanceManager::wearInventoryCategory( cat, FALSE, append );
-}
-
-// helper stuff
-bool move_task_inventory_callback(const LLSD& notification, const LLSD& response, LLMoveInv* move_inv)
-{
-	LLFloaterOpenObject::LLCatAndWear* cat_and_wear = (LLFloaterOpenObject::LLCatAndWear* )move_inv->mUserData;
-	LLViewerObject* object = gObjectList.findObject(move_inv->mObjectID);
-	S32 option = LLNotification::getSelectedOption(notification, response);
-
-	if(option == 0 && object)
-	{
-		if (cat_and_wear && cat_and_wear->mWear)
-		{
-			InventoryObjectList inventory_objects;
-			object->getInventoryContents(inventory_objects);
-			int contents_count = inventory_objects.size()-1; //subtract one for containing folder
-
-			LLInventoryCopyAndWearObserver* inventoryObserver = new LLInventoryCopyAndWearObserver(cat_and_wear->mCatID, contents_count);
-			gInventory.addObserver(inventoryObserver);
-		}
-
-		two_uuids_list_t::iterator move_it;
-		for (move_it = move_inv->mMoveList.begin(); 
-			move_it != move_inv->mMoveList.end(); 
-			++move_it)
-		{
-			object->moveInventory(move_it->first, move_it->second);
-		}
-
-		// update the UI.
-		dialog_refresh_all();
-	}
-
-	if (move_inv->mCallback)
-	{
-		move_inv->mCallback(option, move_inv->mUserData);
-	}
-
-	delete move_inv;
-	return false;
-}
-
-/*
-Next functions intended to reorder items in the inventory folder and save order on server
-Is now used for Favorites folder.
-
-*TODO: refactoring is needed with Favorites Bar functionality. Probably should be moved in LLInventoryModel
-*/
-void saveItemsOrder(LLInventoryModel::item_array_t& items)
-{
-	int sortField = 0;
-
-	// current order is saved by setting incremental values (1, 2, 3, ...) for the sort field
-	for (LLInventoryModel::item_array_t::iterator i = items.begin(); i != items.end(); ++i)
-	{
-		LLViewerInventoryItem* item = *i;
-
-		item->setSortField(++sortField);
-		item->setComplete(TRUE);
-		item->updateServer(FALSE);
-
-		gInventory.updateItem(item);
-	}
-
-	gInventory.notifyObservers();
-}
-
-LLInventoryModel::item_array_t::iterator findItemByUUID(LLInventoryModel::item_array_t& items, const LLUUID& id)
-{
-	LLInventoryModel::item_array_t::iterator result = items.end();
-
-	for (LLInventoryModel::item_array_t::iterator i = items.begin(); i != items.end(); ++i)
-	{
-		if ((*i)->getUUID() == id)
-		{
-			result = i;
-			break;
-		}
-	}
-
-	return result;
-}
-
-void updateItemsOrder(LLInventoryModel::item_array_t& items, const LLUUID& srcItemId, const LLUUID& destItemId)
-{
-	LLViewerInventoryItem* srcItem = gInventory.getItem(srcItemId);
-	LLViewerInventoryItem* destItem = gInventory.getItem(destItemId);
-
-	items.erase(findItemByUUID(items, srcItem->getUUID()));
-	items.insert(findItemByUUID(items, destItem->getUUID()), srcItem);
-}
-
-BOOL LLFolderBridge::dragItemIntoFolder(LLInventoryItem* inv_item,
-										BOOL drop)
-{
-	LLInventoryModel* model = getInventoryModel();
-	if(!model) return FALSE;
-
-	// cannot drag into library
-	if(!isAgentInventory())
-	{
-		return FALSE;
-	}
-
-	LLVOAvatarSelf* avatar = gAgent.getAvatarObject();
-	if(!avatar) return FALSE;
-
-	LLToolDragAndDrop::ESource source = LLToolDragAndDrop::getInstance()->getSource();
-	BOOL accept = FALSE;
-	LLViewerObject* object = NULL;
-	if(LLToolDragAndDrop::SOURCE_AGENT == source)
-	{
-
-		BOOL is_movable = TRUE;
-		switch( inv_item->getActualType() )
-		{
-		case LLAssetType::AT_ROOT_CATEGORY:
-			is_movable = FALSE;
-			break;
-
-		case LLAssetType::AT_CATEGORY:
-			is_movable = !LLAssetType::lookupIsProtectedCategoryType(((LLInventoryCategory*)inv_item)->getPreferredType());
-			break;
-		default:
-			break;
-		}
-
-		LLUUID trash_id = model->findCategoryUUIDForType(LLAssetType::AT_TRASH);
-		BOOL move_is_into_trash = (mUUID == trash_id) || model->isObjectDescendentOf(mUUID, trash_id);
-		LLUUID current_outfit_id = model->findCategoryUUIDForType(LLAssetType::AT_CURRENT_OUTFIT);
-		BOOL move_is_into_current_outfit = (mUUID == current_outfit_id);
-		BOOL move_is_into_outfit = (getCategory() && getCategory()->getPreferredType()==LLAssetType::AT_OUTFIT);
-		
-		if(is_movable && move_is_into_trash)
-		{
-			switch(inv_item->getType())
-			{
-			case LLAssetType::AT_CLOTHING:
-			case LLAssetType::AT_BODYPART:
-				is_movable = !gAgentWearables.isWearingItem(inv_item->getUUID());
-				break;
-
-			case LLAssetType::AT_OBJECT:
-				is_movable = !avatar->isWearingAttachment(inv_item->getUUID());
-				break;
-			default:
-				break;
-			}
-		}
-
-		if ( is_movable )
-		{
-			// Don't allow creating duplicates in the Calling Card/Friends
-			// subfolders, see bug EXT-1599. Check is item direct descendent
-			// of target folder and forbid item's movement if it so.
-			// Note: isItemDirectDescendentOfCategory checks if
-			// passed category is in the Calling Card/Friends folder
-			is_movable = ! LLFriendCardsManager::instance()
-				.isObjDirectDescendentOfCategory (inv_item, getCategory());
-		}
- 
-		LLUUID favorites_id = model->findCategoryUUIDForType(LLAssetType::AT_FAVORITE);
-
-		// we can move item inside a folder only if this folder is Favorites. See EXT-719
-		accept = is_movable && ((mUUID != inv_item->getParentUUID()) || (mUUID == favorites_id));
-		if(accept && drop)
-		{
-			if (inv_item->getType() == LLAssetType::AT_GESTURE
-				&& LLGestureManager::instance().isGestureActive(inv_item->getUUID()) && move_is_into_trash)
-			{
-				LLGestureManager::instance().deactivateGesture(inv_item->getUUID());
-			}
-			// If an item is being dragged between windows, unselect
-			// everything in the active window so that we don't follow
-			// the selection to its new location (which is very
-			// annoying).
-			if (LLFloaterInventory::getActiveInventory())
-			{
-				LLInventoryPanel* active_panel = LLFloaterInventory::getActiveInventory()->getPanel();
-				LLInventoryPanel* panel = dynamic_cast<LLInventoryPanel*>(mInventoryPanel.get());
-				if (active_panel && (panel != active_panel))
-				{
-					active_panel->unSelectAll();
-				}
-			}
-
-			// if dragging from/into favorites folder only reorder items
-			if ((mUUID == inv_item->getParentUUID()) && (favorites_id == mUUID))
-			{
-				LLInventoryModel::cat_array_t cats;
-				LLInventoryModel::item_array_t items;
-				LLIsType is_type(LLAssetType::AT_LANDMARK);
-				model->collectDescendentsIf(favorites_id, cats, items, LLInventoryModel::EXCLUDE_TRASH, is_type);
-
-				LLInventoryPanel* panel = dynamic_cast<LLInventoryPanel*>(mInventoryPanel.get());
-				LLFolderViewItem* itemp = panel ? panel->getRootFolder()->getDraggingOverItem() : NULL;
-				if (itemp)
-				{
-					LLUUID srcItemId = inv_item->getUUID();
-					LLUUID destItemId = itemp->getListener()->getUUID();
-
-					// update order
-					updateItemsOrder(items, srcItemId, destItemId);
-
-					saveItemsOrder(items);
-				}
-			}
-			else if (favorites_id == mUUID) // if target is the favorites folder we use copy
-			{
-				copy_inventory_item(
-					gAgent.getID(),
-					inv_item->getPermissions().getOwner(),
-					inv_item->getUUID(),
-					mUUID,
-					std::string(),
-					LLPointer<LLInventoryCallback>(NULL));
-			}
-			else if (move_is_into_current_outfit || move_is_into_outfit)
-			{
-				// BAP - should skip if dup.
-				if (move_is_into_current_outfit)
-				{
-					LLAppearanceManager::wearItem(inv_item);
-				}
-				else
-				{
-					LLPointer<LLInventoryCallback> cb = NULL;
-					link_inventory_item(
-						gAgent.getID(),
-						inv_item->getUUID(),
-						mUUID,
-						std::string(),
-						LLAssetType::AT_LINK,
-						cb);
-				}
-			}
-			else
-			{
-				// restamp if the move is into the trash.
-				LLInvFVBridge::changeItemParent(
-					model,
-					(LLViewerInventoryItem*)inv_item,
-					mUUID,
-					move_is_into_trash);
-			}
-		}
-	}
-	else if(LLToolDragAndDrop::SOURCE_WORLD == source)
-	{
-		// Make sure the object exists. If we allowed dragging from
-		// anonymous objects, it would be possible to bypass
-		// permissions.
-		object = gObjectList.findObject(inv_item->getParentUUID());
-		if(!object)
-		{
-			llinfos << "Object not found for drop." << llendl;
-			return FALSE;
-		}
-
-		// coming from a task. Need to figure out if the person can
-		// move/copy this item.
-		LLPermissions perm(inv_item->getPermissions());
-		BOOL is_move = FALSE;
-		if((perm.allowCopyBy(gAgent.getID(), gAgent.getGroupID())
-			&& perm.allowTransferTo(gAgent.getID())))
-//		   || gAgent.isGodlike())
-			
-		{
-			accept = TRUE;
-		}
-		else if(object->permYouOwner())
-		{
-			// If the object cannot be copied, but the object the
-			// inventory is owned by the agent, then the item can be
-			// moved from the task to agent inventory.
-			is_move = TRUE;
-			accept = TRUE;
-		}
-		if(drop && accept)
-		{
-			LLMoveInv* move_inv = new LLMoveInv;
-			move_inv->mObjectID = inv_item->getParentUUID();
-			two_uuids_t item_pair(mUUID, inv_item->getUUID());
-			move_inv->mMoveList.push_back(item_pair);
-			move_inv->mCallback = NULL;
-			move_inv->mUserData = NULL;
-			if(is_move)
-			{
-				warn_move_inventory(object, move_inv);
-			}
-			else
-			{
-				LLNotification::Params params("MoveInventoryFromObject");
-				params.functor.function(boost::bind(move_task_inventory_callback, _1, _2, move_inv));
-				LLNotifications::instance().forceResponse(params, 0);
-			}
-		}
-		
-	}
-	else if(LLToolDragAndDrop::SOURCE_NOTECARD == source)
-	{
-		accept = TRUE;
-		if(drop)
-		{
-			copy_inventory_from_notecard(LLToolDragAndDrop::getInstance()->getObjectID(),
-				LLToolDragAndDrop::getInstance()->getSourceID(), inv_item);
-		}
-	}
-	else if(LLToolDragAndDrop::SOURCE_LIBRARY == source)
-	{
-		LLViewerInventoryItem* item = (LLViewerInventoryItem*)inv_item;
-		if(item && item->isComplete())
-		{
-			accept = TRUE;
-			if(drop)
-			{
-				copy_inventory_item(
-					gAgent.getID(),
-					inv_item->getPermissions().getOwner(),
-					inv_item->getUUID(),
-					mUUID,
-					std::string(),
-					LLPointer<LLInventoryCallback>(NULL));
-			}
-		}
-	}
-	else
-	{
-		llwarns << "unhandled drag source" << llendl;
-	}
-	return accept;
-}
-
-// +=================================================+
-// |        LLScriptBridge (DEPRECTED)               |
-// +=================================================+
-
-LLUIImagePtr LLScriptBridge::getIcon() const
-{
-	return get_item_icon(LLAssetType::AT_SCRIPT, LLInventoryType::IT_LSL, 0, FALSE);
-}
-
-// +=================================================+
-// |        LLTextureBridge                          |
-// +=================================================+
-
-LLUIImagePtr LLTextureBridge::getIcon() const
-{
-	return get_item_icon(LLAssetType::AT_TEXTURE, mInvType, 0, FALSE);
-}
-	
-void LLTextureBridge::openItem()
-{
-	LLViewerInventoryItem* item = getItem();
-	
-	if (item)
-	{
-		LLInvFVBridgeAction::doAction(item->getType(),mUUID,getInventoryModel());
-	}
-}
-
-// +=================================================+
-// |        LLSoundBridge                            |
-// +=================================================+
-
-LLUIImagePtr LLSoundBridge::getIcon() const
-{
-	return get_item_icon(LLAssetType::AT_SOUND, LLInventoryType::IT_SOUND, 0, FALSE);
-}
-
-void LLSoundBridge::openItem()
-{
-	LLViewerInventoryItem* item = getItem();
-	
-	if (item)
-	{
-		LLInvFVBridgeAction::doAction(item->getType(),mUUID,getInventoryModel());
-	}
-/*
-// Changed this back to the way it USED to work:
-// only open the preview dialog through the contextual right-click menu
-// double-click just plays the sound
-
-	LLViewerInventoryItem* item = getItem();
-	if(item)
-	{
-		openSoundPreview((void*)this);
-		//send_uuid_sound_trigger(item->getAssetUUID(), 1.0);
-	}
-*/
-}
-
-void LLSoundBridge::previewItem()
-{
-	LLViewerInventoryItem* item = getItem();
-	if(item)
-	{
-		send_sound_trigger(item->getAssetUUID(), 1.0);
-	}
-}
-
-void LLSoundBridge::openSoundPreview(void* which)
-{
-	LLSoundBridge *me = (LLSoundBridge *)which;
-	LLFloaterReg::showInstance("preview_sound", LLSD(me->mUUID), TAKE_FOCUS_YES);
-}
-
-void LLSoundBridge::buildContextMenu(LLMenuGL& menu, U32 flags)
-{
-	lldebugs << "LLTextureBridge::buildContextMenu()" << llendl;
-	std::vector<std::string> items;
-	std::vector<std::string> disabled_items;
-
-	if(isInTrash())
-	{
-		items.push_back(std::string("Purge Item"));
-		if (!isItemRemovable())
-		{
-			disabled_items.push_back(std::string("Purge Item"));
-		}
-
-		items.push_back(std::string("Restore Item"));
-	}
-	else
-	{
-		items.push_back(std::string("Sound Open"));
-		items.push_back(std::string("Properties"));
-
-		getClipboardEntries(true, items, disabled_items, flags);
-	}
-
-	items.push_back(std::string("Sound Separator"));
-	items.push_back(std::string("Sound Play"));
-
-	hideContextEntries(menu, items, disabled_items);
-}
-
-// +=================================================+
-// |        LLLandmarkBridge                         |
-// +=================================================+
-
-LLLandmarkBridge::LLLandmarkBridge(LLInventoryPanel* inventory, const LLUUID& uuid, U32 flags/* = 0x00*/) :
-LLItemBridge(inventory, uuid) 
-{
-	mVisited = FALSE;
-	if (flags & LLInventoryItem::II_FLAGS_LANDMARK_VISITED)
-	{
-		mVisited = TRUE;
-	}
-}
-
-LLUIImagePtr LLLandmarkBridge::getIcon() const
-{
-	return get_item_icon(LLAssetType::AT_LANDMARK, LLInventoryType::IT_LANDMARK, mVisited, FALSE);
-}
-
-void LLLandmarkBridge::buildContextMenu(LLMenuGL& menu, U32 flags)
-{
-	std::vector<std::string> items;
-	std::vector<std::string> disabled_items;
-
-	lldebugs << "LLLandmarkBridge::buildContextMenu()" << llendl;
-	if(isInTrash())
-	{
-		items.push_back(std::string("Purge Item"));
-		if (!isItemRemovable())
-		{
-			disabled_items.push_back(std::string("Purge Item"));
-		}
-
-		items.push_back(std::string("Restore Item"));
-	}
-	else
-	{
-		items.push_back(std::string("Landmark Open"));
-		items.push_back(std::string("Properties"));
-
-		getClipboardEntries(true, items, disabled_items, flags);
-	}
-
-	items.push_back(std::string("Landmark Separator"));
-	items.push_back(std::string("About Landmark"));
-
-	// Disable "About Landmark" menu item for
-	// multiple landmarks selected. Only one landmark
-	// info panel can be shown at a time.
-	if ((flags & FIRST_SELECTED_ITEM) == 0)
-	{
-		disabled_items.push_back(std::string("About Landmark"));
-	}
-
-	hideContextEntries(menu, items, disabled_items);
-}
-
-// Convenience function for the two functions below.
-void teleport_via_landmark(const LLUUID& asset_id)
-{
-	gAgent.teleportViaLandmark( asset_id );
-
-	// we now automatically track the landmark you're teleporting to
-	// because you'll probably arrive at a telehub instead
-	LLFloaterWorldMap* floater_world_map = LLFloaterWorldMap::getInstance();
-	if( floater_world_map )
-	{
-		floater_world_map->trackLandmark( asset_id );
-	}
-}
-
-// virtual
-void LLLandmarkBridge::performAction(LLFolderView* folder, LLInventoryModel* model, std::string action)
-{
-	if ("teleport" == action)
-	{
-		LLViewerInventoryItem* item = getItem();
-		if(item)
-		{
-			teleport_via_landmark(item->getAssetUUID());
-		}
-	}
-	else if ("about" == action)
-	{
-		LLViewerInventoryItem* item = getItem();
-		if(item)
-		{
-			LLSD key;
-			key["type"] = "landmark";
-			key["id"] = item->getUUID();
-
-			LLSideTray::getInstance()->showPanel("panel_places", key);
-		}
-	}
-	else 
-	{
-		LLItemBridge::performAction(folder, model, action);
-	}
-}
-
-static bool open_landmark_callback(const LLSD& notification, const LLSD& response)
-{
-	S32 option = LLNotification::getSelectedOption(notification, response);
-
-	LLUUID asset_id = notification["payload"]["asset_id"].asUUID();
-	if (option == 0)
-	{
-		teleport_via_landmark(asset_id);
-	}
-
-	return false;
-}
-static LLNotificationFunctorRegistration open_landmark_callback_reg("TeleportFromLandmark", open_landmark_callback);
-
-
-void LLLandmarkBridge::openItem()
-{
-	LLViewerInventoryItem* item = getItem();
-	
-	if (item)
-	{
-		LLInvFVBridgeAction::doAction(item->getType(),mUUID,getInventoryModel());
-	}
-/*
-	LLViewerInventoryItem* item = getItem();
-	if( item )
-	{
-		// Opening (double-clicking) a landmark immediately teleports,
-		// but warns you the first time.
-		// open_landmark(item);
-		LLSD payload;
-		payload["asset_id"] = item->getAssetUUID();
-		LLNotifications::instance().add("TeleportFromLandmark", LLSD(), payload);
-	}
-*/
-}
-
-
-// +=================================================+
-// |        LLCallingCardObserver                    |
-// +=================================================+
-void LLCallingCardObserver::changed(U32 mask)
-{
-	mBridgep->refreshFolderViewItem();
-}
-
-// +=================================================+
-// |        LLCallingCardBridge                      |
-// +=================================================+
-
-LLCallingCardBridge::LLCallingCardBridge( LLInventoryPanel* inventory, const LLUUID& uuid ) :
-	LLItemBridge(inventory, uuid)
-{
-	mObserver = new LLCallingCardObserver(this);
-	LLAvatarTracker::instance().addObserver(mObserver);
-}
-
-LLCallingCardBridge::~LLCallingCardBridge()
-{
-	LLAvatarTracker::instance().removeObserver(mObserver);
-	delete mObserver;
-}
-
-void LLCallingCardBridge::refreshFolderViewItem()
-{
-	LLInventoryPanel* panel = dynamic_cast<LLInventoryPanel*>(mInventoryPanel.get());
-	LLFolderViewItem* itemp = panel ? panel->getRootFolder()->getItemByID(mUUID) : NULL;
-	if (itemp)
-	{
-		itemp->refresh();
-	}
-}
-
-// virtual
-void LLCallingCardBridge::performAction(LLFolderView* folder, LLInventoryModel* model, std::string action)
-{
-	if ("begin_im" == action)
-	{
-		LLViewerInventoryItem *item = getItem();
-		if (item && (item->getCreatorUUID() != gAgent.getID()) &&
-			(!item->getCreatorUUID().isNull()))
-		{
-			std::string callingcard_name;
-			gCacheName->getFullName(item->getCreatorUUID(), callingcard_name);
-			gIMMgr->addSession(callingcard_name, IM_NOTHING_SPECIAL, item->getCreatorUUID());
-		}
-	}
-	else if ("lure" == action)
-	{
-		LLViewerInventoryItem *item = getItem();
-		if (item && (item->getCreatorUUID() != gAgent.getID()) &&
-			(!item->getCreatorUUID().isNull()))
-		{
-			LLAvatarActions::offerTeleport(item->getCreatorUUID());
-		}
-	}
-	else LLItemBridge::performAction(folder, model, action);
-}
-
-LLUIImagePtr LLCallingCardBridge::getIcon() const
-{
-	BOOL online = FALSE;
-	LLViewerInventoryItem* item = getItem();
-	if(item)
-	{
-		online = LLAvatarTracker::instance().isBuddyOnline(item->getCreatorUUID());
-	}
-	return get_item_icon(LLAssetType::AT_CALLINGCARD, LLInventoryType::IT_CALLINGCARD, online, FALSE);
-}
-
-std::string LLCallingCardBridge::getLabelSuffix() const
-{
-	LLViewerInventoryItem* item = getItem();
-	if( item && LLAvatarTracker::instance().isBuddyOnline(item->getCreatorUUID()) )
-	{
-		return LLItemBridge::getLabelSuffix() + " (online)";
-	}
-	else
-	{
-		return LLItemBridge::getLabelSuffix();
-	}
-}
-
-void LLCallingCardBridge::openItem()
-{
-	LLViewerInventoryItem* item = getItem();
-	
-	if (item)
-	{
-		LLInvFVBridgeAction::doAction(item->getType(),mUUID,getInventoryModel());
-	}
-/*
-	LLViewerInventoryItem* item = getItem();
-	if(item && !item->getCreatorUUID().isNull())
-	{
-		LLAvatarActions::showProfile(item->getCreatorUUID());
-	}
-*/
-}
-
-void LLCallingCardBridge::buildContextMenu(LLMenuGL& menu, U32 flags)
-{
-	lldebugs << "LLCallingCardBridge::buildContextMenu()" << llendl;
-	std::vector<std::string> items;
-	std::vector<std::string> disabled_items;
-
-	if(isInTrash())
-	{
-		items.push_back(std::string("Purge Item"));
-		if (!isItemRemovable())
-		{
-			disabled_items.push_back(std::string("Purge Item"));
-		}
-
-		items.push_back(std::string("Restore Item"));
-	}
-	else
-	{
-		items.push_back(std::string("Open"));
-		items.push_back(std::string("Properties"));
-
-		getClipboardEntries(true, items, disabled_items, flags);
-
-		LLInventoryItem* item = getItem();
-		BOOL good_card = (item
-						  && (LLUUID::null != item->getCreatorUUID())
-						  && (item->getCreatorUUID() != gAgent.getID()));
-		BOOL user_online = (LLAvatarTracker::instance().isBuddyOnline(item->getCreatorUUID()));
-		items.push_back(std::string("Send Instant Message Separator"));
-		items.push_back(std::string("Send Instant Message"));
-		items.push_back(std::string("Offer Teleport..."));
-		items.push_back(std::string("Conference Chat"));
-
-		if (!good_card)
-		{
-			disabled_items.push_back(std::string("Send Instant Message"));
-		}
-		if (!good_card || !user_online)
-		{
-			disabled_items.push_back(std::string("Offer Teleport..."));
-			disabled_items.push_back(std::string("Conference Chat"));
-		}
-	}
-	hideContextEntries(menu, items, disabled_items);
-}
-
-BOOL LLCallingCardBridge::dragOrDrop(MASK mask, BOOL drop,
-									 EDragAndDropType cargo_type,
-									 void* cargo_data)
-{
-	LLViewerInventoryItem* item = getItem();
-	BOOL rv = FALSE;
-	if(item)
-	{
-		// check the type
-		switch(cargo_type)
-		{
-		case DAD_TEXTURE:
-		case DAD_SOUND:
-		case DAD_LANDMARK:
-		case DAD_SCRIPT:
-		case DAD_CLOTHING:
-		case DAD_OBJECT:
-		case DAD_NOTECARD:
-		case DAD_BODYPART:
-		case DAD_ANIMATION:
-		case DAD_GESTURE:
-			{
-				LLInventoryItem* inv_item = (LLInventoryItem*)cargo_data;
-				const LLPermissions& perm = inv_item->getPermissions();
-				if(gInventory.getItem(inv_item->getUUID())
-				   && perm.allowOperationBy(PERM_TRANSFER, gAgent.getID()))
-				{
-					rv = TRUE;
-					if(drop)
-					{
-						LLToolDragAndDrop::giveInventory(item->getCreatorUUID(),
-														 (LLInventoryItem*)cargo_data);
-					}
-				}
-				else
-				{
-					// It's not in the user's inventory (it's probably in
-					// an object's contents), so disallow dragging it here.
-					// You can't give something you don't yet have.
-					rv = FALSE;
-				}
-				break;
-			}
-		case DAD_CATEGORY:
-			{
-				LLInventoryCategory* inv_cat = (LLInventoryCategory*)cargo_data;
-				if( gInventory.getCategory( inv_cat->getUUID() ) )
-				{
-					rv = TRUE;
-					if(drop)
-					{
-						LLToolDragAndDrop::giveInventoryCategory(
-							item->getCreatorUUID(),
-							inv_cat);
-					}
-				}
-				else
-				{
-					// It's not in the user's inventory (it's probably in
-					// an object's contents), so disallow dragging it here.
-					// You can't give something you don't yet have.
-					rv = FALSE;
-				}
-				break;
-			}
-		default:
-			break;
-		}
-	}
-	return rv;
-}
-
-BOOL LLCallingCardBridge::removeItem()
-{
-	if (LLFriendCardsManager::instance().isItemInAnyFriendsList(getItem()))
-	{
-		LLAvatarActions::removeFriendDialog(getItem()->getCreatorUUID());
-		return FALSE;
-	}
-	else 
-	{
-		return LLItemBridge::removeItem();
-	}
-}
-// +=================================================+
-// |        LLNotecardBridge                         |
-// +=================================================+
-
-LLUIImagePtr LLNotecardBridge::getIcon() const
-{
-	return get_item_icon(LLAssetType::AT_NOTECARD, LLInventoryType::IT_NOTECARD, 0, FALSE);
-}
-
-void LLNotecardBridge::openItem()
-{
-	LLViewerInventoryItem* item = getItem();
-	
-	if (item)
-	{
-		LLInvFVBridgeAction::doAction(item->getType(),mUUID,getInventoryModel());
-	}
-
-/*
-	LLViewerInventoryItem* item = getItem();
-	if (item)
-	{
-		LLFloaterReg::showInstance("preview_notecard", LLSD(item->getUUID()), TAKE_FOCUS_YES);
-	}
-*/
-}
-
-
-// +=================================================+
-// |        LLGestureBridge                          |
-// +=================================================+
-
-LLUIImagePtr LLGestureBridge::getIcon() const
-{
-	return get_item_icon(LLAssetType::AT_GESTURE, LLInventoryType::IT_GESTURE, 0, FALSE);
-}
-
-LLFontGL::StyleFlags LLGestureBridge::getLabelStyle() const
-{
-	if( LLGestureManager::instance().isGestureActive(mUUID) )
-	{
-		return LLFontGL::BOLD;
-	}
-	else
-	{
-		return LLFontGL::NORMAL;
-	}
-}
-
-std::string LLGestureBridge::getLabelSuffix() const
-{
-	if( LLGestureManager::instance().isGestureActive(mUUID) )
-	{
-		return LLItemBridge::getLabelSuffix() + " (active)";
-	}
-	else
-	{
-		return LLItemBridge::getLabelSuffix();
-	}
-}
-
-// virtual
-void LLGestureBridge::performAction(LLFolderView* folder, LLInventoryModel* model, std::string action)
-{
-	if ("activate" == action)
-	{
-		LLGestureManager::instance().activateGesture(mUUID);
-
-		LLViewerInventoryItem* item = gInventory.getItem(mUUID);
-		if (!item) return;
-
-		// Since we just changed the suffix to indicate (active)
-		// the server doesn't need to know, just the viewer.
-		gInventory.updateItem(item);
-		gInventory.notifyObservers();
-	}
-	else if ("deactivate" == action)
-	{
-		LLGestureManager::instance().deactivateGesture(mUUID);
-
-		LLViewerInventoryItem* item = gInventory.getItem(mUUID);
-		if (!item) return;
-
-		// Since we just changed the suffix to indicate (active)
-		// the server doesn't need to know, just the viewer.
-		gInventory.updateItem(item);
-		gInventory.notifyObservers();
-	}
-	else LLItemBridge::performAction(folder, model, action);
-}
-
-void LLGestureBridge::openItem()
-{
-	LLViewerInventoryItem* item = getItem();
-	
-	if (item)
-	{
-		LLInvFVBridgeAction::doAction(item->getType(),mUUID,getInventoryModel());
-	}
-/*
-	LLViewerInventoryItem* item = getItem();
-	if (item)
-	{
-		LLPreviewGesture* preview = LLPreviewGesture::show(mUUID, LLUUID::null);
-		preview->setFocus(TRUE);
-	}
-*/
-}
-
-BOOL LLGestureBridge::removeItem()
-{
-	// Force close the preview window, if it exists
-	LLGestureManager::instance().deactivateGesture(mUUID);
-	return LLItemBridge::removeItem();
-}
-
-void LLGestureBridge::buildContextMenu(LLMenuGL& menu, U32 flags)
-{
-	lldebugs << "LLGestureBridge::buildContextMenu()" << llendl;
-	std::vector<std::string> items;
-	std::vector<std::string> disabled_items;
-	if(isInTrash())
-	{
-		items.push_back(std::string("Purge Item"));
-		if (!isItemRemovable())
-		{
-			disabled_items.push_back(std::string("Purge Item"));
-		}
-
-		items.push_back(std::string("Restore Item"));
-	}
-	else
-	{
-		items.push_back(std::string("Open"));
-		items.push_back(std::string("Properties"));
-
-		getClipboardEntries(true, items, disabled_items, flags);
-
-		items.push_back(std::string("Gesture Separator"));
-		items.push_back(std::string("Activate"));
-		items.push_back(std::string("Deactivate"));
-	}
-	hideContextEntries(menu, items, disabled_items);
-}
-
-// +=================================================+
-// |        LLAnimationBridge                        |
-// +=================================================+
-
-LLUIImagePtr LLAnimationBridge::getIcon() const
-{
-	return get_item_icon(LLAssetType::AT_ANIMATION, LLInventoryType::IT_ANIMATION, 0, FALSE);
-}
-
-void LLAnimationBridge::buildContextMenu(LLMenuGL& menu, U32 flags)
-{
-	std::vector<std::string> items;
-	std::vector<std::string> disabled_items;
-
-	lldebugs << "LLAnimationBridge::buildContextMenu()" << llendl;
-	if(isInTrash())
-	{
-		items.push_back(std::string("Purge Item"));
-		if (!isItemRemovable())
-		{
-			disabled_items.push_back(std::string("Purge Item"));
-		}
-
-		items.push_back(std::string("Restore Item"));
-	}
-	else
-	{
-		items.push_back(std::string("Animation Open"));
-		items.push_back(std::string("Properties"));
-
-		getClipboardEntries(true, items, disabled_items, flags);
-	}
-
-	items.push_back(std::string("Animation Separator"));
-	items.push_back(std::string("Animation Play"));
-	items.push_back(std::string("Animation Audition"));
-
-	hideContextEntries(menu, items, disabled_items);
-
-}
-
-// virtual
-void LLAnimationBridge::performAction(LLFolderView* folder, LLInventoryModel* model, std::string action)
-{
-	if ((action == "playworld") || (action == "playlocal"))
-	{
-		if (getItem())
-		{
-			LLPreviewAnim::e_activation_type activate = LLPreviewAnim::NONE;
-			if ("playworld" == action) activate = LLPreviewAnim::PLAY;
-			if ("playlocal" == action) activate = LLPreviewAnim::AUDITION;
-			
-			LLPreviewAnim* preview = LLFloaterReg::showTypedInstance<LLPreviewAnim>("preview_anim", LLSD(mUUID));
-			if (preview)
-			{
-				preview->activate(activate);
-			}
-		}
-	}
-	else
-	{
-		LLItemBridge::performAction(folder, model, action);
-	}
-}
-
-void LLAnimationBridge::openItem()
-{
-	LLViewerInventoryItem* item = getItem();
-	
-	if (item)
-	{
-		LLInvFVBridgeAction::doAction(item->getType(),mUUID,getInventoryModel());
-	}
-/*
-	LLViewerInventoryItem* item = getItem();
-	if (item)
-	{
-		LLFloaterReg::showInstance("preview_anim", LLSD(mUUID), TAKE_FOCUS_YES);
-	}
-*/
-}
-
-// +=================================================+
-// |        LLObjectBridge                           |
-// +=================================================+
-
-// static
-LLUUID LLObjectBridge::sContextMenuItemID;
-
-LLObjectBridge::LLObjectBridge(LLInventoryPanel* inventory, const LLUUID& uuid, LLInventoryType::EType type, U32 flags) :
-LLItemBridge(inventory, uuid), mInvType(type)
-{
-	mAttachPt = (flags & 0xff); // low bye of inventory flags
-
-	mIsMultiObject = ( flags & LLInventoryItem::II_FLAGS_OBJECT_HAS_MULTIPLE_ITEMS ) ?  TRUE: FALSE;
-}
-
-BOOL LLObjectBridge::isItemRemovable()
-{
-	LLVOAvatarSelf* avatar = gAgent.getAvatarObject();
-	if(!avatar) return FALSE;
-	if(avatar->isWearingAttachment(mUUID)) return FALSE;
-	return LLInvFVBridge::isItemRemovable();
-}
-
-LLUIImagePtr LLObjectBridge::getIcon() const
-{
-	return get_item_icon(LLAssetType::AT_OBJECT, mInvType, mAttachPt, mIsMultiObject );
-}
-
-LLInventoryObject* LLObjectBridge::getObject() const
-{
-	LLInventoryObject* object = NULL;
-	LLInventoryModel* model = getInventoryModel();
-	if(model)
-	{
-		object = (LLInventoryObject*)model->getObject(mUUID);
-	}
-	return object;
-}
-
-// virtual
-void LLObjectBridge::performAction(LLFolderView* folder, LLInventoryModel* model, std::string action)
-{
-	if ("attach" == action)
-	{
-		LLUUID object_id = mUUID;
-		LLViewerInventoryItem* item;
-		item = (LLViewerInventoryItem*)gInventory.getItem(object_id);
-		if(item && gInventory.isObjectDescendentOf(object_id, gInventory.getRootFolderID()))
-		{
-			rez_attachment(item, NULL);
-		}
-		else if(item && item->isComplete())
-		{
-			// must be in library. copy it to our inventory and put it on.
-			LLPointer<LLInventoryCallback> cb = new RezAttachmentCallback(0);
-			copy_inventory_item(
-				gAgent.getID(),
-				item->getPermissions().getOwner(),
-				item->getUUID(),
-				LLUUID::null,
-				std::string(),
-				cb);
-		}
-		gFocusMgr.setKeyboardFocus(NULL);
-	}
-	else if ("detach" == action)
-	{
-		LLInventoryItem* item = gInventory.getItem(mUUID);
-		if(item)
-		{
-			gMessageSystem->newMessageFast(_PREHASH_DetachAttachmentIntoInv);
-			gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
-			gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-			gMessageSystem->addUUIDFast(_PREHASH_ItemID, item->getLinkedUUID());
-			gMessageSystem->sendReliable( gAgent.getRegion()->getHost());
-		}
-		// this object might have been selected, so let the selection manager know it's gone now
-		LLViewerObject *found_obj =
-			gObjectList.findObject(item->getUUID());
-		if (found_obj)
-		{
-			LLSelectMgr::getInstance()->remove(found_obj);
-		}
-		else
-		{
-			llwarns << "object not found - ignoring" << llendl;
-		}
-	}
-	else LLItemBridge::performAction(folder, model, action);
-}
-
-void LLObjectBridge::openItem()
-{
-	LLViewerInventoryItem* item = getItem();
-	
-	if (item)
-	{
-		LLInvFVBridgeAction::doAction(item->getType(),mUUID,getInventoryModel());
-	}
-
-	/*
-	LLFloaterReg::showInstance("properties", mUUID);
-	*/
-}
-
-LLFontGL::StyleFlags LLObjectBridge::getLabelStyle() const
-{ 
-	U8 font = LLFontGL::NORMAL;
-
-	LLVOAvatarSelf* avatar = gAgent.getAvatarObject();
-	if( avatar && avatar->isWearingAttachment( mUUID ) )
-	{
-		font |= LLFontGL::BOLD;
-	}
-
-	LLInventoryItem* item = getItem();
-	if (item && item->getIsLinkType())
-	{
-		font |= LLFontGL::ITALIC;
-	}
-	
-	return (LLFontGL::StyleFlags)font;
-}
-
-std::string LLObjectBridge::getLabelSuffix() const
-{
-	LLVOAvatarSelf* avatar = gAgent.getAvatarObject();
-	if( avatar && avatar->isWearingAttachment( mUUID ) )
-	{
-		std::string attachment_point_name = avatar->getAttachedPointName(mUUID);
-		LLStringUtil::toLower(attachment_point_name);
-		
-		LLStringUtil::format_map_t args;
-		args["[ATTACHMENT_POINT]"] =  attachment_point_name.c_str();
-		return LLItemBridge::getLabelSuffix() + LLTrans::getString("WornOnAttachmentPoint", args);
-	}
-	else
-	{
-		return LLItemBridge::getLabelSuffix();
-	}
-}
-
-void rez_attachment(LLViewerInventoryItem* item, LLViewerJointAttachment* attachment)
-{
-	LLSD payload;
-	payload["item_id"] = item->getLinkedUUID(); // Wear the base object in case this is a link.
-
-	S32 attach_pt = 0;
-	if (gAgent.getAvatarObject() && attachment)
-	{
-		for (LLVOAvatar::attachment_map_t::iterator iter = gAgent.getAvatarObject()->mAttachmentPoints.begin();
-			 iter != gAgent.getAvatarObject()->mAttachmentPoints.end(); ++iter)
-		{
-			if (iter->second == attachment)
-			{
-				attach_pt = iter->first;
-				break;
-			}
-		}
-	}
-
-	payload["attachment_point"] = attach_pt;
-
-#if !ENABLE_MULTIATTACHMENTS
-	if (attachment && attachment->getNumObjects() > 0)
-	{
-		LLNotifications::instance().add("ReplaceAttachment", LLSD(), payload, confirm_replace_attachment_rez);
-	}
-	else
-#endif
-	{
-		LLNotifications::instance().forceResponse(LLNotification::Params("ReplaceAttachment").payload(payload), 0/*YES*/);
-	}
-}
-
-bool confirm_replace_attachment_rez(const LLSD& notification, const LLSD& response)
-{
-	LLVOAvatar *avatarp = gAgent.getAvatarObject();
-		
-	if (!avatarp->canAttachMoreObjects())
-	{
-		LLSD args;
-		args["MAX_ATTACHMENTS"] = llformat("%d", MAX_AGENT_ATTACHMENTS);
-		LLNotifications::instance().add("MaxAttachmentsOnOutfit", args);
-		return false;
-	}
-
-	S32 option = LLNotification::getSelectedOption(notification, response);
-	if (option == 0/*YES*/)
-	{
-		LLViewerInventoryItem* itemp = gInventory.getItem(notification["payload"]["item_id"].asUUID());
-		
-		if (itemp)
-		{
-			LLMessageSystem* msg = gMessageSystem;
-			msg->newMessageFast(_PREHASH_RezSingleAttachmentFromInv);
-			msg->nextBlockFast(_PREHASH_AgentData);
-			msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-			msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-			msg->nextBlockFast(_PREHASH_ObjectData);
-			msg->addUUIDFast(_PREHASH_ItemID, itemp->getUUID());
-			msg->addUUIDFast(_PREHASH_OwnerID, itemp->getPermissions().getOwner());
-			U8 attachment_pt = notification["payload"]["attachment_point"].asInteger();
-#if ENABLE_MULTIATTACHMENTS
-			attachment_pt |= ATTACHMENT_ADD;
-#endif
-			msg->addU8Fast(_PREHASH_AttachmentPt, attachment_pt);
-			pack_permissions_slam(msg, itemp->getFlags(), itemp->getPermissions());
-			msg->addStringFast(_PREHASH_Name, itemp->getName());
-			msg->addStringFast(_PREHASH_Description, itemp->getDescription());
-			msg->sendReliable(gAgent.getRegion()->getHost());
-		}
-	}
-	return false;
-}
-static LLNotificationFunctorRegistration confirm_replace_attachment_rez_reg("ReplaceAttachment", confirm_replace_attachment_rez);
-
-void LLObjectBridge::buildContextMenu(LLMenuGL& menu, U32 flags)
-{
-	std::vector<std::string> items;
-	std::vector<std::string> disabled_items;
-	if(isInTrash())
-	{
-		items.push_back(std::string("Purge Item"));
-		if (!isItemRemovable())
-		{
-			disabled_items.push_back(std::string("Purge Item"));
-		}
-
-		items.push_back(std::string("Restore Item"));
-	}
-	else
-	{
-		LLInventoryItem* item = getItem();
-		if (item && item->getIsLinkType())
-		{
-			items.push_back(std::string("Goto Link"));
-		}
-
-		items.push_back(std::string("Properties"));
-
-		getClipboardEntries(true, items, disabled_items, flags);
-
-		LLObjectBridge::sContextMenuItemID = mUUID;
-
-		if(item)
-		{
-			LLVOAvatarSelf* avatarp = gAgent.getAvatarObject();
-			if( !avatarp )
-			{
-				return;
-			}
-			
-			if( avatarp->isWearingAttachment( mUUID ) )
-			{
-				items.push_back(std::string("Detach From Yourself"));
-			}
-			else
-			if( !isInTrash() && !isLinkedObjectInTrash() )
-			{
-				items.push_back(std::string("Attach Separator"));
-				items.push_back(std::string("Object Wear"));
-				items.push_back(std::string("Attach To"));
-				items.push_back(std::string("Attach To HUD"));
-				// commented out for DEV-32347
-				//items.push_back(std::string("Restore to Last Position"));
-
-				if (!avatarp->canAttachMoreObjects())
-				{
-					disabled_items.push_back(std::string("Object Wear"));
-					disabled_items.push_back(std::string("Attach To"));
-					disabled_items.push_back(std::string("Attach To HUD"));
-				}
-				LLMenuGL* attach_menu = menu.findChildMenuByName("Attach To", TRUE);
-				LLMenuGL* attach_hud_menu = menu.findChildMenuByName("Attach To HUD", TRUE);
-				LLVOAvatar *avatarp = gAgent.getAvatarObject();
-				if (attach_menu 
-					&& (attach_menu->getChildCount() == 0) 
-					&& attach_hud_menu 
-					&& (attach_hud_menu->getChildCount() == 0) 
-					&& avatarp)
-				{
-					for (LLVOAvatar::attachment_map_t::iterator iter = avatarp->mAttachmentPoints.begin(); 
-						 iter != avatarp->mAttachmentPoints.end(); )
-					{
-						LLVOAvatar::attachment_map_t::iterator curiter = iter++;
-						LLViewerJointAttachment* attachment = curiter->second;
-						LLMenuItemCallGL::Params p;
-						std::string submenu_name = attachment->getName();
-						if (LLTrans::getString(submenu_name) != "")
-						{
-						    p.name = (" ")+LLTrans::getString(submenu_name)+" ";
-						}
-						else
-						{
-							p.name = submenu_name;
-						}
-						LLSD cbparams;
-						cbparams["index"] = curiter->first;
-						cbparams["label"] = attachment->getName();
-						p.on_click.function_name = "Inventory.AttachObject";
-						p.on_click.parameter = LLSD(attachment->getName());
-						p.on_enable.function_name = "Attachment.Label";
-						p.on_enable.parameter = cbparams;
-						LLView* parent = attachment->getIsHUDAttachment() ? attach_hud_menu : attach_menu;
-						LLUICtrlFactory::create<LLMenuItemCallGL>(p, parent);
-					}
-				}
-			}
-		}
-	}
-	hideContextEntries(menu, items, disabled_items);
-}
-
-BOOL LLObjectBridge::renameItem(const std::string& new_name)
-{
-	if(!isItemRenameable())
-		return FALSE;
-	LLPreview::dirty(mUUID);
-	LLInventoryModel* model = getInventoryModel();
-	if(!model)
-		return FALSE;
-	LLViewerInventoryItem* item = getItem();
-	if(item && (item->getName() != new_name))
-	{
-		LLPointer<LLViewerInventoryItem> new_item = new LLViewerInventoryItem(item);
-		new_item->rename(new_name);
-		buildDisplayName(new_item, mDisplayName);
-		new_item->updateServer(FALSE);
-		model->updateItem(new_item);
-
-		model->notifyObservers();
-
-		LLVOAvatarSelf* avatar = gAgent.getAvatarObject();
-		if( avatar )
-		{
-			LLViewerObject* obj = avatar->getWornAttachment( item->getUUID() );
-			if( obj )
-			{
-				LLSelectMgr::getInstance()->deselectAll();
-				LLSelectMgr::getInstance()->addAsIndividual( obj, SELECT_ALL_TES, FALSE );
-				LLSelectMgr::getInstance()->selectionSetObjectName( new_name );
-				LLSelectMgr::getInstance()->deselectAll();
-			}
-		}
-	}
-	// return FALSE because we either notified observers (& therefore
-	// rebuilt) or we didn't update.
-	return FALSE;
-}
-
-// +=================================================+
-// |        LLLSLTextBridge                          |
-// +=================================================+
-
-LLUIImagePtr LLLSLTextBridge::getIcon() const
-{
-	return get_item_icon(LLAssetType::AT_SCRIPT, LLInventoryType::IT_LSL, 0, FALSE);
-}
-
-void LLLSLTextBridge::openItem()
-{
-	LLViewerInventoryItem* item = getItem();
-	
-	if (item)
-	{
-		LLInvFVBridgeAction::doAction(item->getType(),mUUID,getInventoryModel());
-	}
-	/*
-	LLViewerInventoryItem* item = getItem();
-	if (item)
-	{
-		LLFloaterReg::showInstance("preview_script", LLSD(mUUID), TAKE_FOCUS_YES);
-	}
-	*/
-}
-
-// +=================================================+
-// |        LLWearableBridge                         |
-// +=================================================+
-
-// *NOTE: hack to get from avatar inventory to avatar
-void wear_inventory_item_on_avatar( LLInventoryItem* item )
-{
-	if(item)
-	{
-		lldebugs << "wear_inventory_item_on_avatar( " << item->getName()
-				 << " )" << llendl;
-
-		LLAppearanceManager::wearItem(item);
-	}
-}
-
-void wear_add_inventory_item_on_avatar( LLInventoryItem* item )
-{
-	if(item)
-	{
-		lldebugs << "wear_add_inventory_item_on_avatar( " << item->getName()
-				 << " )" << llendl;
-			
-		LLWearableList::instance().getAsset(item->getAssetUUID(),
-							   item->getName(),
-							   item->getType(),
-							   LLWearableBridge::onWearAddOnAvatarArrived,
-							   new LLUUID(item->getUUID()));
-	}
-}
-
-void remove_inventory_category_from_avatar( LLInventoryCategory* category )
-{
-	if(!category) return;
-	lldebugs << "remove_inventory_category_from_avatar( " << category->getName()
-			 << " )" << llendl;
-			 
-	
-	if( gFloaterCustomize )
-	{
-		gFloaterCustomize->askToSaveIfDirty(
-			boost::bind(remove_inventory_category_from_avatar_step2, _1, category->getUUID()));
-	}
-	else
-	{
-		remove_inventory_category_from_avatar_step2(TRUE, category->getUUID() );
-	}
-}
-
-struct OnRemoveStruct
-{
-	LLUUID mUUID;
-	OnRemoveStruct(const LLUUID& uuid):
-		mUUID(uuid)
-	{
-	}
-};
-
-void remove_inventory_category_from_avatar_step2( BOOL proceed, LLUUID category_id)
-{
-
-	// Find all the wearables that are in the category's subtree.
-	lldebugs << "remove_inventory_category_from_avatar_step2()" << llendl;
-	if(proceed)
-	{
-		LLInventoryModel::cat_array_t cat_array;
-		LLInventoryModel::item_array_t item_array;
-		LLFindWearables is_wearable;
-		gInventory.collectDescendentsIf(category_id,
-										cat_array,
-										item_array,
-										LLInventoryModel::EXCLUDE_TRASH,
-										is_wearable);
-		S32 i;
-		S32 wearable_count = item_array.count();
-
-		LLInventoryModel::cat_array_t	obj_cat_array;
-		LLInventoryModel::item_array_t	obj_item_array;
-		LLIsType is_object( LLAssetType::AT_OBJECT );
-		gInventory.collectDescendentsIf(category_id,
-										obj_cat_array,
-										obj_item_array,
-										LLInventoryModel::EXCLUDE_TRASH,
-										is_object);
-		S32 obj_count = obj_item_array.count();
-
-		// Find all gestures in this folder
-		LLInventoryModel::cat_array_t	gest_cat_array;
-		LLInventoryModel::item_array_t	gest_item_array;
-		LLIsType is_gesture( LLAssetType::AT_GESTURE );
-		gInventory.collectDescendentsIf(category_id,
-										gest_cat_array,
-										gest_item_array,
-										LLInventoryModel::EXCLUDE_TRASH,
-										is_gesture);
-		S32 gest_count = gest_item_array.count();
-
-		if (wearable_count > 0)	//Loop through wearables.  If worn, remove.
-		{
-			for(i = 0; i  < wearable_count; ++i)
-			{
-				if( gAgentWearables.isWearingItem (item_array.get(i)->getUUID()) )
-				{
-					LLWearableList::instance().getAsset(item_array.get(i)->getAssetUUID(),
-														item_array.get(i)->getName(),
-														item_array.get(i)->getType(),
-														LLWearableBridge::onRemoveFromAvatarArrived,
-														new OnRemoveStruct(item_array.get(i)->getUUID()));
-
-				}
-			}
-		}
-		
-		
-		if (obj_count > 0)
-		{
-			for(i = 0; i  < obj_count; ++i)
-			{
-				gMessageSystem->newMessageFast(_PREHASH_DetachAttachmentIntoInv);
-				gMessageSystem->nextBlockFast(_PREHASH_ObjectData );
-				gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
-				gMessageSystem->addUUIDFast(_PREHASH_ItemID, obj_item_array.get(i)->getUUID() );
-
-				gMessageSystem->sendReliable( gAgent.getRegion()->getHost() );
-
-				// this object might have been selected, so let the selection manager know it's gone now
-				LLViewerObject *found_obj = gObjectList.findObject( obj_item_array.get(i)->getUUID());
-				if (found_obj)
-				{
-					LLSelectMgr::getInstance()->remove(found_obj);
-				}
-				else
-				{
-					llwarns << "object not found, ignoring" << llendl;
-				}
-			}
-		}
-
-		if (gest_count > 0)
-		{
-			for(i = 0; i  < gest_count; ++i)
-			{
-				if ( LLGestureManager::instance().isGestureActive( gest_item_array.get(i)->getUUID()) )
-				{
-					LLGestureManager::instance().deactivateGesture( gest_item_array.get(i)->getUUID() );
-					gInventory.updateItem( gest_item_array.get(i) );
-					gInventory.notifyObservers();
-				}
-
-			}
-		}
-	}
-}
-
-BOOL LLWearableBridge::renameItem(const std::string& new_name)
-{
-	if( gAgentWearables.isWearingItem( mUUID ) )
-	{
-		gAgentWearables.setWearableName( mUUID, new_name );
-	}
-	return LLItemBridge::renameItem(new_name);
-}
-
-BOOL LLWearableBridge::isItemRemovable()
-{
-	if (gAgentWearables.isWearingItem(mUUID)) return FALSE;
-	return LLInvFVBridge::isItemRemovable();
-}
-
-std::string LLWearableBridge::getLabelSuffix() const
-{
-	if( gAgentWearables.isWearingItem( mUUID ) )
-	{
-		return LLItemBridge::getLabelSuffix() + LLTrans::getString("worn");
-	}
-	else
-	{
-		return LLItemBridge::getLabelSuffix();
-	}
-}
-
-LLUIImagePtr LLWearableBridge::getIcon() const
-{
-	return get_item_icon(mAssetType, mInvType, mWearableType, FALSE);
-}
-
-// virtual
-void LLWearableBridge::performAction(LLFolderView* folder, LLInventoryModel* model, std::string action)
-{
-	if ("wear" == action)
-	{
-		wearOnAvatar();
-	}
-	else if ("wear_add" == action)
-	{
-		wearAddOnAvatar();
-	}
-	else if ("edit" == action)
-	{
-		editOnAvatar();
-		return;
-	}
-	else if ("take_off" == action)
-	{
-		if(gAgentWearables.isWearingItem(mUUID))
-		{
-			LLViewerInventoryItem* item = getItem();
-			if (item)
-			{	
-				LLWearableList::instance().getAsset(item->getAssetUUID(),
-													item->getName(),
-													item->getType(),
-													LLWearableBridge::onRemoveFromAvatarArrived,
-													new OnRemoveStruct(mUUID));
-			}
-		}
-	}
-	else LLItemBridge::performAction(folder, model, action);
-}
-
-void LLWearableBridge::openItem()
-{
-	LLViewerInventoryItem* item = getItem();
-	
-	if (item)
-	{
-		LLInvFVBridgeAction::doAction(item->getType(),mUUID,getInventoryModel());
-	}
-	/*
-	if( isInTrash() )
-	{
-		LLNotifications::instance().add("CannotWearTrash");
-	}
-	else if(isAgentInventory())
-	{
-		if( !gAgentWearables.isWearingItem( mUUID ) )
-		{
-			wearOnAvatar();
-		}
-	}
-	else
-	{
-		// must be in the inventory library. copy it to our inventory
-		// and put it on right away.
-		LLViewerInventoryItem* item = getItem();
-		if(item && item->isComplete())
-		{
-			LLPointer<LLInventoryCallback> cb = new WearOnAvatarCallback();
-			copy_inventory_item(
-				gAgent.getID(),
-				item->getPermissions().getOwner(),
-				item->getUUID(),
-				LLUUID::null,
-				std::string(),
-				cb);
-		}
-		else if(item)
-		{
-			// *TODO: We should fetch the item details, and then do
-			// the operation above.
-			LLNotifications::instance().add("CannotWearInfoNotComplete");
-		}
-	}
-	*/
-}
-
-void LLWearableBridge::buildContextMenu(LLMenuGL& menu, U32 flags)
-{
-	lldebugs << "LLWearableBridge::buildContextMenu()" << llendl;
-	std::vector<std::string> items;
-	std::vector<std::string> disabled_items;
-	if(isInTrash())
-	{
-		items.push_back(std::string("Purge Item"));
-		if (!isItemRemovable())
-		{
-			disabled_items.push_back(std::string("Purge Item"));
-		}
-
-		items.push_back(std::string("Restore Item"));
-	}
-	else
-	{	// FWIW, it looks like SUPPRESS_OPEN_ITEM is not set anywhere
-		BOOL no_open = ((flags & SUPPRESS_OPEN_ITEM) == SUPPRESS_OPEN_ITEM);
-
-		// If we have clothing, don't add "Open" as it's the same action as "Wear"   SL-18976
-		LLViewerInventoryItem* item = getItem();
-		if( !no_open && item )
-		{
-			no_open = (item->getType() == LLAssetType::AT_CLOTHING) ||
-					  (item->getType() == LLAssetType::AT_BODYPART);
-		}
-		if (!no_open)
-		{
-			items.push_back(std::string("Open"));
-		}
-
-		if (item && item->getIsLinkType())
-		{
-			items.push_back(std::string("Goto Link"));
-		}
-
-		items.push_back(std::string("Properties"));
-
-		getClipboardEntries(true, items, disabled_items, flags);
-
-		items.push_back(std::string("Wearable Separator"));
-		
-		items.push_back(std::string("Wearable Wear"));
-		items.push_back(std::string("Wearable Add"));
-		items.push_back(std::string("Wearable Edit"));
-
-		if ((flags & FIRST_SELECTED_ITEM) == 0)
-		{
-			disabled_items.push_back(std::string("Wearable Edit"));
-		}
-		// Don't allow items to be worn if their baseobj is in the trash.
-		if (isLinkedObjectInTrash())
-		{
-			disabled_items.push_back(std::string("Wearable Wear"));
-			disabled_items.push_back(std::string("Wearable Add"));
-			disabled_items.push_back(std::string("Wearable Edit"));
-		}
-
-		// Disable wear and take off based on whether the item is worn.
-		if(item)
-		{
-			switch (item->getType())
-			{
-				case LLAssetType::AT_CLOTHING:
-					items.push_back(std::string("Take Off"));
-				case LLAssetType::AT_BODYPART:
-					if (gAgentWearables.isWearingItem(item->getUUID()))
-					{
-						disabled_items.push_back(std::string("Wearable Wear"));
-						disabled_items.push_back(std::string("Wearable Add"));
-					}
-					else
-					{	
-						disabled_items.push_back(std::string("Take Off"));
-					}
-					break;
-				default:
-					break;
-			}
-		}
-	}
-	hideContextEntries(menu, items, disabled_items);
-}
-
-// Called from menus
-// static
-BOOL LLWearableBridge::canWearOnAvatar(void* user_data)
-{
-	LLWearableBridge* self = (LLWearableBridge*)user_data;
-	if(!self) return FALSE;
-	if(!self->isAgentInventory())
-	{
-		LLViewerInventoryItem* item = (LLViewerInventoryItem*)self->getItem();
-		if(!item || !item->isComplete()) return FALSE;
-	}
-	return (!gAgentWearables.isWearingItem(self->mUUID));
-}
-
-// Called from menus
-// static
-void LLWearableBridge::onWearOnAvatar(void* user_data)
-{
-	LLWearableBridge* self = (LLWearableBridge*)user_data;
-	if(!self) return;
-	self->wearOnAvatar();
-}
-
-void LLWearableBridge::wearOnAvatar()
-{
-	// Don't wear anything until initial wearables are loaded, can
-	// destroy clothing items.
-	if (!gAgentWearables.areWearablesLoaded()) 
-	{
-		LLNotifications::instance().add("CanNotChangeAppearanceUntilLoaded");
-		return;
-	}
-
-	LLViewerInventoryItem* item = getItem();
-	if(item)
-	{
-		if(!isAgentInventory())
-		{
-			LLPointer<LLInventoryCallback> cb = new WearOnAvatarCallback();
-			copy_inventory_item(
-				gAgent.getID(),
-				item->getPermissions().getOwner(),
-				item->getUUID(),
-				LLUUID::null,
-				std::string(),
-				cb);
-		}
-		else
-		{
-			wear_inventory_item_on_avatar(item);
-		}
-	}
-}
-
-void LLWearableBridge::wearAddOnAvatar()
-{
-	// Don't wear anything until initial wearables are loaded, can
-	// destroy clothing items.
-	if (!gAgentWearables.areWearablesLoaded()) 
-	{
-		LLNotifications::instance().add("CanNotChangeAppearanceUntilLoaded");
-		return;
-	}
-
-	LLViewerInventoryItem* item = getItem();
-	if(item)
-	{
-		if(!isAgentInventory())
-		{
-			LLPointer<LLInventoryCallback> cb = new WearOnAvatarCallback();
-			copy_inventory_item(
-				gAgent.getID(),
-				item->getPermissions().getOwner(),
-				item->getUUID(),
-				LLUUID::null,
-				std::string(),
-				cb);
-		}
-		else
-		{
-			wear_add_inventory_item_on_avatar(item);
-		}
-	}
-}
-
-// static
-void LLWearableBridge::onWearOnAvatarArrived( LLWearable* wearable, void* userdata )
-{
-	LLUUID* item_id = (LLUUID*) userdata;
-	if(wearable)
-	{
-		LLViewerInventoryItem* item = NULL;
-		item = (LLViewerInventoryItem*)gInventory.getItem(*item_id);
-		if(item)
-		{
-			if(item->getAssetUUID() == wearable->getAssetID())
-			{
-				gAgentWearables.setWearableItem(item, wearable);
-				gInventory.notifyObservers();
-				//self->getFolderItem()->refreshFromRoot();
-			}
-			else
-			{
-				llinfos << "By the time wearable asset arrived, its inv item already pointed to a different asset." << llendl;
-			}
-		}
-	}
-	delete item_id;
-}
-
-// static
-// BAP remove the "add" code path once everything is fully COF-ified.
-void LLWearableBridge::onWearAddOnAvatarArrived( LLWearable* wearable, void* userdata )
-{
-	LLUUID* item_id = (LLUUID*) userdata;
-	if(wearable)
-	{
-		LLViewerInventoryItem* item = NULL;
-		item = (LLViewerInventoryItem*)gInventory.getItem(*item_id);
-		if(item)
-		{
-			if(item->getAssetUUID() == wearable->getAssetID())
-			{
-				bool do_append = true;
-				gAgentWearables.setWearableItem(item, wearable, do_append);
-				gInventory.notifyObservers();
-				//self->getFolderItem()->refreshFromRoot();
-			}
-			else
-			{
-				llinfos << "By the time wearable asset arrived, its inv item already pointed to a different asset." << llendl;
-			}
-		}
-	}
-	delete item_id;
-}
-
-// static
-BOOL LLWearableBridge::canEditOnAvatar(void* user_data)
-{
-	LLWearableBridge* self = (LLWearableBridge*)user_data;
-	if(!self) return FALSE;
-
-	return (gAgentWearables.isWearingItem(self->mUUID));
-}
-
-// static 
-void LLWearableBridge::onEditOnAvatar(void* user_data)
-{
-	LLWearableBridge* self = (LLWearableBridge*)user_data;
-	if(self)
-	{
-		self->editOnAvatar();
-	}
-}
-
-void LLWearableBridge::editOnAvatar()
-{
-	const LLWearable* wearable = gAgentWearables.getWearableFromItemID(mUUID);
-	if( wearable )
-	{
-		// Set the tab to the right wearable.
-		if (gFloaterCustomize)
-			gFloaterCustomize->setCurrentWearableType( wearable->getType() );
-
-		if( CAMERA_MODE_CUSTOMIZE_AVATAR != gAgent.getCameraMode() )
-		{
-			// Start Avatar Customization
-			gAgent.changeCameraToCustomizeAvatar();
-		}
-	}
-}
-
-// static
-BOOL LLWearableBridge::canRemoveFromAvatar(void* user_data)
-{
-	LLWearableBridge* self = (LLWearableBridge*)user_data;
-	if( self && (LLAssetType::AT_BODYPART != self->mAssetType) )
-	{
-		return gAgentWearables.isWearingItem( self->mUUID );
-	}
-	return FALSE;
-}
-
-// static 
-void LLWearableBridge::onRemoveFromAvatar(void* user_data)
-{
-	LLWearableBridge* self = (LLWearableBridge*)user_data;
-	if(!self) return;
-	if(gAgentWearables.isWearingItem(self->mUUID))
-	{
-		LLViewerInventoryItem* item = self->getItem();
-		if (item)
-		{
-			LLUUID parent_id = item->getParentUUID();
-			LLWearableList::instance().getAsset(item->getAssetUUID(),
-												item->getName(),
-												item->getType(),
-												onRemoveFromAvatarArrived,
-												new OnRemoveStruct(LLUUID(self->mUUID)));
-		}
-	}
-}
-
-// static
-void LLWearableBridge::onRemoveFromAvatarArrived(LLWearable* wearable,
-												 void* userdata)
-{
-	OnRemoveStruct *on_remove_struct = (OnRemoveStruct*) userdata;
-	const LLUUID &item_id = gInventory.getLinkedItemID(on_remove_struct->mUUID);
-	if(wearable)
-	{
-		if( gAgentWearables.isWearingItem( item_id ) )
-		{
-			EWearableType type = wearable->getType();
-	
-			if( !(type==WT_SHAPE || type==WT_SKIN || type==WT_HAIR || type==WT_EYES ) ) //&&
-				//!((!gAgent.isTeen()) && ( type==WT_UNDERPANTS || type==WT_UNDERSHIRT )) )
-			{
-				// MULTI_WEARABLE: FIXME HACK - always remove all
-				bool do_remove_all = false;
-				gAgentWearables.removeWearable( type, do_remove_all, 0 );
-			}
-		}
-	}
-
-	// Find and remove this item from the COF.
-	LLInventoryModel::item_array_t items = gInventory.collectLinkedItems(item_id, LLAppearanceManager::getCOF());
-	llassert(items.size() == 1); // Should always have one and only one item linked to this in the COF.
-	for (LLInventoryModel::item_array_t::const_iterator iter = items.begin();
-		 iter != items.end();
-		 ++iter)
-	{
-		const LLViewerInventoryItem *linked_item = (*iter);
-		const LLUUID &item_id = linked_item->getUUID();
-		gInventory.purgeObject(item_id);
-	}
-	gInventory.notifyObservers();
-
-	delete on_remove_struct;
-}
-
-LLInvFVBridgeAction* LLInvFVBridgeAction::createAction(LLAssetType::EType asset_type,
-													   const LLUUID& uuid,LLInventoryModel* model)
-{
-	LLInvFVBridgeAction* action = NULL;
-	switch(asset_type)
-	{
-	case LLAssetType::AT_TEXTURE:
-		action = new LLTextureBridgeAction(uuid,model);
-		break;
-
-	case LLAssetType::AT_SOUND:
-		action = new LLSoundBridgeAction(uuid,model);
-		break;
-
-	case LLAssetType::AT_LANDMARK:
-		action = new LLLandmarkBridgeAction(uuid,model);
-		break;
-		
-	case LLAssetType::AT_CALLINGCARD:
-		action = new LLCallingCardBridgeAction(uuid,model);
-		break;
-
-	case LLAssetType::AT_OBJECT:
-		action = new LLObjectBridgeAction(uuid,model);
-		break;
-
-	case LLAssetType::AT_NOTECARD:
-		action = new LLNotecardBridgeAction(uuid,model);
-		break;
-
-	case LLAssetType::AT_ANIMATION:
-		action = new LLAnimationBridgeAction(uuid,model);
-		break;
-
-	case LLAssetType::AT_GESTURE:
-		action = new LLGestureBridgeAction(uuid,model);
-		break;
-
-	case LLAssetType::AT_LSL_TEXT:
-		action = new LLLSLTextBridgeAction(uuid,model);
-		break;
-
-	case LLAssetType::AT_CLOTHING:
-	case LLAssetType::AT_BODYPART:
-		action = new LLWearableBridgeAction(uuid,model);
-
-		break;
-
-	default:
-		break;
-	}
-	return action;
-}
-
-//static 
-void LLInvFVBridgeAction::doAction(LLAssetType::EType asset_type,
-								   const LLUUID& uuid,LLInventoryModel* model)
-{
-	LLInvFVBridgeAction* action = createAction(asset_type,uuid,model);
-	if(action)
-	{
-		action->doIt();
-		delete action;
-	}
-}
-
-//static 
-void LLInvFVBridgeAction::doAction(const LLUUID& uuid, LLInventoryModel* model)
-{
-	LLAssetType::EType asset_type = model->getItem(uuid)->getType();
-	LLInvFVBridgeAction* action = createAction(asset_type,uuid,model);
-	if(action)
-	{
-		action->doIt();
-		delete action;
-	}
-}
-
-LLViewerInventoryItem* LLInvFVBridgeAction::getItem() const
-{
-	if(mModel)
-		return (LLViewerInventoryItem*)mModel->getItem(mUUID);
-	return NULL;
-}
-
-//virtual 
-void	LLTextureBridgeAction::doIt() 
-{
-	if (getItem())
-	{
-		LLFloaterReg::showInstance("preview_texture", LLSD(mUUID), TAKE_FOCUS_YES);
-	}
-
-	LLInvFVBridgeAction::doIt();
-}
-
-//virtual
-void	LLSoundBridgeAction::doIt() 
-{
-	LLViewerInventoryItem* item = getItem();
-	if(item)
-	{
-		LLFloaterReg::showInstance("preview_sound", LLSD(mUUID), TAKE_FOCUS_YES);
-	}
-	
-	LLInvFVBridgeAction::doIt();
-}
-
-
-//virtual 
-void	LLLandmarkBridgeAction::doIt() 
-{
-	LLViewerInventoryItem* item = getItem();
-	if( item )
-	{
-		// Opening (double-clicking) a landmark immediately teleports,
-		// but warns you the first time.
-		LLSD payload;
-		payload["asset_id"] = item->getAssetUUID();
-		LLNotifications::instance().add("TeleportFromLandmark", LLSD(), payload);
-	}
-
-	LLInvFVBridgeAction::doIt();
-}
-
-
-//virtual 
-void	LLCallingCardBridgeAction::doIt() 
-{
-	LLViewerInventoryItem* item = getItem();
-	if(item && item->getCreatorUUID().notNull())
-	{
-		LLAvatarActions::showProfile(item->getCreatorUUID());
-	}
-
-	LLInvFVBridgeAction::doIt();
-}
-
-//virtual 
-void	
-LLNotecardBridgeAction::doIt() 
-{
-	LLViewerInventoryItem* item = getItem();
-	if (item)
-	{
-		LLFloaterReg::showInstance("preview_notecard", LLSD(item->getUUID()), TAKE_FOCUS_YES);
-	}
-
-	LLInvFVBridgeAction::doIt();
-}
-
-//virtual 
-void	LLGestureBridgeAction::doIt() 
-{
-	LLViewerInventoryItem* item = getItem();
-	if (item)
-	{
-		LLPreviewGesture* preview = LLPreviewGesture::show(mUUID, LLUUID::null);
-		preview->setFocus(TRUE);
-	}
-
-	LLInvFVBridgeAction::doIt();
-}
-
-//virtual 
-void	LLAnimationBridgeAction::doIt() 
-{
-	LLViewerInventoryItem* item = getItem();
-	if (item)
-	{
-		LLFloaterReg::showInstance("preview_anim", LLSD(mUUID), TAKE_FOCUS_YES);
-	}
-
-	LLInvFVBridgeAction::doIt();
-}
-
-
-//virtual 
-void	LLObjectBridgeAction::doIt()
-{
-	LLFloaterReg::showInstance("properties", mUUID);
-
-	LLInvFVBridgeAction::doIt();
-}
-
-
-//virtual 
-void	LLLSLTextBridgeAction::doIt() 
-{
-	LLViewerInventoryItem* item = getItem();
-	if (item)
-	{
-		LLFloaterReg::showInstance("preview_script", LLSD(mUUID), TAKE_FOCUS_YES);
-	}
-
-	LLInvFVBridgeAction::doIt();
-}
-
-
-BOOL LLWearableBridgeAction::isInTrash() const
-{
-	if(!mModel) return FALSE;
-	LLUUID trash_id = mModel->findCategoryUUIDForType(LLAssetType::AT_TRASH);
-	return mModel->isObjectDescendentOf(mUUID, trash_id);
-}
-
-BOOL LLWearableBridgeAction::isAgentInventory() const
-{
-	if(!mModel) return FALSE;
-	if(gInventory.getRootFolderID() == mUUID) return TRUE;
-	return mModel->isObjectDescendentOf(mUUID, gInventory.getRootFolderID());
-}
-
-void LLWearableBridgeAction::wearOnAvatar()
-{
-	// Don't wear anything until initial wearables are loaded, can
-	// destroy clothing items.
-	if (!gAgentWearables.areWearablesLoaded()) 
-	{
-		LLNotifications::instance().add("CanNotChangeAppearanceUntilLoaded");
-		return;
-	}
-
-	LLViewerInventoryItem* item = getItem();
-	if(item)
-	{
-		if(!isAgentInventory())
-		{
-			LLPointer<LLInventoryCallback> cb = new WearOnAvatarCallback();
-			copy_inventory_item(
-				gAgent.getID(),
-				item->getPermissions().getOwner(),
-				item->getUUID(),
-				LLUUID::null,
-				std::string(),
-				cb);
-		}
-		else
-		{
-			wear_inventory_item_on_avatar(item);
-		}
-	}
-}
-
-//virtual 
-void LLWearableBridgeAction::doIt()
-{
-	if(isInTrash())
-	{
-		LLNotifications::instance().add("CannotWearTrash");
-	}
-	else if(isAgentInventory())
-	{
-		if(!gAgentWearables.isWearingItem(mUUID))
-		{
-			wearOnAvatar();
-		}
-	}
-	else
-	{
-		// must be in the inventory library. copy it to our inventory
-		// and put it on right away.
-		LLViewerInventoryItem* item = getItem();
-		if(item && item->isComplete())
-		{
-			LLPointer<LLInventoryCallback> cb = new WearOnAvatarCallback();
-			copy_inventory_item(
-				gAgent.getID(),
-				item->getPermissions().getOwner(),
-				item->getUUID(),
-				LLUUID::null,
-				std::string(),
-				cb);
-		}
-		else if(item)
-		{
-			// *TODO: We should fetch the item details, and then do
-			// the operation above.
-			LLNotifications::instance().add("CannotWearInfoNotComplete");
-		}
-	}
-
-	LLInvFVBridgeAction::doIt();
-}
-
-// +=================================================+
-// |        LLLinkItemBridge                         |
-// +=================================================+
-// For broken links
-
-std::string LLLinkItemBridge::sPrefix("Link: ");
-
-
-LLUIImagePtr LLLinkItemBridge::getIcon() const
-{
-	if (LLViewerInventoryItem *item = getItem())
-	{
-		return get_item_icon(item->getActualType(), LLInventoryType::IT_NONE, 0, FALSE);
-	}
-	return get_item_icon(LLAssetType::AT_LINK, LLInventoryType::IT_NONE, 0, FALSE);
-}
-
-void LLLinkItemBridge::buildContextMenu(LLMenuGL& menu, U32 flags)
-{
-	// *TODO: Translate
-	lldebugs << "LLLink::buildContextMenu()" << llendl;
-	std::vector<std::string> items;
-	std::vector<std::string> disabled_items;
-
-	if(isInTrash())
-	{
-		items.push_back(std::string("Purge Item"));
-		if (!isItemRemovable())
-		{
-			disabled_items.push_back(std::string("Purge Item"));
-		}
-
-		items.push_back(std::string("Restore Item"));
-	}
-	else
-	{	
-		items.push_back(std::string("Delete"));
-		if (!isItemRemovable())
-		{
-			disabled_items.push_back(std::string("Delete"));
-		}
-	}
-	hideContextEntries(menu, items, disabled_items);
-}
-
-
-// +=================================================+
-// |        LLLinkBridge                             |
-// +=================================================+
-// For broken links.
-
-std::string LLLinkFolderBridge::sPrefix("Link: ");
-
-
-LLUIImagePtr LLLinkFolderBridge::getIcon() const
-{
-	LLAssetType::EType preferred_type = LLAssetType::AT_NONE;
-	if (LLViewerInventoryItem *item = getItem())
-	{
-		if (const LLViewerInventoryCategory* cat = item->getLinkedCategory())
-		{
-			preferred_type = cat->getPreferredType();
-		}
-	}
-	return LLFolderBridge::getIcon(preferred_type);
-}
-
-void LLLinkFolderBridge::buildContextMenu(LLMenuGL& menu, U32 flags)
-{
-	// *TODO: Translate
-	lldebugs << "LLLink::buildContextMenu()" << llendl;
-	std::vector<std::string> items;
-	std::vector<std::string> disabled_items;
-
-	if(isInTrash())
-	{
-		items.push_back(std::string("Purge Item"));
-		if (!isItemRemovable())
-		{
-			disabled_items.push_back(std::string("Purge Item"));
-		}
-
-		items.push_back(std::string("Restore Item"));
-	}
-	else
-	{	
-		items.push_back(std::string("Goto Link"));
-		items.push_back(std::string("Delete"));
-		if (!isItemRemovable())
-		{
-			disabled_items.push_back(std::string("Delete"));
-		}
-	}
-	hideContextEntries(menu, items, disabled_items);
-}
-
-void LLLinkFolderBridge::performAction(LLFolderView* folder, LLInventoryModel* model, std::string action)
-{
-	if ("goto" == action)
-	{
-		gotoItem(folder);
-		return;
-	}
-	LLItemBridge::performAction(folder,model,action);
-}
-
-void LLLinkFolderBridge::gotoItem(LLFolderView *folder)
-{
-	const LLUUID &cat_uuid = getFolderID();
-	if (!cat_uuid.isNull())
-	{
-		if (LLFolderViewItem *base_folder = folder->getItemByID(cat_uuid))
-		{
-			if (LLInventoryModel* model = getInventoryModel())
-			{
-				model->fetchDescendentsOf(cat_uuid);
-			}
-			base_folder->setOpen(TRUE);
-			folder->setSelectionFromRoot(base_folder,TRUE);
-			folder->scrollToShowSelection();
-		}
-	}
-}
-
-const LLUUID &LLLinkFolderBridge::getFolderID() const
-{
-	if (LLViewerInventoryItem *link_item = getItem())
-	{
-		if (const LLViewerInventoryCategory *cat = link_item->getLinkedCategory())
-		{
-			const LLUUID& cat_uuid = cat->getUUID();
-			return cat_uuid;
-		}
-	}
-	return LLUUID::null;
-}
+/** 
+ * @file llinventorybridge.cpp
+ * @brief Implementation of the Inventory-Folder-View-Bridge classes.
+ *
+ * $LicenseInfo:firstyear=2001&license=viewergpl$
+ * 
+ * Copyright (c) 2001-2009, Linden Research, Inc.
+ * 
+ * Second Life Viewer Source Code
+ * The source code in this file ("Source Code") is provided by Linden Lab
+ * to you under the terms of the GNU General Public License, version 2.0
+ * ("GPL"), unless you have obtained a separate licensing agreement
+ * ("Other License"), formally executed by you and Linden Lab.  Terms of
+ * the GPL can be found in doc/GPL-license.txt in this distribution, or
+ * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
+ * 
+ * There are special exceptions to the terms and conditions of the GPL as
+ * it is applied to this Source Code. View the full text of the exception
+ * in the file doc/FLOSS-exception.txt in this software distribution, or
+ * online at
+ * http://secondlifegrid.net/programs/open_source/licensing/flossexception
+ * 
+ * By copying, modifying or distributing this software, you acknowledge
+ * that you have read and understood your obligations described above,
+ * and agree to abide by those obligations.
+ * 
+ * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
+ * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
+ * COMPLETENESS OR PERFORMANCE.
+ * $/LicenseInfo$
+ */
+
+#include "llviewerprecompiledheaders.h"
+
+#include <utility> // for std::pair<>
+
+#include "llfloaterinventory.h"
+#include "llinventorybridge.h"
+
+#include "message.h"
+
+#include "llagent.h"
+#include "llagentwearables.h"
+#include "llcallingcard.h"
+#include "llcheckboxctrl.h"		// for radio buttons
+#include "llfloaterreg.h"
+#include "llradiogroup.h"
+#include "llspinctrl.h"
+#include "lltextbox.h"
+#include "llui.h"
+
+#include "llviewercontrol.h"
+#include "llfirstuse.h"
+#include "llfoldertype.h"
+#include "llfloaterchat.h"
+#include "llfloatercustomize.h"
+#include "llfloaterproperties.h"
+#include "llfloaterworldmap.h"
+#include "llfocusmgr.h"
+#include "llfolderview.h"
+#include "llfriendcard.h"
+#include "llavataractions.h"
+#include "llgesturemgr.h"
+#include "lliconctrl.h"
+#include "llinventoryfunctions.h"
+#include "llinventorymodel.h"
+#include "llinventorypanel.h"
+#include "llinventoryclipboard.h"
+#include "lllineeditor.h"
+#include "llmenugl.h"
+#include "llpreviewanim.h"
+#include "llpreviewgesture.h"
+#include "llpreviewnotecard.h"
+#include "llpreviewscript.h"
+#include "llpreviewsound.h"
+#include "llpreviewtexture.h"
+#include "llresmgr.h"
+#include "llscrollcontainer.h"
+#include "llimview.h"
+#include "lltooldraganddrop.h"
+#include "llviewertexturelist.h"
+#include "llviewerinventory.h"
+#include "llviewerobjectlist.h"
+#include "llviewerwindow.h"
+#include "llvoavatar.h"
+#include "llwearable.h"
+#include "llwearablelist.h"
+#include "llviewermessage.h" 
+#include "llviewerregion.h"
+#include "llvoavatarself.h"
+#include "lltabcontainer.h"
+#include "lluictrlfactory.h"
+#include "llselectmgr.h"
+#include "llsidetray.h"
+#include "llfloateropenobject.h"
+#include "lltrans.h"
+#include "llappearancemgr.h"
+
+using namespace LLOldEvents;
+
+// Helpers
+// bug in busy count inc/dec right now, logic is complex... do we really need it?
+void inc_busy_count()
+{
+// 	gViewerWindow->getWindow()->incBusyCount();
+//  check balance of these calls if this code is changed to ever actually
+//  *do* something!
+}
+void dec_busy_count()
+{
+// 	gViewerWindow->getWindow()->decBusyCount();
+//  check balance of these calls if this code is changed to ever actually
+//  *do* something!
+}
+
+// Function declarations
+void wear_add_inventory_item_on_avatar(LLInventoryItem* item);
+void remove_inventory_category_from_avatar(LLInventoryCategory* category);
+void remove_inventory_category_from_avatar_step2( BOOL proceed, LLUUID category_id);
+bool move_task_inventory_callback(const LLSD& notification, const LLSD& response, LLMoveInv*);
+bool confirm_replace_attachment_rez(const LLSD& notification, const LLSD& response);
+
+std::string ICON_NAME[ICON_NAME_COUNT] =
+{
+	"Inv_Texture",
+	"Inv_Sound",
+	"Inv_CallingCard",
+	"Inv_CallingCard",
+	"Inv_Landmark",
+	"Inv_Landmark",
+	"Inv_Script",
+	"Inv_Clothing",
+	"Inv_Object",
+	"Inv_Object",
+	"Inv_Notecard",
+	"Inv_Skin",
+	"Inv_Snapshot",
+
+	"Inv_BodyShape",
+	"Inv_Skin",
+	"Inv_Hair",
+	"Inv_Eye",
+	"Inv_Shirt",
+	"Inv_Pants",
+	"Inv_Shoe",
+	"Inv_Socks",
+	"Inv_Jacket",
+	"Inv_Gloves",
+	"Inv_Undershirt",
+	"Inv_Underpants",
+	"Inv_Skirt",
+	"inv_item_alpha.tga",
+	"inv_item_tattoo.tga",
+
+	"Inv_Animation",
+	"Inv_Gesture",
+
+	"inv_item_linkitem.tga",
+	"inv_item_linkfolder.tga"
+};
+
+
+// +=================================================+
+// |        LLInventoryPanelObserver                 |
+// +=================================================+
+void LLInventoryPanelObserver::changed(U32 mask)
+{
+	mIP->modelChanged(mask);
+}
+
+
+// +=================================================+
+// |        LLInvFVBridge                            |
+// +=================================================+
+
+LLInvFVBridge::LLInvFVBridge(LLInventoryPanel* inventory, const LLUUID& uuid) :
+mUUID(uuid), mInvType(LLInventoryType::IT_NONE)
+{
+	mInventoryPanel = inventory->getHandle();
+}
+
+const std::string& LLInvFVBridge::getName() const
+{
+	LLInventoryObject* obj = getInventoryObject();
+	if(obj)
+	{
+		return obj->getName();
+	}
+	return LLStringUtil::null;
+}
+
+const std::string& LLInvFVBridge::getDisplayName() const
+{
+	return getName();
+}
+
+// Folders have full perms
+PermissionMask LLInvFVBridge::getPermissionMask() const
+{
+
+	return PERM_ALL;
+}
+
+// virtual
+LLAssetType::EType LLInvFVBridge::getPreferredType() const
+{
+	return LLAssetType::AT_NONE;
+}
+
+
+// Folders don't have creation dates.
+time_t LLInvFVBridge::getCreationDate() const
+{
+	return 0;
+}
+
+// Can be destoryed (or moved to trash)
+BOOL LLInvFVBridge::isItemRemovable()
+{
+	LLInventoryModel* model = getInventoryModel();
+	if(!model) return FALSE;
+	if(model->isObjectDescendentOf(mUUID, gInventory.getRootFolderID()))
+	{
+		return TRUE;
+	}
+	return FALSE;
+}
+
+// Sends an update to all link items that point to the base item.
+void LLInvFVBridge::renameLinkedItems(const LLUUID &item_id, const std::string& new_name)
+{
+	LLInventoryModel* model = getInventoryModel();
+	if(!model) return;
+
+	LLInventoryItem* itemp = model->getItem(mUUID);
+	if (!itemp) return;
+
+	if (itemp->getIsLinkType())
+	{
+		return;
+	}
+	
+	LLInventoryModel::item_array_t item_array = model->collectLinkedItems(item_id);
+	for (LLInventoryModel::item_array_t::iterator iter = item_array.begin();
+		 iter != item_array.end();
+		 iter++)
+	{
+		LLViewerInventoryItem *linked_item = (*iter);
+		if (linked_item->getUUID() == item_id) continue;
+		
+		LLPointer<LLViewerInventoryItem> new_item = new LLViewerInventoryItem(linked_item);
+		new_item->rename(new_name);
+		new_item->updateServer(FALSE);
+		model->updateItem(new_item);
+		// model->addChangedMask(LLInventoryObserver::LABEL, linked_item->getUUID());
+	}
+	model->notifyObservers();
+}
+
+// Can be moved to another folder
+BOOL LLInvFVBridge::isItemMovable() const
+{
+	return TRUE;
+}
+
+/*virtual*/
+/**
+ * @brief Adds this item into clipboard storage
+ */
+void LLInvFVBridge::cutToClipboard()
+{
+	if(isItemMovable())
+	{
+		LLInventoryClipboard::instance().cut(mUUID);
+	}
+}
+// *TODO: make sure this does the right thing
+void LLInvFVBridge::showProperties()
+{
+	LLSD key;
+	key["id"] = mUUID;
+	LLSideTray::getInstance()->showPanel("sidepanel_inventory", key);
+
+	// LLFloaterReg::showInstance("properties", mUUID);
+}
+
+void LLInvFVBridge::removeBatch(LLDynamicArray<LLFolderViewEventListener*>& batch)
+{
+	// Deactivate gestures when moving them into Trash
+	LLInvFVBridge* bridge;
+	LLInventoryModel* model = getInventoryModel();
+	LLViewerInventoryItem* item = NULL;
+	LLViewerInventoryCategory* cat = NULL;
+	LLInventoryModel::cat_array_t	descendent_categories;
+	LLInventoryModel::item_array_t	descendent_items;
+	S32 count = batch.count();
+	S32 i,j;
+	for(i = 0; i < count; ++i)
+	{	
+		bridge = (LLInvFVBridge*)(batch.get(i));
+		if(!bridge || !bridge->isItemRemovable()) continue;
+		item = (LLViewerInventoryItem*)model->getItem(bridge->getUUID());
+		if (item)
+		{
+			if(LLAssetType::AT_GESTURE == item->getType())
+			{
+				LLGestureManager::instance().deactivateGesture(item->getUUID());
+			}
+		}
+	}
+	for(i = 0; i < count; ++i)
+	{		
+		bridge = (LLInvFVBridge*)(batch.get(i));
+		if(!bridge || !bridge->isItemRemovable()) continue;
+		cat = (LLViewerInventoryCategory*)model->getCategory(bridge->getUUID());
+		if (cat)
+		{
+			gInventory.collectDescendents( cat->getUUID(), descendent_categories, descendent_items, FALSE );
+			for (j=0; j<descendent_items.count(); j++)
+			{
+				if(LLAssetType::AT_GESTURE == descendent_items[j]->getType())
+				{
+					LLGestureManager::instance().deactivateGesture(descendent_items[j]->getUUID());
+				}
+			}
+		}
+	}
+	removeBatchNoCheck(batch);
+}
+
+void LLInvFVBridge::removeBatchNoCheck(LLDynamicArray<LLFolderViewEventListener*>& batch)
+{
+	// this method moves a bunch of items and folders to the trash. As
+	// per design guidelines for the inventory model, the message is
+	// built and the accounting is performed first. After all of that,
+	// we call LLInventoryModel::moveObject() to move everything
+	// around.
+	LLInvFVBridge* bridge;
+	LLInventoryModel* model = getInventoryModel();
+	if(!model) return;
+	LLMessageSystem* msg = gMessageSystem;
+	LLUUID trash_id = model->findCategoryUUIDForType(LLAssetType::AT_TRASH);
+	LLViewerInventoryItem* item = NULL;
+	LLViewerInventoryCategory* cat = NULL;
+	std::vector<LLUUID> move_ids;
+	LLInventoryModel::update_map_t update;
+	bool start_new_message = true;
+	S32 count = batch.count();
+	S32 i;
+	for(i = 0; i < count; ++i)
+	{
+		bridge = (LLInvFVBridge*)(batch.get(i));
+		if(!bridge || !bridge->isItemRemovable()) continue;
+		item = (LLViewerInventoryItem*)model->getItem(bridge->getUUID());
+		if(item)
+		{
+			if(item->getParentUUID() == trash_id) continue;
+			move_ids.push_back(item->getUUID());
+			LLPreview::hide(item->getUUID());
+			--update[item->getParentUUID()];
+			++update[trash_id];
+			if(start_new_message)
+			{
+				start_new_message = false;
+				msg->newMessageFast(_PREHASH_MoveInventoryItem);
+				msg->nextBlockFast(_PREHASH_AgentData);
+				msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+				msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+				msg->addBOOLFast(_PREHASH_Stamp, TRUE);
+			}
+			msg->nextBlockFast(_PREHASH_InventoryData);
+			msg->addUUIDFast(_PREHASH_ItemID, item->getUUID());
+			msg->addUUIDFast(_PREHASH_FolderID, trash_id);
+			msg->addString("NewName", NULL);
+			if(msg->isSendFullFast(_PREHASH_InventoryData))
+			{
+				start_new_message = true;
+				gAgent.sendReliableMessage();
+				gInventory.accountForUpdate(update);
+				update.clear();
+			}
+		}
+	}
+	if(!start_new_message)
+	{
+		start_new_message = true;
+		gAgent.sendReliableMessage();
+		gInventory.accountForUpdate(update);
+		update.clear();
+	}
+	for(i = 0; i < count; ++i)
+	{
+		bridge = (LLInvFVBridge*)(batch.get(i));
+		if(!bridge || !bridge->isItemRemovable()) continue;
+		cat = (LLViewerInventoryCategory*)model->getCategory(bridge->getUUID());
+		if(cat)
+		{
+			if(cat->getParentUUID() == trash_id) continue;
+			move_ids.push_back(cat->getUUID());
+			--update[cat->getParentUUID()];
+			++update[trash_id];
+			if(start_new_message)
+			{
+				start_new_message = false;
+				msg->newMessageFast(_PREHASH_MoveInventoryFolder);
+				msg->nextBlockFast(_PREHASH_AgentData);
+				msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+				msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+				msg->addBOOL("Stamp", TRUE);
+			}
+			msg->nextBlockFast(_PREHASH_InventoryData);
+			msg->addUUIDFast(_PREHASH_FolderID, cat->getUUID());
+			msg->addUUIDFast(_PREHASH_ParentID, trash_id);
+			if(msg->isSendFullFast(_PREHASH_InventoryData))
+			{
+				start_new_message = true;
+				gAgent.sendReliableMessage();
+				gInventory.accountForUpdate(update);
+				update.clear();
+			}
+		}
+	}
+	if(!start_new_message)
+	{
+		gAgent.sendReliableMessage();
+		gInventory.accountForUpdate(update);
+	}
+
+	// move everything.
+	std::vector<LLUUID>::iterator it = move_ids.begin();
+	std::vector<LLUUID>::iterator end = move_ids.end();
+	for(; it != end; ++it)
+	{
+		gInventory.moveObject((*it), trash_id);
+	}
+
+	// notify inventory observers.
+	model->notifyObservers();
+}
+
+BOOL LLInvFVBridge::isClipboardPasteable() const
+{
+	if (!LLInventoryClipboard::instance().hasContents() || !isAgentInventory())
+	{
+		return FALSE;
+	}
+	LLInventoryModel* model = getInventoryModel();
+	if (!model)
+	{
+		return FALSE;
+	}
+
+	const LLUUID &agent_id = gAgent.getID();
+
+	LLDynamicArray<LLUUID> objects;
+	LLInventoryClipboard::instance().retrieve(objects);
+	S32 count = objects.count();
+	for(S32 i = 0; i < count; i++)
+	{
+		const LLUUID &item_id = objects.get(i);
+
+		// Can't paste folders
+		const LLInventoryCategory *cat = model->getCategory(item_id);
+		if (cat)
+		{
+			return FALSE;
+		}
+
+		const LLInventoryItem *item = model->getItem(item_id);
+		if (item)
+		{
+			if (!item->getPermissions().allowCopyBy(agent_id))
+			{
+				return FALSE;
+			}
+		}
+	}
+	return TRUE;
+}
+
+BOOL LLInvFVBridge::isClipboardPasteableAsLink() const
+{
+	if (!LLInventoryClipboard::instance().hasContents() || !isAgentInventory())
+	{
+		return FALSE;
+	}
+	const LLInventoryModel* model = getInventoryModel();
+	if (!model)
+	{
+		return FALSE;
+	}
+
+	LLDynamicArray<LLUUID> objects;
+	LLInventoryClipboard::instance().retrieve(objects);
+	S32 count = objects.count();
+	for(S32 i = 0; i < count; i++)
+	{
+		const LLInventoryItem *item = model->getItem(objects.get(i));
+		if (item)
+		{
+			if (!LLAssetType::lookupCanLink(item->getActualType()))
+			{
+				return FALSE;
+			}
+		}
+		const LLViewerInventoryCategory *cat = model->getCategory(objects.get(i));
+		if (cat && !LLAssetType::lookupCanLink(cat->getPreferredType()))
+		{
+			return FALSE;
+		}
+	}
+	return TRUE;
+}
+
+void hide_context_entries(LLMenuGL& menu, 
+						const std::vector<std::string> &entries_to_show,
+						const std::vector<std::string> &disabled_entries)
+{
+	const LLView::child_list_t *list = menu.getChildList();
+
+	LLView::child_list_t::const_iterator itor;
+	for (itor = list->begin(); itor != list->end(); ++itor)
+	{
+		std::string name = (*itor)->getName();
+
+		// descend into split menus:
+		LLMenuItemBranchGL* branchp = dynamic_cast<LLMenuItemBranchGL*>(*itor);
+		if ((name == "More") && branchp)
+		{
+			hide_context_entries(*branchp->getBranch(), entries_to_show, disabled_entries);
+		}
+		
+		
+		bool found = false;
+		std::vector<std::string>::const_iterator itor2;
+		for (itor2 = entries_to_show.begin(); itor2 != entries_to_show.end(); ++itor2)
+		{
+			if (*itor2 == name)
+			{
+				found = true;
+			}
+		}
+		if (!found)
+		{
+			(*itor)->setVisible(FALSE);
+		}
+		else
+		{
+			for (itor2 = disabled_entries.begin(); itor2 != disabled_entries.end(); ++itor2)
+			{
+				if (*itor2 == name)
+				{
+					(*itor)->setEnabled(FALSE);
+				}
+			}
+		}
+	}
+}
+
+// Helper for commonly-used entries
+void LLInvFVBridge::getClipboardEntries(bool show_asset_id, 
+										std::vector<std::string> &items, 
+										std::vector<std::string> &disabled_items, U32 flags)
+{
+	items.push_back(std::string("Rename"));
+	if (!isItemRenameable() || (flags & FIRST_SELECTED_ITEM) == 0)
+	{
+		disabled_items.push_back(std::string("Rename"));
+	}
+
+	if (show_asset_id)
+	{
+		items.push_back(std::string("Copy Asset UUID"));
+		if ( (! ( isItemPermissive() || gAgent.isGodlike() ) ) 
+			  || (flags & FIRST_SELECTED_ITEM) == 0)
+		{
+			disabled_items.push_back(std::string("Copy Asset UUID"));
+		}
+	}
+
+	items.push_back(std::string("Copy Separator"));
+
+	items.push_back(std::string("Copy"));
+	if (!isItemCopyable())
+	{
+		disabled_items.push_back(std::string("Copy"));
+	}
+
+	items.push_back(std::string("Paste"));
+	if (!isClipboardPasteable() || (flags & FIRST_SELECTED_ITEM) == 0)
+	{
+		disabled_items.push_back(std::string("Paste"));
+	}
+
+	items.push_back(std::string("Paste As Link"));
+	if (!isClipboardPasteableAsLink() || (flags & FIRST_SELECTED_ITEM) == 0)
+	{
+		disabled_items.push_back(std::string("Paste As Link"));
+	}
+	items.push_back(std::string("Paste Separator"));
+
+	items.push_back(std::string("Delete"));
+	if (!isItemRemovable())
+	{
+		disabled_items.push_back(std::string("Delete"));
+	}
+}
+
+void LLInvFVBridge::buildContextMenu(LLMenuGL& menu, U32 flags)
+{
+	lldebugs << "LLInvFVBridge::buildContextMenu()" << llendl;
+	std::vector<std::string> items;
+	std::vector<std::string> disabled_items;
+	if(isInTrash())
+	{
+		items.push_back(std::string("PurgeItem"));
+		if (!isItemRemovable())
+		{
+			disabled_items.push_back(std::string("PurgeItem"));
+		}
+		items.push_back(std::string("RestoreItem"));
+	}
+	else
+	{
+		items.push_back(std::string("Open"));
+		items.push_back(std::string("Properties"));
+
+		getClipboardEntries(true, items, disabled_items, flags);
+	}
+	hide_context_entries(menu, items, disabled_items);
+}
+
+// *TODO: remove this
+BOOL LLInvFVBridge::startDrag(EDragAndDropType* type, LLUUID* id) const
+{
+	BOOL rv = FALSE;
+
+	const LLInventoryObject* obj = getInventoryObject();
+
+	if(obj)
+	{
+		*type = LLAssetType::lookupDragAndDropType(obj->getActualType());
+		if(*type == DAD_NONE)
+		{
+			return FALSE;
+		}
+		
+		*id = obj->getUUID();
+		//object_ids.put(obj->getUUID());
+
+		if (*type == DAD_CATEGORY)
+		{
+			gInventory.startBackgroundFetch(obj->getUUID());
+		}
+
+		rv = TRUE;
+	}
+
+	return rv;
+}
+
+LLInventoryObject* LLInvFVBridge::getInventoryObject() const
+{
+	LLInventoryObject* obj = NULL;
+	LLInventoryModel* model = getInventoryModel();
+	if(model)
+	{
+		obj = (LLInventoryObject*)model->getObject(mUUID);
+	}
+	return obj;
+}
+
+LLInventoryModel* LLInvFVBridge::getInventoryModel() const
+{
+	LLInventoryPanel* panel = dynamic_cast<LLInventoryPanel*>(mInventoryPanel.get());
+	return panel ? panel->getModel() : NULL;
+}
+
+BOOL LLInvFVBridge::isInTrash() const
+{
+	LLInventoryModel* model = getInventoryModel();
+	if(!model) return FALSE;
+	const LLUUID trash_id = model->findCategoryUUIDForType(LLAssetType::AT_TRASH);
+	return model->isObjectDescendentOf(mUUID, trash_id);
+}
+
+BOOL LLInvFVBridge::isLinkedObjectInTrash() const
+{
+	if (isInTrash()) return TRUE;
+
+	const LLInventoryObject *obj = getInventoryObject();
+	if (obj && obj->getIsLinkType())
+	{
+		LLInventoryModel* model = getInventoryModel();
+		if(!model) return FALSE;
+		const LLUUID trash_id = model->findCategoryUUIDForType(LLAssetType::AT_TRASH);
+		return model->isObjectDescendentOf(obj->getLinkedUUID(), trash_id);
+	}
+	return FALSE;
+}
+
+BOOL LLInvFVBridge::isAgentInventory() const
+{
+	const LLInventoryModel* model = getInventoryModel();
+	if(!model) return FALSE;
+	if(gInventory.getRootFolderID() == mUUID) return TRUE;
+	return model->isObjectDescendentOf(mUUID, gInventory.getRootFolderID());
+}
+
+BOOL LLInvFVBridge::isCOFFolder() const
+{
+	const LLInventoryModel* model = getInventoryModel();
+	if(!model) return TRUE;
+	const LLUUID cof_id = gInventory.findCategoryUUIDForType(LLAssetType::AT_CURRENT_OUTFIT);
+	if (mUUID == cof_id || model->isObjectDescendentOf(mUUID, cof_id))
+	{
+		return TRUE;
+	}
+	return FALSE;
+}
+
+BOOL LLInvFVBridge::isItemPermissive() const
+{
+	return FALSE;
+}
+
+// static
+void LLInvFVBridge::changeItemParent(LLInventoryModel* model,
+									 LLViewerInventoryItem* item,
+									 const LLUUID& new_parent,
+									 BOOL restamp)
+{
+	if(item->getParentUUID() != new_parent)
+	{
+		LLInventoryModel::update_list_t update;
+		LLInventoryModel::LLCategoryUpdate old_folder(item->getParentUUID(),-1);
+		update.push_back(old_folder);
+		LLInventoryModel::LLCategoryUpdate new_folder(new_parent, 1);
+		update.push_back(new_folder);
+		gInventory.accountForUpdate(update);
+
+		LLPointer<LLViewerInventoryItem> new_item = new LLViewerInventoryItem(item);
+		new_item->setParent(new_parent);
+		new_item->updateParentOnServer(restamp);
+		model->updateItem(new_item);
+		model->notifyObservers();
+	}
+}
+
+// static
+void LLInvFVBridge::changeCategoryParent(LLInventoryModel* model,
+										 LLViewerInventoryCategory* cat,
+										 const LLUUID& new_parent,
+										 BOOL restamp)
+{
+	if(cat->getParentUUID() != new_parent)
+	{
+		LLInventoryModel::update_list_t update;
+		LLInventoryModel::LLCategoryUpdate old_folder(cat->getParentUUID(), -1);
+		update.push_back(old_folder);
+		LLInventoryModel::LLCategoryUpdate new_folder(new_parent, 1);
+		update.push_back(new_folder);
+		gInventory.accountForUpdate(update);
+
+		LLPointer<LLViewerInventoryCategory> new_cat = new LLViewerInventoryCategory(cat);
+		new_cat->setParent(new_parent);
+		new_cat->updateParentOnServer(restamp);
+		model->updateCategory(new_cat);
+		model->notifyObservers();
+	}
+}
+
+
+const std::string safe_inv_type_lookup(LLInventoryType::EType inv_type)
+{
+	const std::string rv= LLInventoryType::lookup(inv_type);
+	if(rv.empty())
+	{
+		return std::string("<invalid>");
+	}
+	return rv;
+}
+
+LLInvFVBridge* LLInvFVBridge::createBridge(LLAssetType::EType asset_type,
+										   LLAssetType::EType actual_asset_type,
+										   LLInventoryType::EType inv_type,
+										   LLInventoryPanel* inventory,
+										   const LLUUID& uuid,
+										   U32 flags)
+{
+	LLInvFVBridge* new_listener = NULL;
+	switch(asset_type)
+	{
+		case LLAssetType::AT_TEXTURE:
+			if(!(inv_type == LLInventoryType::IT_TEXTURE || inv_type == LLInventoryType::IT_SNAPSHOT))
+			{
+				llwarns << LLAssetType::lookup(asset_type) << " asset has inventory type " << safe_inv_type_lookup(inv_type) << " on uuid " << uuid << llendl;
+			}
+			new_listener = new LLTextureBridge(inventory, uuid, inv_type);
+			break;
+
+		case LLAssetType::AT_SOUND:
+			if(!(inv_type == LLInventoryType::IT_SOUND))
+			{
+				llwarns << LLAssetType::lookup(asset_type) << " asset has inventory type " << safe_inv_type_lookup(inv_type) << " on uuid " << uuid << llendl;
+			}
+			new_listener = new LLSoundBridge(inventory, uuid);
+			break;
+
+		case LLAssetType::AT_LANDMARK:
+			if(!(inv_type == LLInventoryType::IT_LANDMARK))
+			{
+				llwarns << LLAssetType::lookup(asset_type) << " asset has inventory type " << safe_inv_type_lookup(inv_type) << " on uuid " << uuid << llendl;
+			}
+			new_listener = new LLLandmarkBridge(inventory, uuid, flags);
+			break;
+		
+		case LLAssetType::AT_CALLINGCARD:
+			if(!(inv_type == LLInventoryType::IT_CALLINGCARD))
+			{
+				llwarns << LLAssetType::lookup(asset_type) << " asset has inventory type " << safe_inv_type_lookup(inv_type) << " on uuid " << uuid << llendl;
+			}
+			new_listener = new LLCallingCardBridge(inventory, uuid);
+			break;
+
+		case LLAssetType::AT_SCRIPT:
+			if(!(inv_type == LLInventoryType::IT_LSL))
+			{
+				llwarns << LLAssetType::lookup(asset_type) << " asset has inventory type " << safe_inv_type_lookup(inv_type) << " on uuid " << uuid << llendl;
+			}
+			new_listener = new LLScriptBridge(inventory, uuid);
+			break;
+
+		case LLAssetType::AT_OBJECT:
+			if(!(inv_type == LLInventoryType::IT_OBJECT || inv_type == LLInventoryType::IT_ATTACHMENT))
+			{
+				llwarns << LLAssetType::lookup(asset_type) << " asset has inventory type " << safe_inv_type_lookup(inv_type) << " on uuid " << uuid << llendl;
+			}
+			new_listener = new LLObjectBridge(inventory, uuid, inv_type, flags);
+			break;
+
+		case LLAssetType::AT_NOTECARD:
+			if(!(inv_type == LLInventoryType::IT_NOTECARD))
+			{
+				llwarns << LLAssetType::lookup(asset_type) << " asset has inventory type " << safe_inv_type_lookup(inv_type) << " on uuid " << uuid << llendl;
+			}
+			new_listener = new LLNotecardBridge(inventory, uuid);
+			break;
+
+		case LLAssetType::AT_ANIMATION:
+			if(!(inv_type == LLInventoryType::IT_ANIMATION))
+			{
+				llwarns << LLAssetType::lookup(asset_type) << " asset has inventory type " << safe_inv_type_lookup(inv_type) << " on uuid " << uuid << llendl;
+			}
+			new_listener = new LLAnimationBridge(inventory, uuid);
+			break;
+
+		case LLAssetType::AT_GESTURE:
+			if(!(inv_type == LLInventoryType::IT_GESTURE))
+			{
+				llwarns << LLAssetType::lookup(asset_type) << " asset has inventory type " << safe_inv_type_lookup(inv_type) << " on uuid " << uuid << llendl;
+			}
+			new_listener = new LLGestureBridge(inventory, uuid);
+			break;
+
+		case LLAssetType::AT_LSL_TEXT:
+			if(!(inv_type == LLInventoryType::IT_LSL))
+			{
+				llwarns << LLAssetType::lookup(asset_type) << " asset has inventory type " << safe_inv_type_lookup(inv_type) << " on uuid " << uuid << llendl;
+			}
+			new_listener = new LLLSLTextBridge(inventory, uuid);
+			break;
+
+		case LLAssetType::AT_CLOTHING:
+		case LLAssetType::AT_BODYPART:
+			if(!(inv_type == LLInventoryType::IT_WEARABLE))
+			{
+				llwarns << LLAssetType::lookup(asset_type) << " asset has inventory type " << safe_inv_type_lookup(inv_type) << " on uuid " << uuid << llendl;
+			}
+			new_listener = new LLWearableBridge(inventory, uuid, asset_type, inv_type, (EWearableType)flags);
+			break;
+		case LLAssetType::AT_CATEGORY:
+		case LLAssetType::AT_ROOT_CATEGORY:
+			if (actual_asset_type == LLAssetType::AT_LINK_FOLDER)
+			{
+				// Create a link folder handler instead.
+				new_listener = new LLLinkFolderBridge(inventory, uuid);
+				break;
+			}
+			new_listener = new LLFolderBridge(inventory, uuid);
+			break;
+		case LLAssetType::AT_LINK:
+			// Only should happen for broken links.
+			new_listener = new LLLinkItemBridge(inventory, uuid);
+			break;
+		case LLAssetType::AT_LINK_FOLDER:
+			// Only should happen for broken links.
+			new_listener = new LLLinkItemBridge(inventory, uuid);
+			break;
+		default:
+			llinfos << "Unhandled asset type (llassetstorage.h): "
+					<< (S32)asset_type << llendl;
+			break;
+	}
+
+	if (new_listener)
+	{
+		new_listener->mInvType = inv_type;
+	}
+
+	return new_listener;
+}
+
+void LLInvFVBridge::purgeItem(LLInventoryModel *model, const LLUUID &uuid)
+{
+	LLInventoryCategory* cat = model->getCategory(uuid);
+	if (cat)
+	{
+		model->purgeDescendentsOf(uuid);
+		model->notifyObservers();
+	}
+	LLInventoryObject* obj = model->getObject(uuid);
+	if (obj)
+	{
+		model->purgeObject(uuid);
+		model->notifyObservers();
+	}
+}
+
+// +=================================================+
+// |        InventoryFVBridgeBuilder                 |
+// +=================================================+
+LLInvFVBridge* LLInventoryFVBridgeBuilder::createBridge(LLAssetType::EType asset_type,
+														LLAssetType::EType actual_asset_type,
+														LLInventoryType::EType inv_type,
+														LLInventoryPanel* inventory,
+														const LLUUID& uuid,
+														U32 flags /* = 0x00 */) const
+{
+	return LLInvFVBridge::createBridge(asset_type,
+		actual_asset_type,
+		inv_type,
+		inventory,
+		uuid,
+		flags);
+}
+
+// +=================================================+
+// |        LLItemBridge                             |
+// +=================================================+
+
+void LLItemBridge::performAction(LLFolderView* folder, LLInventoryModel* model, std::string action)
+{
+	if ("goto" == action)
+	{
+		gotoItem(folder);
+	}
+	if ("open" == action)
+	{
+		openItem();
+		return;
+	}
+	else if ("properties" == action)
+	{
+		showProperties();
+		return;
+	}
+	else if ("purge" == action)
+	{
+		purgeItem(model, mUUID);
+		return;
+	}
+	else if ("restoreToWorld" == action)
+	{
+		restoreToWorld();
+		return;
+	}
+	else if ("restore" == action)
+	{
+		restoreItem();
+		return;
+	}
+	else if ("copy_uuid" == action)
+	{
+		// Single item only
+		LLInventoryItem* item = model->getItem(mUUID);
+		if(!item) return;
+		LLUUID asset_id = item->getAssetUUID();
+		std::string buffer;
+		asset_id.toString(buffer);
+
+		gViewerWindow->mWindow->copyTextToClipboard(utf8str_to_wstring(buffer));
+		return;
+	}
+	else if ("copy" == action)
+	{
+		copyToClipboard();
+		return;
+	}
+	else if ("paste" == action)
+	{
+		// Single item only
+		LLInventoryItem* itemp = model->getItem(mUUID);
+		if (!itemp) return;
+
+		LLFolderViewItem* folder_view_itemp = folder->getItemByID(itemp->getParentUUID());
+		if (!folder_view_itemp) return;
+
+		folder_view_itemp->getListener()->pasteFromClipboard();
+		return;
+	}
+	else if ("paste_link" == action)
+	{
+		// Single item only
+		LLInventoryItem* itemp = model->getItem(mUUID);
+		if (!itemp) return;
+
+		LLFolderViewItem* folder_view_itemp = folder->getItemByID(itemp->getParentUUID());
+		if (!folder_view_itemp) return;
+
+		folder_view_itemp->getListener()->pasteLinkFromClipboard();
+		return;
+	}
+}
+
+void LLItemBridge::selectItem()
+{
+	LLViewerInventoryItem* item = (LLViewerInventoryItem*)getItem();
+	if(item && !item->isComplete())
+	{
+		item->fetchFromServer();
+	}
+}
+
+void LLItemBridge::restoreItem()
+{
+	LLViewerInventoryItem* item = (LLViewerInventoryItem*)getItem();
+	if(item)
+	{
+		LLInventoryModel* model = getInventoryModel();
+		const LLUUID new_parent = model->findCategoryUUIDForType(item->getType());
+		// do not restamp on restore.
+		LLInvFVBridge::changeItemParent(model, item, new_parent, FALSE);
+	}
+}
+
+void LLItemBridge::restoreToWorld()
+{
+	LLViewerInventoryItem* itemp = (LLViewerInventoryItem*)getItem();
+	if (itemp)
+	{
+		LLMessageSystem* msg = gMessageSystem;
+		msg->newMessage("RezRestoreToWorld");
+		msg->nextBlockFast(_PREHASH_AgentData);
+		msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+		msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+
+		msg->nextBlockFast(_PREHASH_InventoryData);
+		itemp->packMessage(msg);
+		msg->sendReliable(gAgent.getRegion()->getHost());
+	}
+
+	//Similar functionality to the drag and drop rez logic
+	BOOL remove_from_inventory = FALSE;
+
+	//remove local inventory copy, sim will deal with permissions and removing the item
+	//from the actual inventory if its a no-copy etc
+	if(!itemp->getPermissions().allowCopyBy(gAgent.getID()))
+	{
+		remove_from_inventory = TRUE;
+	}
+
+	// Check if it's in the trash. (again similar to the normal rez logic)
+	const LLUUID trash_id = gInventory.findCategoryUUIDForType(LLAssetType::AT_TRASH);
+	if(gInventory.isObjectDescendentOf(itemp->getUUID(), trash_id))
+	{
+		remove_from_inventory = TRUE;
+	}
+
+	if(remove_from_inventory)
+	{
+		gInventory.deleteObject(itemp->getUUID());
+		gInventory.notifyObservers();
+	}
+}
+
+void LLItemBridge::gotoItem(LLFolderView *folder)
+{
+	LLInventoryObject *obj = getInventoryObject();
+	if (obj && obj->getIsLinkType())
+	{
+		LLInventoryPanel* active_panel = LLFloaterInventory::getActiveInventory()->getPanel();
+		if (active_panel)
+		{
+			active_panel->setSelection(obj->getLinkedUUID(), TAKE_FOCUS_NO);
+		}
+	}
+}
+
+LLUIImagePtr LLItemBridge::getIcon() const
+{
+	return LLUI::getUIImage(ICON_NAME[OBJECT_ICON_NAME]);
+}
+
+PermissionMask LLItemBridge::getPermissionMask() const
+{
+	LLViewerInventoryItem* item = getItem();
+	PermissionMask perm_mask = 0;
+	if(item) 
+	{
+		BOOL copy = item->getPermissions().allowCopyBy(gAgent.getID());
+		BOOL mod = item->getPermissions().allowModifyBy(gAgent.getID());
+		BOOL xfer = item->getPermissions().allowOperationBy(PERM_TRANSFER,
+															gAgent.getID());
+
+		if (copy) perm_mask |= PERM_COPY;
+		if (mod)  perm_mask |= PERM_MODIFY;
+		if (xfer) perm_mask |= PERM_TRANSFER;
+
+	}
+	return perm_mask;
+}
+
+const std::string& LLItemBridge::getDisplayName() const
+{
+	if(mDisplayName.empty())
+	{
+		buildDisplayName(getItem(), mDisplayName);
+	}
+	return mDisplayName;
+}
+
+void LLItemBridge::buildDisplayName(LLInventoryItem* item, std::string& name)
+{
+	if(item) 
+	{
+		name.assign(item->getName());			
+	}
+	else
+	{
+		name.assign(LLStringUtil::null);
+	}
+}
+
+LLFontGL::StyleFlags LLItemBridge::getLabelStyle() const
+{ 
+	U8 font = LLFontGL::NORMAL;
+	
+	if( gAgentWearables.isWearingItem( mUUID ) )
+	{
+		// llinfos << "BOLD" << llendl;
+		font |= LLFontGL::BOLD;
+	}
+
+	const LLViewerInventoryItem* item = getItem();
+	if (item && item->getIsLinkType())
+	{
+		font |= LLFontGL::ITALIC;
+	}
+	return (LLFontGL::StyleFlags)font;
+}
+
+std::string LLItemBridge::getLabelSuffix() const
+{
+	// String table is loaded before login screen and inventory items are
+	// loaded after login, so LLTrans should be ready.
+	static std::string NO_COPY =LLTrans::getString("no_copy");
+	static std::string NO_MOD = LLTrans::getString("no_modify");
+	static std::string NO_XFER = LLTrans::getString("no_transfer");
+	static std::string LINK = LLTrans::getString("link");
+	static std::string BROKEN_LINK = LLTrans::getString("broken_link");
+	std::string suffix;
+	LLInventoryItem* item = getItem();
+	if(item) 
+	{
+		// it's a bit confusing to put nocopy/nomod/etc on calling cards.
+		if(LLAssetType::AT_CALLINGCARD != item->getType()
+		   && item->getPermissions().getOwner() == gAgent.getID())
+		{
+			BOOL broken_link = LLAssetType::lookupIsLinkType(item->getType());
+			if (broken_link) return BROKEN_LINK;
+
+			BOOL link = item->getIsLinkType();
+			if (link) return LINK;
+
+			BOOL copy = item->getPermissions().allowCopyBy(gAgent.getID());
+			if (!copy)
+			{
+				suffix += NO_COPY;
+			}
+			BOOL mod = item->getPermissions().allowModifyBy(gAgent.getID());
+			if (!mod)
+			{
+				suffix += NO_MOD;
+			}
+			BOOL xfer = item->getPermissions().allowOperationBy(PERM_TRANSFER,
+																gAgent.getID());
+			if (!xfer)
+			{
+				suffix += NO_XFER;
+			}
+		}
+	}
+	return suffix;
+}
+
+time_t LLItemBridge::getCreationDate() const
+{
+	LLViewerInventoryItem* item = getItem();
+	if (item)
+	{
+		return item->getCreationDate();
+	}
+	return 0;
+}
+
+
+BOOL LLItemBridge::isItemRenameable() const
+{
+	LLViewerInventoryItem* item = getItem();
+	if(item)
+	{
+		// (For now) Don't allow calling card rename since that may confuse users as to
+		// what the calling card points to.
+		if (item->getInventoryType() == LLInventoryType::IT_CALLINGCARD)
+		{
+			return FALSE;
+		}
+		return (item->getPermissions().allowModifyBy(gAgent.getID()));
+	}
+	return FALSE;
+}
+
+BOOL LLItemBridge::renameItem(const std::string& new_name)
+{
+	if(!isItemRenameable())
+		return FALSE;
+	LLPreview::dirty(mUUID);
+	LLInventoryModel* model = getInventoryModel();
+	if(!model)
+		return FALSE;
+	LLViewerInventoryItem* item = getItem();
+	if(item && (item->getName() != new_name))
+	{
+		LLPointer<LLViewerInventoryItem> new_item = new LLViewerInventoryItem(item);
+		new_item->rename(new_name);
+		buildDisplayName(new_item, mDisplayName);
+		new_item->updateServer(FALSE);
+		model->updateItem(new_item);
+
+		model->notifyObservers();
+	}
+	// return FALSE because we either notified observers (& therefore
+	// rebuilt) or we didn't update.
+	return FALSE;
+}
+
+
+BOOL LLItemBridge::removeItem()
+{
+	if(!isItemRemovable())
+	{
+		return FALSE;
+	}
+	// move it to the trash
+	LLPreview::hide(mUUID, TRUE);
+	LLInventoryModel* model = getInventoryModel();
+	if(!model) return FALSE;
+	LLUUID trash_id = model->findCategoryUUIDForType(LLAssetType::AT_TRASH);
+	LLViewerInventoryItem* item = getItem();
+
+	// if item is not already in trash
+	if(item && !model->isObjectDescendentOf(mUUID, trash_id))
+	{
+		// move to trash, and restamp
+		LLInvFVBridge::changeItemParent(model, item, trash_id, TRUE);
+		// delete was successful
+		return TRUE;
+	}
+	else
+	{
+		// tried to delete already item in trash (should purge?)
+		return FALSE;
+	}
+}
+
+BOOL LLItemBridge::isItemCopyable() const
+{
+	LLViewerInventoryItem* item = getItem();
+	if (item)
+	{
+		// can't copy worn objects. DEV-15183
+		LLVOAvatarSelf *avatarp = gAgent.getAvatarObject();
+		if( !avatarp )
+		{
+			return FALSE;
+		}
+
+		if(avatarp->isWearingAttachment(mUUID))
+		{
+			return FALSE;
+		}
+		
+		// All items can be copied, not all can be pasted.
+		// The only time an item can't be copied is if it's a link 
+		// return (item->getPermissions().allowCopyBy(gAgent.getID()));
+		if (item->getIsLinkType())
+		{
+			return FALSE;
+		}
+		return TRUE;
+	}
+	return FALSE;
+}
+BOOL LLItemBridge::copyToClipboard() const
+{
+	if(isItemCopyable())
+	{
+		LLInventoryClipboard::instance().add(mUUID);
+		return TRUE;
+	}
+	return FALSE;
+}
+
+LLViewerInventoryItem* LLItemBridge::getItem() const
+{
+	LLViewerInventoryItem* item = NULL;
+	LLInventoryModel* model = getInventoryModel();
+	if(model)
+	{
+		item = (LLViewerInventoryItem*)model->getItem(mUUID);
+	}
+	return item;
+}
+
+BOOL LLItemBridge::isItemPermissive() const
+{
+	LLViewerInventoryItem* item = getItem();
+	if(item)
+	{
+		U32 mask = item->getPermissions().getMaskBase();
+		if((mask & PERM_ITEM_UNRESTRICTED) == PERM_ITEM_UNRESTRICTED)
+		{
+			return TRUE;
+		}
+	}
+	return FALSE;
+}
+
+// +=================================================+
+// |        LLFolderBridge                           |
+// +=================================================+
+
+LLFolderBridge* LLFolderBridge::sSelf=NULL;
+
+// Can be moved to another folder
+BOOL LLFolderBridge::isItemMovable() const 
+{
+	LLInventoryObject* obj = getInventoryObject();
+	if(obj)
+	{
+		return (!LLAssetType::lookupIsProtectedCategoryType(((LLInventoryCategory*)obj)->getPreferredType()));
+	}
+	return FALSE;
+}
+
+void LLFolderBridge::selectItem()
+{
+}
+
+
+// Can be destroyed (or moved to trash)
+BOOL LLFolderBridge::isItemRemovable()
+{
+	LLInventoryModel* model = getInventoryModel();
+	if(!model) 
+	{
+		return FALSE;
+	}
+
+	if(!model->isObjectDescendentOf(mUUID, gInventory.getRootFolderID()))
+	{
+		return FALSE;
+	}
+
+	LLVOAvatarSelf* avatar = gAgent.getAvatarObject();
+	if( !avatar )
+	{
+		return FALSE;
+	}
+
+	LLInventoryCategory* category = model->getCategory(mUUID);
+	if( !category )
+	{
+		return FALSE;
+	}
+
+	if(LLAssetType::lookupIsProtectedCategoryType(category->getPreferredType()))
+	{
+		return FALSE;
+	}
+
+	LLInventoryModel::cat_array_t	descendent_categories;
+	LLInventoryModel::item_array_t	descendent_items;
+	gInventory.collectDescendents( mUUID, descendent_categories, descendent_items, FALSE );
+
+	S32 i;
+	for( i = 0; i < descendent_categories.count(); i++ )
+	{
+		LLInventoryCategory* category = descendent_categories[i];
+		if(LLAssetType::lookupIsProtectedCategoryType(category->getPreferredType()))
+		{
+			return FALSE;
+		}
+	}
+
+	for( i = 0; i < descendent_items.count(); i++ )
+	{
+		LLInventoryItem* item = descendent_items[i];
+		if( (item->getType() == LLAssetType::AT_CLOTHING) ||
+			(item->getType() == LLAssetType::AT_BODYPART) )
+		{
+			if(gAgentWearables.isWearingItem(item->getUUID()))
+			{
+				return FALSE;
+			}
+		}
+		else
+		if( item->getType() == LLAssetType::AT_OBJECT )
+		{
+			if(avatar->isWearingAttachment(item->getUUID()))
+			{
+				return FALSE;
+			}
+		}
+	}
+
+	return TRUE;
+}
+
+BOOL LLFolderBridge::isUpToDate() const
+{
+	LLInventoryModel* model = getInventoryModel();
+	if(!model) return FALSE;
+	LLViewerInventoryCategory* category = (LLViewerInventoryCategory*)model->getCategory(mUUID);
+	if( !category )
+	{
+		return FALSE;
+	}
+
+	return category->getVersion() != LLViewerInventoryCategory::VERSION_UNKNOWN;
+}
+
+BOOL LLFolderBridge::isItemCopyable() const
+{
+	return TRUE;
+}
+
+BOOL LLFolderBridge::copyToClipboard() const
+{
+	if(isItemCopyable())
+	{
+		LLInventoryClipboard::instance().add(mUUID);
+		return TRUE;
+	}
+	return FALSE;
+}
+
+BOOL LLFolderBridge::isClipboardPasteable() const
+{
+	if ( ! LLInvFVBridge::isClipboardPasteable() )
+		return FALSE;
+
+	// Don't allow pasting duplicates to the Calling Card/Friends subfolders, see bug EXT-1599
+	if ( LLFriendCardsManager::instance().isCategoryInFriendFolder( getCategory() ) )
+	{
+		LLInventoryModel* model = getInventoryModel();
+		if ( !model )
+		{
+			return FALSE;
+		}
+
+		LLDynamicArray<LLUUID> objects;
+		LLInventoryClipboard::instance().retrieve(objects);
+		const LLViewerInventoryCategory *current_cat = getCategory();
+
+		// Search for the direct descendent of current Friends subfolder among all pasted items, 
+		// and return false if is found.
+		for(S32 i = objects.count() - 1; i >= 0; --i)
+		{
+			const LLUUID &obj_id = objects.get(i);
+			if ( LLFriendCardsManager::instance().isObjDirectDescendentOfCategory(model->getObject(obj_id), current_cat) )
+			{
+				return FALSE;
+			}
+		}
+
+	}
+	return TRUE;
+}
+
+BOOL LLFolderBridge::isClipboardPasteableAsLink() const
+{
+	// Check normal paste-as-link permissions
+	if (!LLInvFVBridge::isClipboardPasteableAsLink())
+	{
+		return FALSE;
+	}
+	
+	const LLInventoryModel* model = getInventoryModel();
+	if (!model)
+	{
+		return FALSE;
+	}
+
+	const LLViewerInventoryCategory *current_cat = getCategory();
+	if (current_cat)
+	{
+		const BOOL is_in_friend_folder = LLFriendCardsManager::instance().isCategoryInFriendFolder( current_cat );
+		const LLUUID &current_cat_id = current_cat->getUUID();
+		LLDynamicArray<LLUUID> objects;
+		LLInventoryClipboard::instance().retrieve(objects);
+		S32 count = objects.count();
+		for(S32 i = 0; i < count; i++)
+		{
+			const LLUUID &obj_id = objects.get(i);
+			const LLInventoryCategory *cat = model->getCategory(obj_id);
+			if (cat)
+			{
+				const LLUUID &cat_id = cat->getUUID();
+				// Don't allow recursive pasting
+				if ((cat_id == current_cat_id) || 
+					model->isObjectDescendentOf(current_cat_id, cat_id))
+				{
+					return FALSE;
+				}
+			}
+			// Don't allow pasting duplicates to the Calling Card/Friends subfolders, see bug EXT-1599
+			if ( is_in_friend_folder )
+			{
+				// If object is direct descendent of current Friends subfolder than return false.
+				// Note: We can't use 'const LLInventoryCategory *cat', because it may be null
+				// in case type of obj_id is LLInventoryItem.
+				if ( LLFriendCardsManager::instance().isObjDirectDescendentOfCategory(model->getObject(obj_id), current_cat) )
+				{
+					return FALSE;
+				}
+			}
+		}
+	}
+	return TRUE;
+
+}
+
+BOOL LLFolderBridge::dragCategoryIntoFolder(LLInventoryCategory* inv_cat,
+											BOOL drop)
+{
+	// This should never happen, but if an inventory item is incorrectly parented, 
+	// the UI will get confused and pass in a NULL.
+	if(!inv_cat) return FALSE;
+
+	LLInventoryModel* model = getInventoryModel();
+	if(!model) return FALSE;
+
+	LLVOAvatarSelf* avatar = gAgent.getAvatarObject();
+	if(!avatar) return FALSE;
+
+	// cannot drag categories into library
+	if(!isAgentInventory())
+	{
+		return FALSE;
+	}
+
+	// check to make sure source is agent inventory, and is represented there.
+	LLToolDragAndDrop::ESource source = LLToolDragAndDrop::getInstance()->getSource();
+	BOOL is_agent_inventory = (model->getCategory(inv_cat->getUUID()) != NULL)
+		&& (LLToolDragAndDrop::SOURCE_AGENT == source);
+
+	BOOL accept = FALSE;
+	S32 i;
+	LLInventoryModel::cat_array_t	descendent_categories;
+	LLInventoryModel::item_array_t	descendent_items;
+	if(is_agent_inventory)
+	{
+		const LLUUID& cat_id = inv_cat->getUUID();
+
+		// Is the destination the trash?
+		const LLUUID trash_id = model->findCategoryUUIDForType(LLAssetType::AT_TRASH);
+		BOOL move_is_into_trash = (mUUID == trash_id)
+				|| model->isObjectDescendentOf(mUUID, trash_id);
+		BOOL is_movable = (!LLAssetType::lookupIsProtectedCategoryType(inv_cat->getPreferredType()));
+		LLUUID current_outfit_id = model->findCategoryUUIDForType(LLAssetType::AT_CURRENT_OUTFIT);
+		BOOL move_is_into_current_outfit = (mUUID == current_outfit_id);
+		BOOL move_is_into_outfit = (getCategory() && getCategory()->getPreferredType()==LLAssetType::AT_OUTFIT);
+		if (move_is_into_current_outfit || move_is_into_outfit)
+		{
+			// BAP - restrictions?
+			is_movable = true;
+		}
+
+		if (mUUID == gInventory.findCategoryUUIDForType(LLAssetType::AT_FAVORITE))
+		{
+			is_movable = FALSE; // It's generally movable but not into Favorites folder. EXT-1604
+		}
+
+		if( is_movable )
+		{
+			gInventory.collectDescendents( cat_id, descendent_categories, descendent_items, FALSE );
+
+			for( i = 0; i < descendent_categories.count(); i++ )
+			{
+				LLInventoryCategory* category = descendent_categories[i];
+				if(LLAssetType::lookupIsProtectedCategoryType(category->getPreferredType()))
+				{
+					// ...can't move "special folders" like Textures
+					is_movable = FALSE;
+					break;
+				}
+			}
+			
+			if( is_movable )
+			{
+				if( move_is_into_trash )
+				{
+					for( i = 0; i < descendent_items.count(); i++ )
+					{
+						LLInventoryItem* item = descendent_items[i];
+						if( (item->getType() == LLAssetType::AT_CLOTHING) ||
+							(item->getType() == LLAssetType::AT_BODYPART) )
+						{
+							if( gAgentWearables.isWearingItem( item->getUUID() ) )
+							{
+								is_movable = FALSE;  // It's generally movable, but not into the trash!
+								break;
+							}
+						}
+						else
+						if( item->getType() == LLAssetType::AT_OBJECT )
+						{
+							if( avatar->isWearingAttachment( item->getUUID() ) )
+							{
+								is_movable = FALSE;  // It's generally movable, but not into the trash!
+								break;
+							}
+						}
+					}
+				}
+			}
+		}
+
+		
+		accept =	is_movable
+					&& (mUUID != cat_id)								// Can't move a folder into itself
+					&& (mUUID != inv_cat->getParentUUID())				// Avoid moves that would change nothing
+					&& !(model->isObjectDescendentOf(mUUID, cat_id));	// Avoid circularity
+		if(accept && drop)
+		{
+			// Look for any gestures and deactivate them
+			if (move_is_into_trash)
+			{
+				for (i = 0; i < descendent_items.count(); i++)
+				{
+					LLInventoryItem* item = descendent_items[i];
+					if (item->getType() == LLAssetType::AT_GESTURE
+						&& LLGestureManager::instance().isGestureActive(item->getUUID()))
+					{
+						LLGestureManager::instance().deactivateGesture(item->getUUID());
+					}
+				}
+			}
+			// if target is an outfit or current outfit folder we use link
+			if (move_is_into_current_outfit || move_is_into_outfit) 
+			{
+#if SUPPORT_ENSEMBLES
+				// BAP - should skip if dup.
+				if (move_is_into_current_outfit)
+				{
+					LLAppearanceManager::wearEnsemble(inv_cat);
+				}
+				else
+				{
+					LLPointer<LLInventoryCallback> cb = NULL;
+					link_inventory_item(
+						gAgent.getID(),
+						inv_cat->getUUID(),
+						mUUID,
+						inv_cat->getName(),
+						LLAssetType::AT_LINK_FOLDER,
+						cb);
+				}
+#endif
+			}
+			else
+			{
+				
+				// Reparent the folder and restamp children if it's moving
+				// into trash.
+				LLInvFVBridge::changeCategoryParent(
+					model,
+					(LLViewerInventoryCategory*)inv_cat,
+					mUUID,
+					move_is_into_trash);
+			}
+		}
+	}
+	else if(LLToolDragAndDrop::SOURCE_WORLD == source)
+	{
+		// content category has same ID as object itself
+		LLUUID object_id = inv_cat->getUUID();
+		LLUUID category_id = mUUID;
+		accept = move_inv_category_world_to_agent(object_id, category_id, drop);
+	}
+	return accept;
+}
+
+void warn_move_inventory(LLViewerObject* object, LLMoveInv* move_inv)
+{
+	const char* dialog = NULL;
+	if (object->flagScripted())
+	{
+		dialog = "MoveInventoryFromScriptedObject";
+	}
+	else
+	{
+		dialog = "MoveInventoryFromObject";
+	}
+	LLNotifications::instance().add(dialog, LLSD(), LLSD(), boost::bind(move_task_inventory_callback, _1, _2, move_inv));
+}
+
+// Move/copy all inventory items from the Contents folder of an in-world
+// object to the agent's inventory, inside a given category.
+BOOL move_inv_category_world_to_agent(const LLUUID& object_id, 
+									  const LLUUID& category_id,
+									  BOOL drop,
+									  void (*callback)(S32, void*),
+									  void* user_data)
+{
+	// Make sure the object exists. If we allowed dragging from
+	// anonymous objects, it would be possible to bypass
+	// permissions.
+	// content category has same ID as object itself
+	LLViewerObject* object = gObjectList.findObject(object_id);
+	if(!object)
+	{
+		llinfos << "Object not found for drop." << llendl;
+		return FALSE;
+	}
+
+	// this folder is coming from an object, as there is only one folder in an object, the root,
+	// we need to collect the entire contents and handle them as a group
+	InventoryObjectList inventory_objects;
+	object->getInventoryContents(inventory_objects);
+
+	if (inventory_objects.empty())
+	{
+		llinfos << "Object contents not found for drop." << llendl;
+		return FALSE;
+	}
+	
+	BOOL accept = TRUE;
+	BOOL is_move = FALSE;
+
+	// coming from a task. Need to figure out if the person can
+	// move/copy this item.
+	InventoryObjectList::iterator it = inventory_objects.begin();
+	InventoryObjectList::iterator end = inventory_objects.end();
+	for ( ; it != end; ++it)
+	{
+		// coming from a task. Need to figure out if the person can
+		// move/copy this item.
+		LLPermissions perm(((LLInventoryItem*)((LLInventoryObject*)(*it)))->getPermissions());
+		if((perm.allowCopyBy(gAgent.getID(), gAgent.getGroupID())
+			&& perm.allowTransferTo(gAgent.getID())))
+//			|| gAgent.isGodlike())
+		{
+			accept = TRUE;
+		}
+		else if(object->permYouOwner())
+		{
+			// If the object cannot be copied, but the object the
+			// inventory is owned by the agent, then the item can be
+			// moved from the task to agent inventory.
+			is_move = TRUE;
+			accept = TRUE;
+		}
+		else
+		{
+			accept = FALSE;
+			break;
+		}
+	}
+
+	if(drop && accept)
+	{
+		it = inventory_objects.begin();
+		InventoryObjectList::iterator first_it = inventory_objects.begin();
+		LLMoveInv* move_inv = new LLMoveInv;
+		move_inv->mObjectID = object_id;
+		move_inv->mCategoryID = category_id;
+		move_inv->mCallback = callback;
+		move_inv->mUserData = user_data;
+
+		for ( ; it != end; ++it)
+		{
+			two_uuids_t two(category_id, (*it)->getUUID());
+			move_inv->mMoveList.push_back(two);
+		}
+
+		if(is_move)
+		{
+			// Callback called from within here.
+			warn_move_inventory(object, move_inv);
+		}
+		else
+		{
+			LLNotification::Params params("MoveInventoryFromObject");
+			params.functor.function(boost::bind(move_task_inventory_callback, _1, _2, move_inv));
+			LLNotifications::instance().forceResponse(params, 0);
+		}
+	}
+	return accept;
+}
+
+bool LLFindCOFValidItems::operator()(LLInventoryCategory* cat,
+									 LLInventoryItem* item)
+{
+	// Valid COF items are:
+	// - links to wearables (body parts or clothing)
+	// - links to attachments
+	// - links to gestures
+	// - links to ensemble folders
+	LLViewerInventoryItem *linked_item = ((LLViewerInventoryItem*)item)->getLinkedItem(); // BAP - safe?
+	if (linked_item)
+	{
+		LLAssetType::EType type = linked_item->getType();
+		return (type == LLAssetType::AT_CLOTHING ||
+				type == LLAssetType::AT_BODYPART ||
+				type == LLAssetType::AT_GESTURE ||
+				type == LLAssetType::AT_OBJECT);
+	}
+	else
+	{
+		LLViewerInventoryCategory *linked_category = ((LLViewerInventoryItem*)item)->getLinkedCategory(); // BAP - safe?
+		// BAP remove AT_NONE support after ensembles are fully working?
+		return (linked_category && 
+				((linked_category->getPreferredType() == LLAssetType::AT_NONE) ||
+				 (LLAssetType::lookupIsEnsembleCategoryType(linked_category->getPreferredType()))));
+	}
+}
+
+
+bool LLFindWearables::operator()(LLInventoryCategory* cat,
+								 LLInventoryItem* item)
+{
+	if(item)
+	{
+		if((item->getType() == LLAssetType::AT_CLOTHING)
+		   || (item->getType() == LLAssetType::AT_BODYPART))
+		{
+			return TRUE;
+		}
+	}
+	return FALSE;
+}
+
+
+
+//Used by LLFolderBridge as callback for directory recursion.
+class LLRightClickInventoryFetchObserver : public LLInventoryFetchObserver
+{
+public:
+	LLRightClickInventoryFetchObserver() :
+		mCopyItems(false)
+	{ };
+	LLRightClickInventoryFetchObserver(const LLUUID& cat_id, bool copy_items) :
+		mCatID(cat_id),
+		mCopyItems(copy_items)
+		{ };
+	virtual void done()
+	{
+		// we've downloaded all the items, so repaint the dialog
+		LLFolderBridge::staticFolderOptionsMenu();
+
+		gInventory.removeObserver(this);
+		delete this;
+	}
+	
+
+protected:
+	LLUUID mCatID;
+	bool mCopyItems;
+
+};
+
+//Used by LLFolderBridge as callback for directory recursion.
+class LLRightClickInventoryFetchDescendentsObserver : public LLInventoryFetchDescendentsObserver
+{
+public:
+	LLRightClickInventoryFetchDescendentsObserver(bool copy_items) : mCopyItems(copy_items) {}
+	~LLRightClickInventoryFetchDescendentsObserver() {}
+	virtual void done();
+protected:
+	bool mCopyItems;
+};
+
+void LLRightClickInventoryFetchDescendentsObserver::done()
+{
+	// Avoid passing a NULL-ref as mCompleteFolders.front() down to
+	// gInventory.collectDescendents()
+	if( mCompleteFolders.empty() )
+	{
+		llwarns << "LLRightClickInventoryFetchDescendentsObserver::done with empty mCompleteFolders" << llendl;
+		dec_busy_count();
+		gInventory.removeObserver(this);
+		delete this;
+		return;
+	}
+
+	// What we do here is get the complete information on the items in
+	// the library, and set up an observer that will wait for that to
+	// happen.
+	LLInventoryModel::cat_array_t cat_array;
+	LLInventoryModel::item_array_t item_array;
+	gInventory.collectDescendents(mCompleteFolders.front(),
+								  cat_array,
+								  item_array,
+								  LLInventoryModel::EXCLUDE_TRASH);
+	S32 count = item_array.count();
+#if 0 // HACK/TODO: Why?
+	// This early causes a giant menu to get produced, and doesn't seem to be needed.
+	if(!count)
+	{
+		llwarns << "Nothing fetched in category " << mCompleteFolders.front()
+				<< llendl;
+		dec_busy_count();
+		gInventory.removeObserver(this);
+		delete this;
+		return;
+	}
+#endif
+
+	LLRightClickInventoryFetchObserver* outfit;
+	outfit = new LLRightClickInventoryFetchObserver(mCompleteFolders.front(), mCopyItems);
+	LLInventoryFetchObserver::item_ref_t ids;
+	for(S32 i = 0; i < count; ++i)
+	{
+		ids.push_back(item_array.get(i)->getUUID());
+	}
+
+	// clean up, and remove this as an observer since the call to the
+	// outfit could notify observers and throw us into an infinite
+	// loop.
+	dec_busy_count();
+	gInventory.removeObserver(this);
+	delete this;
+
+	// increment busy count and either tell the inventory to check &
+	// call done, or add this object to the inventory for observation.
+	inc_busy_count();
+
+	// do the fetch
+	outfit->fetchItems(ids);
+	outfit->done();				//Not interested in waiting and this will be right 99% of the time.
+//Uncomment the following code for laggy Inventory UI.
+/*	if(outfit->isEverythingComplete())
+	{
+		// everything is already here - call done.
+		outfit->done();
+	}
+	else
+	{
+		// it's all on it's way - add an observer, and the inventory
+		// will call done for us when everything is here.
+		gInventory.addObserver(outfit);
+	}*/
+}
+
+
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+// Class LLInventoryWearObserver
+//
+// Observer for "copy and wear" operation to support knowing 
+// when the all of the contents have been added to inventory.
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+class LLInventoryCopyAndWearObserver : public LLInventoryObserver
+{
+public:
+	LLInventoryCopyAndWearObserver(const LLUUID& cat_id, int count) :mCatID(cat_id), mContentsCount(count), mFolderAdded(FALSE) {}
+	virtual ~LLInventoryCopyAndWearObserver() {}
+	virtual void changed(U32 mask);
+
+protected:
+	LLUUID mCatID;
+	int    mContentsCount;
+	BOOL   mFolderAdded;
+};
+
+
+
+void LLInventoryCopyAndWearObserver::changed(U32 mask)
+{
+	if((mask & (LLInventoryObserver::ADD)) != 0)
+	{
+		if (!mFolderAdded) 
+		{
+			const std::set<LLUUID>& changed_items = gInventory.getChangedIDs();
+
+			std::set<LLUUID>::const_iterator id_it = changed_items.begin();
+			std::set<LLUUID>::const_iterator id_end = changed_items.end();
+			for (;id_it != id_end; ++id_it)
+			{
+				if ((*id_it) == mCatID) 
+				{
+					mFolderAdded = TRUE;
+					break;
+				}
+			}
+		}
+
+		if (mFolderAdded) 
+		{
+			LLViewerInventoryCategory* category = gInventory.getCategory(mCatID);
+
+			if (NULL == category)
+			{
+				llwarns << "gInventory.getCategory(" << mCatID
+					<< ") was NULL" << llendl;
+			}
+			else
+			{
+				if (category->getDescendentCount() ==
+				    mContentsCount)
+				{
+					gInventory.removeObserver(this);
+					LLAppearanceManager::wearInventoryCategory(category, FALSE, TRUE);
+					delete this;
+				}
+			}		
+		}
+
+	}
+}
+
+
+
+void LLFolderBridge::performAction(LLFolderView* folder, LLInventoryModel* model, std::string action)
+{
+	if ("open" == action)
+	{
+		openItem();
+		return;
+	}
+	else if ("paste" == action)
+	{
+		pasteFromClipboard();
+		return;
+	}
+	else if ("paste_link" == action)
+	{
+		pasteLinkFromClipboard();
+		return;
+	}
+	else if ("properties" == action)
+	{
+		showProperties();
+		return;
+	}
+	else if ("replaceoutfit" == action)
+	{
+		modifyOutfit(FALSE);
+		return;
+	}
+#if SUPPORT_ENSEMBLES
+	else if ("wearasensemble" == action)
+	{
+		LLInventoryModel* model = getInventoryModel();
+		if(!model) return;
+		LLViewerInventoryCategory* cat = getCategory();
+		if(!cat) return;
+		LLAppearanceManager::wearEnsemble(cat,true);
+		return;
+	}
+#endif
+	else if ("addtooutfit" == action)
+	{
+		modifyOutfit(TRUE);
+		return;
+	}
+	else if ("copy" == action)
+	{
+		copyToClipboard();
+		return;
+	}
+	else if ("removefromoutfit" == action)
+	{
+		LLInventoryModel* model = getInventoryModel();
+		if(!model) return;
+		LLViewerInventoryCategory* cat = getCategory();
+		if(!cat) return;
+		
+		remove_inventory_category_from_avatar ( cat );
+		return;
+	}	
+	else if ("purge" == action)
+	{		
+		purgeItem(model, mUUID);
+		return;
+	}
+	else if ("restore" == action)
+	{
+		restoreItem();
+		return;
+	}
+}
+
+void LLFolderBridge::openItem()
+{
+	lldebugs << "LLFolderBridge::openItem()" << llendl;
+	LLInventoryModel* model = getInventoryModel();
+	if(!model) return;
+	bool fetching_inventory = model->fetchDescendentsOf(mUUID);
+	// Only change folder type if we have the folder contents.
+	if (!fetching_inventory)
+	{
+		// Disabling this for now, it's causing crash when new items are added to folders
+		// since folder type may change before new item item has finished processing.
+		// determineFolderType();
+	}
+}
+
+void LLFolderBridge::closeItem()
+{
+	determineFolderType();
+}
+
+void LLFolderBridge::determineFolderType()
+{
+	if (isUpToDate())
+	{
+		LLInventoryModel* model = getInventoryModel();
+		LLViewerInventoryCategory* category = model->getCategory(mUUID);
+		category->determineFolderType();
+	}
+}
+
+BOOL LLFolderBridge::isItemRenameable() const
+{
+	LLViewerInventoryCategory* cat = (LLViewerInventoryCategory*)getCategory();
+	if(cat && !LLAssetType::lookupIsProtectedCategoryType(cat->getPreferredType())
+	   && (cat->getOwnerID() == gAgent.getID()))
+	{
+		return TRUE;
+	}
+	return FALSE;
+}
+
+void LLFolderBridge::restoreItem()
+{
+	LLViewerInventoryCategory* cat;
+	cat = (LLViewerInventoryCategory*)getCategory();
+	if(cat)
+	{
+		LLInventoryModel* model = getInventoryModel();
+		LLUUID new_parent = model->findCategoryUUIDForType(cat->getType());
+		// do not restamp children on restore
+		LLInvFVBridge::changeCategoryParent(model, cat, new_parent, FALSE);
+	}
+}
+
+LLAssetType::EType LLFolderBridge::getPreferredType() const
+{
+	LLAssetType::EType preferred_type = LLAssetType::AT_NONE;
+	LLViewerInventoryCategory* cat = getCategory();
+	if(cat)
+	{
+		preferred_type = cat->getPreferredType();
+	}
+
+	return preferred_type;
+}
+
+// Icons for folders are based on the preferred type
+LLUIImagePtr LLFolderBridge::getIcon() const
+{
+	LLAssetType::EType preferred_type = LLAssetType::AT_NONE;
+	LLViewerInventoryCategory* cat = getCategory();
+	if(cat)
+	{
+		preferred_type = cat->getPreferredType();
+	}
+	return getIcon(preferred_type);
+}
+
+LLUIImagePtr LLFolderBridge::getIcon(LLAssetType::EType preferred_type)
+{
+	// we only have one folder image now
+	return LLUI::getUIImage("Inv_FolderClosed");
+}
+
+BOOL LLFolderBridge::renameItem(const std::string& new_name)
+{
+	if(!isItemRenameable())
+		return FALSE;
+	LLInventoryModel* model = getInventoryModel();
+	if(!model)
+		return FALSE;
+	LLViewerInventoryCategory* cat = getCategory();
+	if(cat && (cat->getName() != new_name))
+	{
+		LLPointer<LLViewerInventoryCategory> new_cat = new LLViewerInventoryCategory(cat);
+		new_cat->rename(new_name);
+		new_cat->updateServer(FALSE);
+		model->updateCategory(new_cat);
+
+		model->notifyObservers();
+	}
+	// return FALSE because we either notified observers (& therefore
+	// rebuilt) or we didn't update.
+	return FALSE;
+}
+
+BOOL LLFolderBridge::removeItem()
+{
+	if(!isItemRemovable())
+	{
+		return FALSE;
+	}
+	// move it to the trash
+	LLPreview::hide(mUUID);
+	LLInventoryModel* model = getInventoryModel();
+	if(!model) return FALSE;
+
+	LLUUID trash_id = model->findCategoryUUIDForType(LLAssetType::AT_TRASH);
+
+	// Look for any gestures and deactivate them
+	LLInventoryModel::cat_array_t	descendent_categories;
+	LLInventoryModel::item_array_t	descendent_items;
+	gInventory.collectDescendents( mUUID, descendent_categories, descendent_items, FALSE );
+
+	S32 i;
+	for (i = 0; i < descendent_items.count(); i++)
+	{
+		LLInventoryItem* item = descendent_items[i];
+		if (item->getType() == LLAssetType::AT_GESTURE
+			&& LLGestureManager::instance().isGestureActive(item->getUUID()))
+		{
+			LLGestureManager::instance().deactivateGesture(item->getUUID());
+		}
+	}
+
+	// go ahead and do the normal remove if no 'last calling
+	// cards' are being removed.
+	LLViewerInventoryCategory* cat = getCategory();
+	if(cat)
+	{
+		LLInvFVBridge::changeCategoryParent(model, cat, trash_id, TRUE);
+	}
+
+	return TRUE;
+}
+
+void LLFolderBridge::pasteFromClipboard()
+{
+	LLInventoryModel* model = getInventoryModel();
+	if(model && isClipboardPasteable())
+	{
+		LLInventoryItem* item = NULL;
+		LLDynamicArray<LLUUID> objects;
+		LLInventoryClipboard::instance().retrieve(objects);
+		S32 count = objects.count();
+		const LLUUID parent_id(mUUID);
+		for(S32 i = 0; i < count; i++)
+		{
+			item = model->getItem(objects.get(i));
+			if (item)
+			{
+				if(LLInventoryClipboard::instance().isCutMode())
+				{
+					// move_inventory_item() is not enough, 
+					//we have to update inventory locally too
+					changeItemParent(model, dynamic_cast<LLViewerInventoryItem*>(item), parent_id, FALSE);
+				}
+				else
+				{
+					copy_inventory_item(
+						gAgent.getID(),
+						item->getPermissions().getOwner(),
+						item->getUUID(),
+						parent_id,
+						std::string(),
+						LLPointer<LLInventoryCallback>(NULL));
+				}
+			}
+		}
+	}
+}
+
+void LLFolderBridge::pasteLinkFromClipboard()
+{
+	const LLInventoryModel* model = getInventoryModel();
+	if(model)
+	{
+		LLDynamicArray<LLUUID> objects;
+		LLInventoryClipboard::instance().retrieve(objects);
+		S32 count = objects.count();
+		LLUUID parent_id(mUUID);
+		for(S32 i = 0; i < count; i++)
+		{
+			const LLUUID &object_id = objects.get(i);
+#if SUPPORT_ENSEMBLES
+			if (LLInventoryCategory *cat = model->getCategory(object_id))
+			{
+				link_inventory_item(
+					gAgent.getID(),
+					cat->getUUID(),
+					parent_id,
+					cat->getName(),
+					LLAssetType::AT_LINK_FOLDER,
+					LLPointer<LLInventoryCallback>(NULL));
+			}
+			else
+#endif
+			if (LLInventoryItem *item = model->getItem(object_id))
+			{
+				link_inventory_item(
+					gAgent.getID(),
+					item->getUUID(),
+					parent_id,
+					item->getName(),
+					LLAssetType::AT_LINK,
+					LLPointer<LLInventoryCallback>(NULL));
+			}
+		}
+	}
+}
+
+void LLFolderBridge::staticFolderOptionsMenu()
+{
+	if (!sSelf) return;
+	sSelf->folderOptionsMenu();
+}
+
+void LLFolderBridge::folderOptionsMenu()
+{
+	std::vector<std::string> disabled_items;
+
+	LLInventoryModel* model = getInventoryModel();
+	if(!model) return;
+
+	const LLInventoryCategory* category = model->getCategory(mUUID);
+	LLAssetType::EType type = category->getPreferredType();
+	const bool is_default_folder = category && LLAssetType::lookupIsProtectedCategoryType(type);
+	// BAP change once we're no longer treating regular categories as ensembles.
+	const bool is_ensemble = category && (type == LLAssetType::AT_NONE ||
+										  LLAssetType::lookupIsEnsembleCategoryType(type));
+	
+	// calling card related functionality for folders.
+
+	// Only enable calling-card related options for non-default folders.
+	if (!is_default_folder)
+	{
+		LLIsType is_callingcard(LLAssetType::AT_CALLINGCARD);
+		if (mCallingCards || checkFolderForContentsOfType(model, is_callingcard))
+		{
+			mItems.push_back(std::string("Calling Card Separator"));
+			mItems.push_back(std::string("Conference Chat Folder"));
+			mItems.push_back(std::string("IM All Contacts In Folder"));
+		}
+	}
+	
+	// wearables related functionality for folders.
+	//is_wearable
+	LLFindWearables is_wearable;
+	LLIsType is_object( LLAssetType::AT_OBJECT );
+	LLIsType is_gesture( LLAssetType::AT_GESTURE );
+
+	if (mWearables ||
+		checkFolderForContentsOfType(model, is_wearable)  ||
+		checkFolderForContentsOfType(model, is_object) ||
+		checkFolderForContentsOfType(model, is_gesture) )
+	{
+		mItems.push_back(std::string("Folder Wearables Separator"));
+
+		// Only enable add/replace outfit for non-default folders.
+		if (!is_default_folder)
+		{
+			mItems.push_back(std::string("Add To Outfit"));
+			mItems.push_back(std::string("Replace Outfit"));
+		}
+		if (is_ensemble)
+		{
+			mItems.push_back(std::string("Wear As Ensemble"));
+		}
+		mItems.push_back(std::string("Take Off Items"));
+	}
+	hide_context_entries(*mMenu, mItems, disabled_items);
+}
+
+BOOL LLFolderBridge::checkFolderForContentsOfType(LLInventoryModel* model, LLInventoryCollectFunctor& is_type)
+{
+	LLInventoryModel::cat_array_t cat_array;
+	LLInventoryModel::item_array_t item_array;
+	model->collectDescendentsIf(mUUID,
+								cat_array,
+								item_array,
+								LLInventoryModel::EXCLUDE_TRASH,
+								is_type);
+	return ((item_array.count() > 0) ? TRUE : FALSE );
+}
+
+// Flags unused
+void LLFolderBridge::buildContextMenu(LLMenuGL& menu, U32 flags)
+{
+	mItems.clear();
+	mDisabledItems.clear();
+
+	lldebugs << "LLFolderBridge::buildContextMenu()" << llendl;
+//	std::vector<std::string> disabled_items;
+	LLInventoryModel* model = getInventoryModel();
+	if(!model) return;
+	LLUUID trash_id = model->findCategoryUUIDForType(LLAssetType::AT_TRASH);
+	LLUUID lost_and_found_id = model->findCategoryUUIDForType(LLAssetType::AT_LOST_AND_FOUND);
+
+	mItems.clear(); //adding code to clear out member Items (which means Items should not have other data here at this point)
+	mDisabledItems.clear(); //adding code to clear out disabled members from previous 
+	if (lost_and_found_id == mUUID)
+	  {
+		// This is the lost+found folder.
+		  mItems.push_back(std::string("Empty Lost And Found"));
+	  }
+
+	if(trash_id == mUUID)
+	{
+		// This is the trash.
+		mItems.push_back(std::string("Empty Trash"));
+	}
+	else if(model->isObjectDescendentOf(mUUID, trash_id))
+	{
+		// This is a folder in the trash.
+		mItems.clear(); // clear any items that used to exist
+		mItems.push_back(std::string("Purge Item"));
+		if (!isItemRemovable())
+		{
+			mDisabledItems.push_back(std::string("Purge Item"));
+		}
+
+		mItems.push_back(std::string("Restore Item"));
+	}
+	else if(isAgentInventory()) // do not allow creating in library
+	{
+		LLViewerInventoryCategory *cat =  getCategory();
+
+		// BAP removed protected check to re-enable standard ops in untyped folders.
+		// Not sure what the right thing is to do here.
+		if (!isCOFFolder() && cat /*&&
+			LLAssetType::lookupIsProtectedCategoryType(cat->getPreferredType())*/)
+		{
+			// Do not allow to create 2-level subfolder in the Calling Card/Friends folder. EXT-694.
+			if (!LLFriendCardsManager::instance().isCategoryInFriendFolder(cat))
+				mItems.push_back(std::string("New Folder"));
+			mItems.push_back(std::string("New Script"));
+			mItems.push_back(std::string("New Note"));
+			mItems.push_back(std::string("New Gesture"));
+			mItems.push_back(std::string("New Clothes"));
+			mItems.push_back(std::string("New Body Parts"));
+			mItems.push_back(std::string("Change Type"));
+			
+			LLViewerInventoryCategory *cat = getCategory();
+			if (cat && LLAssetType::lookupIsProtectedCategoryType(cat->getPreferredType()))
+			{
+				mDisabledItems.push_back(std::string("Change Type"));
+			}
+			
+			getClipboardEntries(false, mItems, mDisabledItems, flags);
+		}
+		else
+		{
+			// Want some but not all of the items from getClipboardEntries for outfits.
+			if (cat && cat->getPreferredType()==LLAssetType::AT_OUTFIT)
+			{
+				mItems.push_back(std::string("Rename"));
+				mItems.push_back(std::string("Delete"));
+			}
+		}
+
+		//Added by spatters to force inventory pull on right-click to display folder options correctly. 07-17-06
+		mCallingCards = mWearables = FALSE;
+		
+		LLIsType is_callingcard(LLAssetType::AT_CALLINGCARD);
+		if (checkFolderForContentsOfType(model, is_callingcard))
+		{
+			mCallingCards=TRUE;
+		}
+		
+		LLFindWearables is_wearable;
+		LLIsType is_object( LLAssetType::AT_OBJECT );
+		LLIsType is_gesture( LLAssetType::AT_GESTURE );
+		
+		if (checkFolderForContentsOfType(model, is_wearable)  ||
+			checkFolderForContentsOfType(model, is_object) ||
+			checkFolderForContentsOfType(model, is_gesture) )
+		{
+			mWearables=TRUE;
+		}
+		
+		mMenu = &menu;
+		sSelf = this;
+		LLRightClickInventoryFetchDescendentsObserver* fetch = new LLRightClickInventoryFetchDescendentsObserver(FALSE);
+
+		LLInventoryFetchDescendentsObserver::folder_ref_t folders;
+		LLViewerInventoryCategory* category = (LLViewerInventoryCategory*)model->getCategory(mUUID);
+		if (category)
+		{
+			folders.push_back(category->getUUID());
+		}
+		fetch->fetchDescendents(folders);
+		inc_busy_count();
+		if(fetch->isEverythingComplete())
+		{
+			// everything is already here - call done.
+			fetch->done();
+		}
+		else
+		{
+			// it's all on it's way - add an observer, and the inventory
+			// will call done for us when everything is here.
+			gInventory.addObserver(fetch);
+		}
+	}
+	else
+	{
+		mItems.push_back(std::string("--no options--"));
+		mDisabledItems.push_back(std::string("--no options--"));
+	}
+	hide_context_entries(menu, mItems, mDisabledItems);
+}
+
+BOOL LLFolderBridge::hasChildren() const
+{
+	LLInventoryModel* model = getInventoryModel();
+	if(!model) return FALSE;
+	LLInventoryModel::EHasChildren has_children;
+	has_children = gInventory.categoryHasChildren(mUUID);
+	return has_children != LLInventoryModel::CHILDREN_NO;
+}
+
+BOOL LLFolderBridge::dragOrDrop(MASK mask, BOOL drop,
+								EDragAndDropType cargo_type,
+								void* cargo_data)
+{
+	//llinfos << "LLFolderBridge::dragOrDrop()" << llendl;
+	BOOL accept = FALSE;
+	switch(cargo_type)
+	{
+		case DAD_TEXTURE:
+		case DAD_SOUND:
+		case DAD_CALLINGCARD:
+		case DAD_LANDMARK:
+		case DAD_SCRIPT:
+		case DAD_OBJECT:
+		case DAD_NOTECARD:
+		case DAD_CLOTHING:
+		case DAD_BODYPART:
+		case DAD_ANIMATION:
+		case DAD_GESTURE:
+		case DAD_LINK:
+			accept = dragItemIntoFolder((LLInventoryItem*)cargo_data,
+										drop);
+			break;
+		case DAD_CATEGORY:
+			if (LLFriendCardsManager::instance().isAnyFriendCategory(mUUID))
+			{
+				accept = FALSE;
+			}
+			else
+			{
+				accept = dragCategoryIntoFolder((LLInventoryCategory*)cargo_data, drop);
+			}
+			break;
+		default:
+			break;
+	}
+	return accept;
+}
+
+LLViewerInventoryCategory* LLFolderBridge::getCategory() const
+{
+	LLViewerInventoryCategory* cat = NULL;
+	LLInventoryModel* model = getInventoryModel();
+	if(model)
+	{
+		cat = (LLViewerInventoryCategory*)model->getCategory(mUUID);
+	}
+	return cat;
+}
+
+
+// static
+void LLFolderBridge::pasteClipboard(void* user_data)
+{
+	LLFolderBridge* self = (LLFolderBridge*)user_data;
+	if(self) self->pasteFromClipboard();
+}
+
+void LLFolderBridge::createNewCategory(void* user_data)
+{
+	LLFolderBridge* bridge = (LLFolderBridge*)user_data;
+	if(!bridge) return;
+	LLInventoryPanel* panel = dynamic_cast<LLInventoryPanel*>(bridge->mInventoryPanel.get());
+	if (!panel) return;
+	LLInventoryModel* model = panel->getModel();
+	if(!model) return;
+	LLUUID id;
+	id = model->createNewCategory(bridge->getUUID(),
+								  LLAssetType::AT_NONE,
+								  LLStringUtil::null);
+	model->notifyObservers();
+
+	// At this point, the bridge has probably been deleted, but the
+	// view is still there.
+	panel->setSelection(id, TAKE_FOCUS_YES);
+}
+
+void LLFolderBridge::createNewShirt(void* user_data)
+{
+	LLFolderBridge::createWearable((LLFolderBridge*)user_data, WT_SHIRT);
+}
+
+void LLFolderBridge::createNewPants(void* user_data)
+{
+	LLFolderBridge::createWearable((LLFolderBridge*)user_data, WT_PANTS);
+}
+
+void LLFolderBridge::createNewShoes(void* user_data)
+{
+	LLFolderBridge::createWearable((LLFolderBridge*)user_data, WT_SHOES);
+}
+
+void LLFolderBridge::createNewSocks(void* user_data)
+{
+	LLFolderBridge::createWearable((LLFolderBridge*)user_data, WT_SOCKS);
+}
+
+void LLFolderBridge::createNewJacket(void* user_data)
+{
+	LLFolderBridge::createWearable((LLFolderBridge*)user_data, WT_JACKET);
+}
+
+void LLFolderBridge::createNewSkirt(void* user_data)
+{
+	LLFolderBridge::createWearable((LLFolderBridge*)user_data, WT_SKIRT);
+}
+
+void LLFolderBridge::createNewGloves(void* user_data)
+{
+	LLFolderBridge::createWearable((LLFolderBridge*)user_data, WT_GLOVES);
+}
+
+void LLFolderBridge::createNewUndershirt(void* user_data)
+{
+	LLFolderBridge::createWearable((LLFolderBridge*)user_data, WT_UNDERSHIRT);
+}
+
+void LLFolderBridge::createNewUnderpants(void* user_data)
+{
+	LLFolderBridge::createWearable((LLFolderBridge*)user_data, WT_UNDERPANTS);
+}
+
+void LLFolderBridge::createNewShape(void* user_data)
+{
+	LLFolderBridge::createWearable((LLFolderBridge*)user_data, WT_SHAPE);
+}
+
+void LLFolderBridge::createNewSkin(void* user_data)
+{
+	LLFolderBridge::createWearable((LLFolderBridge*)user_data, WT_SKIN);
+}
+
+void LLFolderBridge::createNewHair(void* user_data)
+{
+	LLFolderBridge::createWearable((LLFolderBridge*)user_data, WT_HAIR);
+}
+
+void LLFolderBridge::createNewEyes(void* user_data)
+{
+	LLFolderBridge::createWearable((LLFolderBridge*)user_data, WT_EYES);
+}
+
+// static
+void LLFolderBridge::createWearable(LLFolderBridge* bridge, EWearableType type)
+{
+	if(!bridge) return;
+	LLUUID parent_id = bridge->getUUID();
+	createWearable(parent_id, type);
+}
+
+// Separate function so can be called by global menu as well as right-click
+// menu.
+// static
+void LLFolderBridge::createWearable(LLUUID parent_id, EWearableType type)
+{
+	LLWearable* wearable = LLWearableList::instance().createNewWearable(type);
+	LLAssetType::EType asset_type = wearable->getAssetType();
+	LLInventoryType::EType inv_type = LLInventoryType::IT_WEARABLE;
+	create_inventory_item(gAgent.getID(), gAgent.getSessionID(),
+		parent_id, wearable->getTransactionID(), wearable->getName(),
+		wearable->getDescription(), asset_type, inv_type, wearable->getType(),
+		wearable->getPermissions().getMaskNextOwner(),
+		LLPointer<LLInventoryCallback>(NULL));
+}
+
+void LLFolderBridge::modifyOutfit(BOOL append)
+{
+	LLInventoryModel* model = getInventoryModel();
+	if(!model) return;
+	LLViewerInventoryCategory* cat = getCategory();
+	if(!cat) return;
+	
+	// BAP - was:
+	// wear_inventory_category_on_avatar( cat, append );
+	LLAppearanceManager::wearInventoryCategory( cat, FALSE, append );
+}
+
+// helper stuff
+bool move_task_inventory_callback(const LLSD& notification, const LLSD& response, LLMoveInv* move_inv)
+{
+	LLFloaterOpenObject::LLCatAndWear* cat_and_wear = (LLFloaterOpenObject::LLCatAndWear* )move_inv->mUserData;
+	LLViewerObject* object = gObjectList.findObject(move_inv->mObjectID);
+	S32 option = LLNotification::getSelectedOption(notification, response);
+
+	if(option == 0 && object)
+	{
+		if (cat_and_wear && cat_and_wear->mWear)
+		{
+			InventoryObjectList inventory_objects;
+			object->getInventoryContents(inventory_objects);
+			int contents_count = inventory_objects.size()-1; //subtract one for containing folder
+
+			LLInventoryCopyAndWearObserver* inventoryObserver = new LLInventoryCopyAndWearObserver(cat_and_wear->mCatID, contents_count);
+			gInventory.addObserver(inventoryObserver);
+		}
+
+		two_uuids_list_t::iterator move_it;
+		for (move_it = move_inv->mMoveList.begin(); 
+			move_it != move_inv->mMoveList.end(); 
+			++move_it)
+		{
+			object->moveInventory(move_it->first, move_it->second);
+		}
+
+		// update the UI.
+		dialog_refresh_all();
+	}
+
+	if (move_inv->mCallback)
+	{
+		move_inv->mCallback(option, move_inv->mUserData);
+	}
+
+	delete move_inv;
+	return false;
+}
+
+/*
+Next functions intended to reorder items in the inventory folder and save order on server
+Is now used for Favorites folder.
+
+*TODO: refactoring is needed with Favorites Bar functionality. Probably should be moved in LLInventoryModel
+*/
+void saveItemsOrder(LLInventoryModel::item_array_t& items)
+{
+	int sortField = 0;
+
+	// current order is saved by setting incremental values (1, 2, 3, ...) for the sort field
+	for (LLInventoryModel::item_array_t::iterator i = items.begin(); i != items.end(); ++i)
+	{
+		LLViewerInventoryItem* item = *i;
+
+		item->setSortField(++sortField);
+		item->setComplete(TRUE);
+		item->updateServer(FALSE);
+
+		gInventory.updateItem(item);
+	}
+
+	gInventory.notifyObservers();
+}
+
+LLInventoryModel::item_array_t::iterator findItemByUUID(LLInventoryModel::item_array_t& items, const LLUUID& id)
+{
+	LLInventoryModel::item_array_t::iterator result = items.end();
+
+	for (LLInventoryModel::item_array_t::iterator i = items.begin(); i != items.end(); ++i)
+	{
+		if ((*i)->getUUID() == id)
+		{
+			result = i;
+			break;
+		}
+	}
+
+	return result;
+}
+
+void updateItemsOrder(LLInventoryModel::item_array_t& items, const LLUUID& srcItemId, const LLUUID& destItemId)
+{
+	LLViewerInventoryItem* srcItem = gInventory.getItem(srcItemId);
+	LLViewerInventoryItem* destItem = gInventory.getItem(destItemId);
+
+	items.erase(findItemByUUID(items, srcItem->getUUID()));
+	items.insert(findItemByUUID(items, destItem->getUUID()), srcItem);
+}
+
+BOOL LLFolderBridge::dragItemIntoFolder(LLInventoryItem* inv_item,
+										BOOL drop)
+{
+	LLInventoryModel* model = getInventoryModel();
+	if(!model) return FALSE;
+
+	// cannot drag into library
+	if(!isAgentInventory())
+	{
+		return FALSE;
+	}
+
+	LLVOAvatarSelf* avatar = gAgent.getAvatarObject();
+	if(!avatar) return FALSE;
+
+	LLToolDragAndDrop::ESource source = LLToolDragAndDrop::getInstance()->getSource();
+	BOOL accept = FALSE;
+	LLViewerObject* object = NULL;
+	if(LLToolDragAndDrop::SOURCE_AGENT == source)
+	{
+
+		BOOL is_movable = TRUE;
+		switch( inv_item->getActualType() )
+		{
+		case LLAssetType::AT_ROOT_CATEGORY:
+			is_movable = FALSE;
+			break;
+
+		case LLAssetType::AT_CATEGORY:
+			is_movable = !LLAssetType::lookupIsProtectedCategoryType(((LLInventoryCategory*)inv_item)->getPreferredType());
+			break;
+		default:
+			break;
+		}
+
+		LLUUID trash_id = model->findCategoryUUIDForType(LLAssetType::AT_TRASH);
+		BOOL move_is_into_trash = (mUUID == trash_id) || model->isObjectDescendentOf(mUUID, trash_id);
+		LLUUID current_outfit_id = model->findCategoryUUIDForType(LLAssetType::AT_CURRENT_OUTFIT);
+		BOOL move_is_into_current_outfit = (mUUID == current_outfit_id);
+		BOOL move_is_into_outfit = (getCategory() && getCategory()->getPreferredType()==LLAssetType::AT_OUTFIT);
+		
+		if(is_movable && move_is_into_trash)
+		{
+			switch(inv_item->getType())
+			{
+			case LLAssetType::AT_CLOTHING:
+			case LLAssetType::AT_BODYPART:
+				is_movable = !gAgentWearables.isWearingItem(inv_item->getUUID());
+				break;
+
+			case LLAssetType::AT_OBJECT:
+				is_movable = !avatar->isWearingAttachment(inv_item->getUUID());
+				break;
+			default:
+				break;
+			}
+		}
+
+		if ( is_movable )
+		{
+			// Don't allow creating duplicates in the Calling Card/Friends
+			// subfolders, see bug EXT-1599. Check is item direct descendent
+			// of target folder and forbid item's movement if it so.
+			// Note: isItemDirectDescendentOfCategory checks if
+			// passed category is in the Calling Card/Friends folder
+			is_movable = ! LLFriendCardsManager::instance()
+				.isObjDirectDescendentOfCategory (inv_item, getCategory());
+		}
+ 
+		LLUUID favorites_id = model->findCategoryUUIDForType(LLAssetType::AT_FAVORITE);
+
+		// we can move item inside a folder only if this folder is Favorites. See EXT-719
+		accept = is_movable && ((mUUID != inv_item->getParentUUID()) || (mUUID == favorites_id));
+		if(accept && drop)
+		{
+			if (inv_item->getType() == LLAssetType::AT_GESTURE
+				&& LLGestureManager::instance().isGestureActive(inv_item->getUUID()) && move_is_into_trash)
+			{
+				LLGestureManager::instance().deactivateGesture(inv_item->getUUID());
+			}
+			// If an item is being dragged between windows, unselect
+			// everything in the active window so that we don't follow
+			// the selection to its new location (which is very
+			// annoying).
+			if (LLFloaterInventory::getActiveInventory())
+			{
+				LLInventoryPanel* active_panel = LLFloaterInventory::getActiveInventory()->getPanel();
+				LLInventoryPanel* panel = dynamic_cast<LLInventoryPanel*>(mInventoryPanel.get());
+				if (active_panel && (panel != active_panel))
+				{
+					active_panel->unSelectAll();
+				}
+			}
+
+			// if dragging from/into favorites folder only reorder items
+			if ((mUUID == inv_item->getParentUUID()) && (favorites_id == mUUID))
+			{
+				LLInventoryModel::cat_array_t cats;
+				LLInventoryModel::item_array_t items;
+				LLIsType is_type(LLAssetType::AT_LANDMARK);
+				model->collectDescendentsIf(favorites_id, cats, items, LLInventoryModel::EXCLUDE_TRASH, is_type);
+
+				LLInventoryPanel* panel = dynamic_cast<LLInventoryPanel*>(mInventoryPanel.get());
+				LLFolderViewItem* itemp = panel ? panel->getRootFolder()->getDraggingOverItem() : NULL;
+				if (itemp)
+				{
+					LLUUID srcItemId = inv_item->getUUID();
+					LLUUID destItemId = itemp->getListener()->getUUID();
+
+					// update order
+					updateItemsOrder(items, srcItemId, destItemId);
+
+					saveItemsOrder(items);
+				}
+			}
+			else if (favorites_id == mUUID) // if target is the favorites folder we use copy
+			{
+				copy_inventory_item(
+					gAgent.getID(),
+					inv_item->getPermissions().getOwner(),
+					inv_item->getUUID(),
+					mUUID,
+					std::string(),
+					LLPointer<LLInventoryCallback>(NULL));
+			}
+			else if (move_is_into_current_outfit || move_is_into_outfit)
+			{
+				// BAP - should skip if dup.
+				if (move_is_into_current_outfit)
+				{
+					LLAppearanceManager::wearItem(inv_item);
+				}
+				else
+				{
+					LLPointer<LLInventoryCallback> cb = NULL;
+					link_inventory_item(
+						gAgent.getID(),
+						inv_item->getUUID(),
+						mUUID,
+						std::string(),
+						LLAssetType::AT_LINK,
+						cb);
+				}
+			}
+			else
+			{
+				// restamp if the move is into the trash.
+				LLInvFVBridge::changeItemParent(
+					model,
+					(LLViewerInventoryItem*)inv_item,
+					mUUID,
+					move_is_into_trash);
+			}
+		}
+	}
+	else if(LLToolDragAndDrop::SOURCE_WORLD == source)
+	{
+		// Make sure the object exists. If we allowed dragging from
+		// anonymous objects, it would be possible to bypass
+		// permissions.
+		object = gObjectList.findObject(inv_item->getParentUUID());
+		if(!object)
+		{
+			llinfos << "Object not found for drop." << llendl;
+			return FALSE;
+		}
+
+		// coming from a task. Need to figure out if the person can
+		// move/copy this item.
+		LLPermissions perm(inv_item->getPermissions());
+		BOOL is_move = FALSE;
+		if((perm.allowCopyBy(gAgent.getID(), gAgent.getGroupID())
+			&& perm.allowTransferTo(gAgent.getID())))
+//		   || gAgent.isGodlike())
+			
+		{
+			accept = TRUE;
+		}
+		else if(object->permYouOwner())
+		{
+			// If the object cannot be copied, but the object the
+			// inventory is owned by the agent, then the item can be
+			// moved from the task to agent inventory.
+			is_move = TRUE;
+			accept = TRUE;
+		}
+		if(drop && accept)
+		{
+			LLMoveInv* move_inv = new LLMoveInv;
+			move_inv->mObjectID = inv_item->getParentUUID();
+			two_uuids_t item_pair(mUUID, inv_item->getUUID());
+			move_inv->mMoveList.push_back(item_pair);
+			move_inv->mCallback = NULL;
+			move_inv->mUserData = NULL;
+			if(is_move)
+			{
+				warn_move_inventory(object, move_inv);
+			}
+			else
+			{
+				LLNotification::Params params("MoveInventoryFromObject");
+				params.functor.function(boost::bind(move_task_inventory_callback, _1, _2, move_inv));
+				LLNotifications::instance().forceResponse(params, 0);
+			}
+		}
+		
+	}
+	else if(LLToolDragAndDrop::SOURCE_NOTECARD == source)
+	{
+		accept = TRUE;
+		if(drop)
+		{
+			copy_inventory_from_notecard(LLToolDragAndDrop::getInstance()->getObjectID(),
+				LLToolDragAndDrop::getInstance()->getSourceID(), inv_item);
+		}
+	}
+	else if(LLToolDragAndDrop::SOURCE_LIBRARY == source)
+	{
+		LLViewerInventoryItem* item = (LLViewerInventoryItem*)inv_item;
+		if(item && item->isComplete())
+		{
+			accept = TRUE;
+			if(drop)
+			{
+				copy_inventory_item(
+					gAgent.getID(),
+					inv_item->getPermissions().getOwner(),
+					inv_item->getUUID(),
+					mUUID,
+					std::string(),
+					LLPointer<LLInventoryCallback>(NULL));
+			}
+		}
+	}
+	else
+	{
+		llwarns << "unhandled drag source" << llendl;
+	}
+	return accept;
+}
+
+// +=================================================+
+// |        LLScriptBridge (DEPRECTED)               |
+// +=================================================+
+
+LLUIImagePtr LLScriptBridge::getIcon() const
+{
+	return get_item_icon(LLAssetType::AT_SCRIPT, LLInventoryType::IT_LSL, 0, FALSE);
+}
+
+// +=================================================+
+// |        LLTextureBridge                          |
+// +=================================================+
+
+LLUIImagePtr LLTextureBridge::getIcon() const
+{
+	return get_item_icon(LLAssetType::AT_TEXTURE, mInvType, 0, FALSE);
+}
+	
+void LLTextureBridge::openItem()
+{
+	LLViewerInventoryItem* item = getItem();
+	
+	if (item)
+	{
+		LLInvFVBridgeAction::doAction(item->getType(),mUUID,getInventoryModel());
+	}
+}
+
+// +=================================================+
+// |        LLSoundBridge                            |
+// +=================================================+
+
+LLUIImagePtr LLSoundBridge::getIcon() const
+{
+	return get_item_icon(LLAssetType::AT_SOUND, LLInventoryType::IT_SOUND, 0, FALSE);
+}
+
+void LLSoundBridge::openItem()
+{
+	LLViewerInventoryItem* item = getItem();
+	
+	if (item)
+	{
+		LLInvFVBridgeAction::doAction(item->getType(),mUUID,getInventoryModel());
+	}
+/*
+// Changed this back to the way it USED to work:
+// only open the preview dialog through the contextual right-click menu
+// double-click just plays the sound
+
+	LLViewerInventoryItem* item = getItem();
+	if(item)
+	{
+		openSoundPreview((void*)this);
+		//send_uuid_sound_trigger(item->getAssetUUID(), 1.0);
+	}
+*/
+}
+
+void LLSoundBridge::previewItem()
+{
+	LLViewerInventoryItem* item = getItem();
+	if(item)
+	{
+		send_sound_trigger(item->getAssetUUID(), 1.0);
+	}
+}
+
+void LLSoundBridge::openSoundPreview(void* which)
+{
+	LLSoundBridge *me = (LLSoundBridge *)which;
+	LLFloaterReg::showInstance("preview_sound", LLSD(me->mUUID), TAKE_FOCUS_YES);
+}
+
+void LLSoundBridge::buildContextMenu(LLMenuGL& menu, U32 flags)
+{
+	lldebugs << "LLTextureBridge::buildContextMenu()" << llendl;
+	std::vector<std::string> items;
+	std::vector<std::string> disabled_items;
+
+	if(isInTrash())
+	{
+		items.push_back(std::string("Purge Item"));
+		if (!isItemRemovable())
+		{
+			disabled_items.push_back(std::string("Purge Item"));
+		}
+
+		items.push_back(std::string("Restore Item"));
+	}
+	else
+	{
+		items.push_back(std::string("Sound Open"));
+		items.push_back(std::string("Properties"));
+
+		getClipboardEntries(true, items, disabled_items, flags);
+	}
+
+	items.push_back(std::string("Sound Separator"));
+	items.push_back(std::string("Sound Play"));
+
+	hide_context_entries(menu, items, disabled_items);
+}
+
+// +=================================================+
+// |        LLLandmarkBridge                         |
+// +=================================================+
+
+LLLandmarkBridge::LLLandmarkBridge(LLInventoryPanel* inventory, const LLUUID& uuid, U32 flags/* = 0x00*/) :
+LLItemBridge(inventory, uuid) 
+{
+	mVisited = FALSE;
+	if (flags & LLInventoryItem::II_FLAGS_LANDMARK_VISITED)
+	{
+		mVisited = TRUE;
+	}
+}
+
+LLUIImagePtr LLLandmarkBridge::getIcon() const
+{
+	return get_item_icon(LLAssetType::AT_LANDMARK, LLInventoryType::IT_LANDMARK, mVisited, FALSE);
+}
+
+void LLLandmarkBridge::buildContextMenu(LLMenuGL& menu, U32 flags)
+{
+	std::vector<std::string> items;
+	std::vector<std::string> disabled_items;
+
+	lldebugs << "LLLandmarkBridge::buildContextMenu()" << llendl;
+	if(isInTrash())
+	{
+		items.push_back(std::string("Purge Item"));
+		if (!isItemRemovable())
+		{
+			disabled_items.push_back(std::string("Purge Item"));
+		}
+
+		items.push_back(std::string("Restore Item"));
+	}
+	else
+	{
+		items.push_back(std::string("Landmark Open"));
+		items.push_back(std::string("Properties"));
+
+		getClipboardEntries(true, items, disabled_items, flags);
+	}
+
+	items.push_back(std::string("Landmark Separator"));
+	items.push_back(std::string("About Landmark"));
+
+	// Disable "About Landmark" menu item for
+	// multiple landmarks selected. Only one landmark
+	// info panel can be shown at a time.
+	if ((flags & FIRST_SELECTED_ITEM) == 0)
+	{
+		disabled_items.push_back(std::string("About Landmark"));
+	}
+
+	hide_context_entries(menu, items, disabled_items);
+}
+
+// Convenience function for the two functions below.
+void teleport_via_landmark(const LLUUID& asset_id)
+{
+	gAgent.teleportViaLandmark( asset_id );
+
+	// we now automatically track the landmark you're teleporting to
+	// because you'll probably arrive at a telehub instead
+	LLFloaterWorldMap* floater_world_map = LLFloaterWorldMap::getInstance();
+	if( floater_world_map )
+	{
+		floater_world_map->trackLandmark( asset_id );
+	}
+}
+
+// virtual
+void LLLandmarkBridge::performAction(LLFolderView* folder, LLInventoryModel* model, std::string action)
+{
+	if ("teleport" == action)
+	{
+		LLViewerInventoryItem* item = getItem();
+		if(item)
+		{
+			teleport_via_landmark(item->getAssetUUID());
+		}
+	}
+	else if ("about" == action)
+	{
+		LLViewerInventoryItem* item = getItem();
+		if(item)
+		{
+			LLSD key;
+			key["type"] = "landmark";
+			key["id"] = item->getUUID();
+
+			LLSideTray::getInstance()->showPanel("panel_places", key);
+		}
+	}
+	else 
+	{
+		LLItemBridge::performAction(folder, model, action);
+	}
+}
+
+static bool open_landmark_callback(const LLSD& notification, const LLSD& response)
+{
+	S32 option = LLNotification::getSelectedOption(notification, response);
+
+	LLUUID asset_id = notification["payload"]["asset_id"].asUUID();
+	if (option == 0)
+	{
+		teleport_via_landmark(asset_id);
+	}
+
+	return false;
+}
+static LLNotificationFunctorRegistration open_landmark_callback_reg("TeleportFromLandmark", open_landmark_callback);
+
+
+void LLLandmarkBridge::openItem()
+{
+	LLViewerInventoryItem* item = getItem();
+	
+	if (item)
+	{
+		LLInvFVBridgeAction::doAction(item->getType(),mUUID,getInventoryModel());
+	}
+/*
+	LLViewerInventoryItem* item = getItem();
+	if( item )
+	{
+		// Opening (double-clicking) a landmark immediately teleports,
+		// but warns you the first time.
+		// open_landmark(item);
+		LLSD payload;
+		payload["asset_id"] = item->getAssetUUID();
+		LLNotifications::instance().add("TeleportFromLandmark", LLSD(), payload);
+	}
+*/
+}
+
+
+// +=================================================+
+// |        LLCallingCardObserver                    |
+// +=================================================+
+void LLCallingCardObserver::changed(U32 mask)
+{
+	mBridgep->refreshFolderViewItem();
+}
+
+// +=================================================+
+// |        LLCallingCardBridge                      |
+// +=================================================+
+
+LLCallingCardBridge::LLCallingCardBridge( LLInventoryPanel* inventory, const LLUUID& uuid ) :
+	LLItemBridge(inventory, uuid)
+{
+	mObserver = new LLCallingCardObserver(this);
+	LLAvatarTracker::instance().addObserver(mObserver);
+}
+
+LLCallingCardBridge::~LLCallingCardBridge()
+{
+	LLAvatarTracker::instance().removeObserver(mObserver);
+	delete mObserver;
+}
+
+void LLCallingCardBridge::refreshFolderViewItem()
+{
+	LLInventoryPanel* panel = dynamic_cast<LLInventoryPanel*>(mInventoryPanel.get());
+	LLFolderViewItem* itemp = panel ? panel->getRootFolder()->getItemByID(mUUID) : NULL;
+	if (itemp)
+	{
+		itemp->refresh();
+	}
+}
+
+// virtual
+void LLCallingCardBridge::performAction(LLFolderView* folder, LLInventoryModel* model, std::string action)
+{
+	if ("begin_im" == action)
+	{
+		LLViewerInventoryItem *item = getItem();
+		if (item && (item->getCreatorUUID() != gAgent.getID()) &&
+			(!item->getCreatorUUID().isNull()))
+		{
+			std::string callingcard_name;
+			gCacheName->getFullName(item->getCreatorUUID(), callingcard_name);
+			gIMMgr->addSession(callingcard_name, IM_NOTHING_SPECIAL, item->getCreatorUUID());
+		}
+	}
+	else if ("lure" == action)
+	{
+		LLViewerInventoryItem *item = getItem();
+		if (item && (item->getCreatorUUID() != gAgent.getID()) &&
+			(!item->getCreatorUUID().isNull()))
+		{
+			LLAvatarActions::offerTeleport(item->getCreatorUUID());
+		}
+	}
+	else LLItemBridge::performAction(folder, model, action);
+}
+
+LLUIImagePtr LLCallingCardBridge::getIcon() const
+{
+	BOOL online = FALSE;
+	LLViewerInventoryItem* item = getItem();
+	if(item)
+	{
+		online = LLAvatarTracker::instance().isBuddyOnline(item->getCreatorUUID());
+	}
+	return get_item_icon(LLAssetType::AT_CALLINGCARD, LLInventoryType::IT_CALLINGCARD, online, FALSE);
+}
+
+std::string LLCallingCardBridge::getLabelSuffix() const
+{
+	LLViewerInventoryItem* item = getItem();
+	if( item && LLAvatarTracker::instance().isBuddyOnline(item->getCreatorUUID()) )
+	{
+		return LLItemBridge::getLabelSuffix() + " (online)";
+	}
+	else
+	{
+		return LLItemBridge::getLabelSuffix();
+	}
+}
+
+void LLCallingCardBridge::openItem()
+{
+	LLViewerInventoryItem* item = getItem();
+	
+	if (item)
+	{
+		LLInvFVBridgeAction::doAction(item->getType(),mUUID,getInventoryModel());
+	}
+/*
+	LLViewerInventoryItem* item = getItem();
+	if(item && !item->getCreatorUUID().isNull())
+	{
+		LLAvatarActions::showProfile(item->getCreatorUUID());
+	}
+*/
+}
+
+void LLCallingCardBridge::buildContextMenu(LLMenuGL& menu, U32 flags)
+{
+	lldebugs << "LLCallingCardBridge::buildContextMenu()" << llendl;
+	std::vector<std::string> items;
+	std::vector<std::string> disabled_items;
+
+	if(isInTrash())
+	{
+		items.push_back(std::string("Purge Item"));
+		if (!isItemRemovable())
+		{
+			disabled_items.push_back(std::string("Purge Item"));
+		}
+
+		items.push_back(std::string("Restore Item"));
+	}
+	else
+	{
+		items.push_back(std::string("Open"));
+		items.push_back(std::string("Properties"));
+
+		getClipboardEntries(true, items, disabled_items, flags);
+
+		LLInventoryItem* item = getItem();
+		BOOL good_card = (item
+						  && (LLUUID::null != item->getCreatorUUID())
+						  && (item->getCreatorUUID() != gAgent.getID()));
+		BOOL user_online = (LLAvatarTracker::instance().isBuddyOnline(item->getCreatorUUID()));
+		items.push_back(std::string("Send Instant Message Separator"));
+		items.push_back(std::string("Send Instant Message"));
+		items.push_back(std::string("Offer Teleport..."));
+		items.push_back(std::string("Conference Chat"));
+
+		if (!good_card)
+		{
+			disabled_items.push_back(std::string("Send Instant Message"));
+		}
+		if (!good_card || !user_online)
+		{
+			disabled_items.push_back(std::string("Offer Teleport..."));
+			disabled_items.push_back(std::string("Conference Chat"));
+		}
+	}
+	hide_context_entries(menu, items, disabled_items);
+}
+
+BOOL LLCallingCardBridge::dragOrDrop(MASK mask, BOOL drop,
+									 EDragAndDropType cargo_type,
+									 void* cargo_data)
+{
+	LLViewerInventoryItem* item = getItem();
+	BOOL rv = FALSE;
+	if(item)
+	{
+		// check the type
+		switch(cargo_type)
+		{
+		case DAD_TEXTURE:
+		case DAD_SOUND:
+		case DAD_LANDMARK:
+		case DAD_SCRIPT:
+		case DAD_CLOTHING:
+		case DAD_OBJECT:
+		case DAD_NOTECARD:
+		case DAD_BODYPART:
+		case DAD_ANIMATION:
+		case DAD_GESTURE:
+			{
+				LLInventoryItem* inv_item = (LLInventoryItem*)cargo_data;
+				const LLPermissions& perm = inv_item->getPermissions();
+				if(gInventory.getItem(inv_item->getUUID())
+				   && perm.allowOperationBy(PERM_TRANSFER, gAgent.getID()))
+				{
+					rv = TRUE;
+					if(drop)
+					{
+						LLToolDragAndDrop::giveInventory(item->getCreatorUUID(),
+														 (LLInventoryItem*)cargo_data);
+					}
+				}
+				else
+				{
+					// It's not in the user's inventory (it's probably in
+					// an object's contents), so disallow dragging it here.
+					// You can't give something you don't yet have.
+					rv = FALSE;
+				}
+				break;
+			}
+		case DAD_CATEGORY:
+			{
+				LLInventoryCategory* inv_cat = (LLInventoryCategory*)cargo_data;
+				if( gInventory.getCategory( inv_cat->getUUID() ) )
+				{
+					rv = TRUE;
+					if(drop)
+					{
+						LLToolDragAndDrop::giveInventoryCategory(
+							item->getCreatorUUID(),
+							inv_cat);
+					}
+				}
+				else
+				{
+					// It's not in the user's inventory (it's probably in
+					// an object's contents), so disallow dragging it here.
+					// You can't give something you don't yet have.
+					rv = FALSE;
+				}
+				break;
+			}
+		default:
+			break;
+		}
+	}
+	return rv;
+}
+
+BOOL LLCallingCardBridge::removeItem()
+{
+	if (LLFriendCardsManager::instance().isItemInAnyFriendsList(getItem()))
+	{
+		LLAvatarActions::removeFriendDialog(getItem()->getCreatorUUID());
+		return FALSE;
+	}
+	else 
+	{
+		return LLItemBridge::removeItem();
+	}
+}
+// +=================================================+
+// |        LLNotecardBridge                         |
+// +=================================================+
+
+LLUIImagePtr LLNotecardBridge::getIcon() const
+{
+	return get_item_icon(LLAssetType::AT_NOTECARD, LLInventoryType::IT_NOTECARD, 0, FALSE);
+}
+
+void LLNotecardBridge::openItem()
+{
+	LLViewerInventoryItem* item = getItem();
+	
+	if (item)
+	{
+		LLInvFVBridgeAction::doAction(item->getType(),mUUID,getInventoryModel());
+	}
+
+/*
+	LLViewerInventoryItem* item = getItem();
+	if (item)
+	{
+		LLFloaterReg::showInstance("preview_notecard", LLSD(item->getUUID()), TAKE_FOCUS_YES);
+	}
+*/
+}
+
+
+// +=================================================+
+// |        LLGestureBridge                          |
+// +=================================================+
+
+LLUIImagePtr LLGestureBridge::getIcon() const
+{
+	return get_item_icon(LLAssetType::AT_GESTURE, LLInventoryType::IT_GESTURE, 0, FALSE);
+}
+
+LLFontGL::StyleFlags LLGestureBridge::getLabelStyle() const
+{
+	if( LLGestureManager::instance().isGestureActive(mUUID) )
+	{
+		return LLFontGL::BOLD;
+	}
+	else
+	{
+		return LLFontGL::NORMAL;
+	}
+}
+
+std::string LLGestureBridge::getLabelSuffix() const
+{
+	if( LLGestureManager::instance().isGestureActive(mUUID) )
+	{
+		return LLItemBridge::getLabelSuffix() + " (active)";
+	}
+	else
+	{
+		return LLItemBridge::getLabelSuffix();
+	}
+}
+
+// virtual
+void LLGestureBridge::performAction(LLFolderView* folder, LLInventoryModel* model, std::string action)
+{
+	if ("activate" == action)
+	{
+		LLGestureManager::instance().activateGesture(mUUID);
+
+		LLViewerInventoryItem* item = gInventory.getItem(mUUID);
+		if (!item) return;
+
+		// Since we just changed the suffix to indicate (active)
+		// the server doesn't need to know, just the viewer.
+		gInventory.updateItem(item);
+		gInventory.notifyObservers();
+	}
+	else if ("deactivate" == action)
+	{
+		LLGestureManager::instance().deactivateGesture(mUUID);
+
+		LLViewerInventoryItem* item = gInventory.getItem(mUUID);
+		if (!item) return;
+
+		// Since we just changed the suffix to indicate (active)
+		// the server doesn't need to know, just the viewer.
+		gInventory.updateItem(item);
+		gInventory.notifyObservers();
+	}
+	else LLItemBridge::performAction(folder, model, action);
+}
+
+void LLGestureBridge::openItem()
+{
+	LLViewerInventoryItem* item = getItem();
+	
+	if (item)
+	{
+		LLInvFVBridgeAction::doAction(item->getType(),mUUID,getInventoryModel());
+	}
+/*
+	LLViewerInventoryItem* item = getItem();
+	if (item)
+	{
+		LLPreviewGesture* preview = LLPreviewGesture::show(mUUID, LLUUID::null);
+		preview->setFocus(TRUE);
+	}
+*/
+}
+
+BOOL LLGestureBridge::removeItem()
+{
+	// Force close the preview window, if it exists
+	LLGestureManager::instance().deactivateGesture(mUUID);
+	return LLItemBridge::removeItem();
+}
+
+void LLGestureBridge::buildContextMenu(LLMenuGL& menu, U32 flags)
+{
+	lldebugs << "LLGestureBridge::buildContextMenu()" << llendl;
+	std::vector<std::string> items;
+	std::vector<std::string> disabled_items;
+	if(isInTrash())
+	{
+		items.push_back(std::string("Purge Item"));
+		if (!isItemRemovable())
+		{
+			disabled_items.push_back(std::string("Purge Item"));
+		}
+
+		items.push_back(std::string("Restore Item"));
+	}
+	else
+	{
+		items.push_back(std::string("Open"));
+		items.push_back(std::string("Properties"));
+
+		getClipboardEntries(true, items, disabled_items, flags);
+
+		items.push_back(std::string("Gesture Separator"));
+		items.push_back(std::string("Activate"));
+		items.push_back(std::string("Deactivate"));
+	}
+	hide_context_entries(menu, items, disabled_items);
+}
+
+// +=================================================+
+// |        LLAnimationBridge                        |
+// +=================================================+
+
+LLUIImagePtr LLAnimationBridge::getIcon() const
+{
+	return get_item_icon(LLAssetType::AT_ANIMATION, LLInventoryType::IT_ANIMATION, 0, FALSE);
+}
+
+void LLAnimationBridge::buildContextMenu(LLMenuGL& menu, U32 flags)
+{
+	std::vector<std::string> items;
+	std::vector<std::string> disabled_items;
+
+	lldebugs << "LLAnimationBridge::buildContextMenu()" << llendl;
+	if(isInTrash())
+	{
+		items.push_back(std::string("Purge Item"));
+		if (!isItemRemovable())
+		{
+			disabled_items.push_back(std::string("Purge Item"));
+		}
+
+		items.push_back(std::string("Restore Item"));
+	}
+	else
+	{
+		items.push_back(std::string("Animation Open"));
+		items.push_back(std::string("Properties"));
+
+		getClipboardEntries(true, items, disabled_items, flags);
+	}
+
+	items.push_back(std::string("Animation Separator"));
+	items.push_back(std::string("Animation Play"));
+	items.push_back(std::string("Animation Audition"));
+
+	hide_context_entries(menu, items, disabled_items);
+
+}
+
+// virtual
+void LLAnimationBridge::performAction(LLFolderView* folder, LLInventoryModel* model, std::string action)
+{
+	if ((action == "playworld") || (action == "playlocal"))
+	{
+		if (getItem())
+		{
+			LLPreviewAnim::e_activation_type activate = LLPreviewAnim::NONE;
+			if ("playworld" == action) activate = LLPreviewAnim::PLAY;
+			if ("playlocal" == action) activate = LLPreviewAnim::AUDITION;
+			
+			LLPreviewAnim* preview = LLFloaterReg::showTypedInstance<LLPreviewAnim>("preview_anim", LLSD(mUUID));
+			if (preview)
+			{
+				preview->activate(activate);
+			}
+		}
+	}
+	else
+	{
+		LLItemBridge::performAction(folder, model, action);
+	}
+}
+
+void LLAnimationBridge::openItem()
+{
+	LLViewerInventoryItem* item = getItem();
+	
+	if (item)
+	{
+		LLInvFVBridgeAction::doAction(item->getType(),mUUID,getInventoryModel());
+	}
+/*
+	LLViewerInventoryItem* item = getItem();
+	if (item)
+	{
+		LLFloaterReg::showInstance("preview_anim", LLSD(mUUID), TAKE_FOCUS_YES);
+	}
+*/
+}
+
+// +=================================================+
+// |        LLObjectBridge                           |
+// +=================================================+
+
+// static
+LLUUID LLObjectBridge::sContextMenuItemID;
+
+LLObjectBridge::LLObjectBridge(LLInventoryPanel* inventory, const LLUUID& uuid, LLInventoryType::EType type, U32 flags) :
+LLItemBridge(inventory, uuid), mInvType(type)
+{
+	mAttachPt = (flags & 0xff); // low bye of inventory flags
+
+	mIsMultiObject = ( flags & LLInventoryItem::II_FLAGS_OBJECT_HAS_MULTIPLE_ITEMS ) ?  TRUE: FALSE;
+}
+
+BOOL LLObjectBridge::isItemRemovable()
+{
+	LLVOAvatarSelf* avatar = gAgent.getAvatarObject();
+	if(!avatar) return FALSE;
+	if(avatar->isWearingAttachment(mUUID)) return FALSE;
+	return LLInvFVBridge::isItemRemovable();
+}
+
+LLUIImagePtr LLObjectBridge::getIcon() const
+{
+	return get_item_icon(LLAssetType::AT_OBJECT, mInvType, mAttachPt, mIsMultiObject );
+}
+
+LLInventoryObject* LLObjectBridge::getObject() const
+{
+	LLInventoryObject* object = NULL;
+	LLInventoryModel* model = getInventoryModel();
+	if(model)
+	{
+		object = (LLInventoryObject*)model->getObject(mUUID);
+	}
+	return object;
+}
+
+// virtual
+void LLObjectBridge::performAction(LLFolderView* folder, LLInventoryModel* model, std::string action)
+{
+	if ("attach" == action)
+	{
+		LLUUID object_id = mUUID;
+		LLViewerInventoryItem* item;
+		item = (LLViewerInventoryItem*)gInventory.getItem(object_id);
+		if(item && gInventory.isObjectDescendentOf(object_id, gInventory.getRootFolderID()))
+		{
+			rez_attachment(item, NULL);
+		}
+		else if(item && item->isComplete())
+		{
+			// must be in library. copy it to our inventory and put it on.
+			LLPointer<LLInventoryCallback> cb = new RezAttachmentCallback(0);
+			copy_inventory_item(
+				gAgent.getID(),
+				item->getPermissions().getOwner(),
+				item->getUUID(),
+				LLUUID::null,
+				std::string(),
+				cb);
+		}
+		gFocusMgr.setKeyboardFocus(NULL);
+	}
+	else if ("detach" == action)
+	{
+		LLInventoryItem* item = gInventory.getItem(mUUID);
+		if(item)
+		{
+			gMessageSystem->newMessageFast(_PREHASH_DetachAttachmentIntoInv);
+			gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
+			gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+			gMessageSystem->addUUIDFast(_PREHASH_ItemID, item->getLinkedUUID());
+			gMessageSystem->sendReliable( gAgent.getRegion()->getHost());
+		}
+		// this object might have been selected, so let the selection manager know it's gone now
+		LLViewerObject *found_obj =
+			gObjectList.findObject(item->getUUID());
+		if (found_obj)
+		{
+			LLSelectMgr::getInstance()->remove(found_obj);
+		}
+		else
+		{
+			llwarns << "object not found - ignoring" << llendl;
+		}
+	}
+	else LLItemBridge::performAction(folder, model, action);
+}
+
+void LLObjectBridge::openItem()
+{
+	LLViewerInventoryItem* item = getItem();
+	
+	if (item)
+	{
+		LLInvFVBridgeAction::doAction(item->getType(),mUUID,getInventoryModel());
+	}
+
+	LLSD key;
+	key["id"] = mUUID;
+	LLSideTray::getInstance()->showPanel("sidepanel_inventory", key);
+
+	/*
+	LLFloaterReg::showInstance("properties", mUUID);
+	*/
+}
+
+LLFontGL::StyleFlags LLObjectBridge::getLabelStyle() const
+{ 
+	U8 font = LLFontGL::NORMAL;
+
+	LLVOAvatarSelf* avatar = gAgent.getAvatarObject();
+	if( avatar && avatar->isWearingAttachment( mUUID ) )
+	{
+		font |= LLFontGL::BOLD;
+	}
+
+	LLInventoryItem* item = getItem();
+	if (item && item->getIsLinkType())
+	{
+		font |= LLFontGL::ITALIC;
+	}
+	
+	return (LLFontGL::StyleFlags)font;
+}
+
+std::string LLObjectBridge::getLabelSuffix() const
+{
+	LLVOAvatarSelf* avatar = gAgent.getAvatarObject();
+	if( avatar && avatar->isWearingAttachment( mUUID ) )
+	{
+		std::string attachment_point_name = avatar->getAttachedPointName(mUUID);
+		LLStringUtil::toLower(attachment_point_name);
+		
+		LLStringUtil::format_map_t args;
+		args["[ATTACHMENT_POINT]"] =  attachment_point_name.c_str();
+		return LLItemBridge::getLabelSuffix() + LLTrans::getString("WornOnAttachmentPoint", args);
+	}
+	else
+	{
+		return LLItemBridge::getLabelSuffix();
+	}
+}
+
+void rez_attachment(LLViewerInventoryItem* item, LLViewerJointAttachment* attachment)
+{
+	LLSD payload;
+	payload["item_id"] = item->getLinkedUUID(); // Wear the base object in case this is a link.
+
+	S32 attach_pt = 0;
+	if (gAgent.getAvatarObject() && attachment)
+	{
+		for (LLVOAvatar::attachment_map_t::iterator iter = gAgent.getAvatarObject()->mAttachmentPoints.begin();
+			 iter != gAgent.getAvatarObject()->mAttachmentPoints.end(); ++iter)
+		{
+			if (iter->second == attachment)
+			{
+				attach_pt = iter->first;
+				break;
+			}
+		}
+	}
+
+	payload["attachment_point"] = attach_pt;
+
+#if !ENABLE_MULTIATTACHMENTS
+	if (attachment && attachment->getNumObjects() > 0)
+	{
+		LLNotifications::instance().add("ReplaceAttachment", LLSD(), payload, confirm_replace_attachment_rez);
+	}
+	else
+#endif
+	{
+		LLNotifications::instance().forceResponse(LLNotification::Params("ReplaceAttachment").payload(payload), 0/*YES*/);
+	}
+}
+
+bool confirm_replace_attachment_rez(const LLSD& notification, const LLSD& response)
+{
+	LLVOAvatar *avatarp = gAgent.getAvatarObject();
+		
+	if (!avatarp->canAttachMoreObjects())
+	{
+		LLSD args;
+		args["MAX_ATTACHMENTS"] = llformat("%d", MAX_AGENT_ATTACHMENTS);
+		LLNotifications::instance().add("MaxAttachmentsOnOutfit", args);
+		return false;
+	}
+
+	S32 option = LLNotification::getSelectedOption(notification, response);
+	if (option == 0/*YES*/)
+	{
+		LLViewerInventoryItem* itemp = gInventory.getItem(notification["payload"]["item_id"].asUUID());
+		
+		if (itemp)
+		{
+			LLMessageSystem* msg = gMessageSystem;
+			msg->newMessageFast(_PREHASH_RezSingleAttachmentFromInv);
+			msg->nextBlockFast(_PREHASH_AgentData);
+			msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+			msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+			msg->nextBlockFast(_PREHASH_ObjectData);
+			msg->addUUIDFast(_PREHASH_ItemID, itemp->getUUID());
+			msg->addUUIDFast(_PREHASH_OwnerID, itemp->getPermissions().getOwner());
+			U8 attachment_pt = notification["payload"]["attachment_point"].asInteger();
+#if ENABLE_MULTIATTACHMENTS
+			attachment_pt |= ATTACHMENT_ADD;
+#endif
+			msg->addU8Fast(_PREHASH_AttachmentPt, attachment_pt);
+			pack_permissions_slam(msg, itemp->getFlags(), itemp->getPermissions());
+			msg->addStringFast(_PREHASH_Name, itemp->getName());
+			msg->addStringFast(_PREHASH_Description, itemp->getDescription());
+			msg->sendReliable(gAgent.getRegion()->getHost());
+		}
+	}
+	return false;
+}
+static LLNotificationFunctorRegistration confirm_replace_attachment_rez_reg("ReplaceAttachment", confirm_replace_attachment_rez);
+
+void LLObjectBridge::buildContextMenu(LLMenuGL& menu, U32 flags)
+{
+	std::vector<std::string> items;
+	std::vector<std::string> disabled_items;
+	if(isInTrash())
+	{
+		items.push_back(std::string("Purge Item"));
+		if (!isItemRemovable())
+		{
+			disabled_items.push_back(std::string("Purge Item"));
+		}
+
+		items.push_back(std::string("Restore Item"));
+	}
+	else
+	{
+		LLInventoryItem* item = getItem();
+		if (item && item->getIsLinkType())
+		{
+			items.push_back(std::string("Goto Link"));
+		}
+
+		items.push_back(std::string("Properties"));
+
+		getClipboardEntries(true, items, disabled_items, flags);
+
+		LLObjectBridge::sContextMenuItemID = mUUID;
+
+		if(item)
+		{
+			LLVOAvatarSelf* avatarp = gAgent.getAvatarObject();
+			if( !avatarp )
+			{
+				return;
+			}
+			
+			if( avatarp->isWearingAttachment( mUUID ) )
+			{
+				items.push_back(std::string("Detach From Yourself"));
+			}
+			else
+			if( !isInTrash() && !isLinkedObjectInTrash() )
+			{
+				items.push_back(std::string("Attach Separator"));
+				items.push_back(std::string("Object Wear"));
+				items.push_back(std::string("Attach To"));
+				items.push_back(std::string("Attach To HUD"));
+				// commented out for DEV-32347
+				//items.push_back(std::string("Restore to Last Position"));
+
+				if (!avatarp->canAttachMoreObjects())
+				{
+					disabled_items.push_back(std::string("Object Wear"));
+					disabled_items.push_back(std::string("Attach To"));
+					disabled_items.push_back(std::string("Attach To HUD"));
+				}
+				LLMenuGL* attach_menu = menu.findChildMenuByName("Attach To", TRUE);
+				LLMenuGL* attach_hud_menu = menu.findChildMenuByName("Attach To HUD", TRUE);
+				LLVOAvatar *avatarp = gAgent.getAvatarObject();
+				if (attach_menu 
+					&& (attach_menu->getChildCount() == 0) 
+					&& attach_hud_menu 
+					&& (attach_hud_menu->getChildCount() == 0) 
+					&& avatarp)
+				{
+					for (LLVOAvatar::attachment_map_t::iterator iter = avatarp->mAttachmentPoints.begin(); 
+						 iter != avatarp->mAttachmentPoints.end(); )
+					{
+						LLVOAvatar::attachment_map_t::iterator curiter = iter++;
+						LLViewerJointAttachment* attachment = curiter->second;
+						LLMenuItemCallGL::Params p;
+						std::string submenu_name = attachment->getName();
+						if (LLTrans::getString(submenu_name) != "")
+						{
+						    p.name = (" ")+LLTrans::getString(submenu_name)+" ";
+						}
+						else
+						{
+							p.name = submenu_name;
+						}
+						LLSD cbparams;
+						cbparams["index"] = curiter->first;
+						cbparams["label"] = attachment->getName();
+						p.on_click.function_name = "Inventory.AttachObject";
+						p.on_click.parameter = LLSD(attachment->getName());
+						p.on_enable.function_name = "Attachment.Label";
+						p.on_enable.parameter = cbparams;
+						LLView* parent = attachment->getIsHUDAttachment() ? attach_hud_menu : attach_menu;
+						LLUICtrlFactory::create<LLMenuItemCallGL>(p, parent);
+					}
+				}
+			}
+		}
+	}
+	hide_context_entries(menu, items, disabled_items);
+}
+
+BOOL LLObjectBridge::renameItem(const std::string& new_name)
+{
+	if(!isItemRenameable())
+		return FALSE;
+	LLPreview::dirty(mUUID);
+	LLInventoryModel* model = getInventoryModel();
+	if(!model)
+		return FALSE;
+	LLViewerInventoryItem* item = getItem();
+	if(item && (item->getName() != new_name))
+	{
+		LLPointer<LLViewerInventoryItem> new_item = new LLViewerInventoryItem(item);
+		new_item->rename(new_name);
+		buildDisplayName(new_item, mDisplayName);
+		new_item->updateServer(FALSE);
+		model->updateItem(new_item);
+
+		model->notifyObservers();
+
+		LLVOAvatarSelf* avatar = gAgent.getAvatarObject();
+		if( avatar )
+		{
+			LLViewerObject* obj = avatar->getWornAttachment( item->getUUID() );
+			if( obj )
+			{
+				LLSelectMgr::getInstance()->deselectAll();
+				LLSelectMgr::getInstance()->addAsIndividual( obj, SELECT_ALL_TES, FALSE );
+				LLSelectMgr::getInstance()->selectionSetObjectName( new_name );
+				LLSelectMgr::getInstance()->deselectAll();
+			}
+		}
+	}
+	// return FALSE because we either notified observers (& therefore
+	// rebuilt) or we didn't update.
+	return FALSE;
+}
+
+// +=================================================+
+// |        LLLSLTextBridge                          |
+// +=================================================+
+
+LLUIImagePtr LLLSLTextBridge::getIcon() const
+{
+	return get_item_icon(LLAssetType::AT_SCRIPT, LLInventoryType::IT_LSL, 0, FALSE);
+}
+
+void LLLSLTextBridge::openItem()
+{
+	LLViewerInventoryItem* item = getItem();
+	
+	if (item)
+	{
+		LLInvFVBridgeAction::doAction(item->getType(),mUUID,getInventoryModel());
+	}
+	/*
+	LLViewerInventoryItem* item = getItem();
+	if (item)
+	{
+		LLFloaterReg::showInstance("preview_script", LLSD(mUUID), TAKE_FOCUS_YES);
+	}
+	*/
+}
+
+// +=================================================+
+// |        LLWearableBridge                         |
+// +=================================================+
+
+// *NOTE: hack to get from avatar inventory to avatar
+void wear_inventory_item_on_avatar( LLInventoryItem* item )
+{
+	if(item)
+	{
+		lldebugs << "wear_inventory_item_on_avatar( " << item->getName()
+				 << " )" << llendl;
+
+		LLAppearanceManager::wearItem(item);
+	}
+}
+
+void wear_add_inventory_item_on_avatar( LLInventoryItem* item )
+{
+	if(item)
+	{
+		lldebugs << "wear_add_inventory_item_on_avatar( " << item->getName()
+				 << " )" << llendl;
+			
+		LLWearableList::instance().getAsset(item->getAssetUUID(),
+							   item->getName(),
+							   item->getType(),
+							   LLWearableBridge::onWearAddOnAvatarArrived,
+							   new LLUUID(item->getUUID()));
+	}
+}
+
+void remove_inventory_category_from_avatar( LLInventoryCategory* category )
+{
+	if(!category) return;
+	lldebugs << "remove_inventory_category_from_avatar( " << category->getName()
+			 << " )" << llendl;
+			 
+	
+	if( gFloaterCustomize )
+	{
+		gFloaterCustomize->askToSaveIfDirty(
+			boost::bind(remove_inventory_category_from_avatar_step2, _1, category->getUUID()));
+	}
+	else
+	{
+		remove_inventory_category_from_avatar_step2(TRUE, category->getUUID() );
+	}
+}
+
+struct OnRemoveStruct
+{
+	LLUUID mUUID;
+	OnRemoveStruct(const LLUUID& uuid):
+		mUUID(uuid)
+	{
+	}
+};
+
+void remove_inventory_category_from_avatar_step2( BOOL proceed, LLUUID category_id)
+{
+
+	// Find all the wearables that are in the category's subtree.
+	lldebugs << "remove_inventory_category_from_avatar_step2()" << llendl;
+	if(proceed)
+	{
+		LLInventoryModel::cat_array_t cat_array;
+		LLInventoryModel::item_array_t item_array;
+		LLFindWearables is_wearable;
+		gInventory.collectDescendentsIf(category_id,
+										cat_array,
+										item_array,
+										LLInventoryModel::EXCLUDE_TRASH,
+										is_wearable);
+		S32 i;
+		S32 wearable_count = item_array.count();
+
+		LLInventoryModel::cat_array_t	obj_cat_array;
+		LLInventoryModel::item_array_t	obj_item_array;
+		LLIsType is_object( LLAssetType::AT_OBJECT );
+		gInventory.collectDescendentsIf(category_id,
+										obj_cat_array,
+										obj_item_array,
+										LLInventoryModel::EXCLUDE_TRASH,
+										is_object);
+		S32 obj_count = obj_item_array.count();
+
+		// Find all gestures in this folder
+		LLInventoryModel::cat_array_t	gest_cat_array;
+		LLInventoryModel::item_array_t	gest_item_array;
+		LLIsType is_gesture( LLAssetType::AT_GESTURE );
+		gInventory.collectDescendentsIf(category_id,
+										gest_cat_array,
+										gest_item_array,
+										LLInventoryModel::EXCLUDE_TRASH,
+										is_gesture);
+		S32 gest_count = gest_item_array.count();
+
+		if (wearable_count > 0)	//Loop through wearables.  If worn, remove.
+		{
+			for(i = 0; i  < wearable_count; ++i)
+			{
+				if( gAgentWearables.isWearingItem (item_array.get(i)->getUUID()) )
+				{
+					LLWearableList::instance().getAsset(item_array.get(i)->getAssetUUID(),
+														item_array.get(i)->getName(),
+														item_array.get(i)->getType(),
+														LLWearableBridge::onRemoveFromAvatarArrived,
+														new OnRemoveStruct(item_array.get(i)->getUUID()));
+
+				}
+			}
+		}
+		
+		
+		if (obj_count > 0)
+		{
+			for(i = 0; i  < obj_count; ++i)
+			{
+				gMessageSystem->newMessageFast(_PREHASH_DetachAttachmentIntoInv);
+				gMessageSystem->nextBlockFast(_PREHASH_ObjectData );
+				gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
+				gMessageSystem->addUUIDFast(_PREHASH_ItemID, obj_item_array.get(i)->getUUID() );
+
+				gMessageSystem->sendReliable( gAgent.getRegion()->getHost() );
+
+				// this object might have been selected, so let the selection manager know it's gone now
+				LLViewerObject *found_obj = gObjectList.findObject( obj_item_array.get(i)->getUUID());
+				if (found_obj)
+				{
+					LLSelectMgr::getInstance()->remove(found_obj);
+				}
+				else
+				{
+					llwarns << "object not found, ignoring" << llendl;
+				}
+			}
+		}
+
+		if (gest_count > 0)
+		{
+			for(i = 0; i  < gest_count; ++i)
+			{
+				if ( LLGestureManager::instance().isGestureActive( gest_item_array.get(i)->getUUID()) )
+				{
+					LLGestureManager::instance().deactivateGesture( gest_item_array.get(i)->getUUID() );
+					gInventory.updateItem( gest_item_array.get(i) );
+					gInventory.notifyObservers();
+				}
+
+			}
+		}
+	}
+}
+
+BOOL LLWearableBridge::renameItem(const std::string& new_name)
+{
+	if( gAgentWearables.isWearingItem( mUUID ) )
+	{
+		gAgentWearables.setWearableName( mUUID, new_name );
+	}
+	return LLItemBridge::renameItem(new_name);
+}
+
+BOOL LLWearableBridge::isItemRemovable()
+{
+	if (gAgentWearables.isWearingItem(mUUID)) return FALSE;
+	return LLInvFVBridge::isItemRemovable();
+}
+
+std::string LLWearableBridge::getLabelSuffix() const
+{
+	if( gAgentWearables.isWearingItem( mUUID ) )
+	{
+		return LLItemBridge::getLabelSuffix() + LLTrans::getString("worn");
+	}
+	else
+	{
+		return LLItemBridge::getLabelSuffix();
+	}
+}
+
+LLUIImagePtr LLWearableBridge::getIcon() const
+{
+	return get_item_icon(mAssetType, mInvType, mWearableType, FALSE);
+}
+
+// virtual
+void LLWearableBridge::performAction(LLFolderView* folder, LLInventoryModel* model, std::string action)
+{
+	if ("wear" == action)
+	{
+		wearOnAvatar();
+	}
+	else if ("wear_add" == action)
+	{
+		wearAddOnAvatar();
+	}
+	else if ("edit" == action)
+	{
+		editOnAvatar();
+		return;
+	}
+	else if ("take_off" == action)
+	{
+		if(gAgentWearables.isWearingItem(mUUID))
+		{
+			LLViewerInventoryItem* item = getItem();
+			if (item)
+			{	
+				LLWearableList::instance().getAsset(item->getAssetUUID(),
+													item->getName(),
+													item->getType(),
+													LLWearableBridge::onRemoveFromAvatarArrived,
+													new OnRemoveStruct(mUUID));
+			}
+		}
+	}
+	else LLItemBridge::performAction(folder, model, action);
+}
+
+void LLWearableBridge::openItem()
+{
+	LLViewerInventoryItem* item = getItem();
+	
+	if (item)
+	{
+		LLInvFVBridgeAction::doAction(item->getType(),mUUID,getInventoryModel());
+	}
+	/*
+	if( isInTrash() )
+	{
+		LLNotifications::instance().add("CannotWearTrash");
+	}
+	else if(isAgentInventory())
+	{
+		if( !gAgentWearables.isWearingItem( mUUID ) )
+		{
+			wearOnAvatar();
+		}
+	}
+	else
+	{
+		// must be in the inventory library. copy it to our inventory
+		// and put it on right away.
+		LLViewerInventoryItem* item = getItem();
+		if(item && item->isComplete())
+		{
+			LLPointer<LLInventoryCallback> cb = new WearOnAvatarCallback();
+			copy_inventory_item(
+				gAgent.getID(),
+				item->getPermissions().getOwner(),
+				item->getUUID(),
+				LLUUID::null,
+				std::string(),
+				cb);
+		}
+		else if(item)
+		{
+			// *TODO: We should fetch the item details, and then do
+			// the operation above.
+			LLNotifications::instance().add("CannotWearInfoNotComplete");
+		}
+	}
+	*/
+}
+
+void LLWearableBridge::buildContextMenu(LLMenuGL& menu, U32 flags)
+{
+	lldebugs << "LLWearableBridge::buildContextMenu()" << llendl;
+	std::vector<std::string> items;
+	std::vector<std::string> disabled_items;
+	if(isInTrash())
+	{
+		items.push_back(std::string("Purge Item"));
+		if (!isItemRemovable())
+		{
+			disabled_items.push_back(std::string("Purge Item"));
+		}
+
+		items.push_back(std::string("Restore Item"));
+	}
+	else
+	{	// FWIW, it looks like SUPPRESS_OPEN_ITEM is not set anywhere
+		BOOL no_open = ((flags & SUPPRESS_OPEN_ITEM) == SUPPRESS_OPEN_ITEM);
+
+		// If we have clothing, don't add "Open" as it's the same action as "Wear"   SL-18976
+		LLViewerInventoryItem* item = getItem();
+		if( !no_open && item )
+		{
+			no_open = (item->getType() == LLAssetType::AT_CLOTHING) ||
+					  (item->getType() == LLAssetType::AT_BODYPART);
+		}
+		if (!no_open)
+		{
+			items.push_back(std::string("Open"));
+		}
+
+		if (item && item->getIsLinkType())
+		{
+			items.push_back(std::string("Goto Link"));
+		}
+
+		items.push_back(std::string("Properties"));
+
+		getClipboardEntries(true, items, disabled_items, flags);
+
+		items.push_back(std::string("Wearable Separator"));
+		
+		items.push_back(std::string("Wearable Wear"));
+		items.push_back(std::string("Wearable Add"));
+		items.push_back(std::string("Wearable Edit"));
+
+		if ((flags & FIRST_SELECTED_ITEM) == 0)
+		{
+			disabled_items.push_back(std::string("Wearable Edit"));
+		}
+		// Don't allow items to be worn if their baseobj is in the trash.
+		if (isLinkedObjectInTrash())
+		{
+			disabled_items.push_back(std::string("Wearable Wear"));
+			disabled_items.push_back(std::string("Wearable Add"));
+			disabled_items.push_back(std::string("Wearable Edit"));
+		}
+
+		// Disable wear and take off based on whether the item is worn.
+		if(item)
+		{
+			switch (item->getType())
+			{
+				case LLAssetType::AT_CLOTHING:
+					items.push_back(std::string("Take Off"));
+				case LLAssetType::AT_BODYPART:
+					if (gAgentWearables.isWearingItem(item->getUUID()))
+					{
+						disabled_items.push_back(std::string("Wearable Wear"));
+						disabled_items.push_back(std::string("Wearable Add"));
+					}
+					else
+					{	
+						disabled_items.push_back(std::string("Take Off"));
+					}
+					break;
+				default:
+					break;
+			}
+		}
+	}
+	hide_context_entries(menu, items, disabled_items);
+}
+
+// Called from menus
+// static
+BOOL LLWearableBridge::canWearOnAvatar(void* user_data)
+{
+	LLWearableBridge* self = (LLWearableBridge*)user_data;
+	if(!self) return FALSE;
+	if(!self->isAgentInventory())
+	{
+		LLViewerInventoryItem* item = (LLViewerInventoryItem*)self->getItem();
+		if(!item || !item->isComplete()) return FALSE;
+	}
+	return (!gAgentWearables.isWearingItem(self->mUUID));
+}
+
+// Called from menus
+// static
+void LLWearableBridge::onWearOnAvatar(void* user_data)
+{
+	LLWearableBridge* self = (LLWearableBridge*)user_data;
+	if(!self) return;
+	self->wearOnAvatar();
+}
+
+void LLWearableBridge::wearOnAvatar()
+{
+	// Don't wear anything until initial wearables are loaded, can
+	// destroy clothing items.
+	if (!gAgentWearables.areWearablesLoaded()) 
+	{
+		LLNotifications::instance().add("CanNotChangeAppearanceUntilLoaded");
+		return;
+	}
+
+	LLViewerInventoryItem* item = getItem();
+	if(item)
+	{
+		if(!isAgentInventory())
+		{
+			LLPointer<LLInventoryCallback> cb = new WearOnAvatarCallback();
+			copy_inventory_item(
+				gAgent.getID(),
+				item->getPermissions().getOwner(),
+				item->getUUID(),
+				LLUUID::null,
+				std::string(),
+				cb);
+		}
+		else
+		{
+			wear_inventory_item_on_avatar(item);
+		}
+	}
+}
+
+void LLWearableBridge::wearAddOnAvatar()
+{
+	// Don't wear anything until initial wearables are loaded, can
+	// destroy clothing items.
+	if (!gAgentWearables.areWearablesLoaded()) 
+	{
+		LLNotifications::instance().add("CanNotChangeAppearanceUntilLoaded");
+		return;
+	}
+
+	LLViewerInventoryItem* item = getItem();
+	if(item)
+	{
+		if(!isAgentInventory())
+		{
+			LLPointer<LLInventoryCallback> cb = new WearOnAvatarCallback();
+			copy_inventory_item(
+				gAgent.getID(),
+				item->getPermissions().getOwner(),
+				item->getUUID(),
+				LLUUID::null,
+				std::string(),
+				cb);
+		}
+		else
+		{
+			wear_add_inventory_item_on_avatar(item);
+		}
+	}
+}
+
+// static
+void LLWearableBridge::onWearOnAvatarArrived( LLWearable* wearable, void* userdata )
+{
+	LLUUID* item_id = (LLUUID*) userdata;
+	if(wearable)
+	{
+		LLViewerInventoryItem* item = NULL;
+		item = (LLViewerInventoryItem*)gInventory.getItem(*item_id);
+		if(item)
+		{
+			if(item->getAssetUUID() == wearable->getAssetID())
+			{
+				gAgentWearables.setWearableItem(item, wearable);
+				gInventory.notifyObservers();
+				//self->getFolderItem()->refreshFromRoot();
+			}
+			else
+			{
+				llinfos << "By the time wearable asset arrived, its inv item already pointed to a different asset." << llendl;
+			}
+		}
+	}
+	delete item_id;
+}
+
+// static
+// BAP remove the "add" code path once everything is fully COF-ified.
+void LLWearableBridge::onWearAddOnAvatarArrived( LLWearable* wearable, void* userdata )
+{
+	LLUUID* item_id = (LLUUID*) userdata;
+	if(wearable)
+	{
+		LLViewerInventoryItem* item = NULL;
+		item = (LLViewerInventoryItem*)gInventory.getItem(*item_id);
+		if(item)
+		{
+			if(item->getAssetUUID() == wearable->getAssetID())
+			{
+				bool do_append = true;
+				gAgentWearables.setWearableItem(item, wearable, do_append);
+				gInventory.notifyObservers();
+				//self->getFolderItem()->refreshFromRoot();
+			}
+			else
+			{
+				llinfos << "By the time wearable asset arrived, its inv item already pointed to a different asset." << llendl;
+			}
+		}
+	}
+	delete item_id;
+}
+
+// static
+BOOL LLWearableBridge::canEditOnAvatar(void* user_data)
+{
+	LLWearableBridge* self = (LLWearableBridge*)user_data;
+	if(!self) return FALSE;
+
+	return (gAgentWearables.isWearingItem(self->mUUID));
+}
+
+// static 
+void LLWearableBridge::onEditOnAvatar(void* user_data)
+{
+	LLWearableBridge* self = (LLWearableBridge*)user_data;
+	if(self)
+	{
+		self->editOnAvatar();
+	}
+}
+
+void LLWearableBridge::editOnAvatar()
+{
+	const LLWearable* wearable = gAgentWearables.getWearableFromItemID(mUUID);
+	if( wearable )
+	{
+		// Set the tab to the right wearable.
+		if (gFloaterCustomize)
+			gFloaterCustomize->setCurrentWearableType( wearable->getType() );
+
+		if( CAMERA_MODE_CUSTOMIZE_AVATAR != gAgent.getCameraMode() )
+		{
+			// Start Avatar Customization
+			gAgent.changeCameraToCustomizeAvatar();
+		}
+	}
+}
+
+// static
+BOOL LLWearableBridge::canRemoveFromAvatar(void* user_data)
+{
+	LLWearableBridge* self = (LLWearableBridge*)user_data;
+	if( self && (LLAssetType::AT_BODYPART != self->mAssetType) )
+	{
+		return gAgentWearables.isWearingItem( self->mUUID );
+	}
+	return FALSE;
+}
+
+// static 
+void LLWearableBridge::onRemoveFromAvatar(void* user_data)
+{
+	LLWearableBridge* self = (LLWearableBridge*)user_data;
+	if(!self) return;
+	if(gAgentWearables.isWearingItem(self->mUUID))
+	{
+		LLViewerInventoryItem* item = self->getItem();
+		if (item)
+		{
+			LLUUID parent_id = item->getParentUUID();
+			LLWearableList::instance().getAsset(item->getAssetUUID(),
+												item->getName(),
+												item->getType(),
+												onRemoveFromAvatarArrived,
+												new OnRemoveStruct(LLUUID(self->mUUID)));
+		}
+	}
+}
+
+// static
+void LLWearableBridge::onRemoveFromAvatarArrived(LLWearable* wearable,
+												 void* userdata)
+{
+	OnRemoveStruct *on_remove_struct = (OnRemoveStruct*) userdata;
+	const LLUUID &item_id = gInventory.getLinkedItemID(on_remove_struct->mUUID);
+	if(wearable)
+	{
+		if( gAgentWearables.isWearingItem( item_id ) )
+		{
+			EWearableType type = wearable->getType();
+	
+			if( !(type==WT_SHAPE || type==WT_SKIN || type==WT_HAIR || type==WT_EYES ) ) //&&
+				//!((!gAgent.isTeen()) && ( type==WT_UNDERPANTS || type==WT_UNDERSHIRT )) )
+			{
+				// MULTI_WEARABLE: FIXME HACK - always remove all
+				bool do_remove_all = false;
+				gAgentWearables.removeWearable( type, do_remove_all, 0 );
+			}
+		}
+	}
+
+	// Find and remove this item from the COF.
+	LLInventoryModel::item_array_t items = gInventory.collectLinkedItems(item_id, LLAppearanceManager::getCOF());
+	llassert(items.size() == 1); // Should always have one and only one item linked to this in the COF.
+	for (LLInventoryModel::item_array_t::const_iterator iter = items.begin();
+		 iter != items.end();
+		 ++iter)
+	{
+		const LLViewerInventoryItem *linked_item = (*iter);
+		const LLUUID &item_id = linked_item->getUUID();
+		gInventory.purgeObject(item_id);
+	}
+	gInventory.notifyObservers();
+
+	delete on_remove_struct;
+}
+
+LLInvFVBridgeAction* LLInvFVBridgeAction::createAction(LLAssetType::EType asset_type,
+													   const LLUUID& uuid,LLInventoryModel* model)
+{
+	LLInvFVBridgeAction* action = NULL;
+	switch(asset_type)
+	{
+	case LLAssetType::AT_TEXTURE:
+		action = new LLTextureBridgeAction(uuid,model);
+		break;
+
+	case LLAssetType::AT_SOUND:
+		action = new LLSoundBridgeAction(uuid,model);
+		break;
+
+	case LLAssetType::AT_LANDMARK:
+		action = new LLLandmarkBridgeAction(uuid,model);
+		break;
+		
+	case LLAssetType::AT_CALLINGCARD:
+		action = new LLCallingCardBridgeAction(uuid,model);
+		break;
+
+	case LLAssetType::AT_OBJECT:
+		action = new LLObjectBridgeAction(uuid,model);
+		break;
+
+	case LLAssetType::AT_NOTECARD:
+		action = new LLNotecardBridgeAction(uuid,model);
+		break;
+
+	case LLAssetType::AT_ANIMATION:
+		action = new LLAnimationBridgeAction(uuid,model);
+		break;
+
+	case LLAssetType::AT_GESTURE:
+		action = new LLGestureBridgeAction(uuid,model);
+		break;
+
+	case LLAssetType::AT_LSL_TEXT:
+		action = new LLLSLTextBridgeAction(uuid,model);
+		break;
+
+	case LLAssetType::AT_CLOTHING:
+	case LLAssetType::AT_BODYPART:
+		action = new LLWearableBridgeAction(uuid,model);
+
+		break;
+
+	default:
+		break;
+	}
+	return action;
+}
+
+//static 
+void LLInvFVBridgeAction::doAction(LLAssetType::EType asset_type,
+								   const LLUUID& uuid,LLInventoryModel* model)
+{
+	LLInvFVBridgeAction* action = createAction(asset_type,uuid,model);
+	if(action)
+	{
+		action->doIt();
+		delete action;
+	}
+}
+
+//static 
+void LLInvFVBridgeAction::doAction(const LLUUID& uuid, LLInventoryModel* model)
+{
+	LLAssetType::EType asset_type = model->getItem(uuid)->getType();
+	LLInvFVBridgeAction* action = createAction(asset_type,uuid,model);
+	if(action)
+	{
+		action->doIt();
+		delete action;
+	}
+}
+
+LLViewerInventoryItem* LLInvFVBridgeAction::getItem() const
+{
+	if(mModel)
+		return (LLViewerInventoryItem*)mModel->getItem(mUUID);
+	return NULL;
+}
+
+//virtual 
+void	LLTextureBridgeAction::doIt() 
+{
+	if (getItem())
+	{
+		LLFloaterReg::showInstance("preview_texture", LLSD(mUUID), TAKE_FOCUS_YES);
+	}
+
+	LLInvFVBridgeAction::doIt();
+}
+
+//virtual
+void	LLSoundBridgeAction::doIt() 
+{
+	LLViewerInventoryItem* item = getItem();
+	if(item)
+	{
+		LLFloaterReg::showInstance("preview_sound", LLSD(mUUID), TAKE_FOCUS_YES);
+	}
+	
+	LLInvFVBridgeAction::doIt();
+}
+
+
+//virtual 
+void	LLLandmarkBridgeAction::doIt() 
+{
+	LLViewerInventoryItem* item = getItem();
+	if( item )
+	{
+		// Opening (double-clicking) a landmark immediately teleports,
+		// but warns you the first time.
+		LLSD payload;
+		payload["asset_id"] = item->getAssetUUID();
+		LLNotifications::instance().add("TeleportFromLandmark", LLSD(), payload);
+	}
+
+	LLInvFVBridgeAction::doIt();
+}
+
+
+//virtual 
+void	LLCallingCardBridgeAction::doIt() 
+{
+	LLViewerInventoryItem* item = getItem();
+	if(item && item->getCreatorUUID().notNull())
+	{
+		LLAvatarActions::showProfile(item->getCreatorUUID());
+	}
+
+	LLInvFVBridgeAction::doIt();
+}
+
+//virtual 
+void	
+LLNotecardBridgeAction::doIt() 
+{
+	LLViewerInventoryItem* item = getItem();
+	if (item)
+	{
+		LLFloaterReg::showInstance("preview_notecard", LLSD(item->getUUID()), TAKE_FOCUS_YES);
+	}
+
+	LLInvFVBridgeAction::doIt();
+}
+
+//virtual 
+void	LLGestureBridgeAction::doIt() 
+{
+	LLViewerInventoryItem* item = getItem();
+	if (item)
+	{
+		LLPreviewGesture* preview = LLPreviewGesture::show(mUUID, LLUUID::null);
+		preview->setFocus(TRUE);
+	}
+
+	LLInvFVBridgeAction::doIt();
+}
+
+//virtual 
+void	LLAnimationBridgeAction::doIt() 
+{
+	LLViewerInventoryItem* item = getItem();
+	if (item)
+	{
+		LLFloaterReg::showInstance("preview_anim", LLSD(mUUID), TAKE_FOCUS_YES);
+	}
+
+	LLInvFVBridgeAction::doIt();
+}
+
+
+//virtual 
+void	LLObjectBridgeAction::doIt()
+{
+	LLFloaterReg::showInstance("properties", mUUID);
+
+	LLInvFVBridgeAction::doIt();
+}
+
+
+//virtual 
+void	LLLSLTextBridgeAction::doIt() 
+{
+	LLViewerInventoryItem* item = getItem();
+	if (item)
+	{
+		LLFloaterReg::showInstance("preview_script", LLSD(mUUID), TAKE_FOCUS_YES);
+	}
+
+	LLInvFVBridgeAction::doIt();
+}
+
+
+BOOL LLWearableBridgeAction::isInTrash() const
+{
+	if(!mModel) return FALSE;
+	LLUUID trash_id = mModel->findCategoryUUIDForType(LLAssetType::AT_TRASH);
+	return mModel->isObjectDescendentOf(mUUID, trash_id);
+}
+
+BOOL LLWearableBridgeAction::isAgentInventory() const
+{
+	if(!mModel) return FALSE;
+	if(gInventory.getRootFolderID() == mUUID) return TRUE;
+	return mModel->isObjectDescendentOf(mUUID, gInventory.getRootFolderID());
+}
+
+void LLWearableBridgeAction::wearOnAvatar()
+{
+	// Don't wear anything until initial wearables are loaded, can
+	// destroy clothing items.
+	if (!gAgentWearables.areWearablesLoaded()) 
+	{
+		LLNotifications::instance().add("CanNotChangeAppearanceUntilLoaded");
+		return;
+	}
+
+	LLViewerInventoryItem* item = getItem();
+	if(item)
+	{
+		if(!isAgentInventory())
+		{
+			LLPointer<LLInventoryCallback> cb = new WearOnAvatarCallback();
+			copy_inventory_item(
+				gAgent.getID(),
+				item->getPermissions().getOwner(),
+				item->getUUID(),
+				LLUUID::null,
+				std::string(),
+				cb);
+		}
+		else
+		{
+			wear_inventory_item_on_avatar(item);
+		}
+	}
+}
+
+//virtual 
+void LLWearableBridgeAction::doIt()
+{
+	if(isInTrash())
+	{
+		LLNotifications::instance().add("CannotWearTrash");
+	}
+	else if(isAgentInventory())
+	{
+		if(!gAgentWearables.isWearingItem(mUUID))
+		{
+			wearOnAvatar();
+		}
+	}
+	else
+	{
+		// must be in the inventory library. copy it to our inventory
+		// and put it on right away.
+		LLViewerInventoryItem* item = getItem();
+		if(item && item->isComplete())
+		{
+			LLPointer<LLInventoryCallback> cb = new WearOnAvatarCallback();
+			copy_inventory_item(
+				gAgent.getID(),
+				item->getPermissions().getOwner(),
+				item->getUUID(),
+				LLUUID::null,
+				std::string(),
+				cb);
+		}
+		else if(item)
+		{
+			// *TODO: We should fetch the item details, and then do
+			// the operation above.
+			LLNotifications::instance().add("CannotWearInfoNotComplete");
+		}
+	}
+
+	LLInvFVBridgeAction::doIt();
+}
+
+// +=================================================+
+// |        LLLinkItemBridge                         |
+// +=================================================+
+// For broken links
+
+std::string LLLinkItemBridge::sPrefix("Link: ");
+
+
+LLUIImagePtr LLLinkItemBridge::getIcon() const
+{
+	if (LLViewerInventoryItem *item = getItem())
+	{
+		return get_item_icon(item->getActualType(), LLInventoryType::IT_NONE, 0, FALSE);
+	}
+	return get_item_icon(LLAssetType::AT_LINK, LLInventoryType::IT_NONE, 0, FALSE);
+}
+
+void LLLinkItemBridge::buildContextMenu(LLMenuGL& menu, U32 flags)
+{
+	// *TODO: Translate
+	lldebugs << "LLLink::buildContextMenu()" << llendl;
+	std::vector<std::string> items;
+	std::vector<std::string> disabled_items;
+
+	if(isInTrash())
+	{
+		items.push_back(std::string("Purge Item"));
+		if (!isItemRemovable())
+		{
+			disabled_items.push_back(std::string("Purge Item"));
+		}
+
+		items.push_back(std::string("Restore Item"));
+	}
+	else
+	{	
+		items.push_back(std::string("Delete"));
+		if (!isItemRemovable())
+		{
+			disabled_items.push_back(std::string("Delete"));
+		}
+	}
+	hide_context_entries(menu, items, disabled_items);
+}
+
+
+// +=================================================+
+// |        LLLinkBridge                             |
+// +=================================================+
+// For broken links.
+
+std::string LLLinkFolderBridge::sPrefix("Link: ");
+
+
+LLUIImagePtr LLLinkFolderBridge::getIcon() const
+{
+	LLAssetType::EType preferred_type = LLAssetType::AT_NONE;
+	if (LLViewerInventoryItem *item = getItem())
+	{
+		if (const LLViewerInventoryCategory* cat = item->getLinkedCategory())
+		{
+			preferred_type = cat->getPreferredType();
+		}
+	}
+	return LLFolderBridge::getIcon(preferred_type);
+}
+
+void LLLinkFolderBridge::buildContextMenu(LLMenuGL& menu, U32 flags)
+{
+	// *TODO: Translate
+	lldebugs << "LLLink::buildContextMenu()" << llendl;
+	std::vector<std::string> items;
+	std::vector<std::string> disabled_items;
+
+	if(isInTrash())
+	{
+		items.push_back(std::string("Purge Item"));
+		if (!isItemRemovable())
+		{
+			disabled_items.push_back(std::string("Purge Item"));
+		}
+
+		items.push_back(std::string("Restore Item"));
+	}
+	else
+	{	
+		items.push_back(std::string("Goto Link"));
+		items.push_back(std::string("Delete"));
+		if (!isItemRemovable())
+		{
+			disabled_items.push_back(std::string("Delete"));
+		}
+	}
+	hide_context_entries(menu, items, disabled_items);
+}
+
+void LLLinkFolderBridge::performAction(LLFolderView* folder, LLInventoryModel* model, std::string action)
+{
+	if ("goto" == action)
+	{
+		gotoItem(folder);
+		return;
+	}
+	LLItemBridge::performAction(folder,model,action);
+}
+
+void LLLinkFolderBridge::gotoItem(LLFolderView *folder)
+{
+	const LLUUID &cat_uuid = getFolderID();
+	if (!cat_uuid.isNull())
+	{
+		if (LLFolderViewItem *base_folder = folder->getItemByID(cat_uuid))
+		{
+			if (LLInventoryModel* model = getInventoryModel())
+			{
+				model->fetchDescendentsOf(cat_uuid);
+			}
+			base_folder->setOpen(TRUE);
+			folder->setSelectionFromRoot(base_folder,TRUE);
+			folder->scrollToShowSelection();
+		}
+	}
+}
+
+const LLUUID &LLLinkFolderBridge::getFolderID() const
+{
+	if (LLViewerInventoryItem *link_item = getItem())
+	{
+		if (const LLViewerInventoryCategory *cat = link_item->getLinkedCategory())
+		{
+			const LLUUID& cat_uuid = cat->getUUID();
+			return cat_uuid;
+		}
+	}
+	return LLUUID::null;
+}
diff --git a/indra/newview/llinventorybridge.h b/indra/newview/llinventorybridge.h
index 6b2a2d32dec..3f3513a665e 100644
--- a/indra/newview/llinventorybridge.h
+++ b/indra/newview/llinventorybridge.h
@@ -41,6 +41,7 @@
 #include "llfoldervieweventlistener.h"
 
 class LLInventoryPanel;
+class LLMenuGL;
 
 enum EInventoryIcon
 {
@@ -121,7 +122,7 @@ class LLInventoryPanelObserver : public LLInventoryObserver
 };
 
 const std::string safe_inv_type_lookup(LLInventoryType::EType inv_type);
-void hideContextEntries(LLMenuGL& menu, 
+void hide_context_entries(LLMenuGL& menu, 
 						const std::vector<std::string> &entries_to_show,
 						const std::vector<std::string> &disabled_entries);
 
@@ -807,5 +808,9 @@ BOOL move_inv_category_world_to_agent(const LLUUID& object_id,
 
 void teleport_via_landmark(const LLUUID& asset_id);
 
+// Utility function to hide all entries except those in the list
+void hide_context_entries(LLMenuGL& menu, 
+		const std::vector<std::string> &entries_to_show, 
+		const std::vector<std::string> &disabled_entries);
 
 #endif // LL_LLINVENTORYBRIDGE_H
diff --git a/indra/newview/llinventoryfunctions.cpp b/indra/newview/llinventoryfunctions.cpp
new file mode 100644
index 00000000000..694f7026544
--- /dev/null
+++ b/indra/newview/llinventoryfunctions.cpp
@@ -0,0 +1,344 @@
+/** 
+ * @file llfloaterinventory.cpp
+ * @brief Implementation of the inventory view and associated stuff.
+ *
+ * $LicenseInfo:firstyear=2001&license=viewergpl$
+ * 
+ * Copyright (c) 2001-2009, Linden Research, Inc.
+ * 
+ * Second Life Viewer Source Code
+ * The source code in this file ("Source Code") is provided by Linden Lab
+ * to you under the terms of the GNU General Public License, version 2.0
+ * ("GPL"), unless you have obtained a separate licensing agreement
+ * ("Other License"), formally executed by you and Linden Lab.  Terms of
+ * the GPL can be found in doc/GPL-license.txt in this distribution, or
+ * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
+ * 
+ * There are special exceptions to the terms and conditions of the GPL as
+ * it is applied to this Source Code. View the full text of the exception
+ * in the file doc/FLOSS-exception.txt in this software distribution, or
+ * online at
+ * http://secondlifegrid.net/programs/open_source/licensing/flossexception
+ * 
+ * By copying, modifying or distributing this software, you acknowledge
+ * that you have read and understood your obligations described above,
+ * and agree to abide by those obligations.
+ * 
+ * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
+ * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
+ * COMPLETENESS OR PERFORMANCE.
+ * $/LicenseInfo$
+ */
+
+#include "llviewerprecompiledheaders.h"
+
+#include <utility> // for std::pair<>
+
+#include "llinventoryfunctions.h"
+
+// library includes
+#include "llagent.h"
+#include "llagentwearables.h"
+#include "llcallingcard.h"
+#include "llfloaterreg.h"
+#include "llsdserialize.h"
+#include "llfiltereditor.h"
+#include "llspinctrl.h"
+#include "llui.h"
+#include "message.h"
+
+// newview includes
+#include "llappearancemgr.h"
+#include "llappviewer.h"
+#include "llfirstuse.h"
+#include "llfloaterchat.h"
+#include "llfloatercustomize.h"
+#include "llfocusmgr.h"
+#include "llfolderview.h"
+#include "llgesturemgr.h"
+#include "lliconctrl.h"
+#include "llimview.h"
+#include "llinventorybridge.h"
+#include "llinventoryclipboard.h"
+#include "llinventorymodel.h"
+#include "llinventorypanel.h"
+#include "lllineeditor.h"
+#include "llmenugl.h"
+#include "llpreviewanim.h"
+#include "llpreviewgesture.h"
+#include "llpreviewnotecard.h"
+#include "llpreviewscript.h"
+#include "llpreviewsound.h"
+#include "llpreviewtexture.h"
+#include "llresmgr.h"
+#include "llscrollbar.h"
+#include "llscrollcontainer.h"
+#include "llselectmgr.h"
+#include "lltabcontainer.h"
+#include "lltooldraganddrop.h"
+#include "lluictrlfactory.h"
+#include "llviewerinventory.h"
+#include "llviewermessage.h"
+#include "llviewerobjectlist.h"
+#include "llviewerregion.h"
+#include "llviewerwindow.h"
+#include "llvoavatarself.h"
+#include "llwearablelist.h"
+
+BOOL LLInventoryState::sWearNewClothing = FALSE;
+LLUUID LLInventoryState::sWearNewClothingTransactionID;
+
+void LLSaveFolderState::setApply(BOOL apply)
+{
+	mApply = apply; 
+	// before generating new list of open folders, clear the old one
+	if(!apply) 
+	{
+		clearOpenFolders(); 
+	}
+}
+
+void LLSaveFolderState::doFolder(LLFolderViewFolder* folder)
+{
+	LLMemType mt(LLMemType::MTYPE_INVENTORY_DO_FOLDER);
+	if(mApply)
+	{
+		// we're applying the open state
+		LLInvFVBridge* bridge = (LLInvFVBridge*)folder->getListener();
+		if(!bridge) return;
+		LLUUID id(bridge->getUUID());
+		if(mOpenFolders.find(id) != mOpenFolders.end())
+		{
+			folder->setOpen(TRUE);
+		}
+		else
+		{
+			// keep selected filter in its current state, this is less jarring to user
+			if (!folder->isSelected())
+			{
+				folder->setOpen(FALSE);
+			}
+		}
+	}
+	else
+	{
+		// we're recording state at this point
+		if(folder->isOpen())
+		{
+			LLInvFVBridge* bridge = (LLInvFVBridge*)folder->getListener();
+			if(!bridge) return;
+			mOpenFolders.insert(bridge->getUUID());
+		}
+	}
+}
+
+void LLOpenFilteredFolders::doItem(LLFolderViewItem *item)
+{
+	if (item->getFiltered())
+	{
+		item->getParentFolder()->setOpenArrangeRecursively(TRUE, LLFolderViewFolder::RECURSE_UP);
+	}
+}
+
+void LLOpenFilteredFolders::doFolder(LLFolderViewFolder* folder)
+{
+	if (folder->getFiltered() && folder->getParentFolder())
+	{
+		folder->getParentFolder()->setOpenArrangeRecursively(TRUE, LLFolderViewFolder::RECURSE_UP);
+	}
+	// if this folder didn't pass the filter, and none of its descendants did
+	else if (!folder->getFiltered() && !folder->hasFilteredDescendants())
+	{
+		folder->setOpenArrangeRecursively(FALSE, LLFolderViewFolder::RECURSE_NO);
+	}
+}
+
+void LLSelectFirstFilteredItem::doItem(LLFolderViewItem *item)
+{
+	if (item->getFiltered() && !mItemSelected)
+	{
+		item->getRoot()->setSelection(item, FALSE, FALSE);
+		if (item->getParentFolder())
+		{
+			item->getParentFolder()->setOpenArrangeRecursively(TRUE, LLFolderViewFolder::RECURSE_UP);
+		}
+		item->getRoot()->scrollToShowSelection();
+		mItemSelected = TRUE;
+	}
+}
+
+void LLSelectFirstFilteredItem::doFolder(LLFolderViewFolder* folder)
+{
+	if (folder->getFiltered() && !mItemSelected)
+	{
+		folder->getRoot()->setSelection(folder, FALSE, FALSE);
+		if (folder->getParentFolder())
+		{
+			folder->getParentFolder()->setOpenArrangeRecursively(TRUE, LLFolderViewFolder::RECURSE_UP);
+		}
+		folder->getRoot()->scrollToShowSelection();
+		mItemSelected = TRUE;
+	}
+}
+
+void LLOpenFoldersWithSelection::doItem(LLFolderViewItem *item)
+{
+	if (item->getParentFolder() && item->isSelected())
+	{
+		item->getParentFolder()->setOpenArrangeRecursively(TRUE, LLFolderViewFolder::RECURSE_UP);
+	}
+}
+
+void LLOpenFoldersWithSelection::doFolder(LLFolderViewFolder* folder)
+{
+	if (folder->getParentFolder() && folder->isSelected())
+	{
+		folder->getParentFolder()->setOpenArrangeRecursively(TRUE, LLFolderViewFolder::RECURSE_UP);
+	}
+}
+
+const std::string& get_item_icon_name(LLAssetType::EType asset_type,
+							 LLInventoryType::EType inventory_type,
+							 U32 attachment_point,
+							 BOOL item_is_multi )
+{
+	EInventoryIcon idx = OBJECT_ICON_NAME;
+	if ( item_is_multi )
+	{
+		idx = OBJECT_MULTI_ICON_NAME;
+	}
+	
+	switch(asset_type)
+	{
+	case LLAssetType::AT_TEXTURE:
+		if(LLInventoryType::IT_SNAPSHOT == inventory_type)
+		{
+			idx = SNAPSHOT_ICON_NAME;
+		}
+		else
+		{
+			idx = TEXTURE_ICON_NAME;
+		}
+		break;
+
+	case LLAssetType::AT_SOUND:
+		idx = SOUND_ICON_NAME;
+		break;
+	case LLAssetType::AT_CALLINGCARD:
+		if(attachment_point!= 0)
+		{
+			idx = CALLINGCARD_ONLINE_ICON_NAME;
+		}
+		else
+		{
+			idx = CALLINGCARD_OFFLINE_ICON_NAME;
+		}
+		break;
+	case LLAssetType::AT_LANDMARK:
+		if(attachment_point!= 0)
+		{
+			idx = LANDMARK_VISITED_ICON_NAME;
+		}
+		else
+		{
+			idx = LANDMARK_ICON_NAME;
+		}
+		break;
+	case LLAssetType::AT_SCRIPT:
+	case LLAssetType::AT_LSL_TEXT:
+	case LLAssetType::AT_LSL_BYTECODE:
+		idx = SCRIPT_ICON_NAME;
+		break;
+	case LLAssetType::AT_CLOTHING:
+		idx = CLOTHING_ICON_NAME;
+	case LLAssetType::AT_BODYPART :
+		if(LLAssetType::AT_BODYPART == asset_type)
+		{
+			idx = BODYPART_ICON_NAME;
+		}
+		switch(LLInventoryItem::II_FLAGS_WEARABLES_MASK & attachment_point)
+		{
+		case WT_SHAPE:
+			idx = BODYPART_SHAPE_ICON_NAME;
+			break;
+		case WT_SKIN:
+			idx = BODYPART_SKIN_ICON_NAME;
+			break;
+		case WT_HAIR:
+			idx = BODYPART_HAIR_ICON_NAME;
+			break;
+		case WT_EYES:
+			idx = BODYPART_EYES_ICON_NAME;
+			break;
+		case WT_SHIRT:
+			idx = CLOTHING_SHIRT_ICON_NAME;
+			break;
+		case WT_PANTS:
+			idx = CLOTHING_PANTS_ICON_NAME;
+			break;
+		case WT_SHOES:
+			idx = CLOTHING_SHOES_ICON_NAME;
+			break;
+		case WT_SOCKS:
+			idx = CLOTHING_SOCKS_ICON_NAME;
+			break;
+		case WT_JACKET:
+			idx = CLOTHING_JACKET_ICON_NAME;
+			break;
+		case WT_GLOVES:
+			idx = CLOTHING_GLOVES_ICON_NAME;
+			break;
+		case WT_UNDERSHIRT:
+			idx = CLOTHING_UNDERSHIRT_ICON_NAME;
+			break;
+		case WT_UNDERPANTS:
+			idx = CLOTHING_UNDERPANTS_ICON_NAME;
+			break;
+		case WT_SKIRT:
+			idx = CLOTHING_SKIRT_ICON_NAME;
+			break;
+		case WT_ALPHA:
+			idx = CLOTHING_ALPHA_ICON_NAME;
+			break;
+		case WT_TATTOO:
+			idx = CLOTHING_TATTOO_ICON_NAME;
+			break;
+		default:
+			// no-op, go with choice above
+			break;
+		}
+		break;
+	case LLAssetType::AT_NOTECARD:
+		idx = NOTECARD_ICON_NAME;
+		break;
+	case LLAssetType::AT_ANIMATION:
+		idx = ANIMATION_ICON_NAME;
+		break;
+	case LLAssetType::AT_GESTURE:
+		idx = GESTURE_ICON_NAME;
+		break;
+	case LLAssetType::AT_FAVORITE:
+		//TODO - need bette idx
+		idx = LANDMARK_ICON_NAME;
+		break;
+	case LLAssetType::AT_LINK:
+		idx = LINKITEM_ICON_NAME;
+		break;
+	case LLAssetType::AT_LINK_FOLDER:
+		idx = LINKFOLDER_ICON_NAME;
+		break;
+	default:
+		break;
+	}
+	
+	return ICON_NAME[idx];
+}
+
+LLUIImagePtr get_item_icon(LLAssetType::EType asset_type,
+							 LLInventoryType::EType inventory_type,
+							 U32 attachment_point,
+							 BOOL item_is_multi)
+{
+	const std::string& icon_name = get_item_icon_name(asset_type, inventory_type, attachment_point, item_is_multi );
+	return LLUI::getUIImage(icon_name);
+}
diff --git a/indra/newview/llinventoryfunctions.h b/indra/newview/llinventoryfunctions.h
new file mode 100644
index 00000000000..efd40576a76
--- /dev/null
+++ b/indra/newview/llinventoryfunctions.h
@@ -0,0 +1,136 @@
+/** 
+ * @file llinventoryfunctions.h
+ * @brief Miscellaneous inventory-related functions and classes
+ * class definition
+ *
+ * $LicenseInfo:firstyear=2001&license=viewergpl$
+ * 
+ * Copyright (c) 2001-2009, Linden Research, Inc.
+ * 
+ * Second Life Viewer Source Code
+ * The source code in this file ("Source Code") is provided by Linden Lab
+ * to you under the terms of the GNU General Public License, version 2.0
+ * ("GPL"), unless you have obtained a separate licensing agreement
+ * ("Other License"), formally executed by you and Linden Lab.  Terms of
+ * the GPL can be found in doc/GPL-license.txt in this distribution, or
+ * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
+ * 
+ * There are special exceptions to the terms and conditions of the GPL as
+ * it is applied to this Source Code. View the full text of the exception
+ * in the file doc/FLOSS-exception.txt in this software distribution, or
+ * online at
+ * http://secondlifegrid.net/programs/open_source/licensing/flossexception
+ * 
+ * By copying, modifying or distributing this software, you acknowledge
+ * that you have read and understood your obligations described above,
+ * and agree to abide by those obligations.
+ * 
+ * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
+ * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
+ * COMPLETENESS OR PERFORMANCE.
+ * $/LicenseInfo$
+ */
+
+#ifndef LL_LLINVENTORYFUNCTIONS_H
+#define LL_LLINVENTORYFUNCTIONS_H
+
+#include "llassetstorage.h"
+#include "lldarray.h"
+#include "llfloater.h"
+#include "llinventory.h"
+#include "llinventoryfilter.h"
+#include "llfolderview.h"
+#include "llinventorymodel.h"
+#include "lluictrlfactory.h"
+#include <set>
+
+
+class LLFolderViewItem;
+class LLInventoryFilter;
+class LLInventoryModel;
+class LLInventoryPanel;
+class LLInvFVBridge;
+class LLInventoryFVBridgeBuilder;
+class LLMenuBarGL;
+class LLCheckBoxCtrl;
+class LLSpinCtrl;
+class LLScrollContainer;
+class LLTextBox;
+class LLIconCtrl;
+class LLSaveFolderState;
+class LLFilterEditor;
+class LLTabContainer;
+
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+//
+// This is a collection of miscellaneous functions and classes
+// that don't fit cleanly into any other class header.
+//
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+class LLInventoryState
+{
+public:
+	// HACK: Until we can route this info through the instant message hierarchy
+	static BOOL sWearNewClothing;
+	static LLUUID sWearNewClothingTransactionID;	// wear all clothing in this transaction	
+};
+
+class LLSelectFirstFilteredItem : public LLFolderViewFunctor
+{
+public:
+	LLSelectFirstFilteredItem() : mItemSelected(FALSE) {}
+	virtual ~LLSelectFirstFilteredItem() {}
+	virtual void doFolder(LLFolderViewFolder* folder);
+	virtual void doItem(LLFolderViewItem* item);
+	BOOL wasItemSelected() { return mItemSelected; }
+protected:
+	BOOL	mItemSelected;
+};
+
+class LLOpenFilteredFolders : public LLFolderViewFunctor
+{
+public:
+	LLOpenFilteredFolders()  {}
+	virtual ~LLOpenFilteredFolders() {}
+	virtual void doFolder(LLFolderViewFolder* folder);
+	virtual void doItem(LLFolderViewItem* item);
+};
+
+class LLSaveFolderState : public LLFolderViewFunctor
+{
+public:
+	LLSaveFolderState() : mApply(FALSE) {}
+	virtual ~LLSaveFolderState() {}
+	virtual void doFolder(LLFolderViewFolder* folder);
+	virtual void doItem(LLFolderViewItem* item) {}
+	void setApply(BOOL apply);
+	void clearOpenFolders() { mOpenFolders.clear(); }
+protected:
+	std::set<LLUUID> mOpenFolders;
+	BOOL mApply;
+};
+
+class LLOpenFoldersWithSelection : public LLFolderViewFunctor
+{
+public:
+	LLOpenFoldersWithSelection() {}
+	virtual ~LLOpenFoldersWithSelection() {}
+	virtual void doFolder(LLFolderViewFolder* folder);
+	virtual void doItem(LLFolderViewItem* item);
+};
+
+const std::string& get_item_icon_name(LLAssetType::EType asset_type,
+							 LLInventoryType::EType inventory_type,
+							 U32 attachment_point, 
+							 BOOL item_is_multi );
+
+LLUIImagePtr get_item_icon(LLAssetType::EType asset_type,
+							 LLInventoryType::EType inventory_type,
+							 U32 attachment_point, 
+							 BOOL item_is_multi );
+
+#endif // LL_LLINVENTORYFUNCTIONS_H
+
+
+
diff --git a/indra/newview/llinventorymodel.cpp b/indra/newview/llinventorymodel.cpp
index 1d7cbde0d56..23439191f3d 100644
--- a/indra/newview/llinventorymodel.cpp
+++ b/indra/newview/llinventorymodel.cpp
@@ -46,6 +46,8 @@
 #include "llfloater.h"
 #include "llfocusmgr.h"
 #include "llinventorybridge.h"
+#include "llinventoryfunctions.h"
+#include "llinventorypanel.h"
 #include "llfloaterinventory.h"
 #include "llviewerinventory.h"
 #include "llviewermessage.h"
@@ -3174,13 +3176,13 @@ void LLInventoryModel::processBulkUpdateInventory(LLMessageSystem* msg, void**)
 	// The incoming inventory could span more than one BulkInventoryUpdate packet,
 	// so record the transaction ID for this purchase, then wear all clothing
 	// that comes in as part of that transaction ID.  JC
-	if (LLFloaterInventory::sWearNewClothing)
+	if (LLInventoryState::sWearNewClothing)
 	{
-		LLFloaterInventory::sWearNewClothingTransactionID = tid;
-		LLFloaterInventory::sWearNewClothing = FALSE;
+		LLInventoryState::sWearNewClothingTransactionID = tid;
+		LLInventoryState::sWearNewClothing = FALSE;
 	}
 
-	if (tid == LLFloaterInventory::sWearNewClothingTransactionID)
+	if (tid == LLInventoryState::sWearNewClothingTransactionID)
 	{
 		count = wearable_ids.size();
 		for (i = 0; i < count; ++i)
diff --git a/indra/newview/llpanelcontents.cpp b/indra/newview/llpanelcontents.cpp
index ea528a1df89..c28792a711d 100644
--- a/indra/newview/llpanelcontents.cpp
+++ b/indra/newview/llpanelcontents.cpp
@@ -51,7 +51,7 @@
 // project includes
 #include "llagent.h"
 #include "llfloaterbulkpermission.h"
-#include "llpanelinventory.h"
+#include "llpanelobjectinventory.h"
 #include "llpreviewscript.h"
 #include "llresmgr.h"
 #include "llselectmgr.h"
@@ -89,14 +89,14 @@ BOOL LLPanelContents::postBuild()
 	childSetAction("button new script",&LLPanelContents::onClickNewScript, this);
 	childSetAction("button permissions",&LLPanelContents::onClickPermissions, this);
 
-	mPanelInventory = getChild<LLPanelInventory>("contents_inventory");
+	mPanelInventoryObject = getChild<LLPanelObjectInventory>("contents_inventory");
 
 	return TRUE;
 }
 
 LLPanelContents::LLPanelContents()
 	:	LLPanel(),
-		mPanelInventory(NULL)
+		mPanelInventoryObject(NULL)
 {
 }
 
@@ -139,9 +139,9 @@ void LLPanelContents::refresh()
 	LLViewerObject* object = LLSelectMgr::getInstance()->getSelection()->getFirstRootObject(children_ok);
 
 	getState(object);
-	if (mPanelInventory)
+	if (mPanelInventoryObject)
 	{
-		mPanelInventory->refresh();
+		mPanelInventoryObject->refresh();
 	}	
 }
 
diff --git a/indra/newview/llpanelcontents.h b/indra/newview/llpanelcontents.h
index bab980b5246..14256845a6c 100644
--- a/indra/newview/llpanelcontents.h
+++ b/indra/newview/llpanelcontents.h
@@ -35,9 +35,14 @@
 
 #include "v3math.h"
 #include "llpanel.h"
+#include "llinventory.h"
+#include "lluuid.h"
+#include "llmap.h"
+#include "llviewerobject.h"
+#include "llvoinventorylistener.h"
 
 class LLButton;
-class LLPanelInventory;
+class LLPanelObjectInventory;
 class LLViewerObject;
 class LLCheckBoxCtrl;
 class LLSpinCtrl;
@@ -70,7 +75,7 @@ class LLPanelContents : public LLPanel
 	void				getState(LLViewerObject *object);
 
 public:
-	LLPanelInventory* mPanelInventory;
+	LLPanelObjectInventory* mPanelInventoryObject;
 };
 
-#endif
+#endif // LL_LLPANELCONTENTS_H
diff --git a/indra/newview/llpanelgroupnotices.cpp b/indra/newview/llpanelgroupnotices.cpp
index 0ce85818dd6..22138a81eca 100644
--- a/indra/newview/llpanelgroupnotices.cpp
+++ b/indra/newview/llpanelgroupnotices.cpp
@@ -38,6 +38,7 @@
 
 #include "llinventory.h"
 #include "llviewerinventory.h"
+#include "llinventoryfunctions.h"
 #include "llinventorymodel.h"
 #include "llfloaterinventory.h"
 #include "llagent.h"
diff --git a/indra/newview/llpanellandmarks.cpp b/indra/newview/llpanellandmarks.cpp
index 3d0db710453..7bc42b36f9c 100644
--- a/indra/newview/llpanellandmarks.cpp
+++ b/indra/newview/llpanellandmarks.cpp
@@ -1,954 +1,955 @@
-/**
- * @file llpanellandmarks.cpp
- * @brief Landmarks tab for Side Bar "Places" panel
- *
- * $LicenseInfo:firstyear=2009&license=viewergpl$
- *
- * Copyright (c) 2001-2009, Linden Research, Inc.
- *
- * Second Life Viewer Source Code
- * The source code in this file ("Source Code") is provided by Linden Lab
- * to you under the terms of the GNU General Public License, version 2.0
- * ("GPL"), unless you have obtained a separate licensing agreement
- * ("Other License"), formally executed by you and Linden Lab.  Terms of
- * the GPL can be found in doc/GPL-license.txt in this distribution, or
- * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
- *
- * There are special exceptions to the terms and conditions of the GPL as
- * it is applied to this Source Code. View the full text of the exception
- * in the file doc/FLOSS-exception.txt in this software distribution, or
- * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception
- *
- * By copying, modifying or distributing this software, you acknowledge
- * that you have read and understood your obligations described above,
- * and agree to abide by those obligations.
- *
- * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
- * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
- * COMPLETENESS OR PERFORMANCE.
- * $/LicenseInfo$
- */
-
-#include "llviewerprecompiledheaders.h"
-
-#include "llpanellandmarks.h"
-
-#include "llbutton.h"
-#include "llfloaterreg.h"
-#include "llsdutil.h"
-#include "llsdutil_math.h"
-
-#include "llaccordionctrl.h"
-#include "llaccordionctrltab.h"
-#include "llagent.h"
-#include "llagentpicksinfo.h"
-#include "llagentui.h"
-#include "llcallbacklist.h"
-#include "lldndbutton.h"
-#include "llfloaterworldmap.h"
-#include "llfolderviewitem.h"
-#include "llinventorysubtreepanel.h"
-#include "lllandmarkactions.h"
-#include "llplacesinventorybridge.h"
-#include "llsidetray.h"
-#include "llviewermenu.h"
-#include "llviewerregion.h"
-
-// Not yet implemented; need to remove buildPanel() from constructor when we switch
-//static LLRegisterPanelClassWrapper<LLLandmarksPanel> t_landmarks("panel_landmarks");
-
-static const std::string OPTIONS_BUTTON_NAME = "options_gear_btn";
-static const std::string ADD_BUTTON_NAME = "add_btn";
-static const std::string ADD_FOLDER_BUTTON_NAME = "add_folder_btn";
-static const std::string TRASH_BUTTON_NAME = "trash_btn";
-
-
-// helper functions
-static void filter_list(LLInventorySubTreePanel* inventory_list, const std::string& string);
-
-
-LLLandmarksPanel::LLLandmarksPanel()
-	:	LLPanelPlacesTab()
-	,	mFavoritesInventoryPanel(NULL)
-	,	mLandmarksInventoryPanel(NULL)
-	,	mMyInventoryPanel(NULL)
-	,	mLibraryInventoryPanel(NULL)
-	,	mCurrentSelectedList(NULL)
-	,	mListCommands(NULL)
-	,	mGearFolderMenu(NULL)
-	,	mGearLandmarkMenu(NULL)
-	,	mDirtyFilter(false)
-{
-	LLUICtrlFactory::getInstance()->buildPanel(this, "panel_landmarks.xml");
-}
-
-LLLandmarksPanel::~LLLandmarksPanel()
-{
-}
-
-BOOL LLLandmarksPanel::postBuild()
-{
-	if (!gInventory.isInventoryUsable())
-		return FALSE;
-
-	// mast be called before any other initXXX methods to init Gear menu
-	initListCommandsHandlers();
-
-	U32 sort_order = gSavedSettings.getU32(LLInventoryPanel::DEFAULT_SORT_ORDER);
-	mSortByDate = sort_order & LLInventoryFilter::SO_DATE;
-	initFavoritesInventroyPanel();
-	initLandmarksInventroyPanel();
-	initMyInventroyPanel();
-	initLibraryInventroyPanel();
-
-	gIdleCallbacks.addFunction(LLLandmarksPanel::doIdle, this);
-	return TRUE;
-}
-
-// virtual
-void LLLandmarksPanel::onSearchEdit(const std::string& string)
-{
-	static std::string prev_string("");
-
-	if (prev_string == string) return;
-
-	// show all folders in Landmarks Accordion for empty filter
-	mLandmarksInventoryPanel->setShowFolderState(string.empty() ?
-		LLInventoryFilter::SHOW_ALL_FOLDERS :
-		LLInventoryFilter::SHOW_NON_EMPTY_FOLDERS
-		);
-
-	filter_list(mFavoritesInventoryPanel, string);
-	filter_list(mLandmarksInventoryPanel, string);
-	filter_list(mMyInventoryPanel, string);
-	filter_list(mLibraryInventoryPanel, string);
-
-	prev_string = string;
-	mDirtyFilter = true;
-
-	// give FolderView a chance to be refreshed. So, made all accordions visible
-	for (accordion_tabs_t::const_iterator iter = mAccordionTabs.begin(); iter != mAccordionTabs.end(); ++iter)
-	{
-		LLAccordionCtrlTab* tab = *iter;
-		tab->setVisible(true);
-	}
-}
-
-// virtual
-void LLLandmarksPanel::onShowOnMap()
-{
-	if (NULL == mCurrentSelectedList)
-	{
-		llwarns << "There are no selected list. No actions are performed." << llendl;
-		return;
-	}
-	LLLandmark* landmark = getCurSelectedLandmark();
-	if (!landmark)
-		return;
-
-	LLVector3d landmark_global_pos;
-	if (!landmark->getGlobalPos(landmark_global_pos))
-		return;
-	
-	LLFloaterWorldMap* worldmap_instance = LLFloaterWorldMap::getInstance();
-	if (!landmark_global_pos.isExactlyZero() && worldmap_instance)
-	{
-		worldmap_instance->trackLocation(landmark_global_pos);
-		LLFloaterReg::showInstance("world_map", "center");
-	}
-}
-
-// virtual
-void LLLandmarksPanel::onTeleport()
-{
-	LLFolderViewItem* current_item = getCurSelectedItem();
-	if (!current_item)
-	{
-		llwarns << "There are no selected list. No actions are performed." << llendl;
-		return;
-	}
-
-	LLFolderViewEventListener* listenerp = current_item->getListener();
-	if (listenerp->getInventoryType() == LLInventoryType::IT_LANDMARK)
-	{
-		listenerp->openItem();
-	}
-}
-
-// virtual
-void LLLandmarksPanel::updateVerbs()
-{
-	if (!isTabVisible()) 
-		return;
-
-	BOOL enabled = isLandmarkSelected();
-	mTeleportBtn->setEnabled(enabled);
-	mShowOnMapBtn->setEnabled(enabled);
-
-	// TODO: mantipov: Uncomment when mShareBtn is supported
-	// Share button should be enabled when neither a folder nor a landmark is selected
-	//mShareBtn->setEnabled(NULL != current_item);
-
-	updateListCommands();
-}
-
-void LLLandmarksPanel::onSelectionChange(LLInventorySubTreePanel* inventory_list, const std::deque<LLFolderViewItem*> &items, BOOL user_action)
-{
-	if (user_action && (items.size() > 0))
-	{
-		deselectOtherThan(inventory_list);
-		mCurrentSelectedList = inventory_list;
-	}
-
-	LLFolderViewItem* current_item = inventory_list->getRootFolder()->getCurSelectedItem();
-	if (!current_item)
-		return;
-
-	updateVerbs();
-}
-
-void LLLandmarksPanel::onSelectorButtonClicked()
-{
-	// TODO: mantipov: update getting of selected item
-	// TODO: bind to "i" button
-	LLFolderViewItem* cur_item = mFavoritesInventoryPanel->getRootFolder()->getCurSelectedItem();
-
-	LLFolderViewEventListener* listenerp = cur_item->getListener();
-	if (listenerp->getInventoryType() == LLInventoryType::IT_LANDMARK)
-	{
-		LLSD key;
-		key["type"] = "landmark";
-		key["id"] = listenerp->getUUID();
-
-		LLSideTray::getInstance()->showPanel("panel_places", key);
-	}
-}
-
-//////////////////////////////////////////////////////////////////////////
-// PROTECTED METHODS
-//////////////////////////////////////////////////////////////////////////
-
-bool LLLandmarksPanel::isLandmarkSelected() const 
-{
-	LLFolderViewItem* current_item = getCurSelectedItem();
-	if(current_item && current_item->getListener()->getInventoryType() == LLInventoryType::IT_LANDMARK)
-	{
-		return true;
-	}
-
-	return false;
-}
-
-bool LLLandmarksPanel::isReceivedFolderSelected() const
-{
-	// Received Folder can be only in Landmarks accordion
-	if (mCurrentSelectedList != mLandmarksInventoryPanel) return false;
-
-	// *TODO: it should be filled with logic when EXT-976 is done.
-
-	llwarns << "Not implemented yet until EXT-976 is done." << llendl;
-
-	return false;
-}
-LLLandmark* LLLandmarksPanel::getCurSelectedLandmark() const
-{
-
-	LLFolderViewItem* cur_item = getCurSelectedItem();
-	if(cur_item && cur_item->getListener()->getInventoryType() == LLInventoryType::IT_LANDMARK)
-	{ 
-		return LLLandmarkActions::getLandmark(cur_item->getListener()->getUUID());
-	}
-	return NULL;
-}
-
-LLFolderViewItem* LLLandmarksPanel::getCurSelectedItem () const 
-{
-	return mCurrentSelectedList ?  mCurrentSelectedList->getRootFolder()->getCurSelectedItem() : NULL;
-}
-
-void LLLandmarksPanel::updateSortOrder(LLInventoryPanel* panel, bool byDate)
-{
-	if(!panel) return; 
-
-	U32 order = panel->getSortOrder();
-	if (byDate)
-	{
-		panel->setSortOrder( order | LLInventoryFilter::SO_DATE );
-	}
-	else 
-	{
-		panel->setSortOrder( order & ~LLInventoryFilter::SO_DATE );
-	}
-}
-
-// virtual
-void LLLandmarksPanel::processParcelInfo(const LLParcelData& parcel_data)
-{
-	//this function will be called after user will try to create a pick for selected landmark.
-	// We have to make request to sever to get parcel_id and snaption_id. 
-	if(isLandmarkSelected())
-	{
-		LLLandmark* landmark  =  getCurSelectedLandmark();
-		LLFolderViewItem* cur_item = getCurSelectedItem();
-		LLUUID id = cur_item->getListener()->getUUID();
-		LLInventoryItem* inv_item =  mCurrentSelectedList->getModel()->getItem(id);
-		if(landmark)
-		{
-			LLPanelPickEdit* panel_pick = LLPanelPickEdit::create();
-			LLVector3d landmark_global_pos;
-			landmark->getGlobalPos(landmark_global_pos);
-
-			// let's toggle pick panel into  panel places
-			LLPanel* panel_places =  LLSideTray::getInstance()->getChild<LLPanel>("panel_places");//-> sidebar_places
-			panel_places->addChild(panel_pick);
-			LLRect paren_rect(panel_places->getRect());
-			panel_pick->reshape(paren_rect.getWidth(),paren_rect.getHeight(), TRUE);
-			panel_pick->setRect(paren_rect);
-			panel_pick->onOpen(LLSD());
-
-			LLPickData data;
-			data.pos_global = landmark_global_pos;
-			data.name = cur_item->getName();
-			data.desc = inv_item->getDescription();
-			data.snapshot_id = parcel_data.snapshot_id;
-			data.parcel_id = parcel_data.parcel_id;
-			panel_pick->setPickData(&data);
-
-			LLSD params;
-			params["parcel_id"] =parcel_data.parcel_id;
-			/* set exit callback to get back onto panel places  
-			 in callback we will make cleaning up( delete pick_panel instance, 
-			 remove landmark panel from observer list
-			*/ 
-			panel_pick->setExitCallback(boost::bind(&LLLandmarksPanel::onPickPanelExit,this,
-					panel_pick, panel_places,params));
-			panel_pick->setSaveCallback(boost::bind(&LLLandmarksPanel::onPickPanelExit,this,
-				panel_pick, panel_places,params));
-			panel_pick->setCancelCallback(boost::bind(&LLLandmarksPanel::onPickPanelExit,this,
-							panel_pick, panel_places,params));
-		}
-	}
-}
-
-// virtual
-void LLLandmarksPanel::setParcelID(const LLUUID& parcel_id)
-{
-	if (!parcel_id.isNull())
-	{
-		LLRemoteParcelInfoProcessor::getInstance()->addObserver(parcel_id, this);
-		LLRemoteParcelInfoProcessor::getInstance()->sendParcelInfoRequest(parcel_id);
-	}
-}
-
-// virtual
-void LLLandmarksPanel::setErrorStatus(U32 status, const std::string& reason)
-{
-	llerrs<< "Can't handle remote parcel request."<< " Http Status: "<< status << ". Reason : "<< reason<<llendl;
-}
-
-
-//////////////////////////////////////////////////////////////////////////
-// PRIVATE METHODS
-//////////////////////////////////////////////////////////////////////////
-
-void LLLandmarksPanel::initFavoritesInventroyPanel()
-{
-	mFavoritesInventoryPanel = getChild<LLInventorySubTreePanel>("favorites_list");
-
-	initLandmarksPanel(mFavoritesInventoryPanel);
-
-	initAccordion("tab_favorites", mFavoritesInventoryPanel);
-}
-
-void LLLandmarksPanel::initLandmarksInventroyPanel()
-{
-	mLandmarksInventoryPanel = getChild<LLInventorySubTreePanel>("landmarks_list");
-
-	initLandmarksPanel(mLandmarksInventoryPanel);
-
-	mLandmarksInventoryPanel->setShowFolderState(LLInventoryFilter::SHOW_ALL_FOLDERS);
-
-	// subscribe to have auto-rename functionality while creating New Folder
-	mLandmarksInventoryPanel->setSelectCallback(boost::bind(&LLInventoryPanel::onSelectionChange, mLandmarksInventoryPanel, _1, _2));
-
-	initAccordion("tab_landmarks", mLandmarksInventoryPanel);
-}
-
-void LLLandmarksPanel::initMyInventroyPanel()
-{
-	mMyInventoryPanel= getChild<LLInventorySubTreePanel>("my_inventory_list");
-
-	initLandmarksPanel(mMyInventoryPanel);
-
-	initAccordion("tab_inventory", mMyInventoryPanel);
-}
-
-void LLLandmarksPanel::initLibraryInventroyPanel()
-{
-	mLibraryInventoryPanel = getChild<LLInventorySubTreePanel>("library_list");
-
-	initLandmarksPanel(mLibraryInventoryPanel);
-
-	initAccordion("tab_library", mLibraryInventoryPanel);
-}
-
-void LLLandmarksPanel::initLandmarksPanel(LLInventorySubTreePanel* inventory_list)
-{
-	inventory_list->setFilterTypes(0x1 << LLInventoryType::IT_LANDMARK);
-	inventory_list->setSelectCallback(boost::bind(&LLLandmarksPanel::onSelectionChange, this, inventory_list, _1, _2));
-
-	inventory_list->setShowFolderState(LLInventoryFilter::SHOW_NON_EMPTY_FOLDERS);
-	updateSortOrder(inventory_list, mSortByDate);
-
-	LLPlacesFolderView* root_folder = dynamic_cast<LLPlacesFolderView*>(inventory_list->getRootFolder());
-	if (root_folder)
-	{
-		root_folder->setupMenuHandle(LLInventoryType::IT_CATEGORY, mGearFolderMenu->getHandle());
-		root_folder->setupMenuHandle(LLInventoryType::IT_LANDMARK, mGearLandmarkMenu->getHandle());
-	}
-
-	// save initial folder state to avoid incorrect work while switching between Landmarks & Teleport History tabs
-	// See EXT-1609.
-	inventory_list->saveFolderState();
-}
-
-void LLLandmarksPanel::initAccordion(const std::string& accordion_tab_name, LLInventorySubTreePanel* inventory_list)
-{
-	LLAccordionCtrlTab* accordion_tab = getChild<LLAccordionCtrlTab>(accordion_tab_name);
-	mAccordionTabs.push_back(accordion_tab);
-	accordion_tab->setDropDownStateChangedCallback(
-		boost::bind(&LLLandmarksPanel::onAccordionExpandedCollapsed, this, _2, inventory_list));
-}
-
-void LLLandmarksPanel::onAccordionExpandedCollapsed(const LLSD& param, LLInventorySubTreePanel* inventory_list)
-{
-	bool expanded = param.asBoolean();
-
-	if(!expanded && (mCurrentSelectedList == inventory_list))
-	{
-		inventory_list->getRootFolder()->clearSelection();
-
-		mCurrentSelectedList = NULL;
-		updateVerbs();
-	}
-}
-
-void LLLandmarksPanel::deselectOtherThan(const LLInventorySubTreePanel* inventory_list)
-{
-	if (inventory_list != mFavoritesInventoryPanel)
-	{
-		mFavoritesInventoryPanel->getRootFolder()->clearSelection();
-	}
-
-	if (inventory_list != mLandmarksInventoryPanel)
-	{
-		mLandmarksInventoryPanel->getRootFolder()->clearSelection();
-	}
-	if (inventory_list != mMyInventoryPanel)
-	{
-		mMyInventoryPanel->getRootFolder()->clearSelection();
-	}
-	if (inventory_list != mLibraryInventoryPanel)
-	{
-		mLibraryInventoryPanel->getRootFolder()->clearSelection();
-	}
-}
-
-// List Commands Handlers
-void LLLandmarksPanel::initListCommandsHandlers()
-{
-	mListCommands = getChild<LLPanel>("bottom_panel");
-
-	mListCommands->childSetAction(OPTIONS_BUTTON_NAME, boost::bind(&LLLandmarksPanel::onActionsButtonClick, this));
-	mListCommands->childSetAction(TRASH_BUTTON_NAME, boost::bind(&LLLandmarksPanel::onTrashButtonClick, this));
-	mListCommands->getChild<LLButton>(ADD_BUTTON_NAME)->setHeldDownCallback(boost::bind(&LLLandmarksPanel::onAddButtonHeldDown, this));
-	static const LLSD add_landmark_command("add_landmark");
-	mListCommands->childSetAction(ADD_BUTTON_NAME, boost::bind(&LLLandmarksPanel::onAddAction, this, add_landmark_command));
-
-	LLDragAndDropButton* trash_btn = mListCommands->getChild<LLDragAndDropButton>(TRASH_BUTTON_NAME);
-	trash_btn->setDragAndDropHandler(boost::bind(&LLLandmarksPanel::handleDragAndDropToTrash, this
-			,	_4 // BOOL drop
-			,	_5 // EDragAndDropType cargo_type
-			,	_7 // EAcceptance* accept
-			));
-
-	mCommitCallbackRegistrar.add("Places.LandmarksGear.Add.Action", boost::bind(&LLLandmarksPanel::onAddAction, this, _2));
-	mCommitCallbackRegistrar.add("Places.LandmarksGear.CopyPaste.Action", boost::bind(&LLLandmarksPanel::onClipboardAction, this, _2));
-	mCommitCallbackRegistrar.add("Places.LandmarksGear.Custom.Action", boost::bind(&LLLandmarksPanel::onCustomAction, this, _2));
-	mCommitCallbackRegistrar.add("Places.LandmarksGear.Folding.Action", boost::bind(&LLLandmarksPanel::onFoldingAction, this, _2));
-	mEnableCallbackRegistrar.add("Places.LandmarksGear.Check", boost::bind(&LLLandmarksPanel::isActionChecked, this, _2));
-	mEnableCallbackRegistrar.add("Places.LandmarksGear.Enable", boost::bind(&LLLandmarksPanel::isActionEnabled, this, _2));
-	mGearLandmarkMenu = LLUICtrlFactory::getInstance()->createFromFile<LLMenuGL>("menu_places_gear_landmark.xml", gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance());
-	mGearFolderMenu = LLUICtrlFactory::getInstance()->createFromFile<LLMenuGL>("menu_places_gear_folder.xml", gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance());
-	mMenuAdd = LLUICtrlFactory::getInstance()->createFromFile<LLMenuGL>("menu_place_add_button.xml", gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance());
-}
-
-
-void LLLandmarksPanel::updateListCommands()
-{
-	bool add_folder_enabled = isActionEnabled("category");
-	bool trash_enabled = isActionEnabled("delete");
-
-	// keep Options & Add Landmark buttons always enabled
-	mListCommands->childSetEnabled(ADD_FOLDER_BUTTON_NAME, add_folder_enabled);
-	mListCommands->childSetEnabled(TRASH_BUTTON_NAME, trash_enabled);
-}
-
-void LLLandmarksPanel::onActionsButtonClick()
-{
-	LLFolderViewItem* cur_item = NULL;
-	if(mCurrentSelectedList)
-		cur_item = mCurrentSelectedList->getRootFolder()->getCurSelectedItem();
-	
-	if(!cur_item)
-		return;
-	
-	LLFolderViewEventListener* listenerp = cur_item->getListener();
-	
-	LLMenuGL* menu  =NULL;
-	if (listenerp->getInventoryType() == LLInventoryType::IT_LANDMARK)
-	{
-		menu = mGearLandmarkMenu;
-	}
-	else if (listenerp->getInventoryType() == LLInventoryType::IT_CATEGORY)
-	{
-		mGearFolderMenu->getChild<LLMenuItemCallGL>("expand")->setVisible(!cur_item->isOpen());
-		mGearFolderMenu->getChild<LLMenuItemCallGL>("collapse")->setVisible(cur_item->isOpen());
-		menu = mGearFolderMenu;
-	}
-	showActionMenu(menu,OPTIONS_BUTTON_NAME);
-}
-
-void LLLandmarksPanel::onAddButtonHeldDown()
-{
-	showActionMenu(mMenuAdd,ADD_BUTTON_NAME);
-}
-
-void LLLandmarksPanel::showActionMenu(LLMenuGL* menu, std::string spawning_view_name)
-{
-	if (menu)
-	{
-		menu->buildDrawLabels();
-		menu->updateParent(LLMenuGL::sMenuContainer);
-		LLView* spawning_view = getChild<LLView> (spawning_view_name);
-		S32 menu_x, menu_y;
-		//show menu in co-ordinates of panel
-		spawning_view->localPointToOtherView(0, spawning_view->getRect().getHeight(), &menu_x, &menu_y, this);
-		menu_y += menu->getRect().getHeight();
-		LLMenuGL::showPopup(this, menu, menu_x, menu_y);
-	}
-}
-
-void LLLandmarksPanel::onTrashButtonClick() const
-{
-	onClipboardAction("delete");
-}
-
-void LLLandmarksPanel::onAddAction(const LLSD& userdata) const
-{
-	std::string command_name = userdata.asString();
-	if("add_landmark" == command_name)
-	{
-		if(LLLandmarkActions::landmarkAlreadyExists())
-		{
-			std::string location;
-			LLAgentUI::buildLocationString(location, LLAgentUI::LOCATION_FORMAT_FULL);
-			llwarns<<" Landmark already exists at location:  "<< location<<llendl;
-			return;
-		}
-		LLSideTray::getInstance()->showPanel("panel_places", LLSD().insert("type", "create_landmark"));
-	} 
-	else if ("category" == command_name)
-	{
-		LLFolderViewItem* item = getCurSelectedItem();
-		if (item && mCurrentSelectedList == mLandmarksInventoryPanel)
-		{
-			LLFolderViewEventListener* folder_bridge = NULL;
-			if (item-> getListener()->getInventoryType()
-					== LLInventoryType::IT_LANDMARK)
-			{
-				// for a landmark get parent folder bridge
-				folder_bridge = item->getParentFolder()->getListener();
-			}
-			else if (item-> getListener()->getInventoryType()
-					== LLInventoryType::IT_CATEGORY)
-			{
-				// for a folder get its own bridge
-				folder_bridge = item->getListener();
-			}
-
-			menu_create_inventory_item(mCurrentSelectedList->getRootFolder(),
-					dynamic_cast<LLFolderBridge*> (folder_bridge), LLSD(
-							"category"), gInventory.findCategoryUUIDForType(
-							LLAssetType::AT_LANDMARK));
-		}
-	}
-}
-
-void LLLandmarksPanel::onClipboardAction(const LLSD& userdata) const
-{
-	if(!mCurrentSelectedList) 
-		return;
-	std::string command_name = userdata.asString();
-    if("copy_slurl" == command_name)
-	{
-    	LLFolderViewItem* cur_item = getCurSelectedItem();
-		if(cur_item)
-			LLLandmarkActions::copySLURLtoClipboard(cur_item->getListener()->getUUID());
-	}
-	else if ( "paste" == command_name)
-	{
-		mCurrentSelectedList->getRootFolder()->paste();
-	} 
-	else if ( "cut" == command_name)
-	{
-		mCurrentSelectedList->getRootFolder()->cut();
-	}
-	else
-	{
-		mCurrentSelectedList->getRootFolder()->doToSelected(mCurrentSelectedList->getModel(),command_name);
-	}
-}
-
-void LLLandmarksPanel::onFoldingAction(const LLSD& userdata)
-{
-	if(!mCurrentSelectedList) return;
-
-	LLFolderView* root_folder = mCurrentSelectedList->getRootFolder();
-	std::string command_name = userdata.asString();
-
-	if ("expand_all" == command_name)
-	{
-		root_folder->setOpenArrangeRecursively(TRUE, LLFolderViewFolder::RECURSE_DOWN);
-		root_folder->arrangeAll();
-	}
-	else if ("collapse_all" == command_name)
-	{
-		root_folder->closeAllFolders();
-	}
-	else if ( "sort_by_date" == command_name)
-	{
-		mSortByDate = !mSortByDate;
-		updateSortOrder(mLandmarksInventoryPanel, mSortByDate);
-		updateSortOrder(mMyInventoryPanel, mSortByDate);
-		updateSortOrder(mLibraryInventoryPanel, mSortByDate);
-	}
-	else
-	{
-		root_folder->doToSelected(&gInventory, userdata);
-	}
-}
-
-bool LLLandmarksPanel::isActionChecked(const LLSD& userdata) const
-{
-	const std::string command_name = userdata.asString();
-
-	if ( "sort_by_date" == command_name)
-	{
-		return  mSortByDate;
-	}
-
-	return false;
-}
-
-bool LLLandmarksPanel::isActionEnabled(const LLSD& userdata) const
-{
-	std::string command_name = userdata.asString();
-
-
-	LLPlacesFolderView* rootFolderView = mCurrentSelectedList ?
-		static_cast<LLPlacesFolderView*>(mCurrentSelectedList->getRootFolder()) : NULL;
-
-	if (NULL == rootFolderView) return false;
-
-	// disable some commands for multi-selection. EXT-1757
-	if (rootFolderView->getSelectedCount() > 1)
-	{
-		if (   "teleport"		== command_name 
-			|| "more_info"		== command_name
-			|| "rename"			== command_name
-			|| "show_on_map"	== command_name
-			|| "copy_slurl"		== command_name
-			)
-		{
-			return false;
-		}
-
-	}
-
-	// disable some commands for Favorites accordion. EXT-1758
-	if (mCurrentSelectedList == mFavoritesInventoryPanel)
-	{
-		if (   "expand_all"		== command_name
-			|| "collapse_all"	== command_name
-			|| "sort_by_date"	== command_name
-			)
-			return false;
-	}
-
-
-	if("category" == command_name)
-	{
-		// we can add folder only in Landmarks Accordion
-		if (mCurrentSelectedList == mLandmarksInventoryPanel)
-		{
-			// ... but except Received folder
-			return !isReceivedFolderSelected();
-		}
-		else return false;
-	}
-	else if("paste" == command_name || "rename" == command_name || "cut" == command_name || "delete" == command_name)
-	{
-		return canSelectedBeModified(command_name);
-	}
-	else if ( "sort_by_date" == command_name)
-	{
-		return  mSortByDate;
-	}
-	else if("create_pick" == command_name)
-	{
-		return !LLAgentPicksInfo::getInstance()->isPickLimitReached();
-	}
-	else
-	{
-		llwarns << "Unprocessed command has come: " << command_name << llendl;
-	}
-
-	return true;
-}
-
-void LLLandmarksPanel::onCustomAction(const LLSD& userdata)
-{
-	LLFolderViewItem* cur_item = getCurSelectedItem();
-	if(!cur_item)
-		return ;
-	std::string command_name = userdata.asString();
-	if("more_info" == command_name)
-	{
-		cur_item->getListener()->performAction(mCurrentSelectedList->getRootFolder(),mCurrentSelectedList->getModel(),"about");
-	}
-	else if ("teleport" == command_name)
-	{
-		onTeleport();
-	}
-	else if ("show_on_map" == command_name)
-	{
-		onShowOnMap();
-	}
-	else if ("create_pick" == command_name)
-	{
-		LLLandmark* landmark = getCurSelectedLandmark();
-		if(!landmark) return;
-		
-		LLViewerRegion* region = gAgent.getRegion();
-		if (!region) return;
-
-		LLGlobalVec pos_global;
-		LLUUID region_id;
-		landmark->getGlobalPos(pos_global);
-		landmark->getRegionID(region_id);
-		LLVector3 region_pos((F32)fmod(pos_global.mdV[VX], (F64)REGION_WIDTH_METERS),
-						  (F32)fmod(pos_global.mdV[VY], (F64)REGION_WIDTH_METERS),
-						  (F32)pos_global.mdV[VZ]);
-
-		LLSD body;
-		std::string url = region->getCapability("RemoteParcelRequest");
-		if (!url.empty())
-		{
-			body["location"] = ll_sd_from_vector3(region_pos);
-			if (!region_id.isNull())
-			{
-				body["region_id"] = region_id;
-			}
-			if (!pos_global.isExactlyZero())
-			{
-				U64 region_handle = to_region_handle(pos_global);
-				body["region_handle"] = ll_sd_from_U64(region_handle);
-			}
-			LLHTTPClient::post(url, body, new LLRemoteParcelRequestResponder(getObserverHandle()));
-		}
-		else 
-		{
-			llwarns << "Can't create pick for landmark for region" << region_id 
-					<< ". Region: "	<< region->getName() 
-					<< " does not support RemoteParcelRequest" << llendl; 
-		}
-	}
-}
-
-/*
-Processes such actions: cut/rename/delete/paste actions
-
-Rules:
- 1. We can't perform any action in Library
- 2. For Landmarks we can:
-	- cut/rename/delete in any other accordions
-	- paste - only in Favorites, Landmarks accordions
- 3. For Folders we can: perform any action in Landmarks accordion, except Received folder
- 4. We can not paste folders from Clipboard (processed by LLFolderView::canPaste())
- 5. Check LLFolderView/Inventory Bridges rules
- */
-bool LLLandmarksPanel::canSelectedBeModified(const std::string& command_name) const
-{
-	// validate own rules first
-
-	// nothing can be modified in Library
-	if (mLibraryInventoryPanel == mCurrentSelectedList) return false;
-
-	bool can_be_modified = false;
-
-	// landmarks can be modified in any other accordion...
-	if (isLandmarkSelected())
-	{
-		can_be_modified = true;
-
-		// we can modify landmarks anywhere except paste to My Inventory
-		if ("paste" == command_name)
-		{
-			can_be_modified = (mCurrentSelectedList != mMyInventoryPanel);
-		}
-	}
-	else
-	{
-		// ...folders only in the Landmarks accordion...
-		can_be_modified = mLandmarksInventoryPanel == mCurrentSelectedList;
-
-		// ...except "Received" folder
-		can_be_modified &= !isReceivedFolderSelected();
-	}
-
-	// then ask LLFolderView permissions
-	if (can_be_modified)
-	{
-		if ("cut" == command_name)
-		{
-			can_be_modified = mCurrentSelectedList->getRootFolder()->canCut();
-		}
-		else if ("rename" == command_name)
-		{
-			can_be_modified = getCurSelectedItem()->getListener()->isItemRenameable();
-		}
-		else if ("delete" == command_name)
-		{
-			can_be_modified = getCurSelectedItem()->getListener()->isItemRemovable();
-		}
-		else if("paste" == command_name)
-		{
-			return mCurrentSelectedList->getRootFolder()->canPaste();
-		}
-		else
-		{
-			llwarns << "Unprocessed command has come: " << command_name << llendl;
-		}
-	}
-
-	return can_be_modified;
-}
-
-void LLLandmarksPanel::onPickPanelExit( LLPanelPickEdit* pick_panel, LLView* owner, const LLSD& params)
-{
-	pick_panel->setVisible(FALSE);
-	owner->removeChild(pick_panel);
-	//we need remove  observer to  avoid  processParcelInfo in the future.
-	LLRemoteParcelInfoProcessor::getInstance()->removeObserver(params["parcel_id"].asUUID(), this);
-
-	delete pick_panel;
-	pick_panel = NULL;
-}
-
-bool LLLandmarksPanel::handleDragAndDropToTrash(BOOL drop, EDragAndDropType cargo_type, EAcceptance* accept)
-{
-	*accept = ACCEPT_NO;
-
-	switch (cargo_type)
-	{
-
-	case DAD_LANDMARK:
-	case DAD_CATEGORY:
-		{
-			bool is_enabled = isActionEnabled("delete");
-
-			if (is_enabled) *accept = ACCEPT_YES_MULTI;
-
-			if (is_enabled && drop)
-			{
-				onClipboardAction("delete");
-			}
-		}
-		break;
-	default:
-		break;
-	}
-
-	return true;
-}
-
-
-void LLLandmarksPanel::doIdle(void* landmarks_panel)
-{
-	LLLandmarksPanel* panel = (LLLandmarksPanel* ) landmarks_panel;
-
-	if (panel->mDirtyFilter)
-	{
-		panel->updateFilteredAccordions();
-	}
-
-}
-
-void LLLandmarksPanel::updateFilteredAccordions()
-{
-	LLInventoryPanel* inventory_list = NULL;
-	LLAccordionCtrlTab* accordion_tab = NULL;
-	for (accordion_tabs_t::const_iterator iter = mAccordionTabs.begin(); iter != mAccordionTabs.end(); ++iter)
-	{
-		accordion_tab = *iter;
-		inventory_list = dynamic_cast<LLInventorySubTreePanel*> (accordion_tab->getAccordionView());
-		if (NULL == inventory_list) continue;
-		LLFolderView* fv = inventory_list->getRootFolder();
-
-		bool has_visible_children = fv->hasVisibleChildren();
-
-		accordion_tab->setVisible(has_visible_children);
-	}
-
-	// we have to arrange accordion tabs for cases when filter string is less restrictive but 
-	// all items are still filtered.
-	static LLAccordionCtrl* accordion = getChild<LLAccordionCtrl>("landmarks_accordion");
-	accordion->arrange();
-
-	// now filter state is applied to accordion tabs
-	mDirtyFilter = false;
-}
-
-
-//////////////////////////////////////////////////////////////////////////
-// HELPER FUNCTIONS
-//////////////////////////////////////////////////////////////////////////
-static void filter_list(LLInventorySubTreePanel* inventory_list, const std::string& string)
-{
-	if (string == "")
-	{
-		inventory_list->setFilterSubString(LLStringUtil::null);
-
-		// re-open folders that were initially open
-		inventory_list->restoreFolderState();
-	}
-
-	gInventory.startBackgroundFetch();
-
-	if (inventory_list->getFilterSubString().empty() && string.empty())
-	{
-		// current filter and new filter empty, do nothing
-		return;
-	}
-
-	// save current folder open state if no filter currently applied
-	if (inventory_list->getRootFolder()->getFilterSubString().empty())
-	{
-		inventory_list->saveFolderState();
-	}
-
-	// set new filter string
-	inventory_list->setFilterSubString(string);
-}
-// EOF
+/**
+ * @file llpanellandmarks.cpp
+ * @brief Landmarks tab for Side Bar "Places" panel
+ *
+ * $LicenseInfo:firstyear=2009&license=viewergpl$
+ *
+ * Copyright (c) 2001-2009, Linden Research, Inc.
+ *
+ * Second Life Viewer Source Code
+ * The source code in this file ("Source Code") is provided by Linden Lab
+ * to you under the terms of the GNU General Public License, version 2.0
+ * ("GPL"), unless you have obtained a separate licensing agreement
+ * ("Other License"), formally executed by you and Linden Lab.  Terms of
+ * the GPL can be found in doc/GPL-license.txt in this distribution, or
+ * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
+ *
+ * There are special exceptions to the terms and conditions of the GPL as
+ * it is applied to this Source Code. View the full text of the exception
+ * in the file doc/FLOSS-exception.txt in this software distribution, or
+ * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception
+ *
+ * By copying, modifying or distributing this software, you acknowledge
+ * that you have read and understood your obligations described above,
+ * and agree to abide by those obligations.
+ *
+ * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
+ * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
+ * COMPLETENESS OR PERFORMANCE.
+ * $/LicenseInfo$
+ */
+
+#include "llviewerprecompiledheaders.h"
+
+#include "llpanellandmarks.h"
+
+#include "llbutton.h"
+#include "llfloaterreg.h"
+#include "llsdutil.h"
+#include "llsdutil_math.h"
+
+#include "llaccordionctrl.h"
+#include "llaccordionctrltab.h"
+#include "llagent.h"
+#include "llagentpicksinfo.h"
+#include "llagentui.h"
+#include "llcallbacklist.h"
+#include "lldndbutton.h"
+#include "llfloaterworldmap.h"
+#include "llfolderviewitem.h"
+#include "llinventorypanel.h"
+#include "llinventorysubtreepanel.h"
+#include "lllandmarkactions.h"
+#include "llplacesinventorybridge.h"
+#include "llsidetray.h"
+#include "llviewermenu.h"
+#include "llviewerregion.h"
+
+// Not yet implemented; need to remove buildPanel() from constructor when we switch
+//static LLRegisterPanelClassWrapper<LLLandmarksPanel> t_landmarks("panel_landmarks");
+
+static const std::string OPTIONS_BUTTON_NAME = "options_gear_btn";
+static const std::string ADD_BUTTON_NAME = "add_btn";
+static const std::string ADD_FOLDER_BUTTON_NAME = "add_folder_btn";
+static const std::string TRASH_BUTTON_NAME = "trash_btn";
+
+
+// helper functions
+static void filter_list(LLInventorySubTreePanel* inventory_list, const std::string& string);
+
+
+LLLandmarksPanel::LLLandmarksPanel()
+	:	LLPanelPlacesTab()
+	,	mFavoritesInventoryPanel(NULL)
+	,	mLandmarksInventoryPanel(NULL)
+	,	mMyInventoryPanel(NULL)
+	,	mLibraryInventoryPanel(NULL)
+	,	mCurrentSelectedList(NULL)
+	,	mListCommands(NULL)
+	,	mGearFolderMenu(NULL)
+	,	mGearLandmarkMenu(NULL)
+	,	mDirtyFilter(false)
+{
+	LLUICtrlFactory::getInstance()->buildPanel(this, "panel_landmarks.xml");
+}
+
+LLLandmarksPanel::~LLLandmarksPanel()
+{
+}
+
+BOOL LLLandmarksPanel::postBuild()
+{
+	if (!gInventory.isInventoryUsable())
+		return FALSE;
+
+	// mast be called before any other initXXX methods to init Gear menu
+	initListCommandsHandlers();
+
+	U32 sort_order = gSavedSettings.getU32(LLInventoryPanel::DEFAULT_SORT_ORDER);
+	mSortByDate = sort_order & LLInventoryFilter::SO_DATE;
+	initFavoritesInventroyPanel();
+	initLandmarksInventroyPanel();
+	initMyInventroyPanel();
+	initLibraryInventroyPanel();
+
+	gIdleCallbacks.addFunction(LLLandmarksPanel::doIdle, this);
+	return TRUE;
+}
+
+// virtual
+void LLLandmarksPanel::onSearchEdit(const std::string& string)
+{
+	static std::string prev_string("");
+
+	if (prev_string == string) return;
+
+	// show all folders in Landmarks Accordion for empty filter
+	mLandmarksInventoryPanel->setShowFolderState(string.empty() ?
+		LLInventoryFilter::SHOW_ALL_FOLDERS :
+		LLInventoryFilter::SHOW_NON_EMPTY_FOLDERS
+		);
+
+	filter_list(mFavoritesInventoryPanel, string);
+	filter_list(mLandmarksInventoryPanel, string);
+	filter_list(mMyInventoryPanel, string);
+	filter_list(mLibraryInventoryPanel, string);
+
+	prev_string = string;
+	mDirtyFilter = true;
+
+	// give FolderView a chance to be refreshed. So, made all accordions visible
+	for (accordion_tabs_t::const_iterator iter = mAccordionTabs.begin(); iter != mAccordionTabs.end(); ++iter)
+	{
+		LLAccordionCtrlTab* tab = *iter;
+		tab->setVisible(true);
+	}
+}
+
+// virtual
+void LLLandmarksPanel::onShowOnMap()
+{
+	if (NULL == mCurrentSelectedList)
+	{
+		llwarns << "There are no selected list. No actions are performed." << llendl;
+		return;
+	}
+	LLLandmark* landmark = getCurSelectedLandmark();
+	if (!landmark)
+		return;
+
+	LLVector3d landmark_global_pos;
+	if (!landmark->getGlobalPos(landmark_global_pos))
+		return;
+	
+	LLFloaterWorldMap* worldmap_instance = LLFloaterWorldMap::getInstance();
+	if (!landmark_global_pos.isExactlyZero() && worldmap_instance)
+	{
+		worldmap_instance->trackLocation(landmark_global_pos);
+		LLFloaterReg::showInstance("world_map", "center");
+	}
+}
+
+// virtual
+void LLLandmarksPanel::onTeleport()
+{
+	LLFolderViewItem* current_item = getCurSelectedItem();
+	if (!current_item)
+	{
+		llwarns << "There are no selected list. No actions are performed." << llendl;
+		return;
+	}
+
+	LLFolderViewEventListener* listenerp = current_item->getListener();
+	if (listenerp->getInventoryType() == LLInventoryType::IT_LANDMARK)
+	{
+		listenerp->openItem();
+	}
+}
+
+// virtual
+void LLLandmarksPanel::updateVerbs()
+{
+	if (!isTabVisible()) 
+		return;
+
+	BOOL enabled = isLandmarkSelected();
+	mTeleportBtn->setEnabled(enabled);
+	mShowOnMapBtn->setEnabled(enabled);
+
+	// TODO: mantipov: Uncomment when mShareBtn is supported
+	// Share button should be enabled when neither a folder nor a landmark is selected
+	//mShareBtn->setEnabled(NULL != current_item);
+
+	updateListCommands();
+}
+
+void LLLandmarksPanel::onSelectionChange(LLInventorySubTreePanel* inventory_list, const std::deque<LLFolderViewItem*> &items, BOOL user_action)
+{
+	if (user_action && (items.size() > 0))
+	{
+		deselectOtherThan(inventory_list);
+		mCurrentSelectedList = inventory_list;
+	}
+
+	LLFolderViewItem* current_item = inventory_list->getRootFolder()->getCurSelectedItem();
+	if (!current_item)
+		return;
+
+	updateVerbs();
+}
+
+void LLLandmarksPanel::onSelectorButtonClicked()
+{
+	// TODO: mantipov: update getting of selected item
+	// TODO: bind to "i" button
+	LLFolderViewItem* cur_item = mFavoritesInventoryPanel->getRootFolder()->getCurSelectedItem();
+
+	LLFolderViewEventListener* listenerp = cur_item->getListener();
+	if (listenerp->getInventoryType() == LLInventoryType::IT_LANDMARK)
+	{
+		LLSD key;
+		key["type"] = "landmark";
+		key["id"] = listenerp->getUUID();
+
+		LLSideTray::getInstance()->showPanel("panel_places", key);
+	}
+}
+
+//////////////////////////////////////////////////////////////////////////
+// PROTECTED METHODS
+//////////////////////////////////////////////////////////////////////////
+
+bool LLLandmarksPanel::isLandmarkSelected() const 
+{
+	LLFolderViewItem* current_item = getCurSelectedItem();
+	if(current_item && current_item->getListener()->getInventoryType() == LLInventoryType::IT_LANDMARK)
+	{
+		return true;
+	}
+
+	return false;
+}
+
+bool LLLandmarksPanel::isReceivedFolderSelected() const
+{
+	// Received Folder can be only in Landmarks accordion
+	if (mCurrentSelectedList != mLandmarksInventoryPanel) return false;
+
+	// *TODO: it should be filled with logic when EXT-976 is done.
+
+	llwarns << "Not implemented yet until EXT-976 is done." << llendl;
+
+	return false;
+}
+LLLandmark* LLLandmarksPanel::getCurSelectedLandmark() const
+{
+
+	LLFolderViewItem* cur_item = getCurSelectedItem();
+	if(cur_item && cur_item->getListener()->getInventoryType() == LLInventoryType::IT_LANDMARK)
+	{ 
+		return LLLandmarkActions::getLandmark(cur_item->getListener()->getUUID());
+	}
+	return NULL;
+}
+
+LLFolderViewItem* LLLandmarksPanel::getCurSelectedItem () const 
+{
+	return mCurrentSelectedList ?  mCurrentSelectedList->getRootFolder()->getCurSelectedItem() : NULL;
+}
+
+void LLLandmarksPanel::updateSortOrder(LLInventoryPanel* panel, bool byDate)
+{
+	if(!panel) return; 
+
+	U32 order = panel->getSortOrder();
+	if (byDate)
+	{
+		panel->setSortOrder( order | LLInventoryFilter::SO_DATE );
+	}
+	else 
+	{
+		panel->setSortOrder( order & ~LLInventoryFilter::SO_DATE );
+	}
+}
+
+// virtual
+void LLLandmarksPanel::processParcelInfo(const LLParcelData& parcel_data)
+{
+	//this function will be called after user will try to create a pick for selected landmark.
+	// We have to make request to sever to get parcel_id and snaption_id. 
+	if(isLandmarkSelected())
+	{
+		LLLandmark* landmark  =  getCurSelectedLandmark();
+		LLFolderViewItem* cur_item = getCurSelectedItem();
+		LLUUID id = cur_item->getListener()->getUUID();
+		LLInventoryItem* inv_item =  mCurrentSelectedList->getModel()->getItem(id);
+		if(landmark)
+		{
+			LLPanelPickEdit* panel_pick = LLPanelPickEdit::create();
+			LLVector3d landmark_global_pos;
+			landmark->getGlobalPos(landmark_global_pos);
+
+			// let's toggle pick panel into  panel places
+			LLPanel* panel_places =  LLSideTray::getInstance()->getChild<LLPanel>("panel_places");//-> sidebar_places
+			panel_places->addChild(panel_pick);
+			LLRect paren_rect(panel_places->getRect());
+			panel_pick->reshape(paren_rect.getWidth(),paren_rect.getHeight(), TRUE);
+			panel_pick->setRect(paren_rect);
+			panel_pick->onOpen(LLSD());
+
+			LLPickData data;
+			data.pos_global = landmark_global_pos;
+			data.name = cur_item->getName();
+			data.desc = inv_item->getDescription();
+			data.snapshot_id = parcel_data.snapshot_id;
+			data.parcel_id = parcel_data.parcel_id;
+			panel_pick->setPickData(&data);
+
+			LLSD params;
+			params["parcel_id"] =parcel_data.parcel_id;
+			/* set exit callback to get back onto panel places  
+			 in callback we will make cleaning up( delete pick_panel instance, 
+			 remove landmark panel from observer list
+			*/ 
+			panel_pick->setExitCallback(boost::bind(&LLLandmarksPanel::onPickPanelExit,this,
+					panel_pick, panel_places,params));
+			panel_pick->setSaveCallback(boost::bind(&LLLandmarksPanel::onPickPanelExit,this,
+				panel_pick, panel_places,params));
+			panel_pick->setCancelCallback(boost::bind(&LLLandmarksPanel::onPickPanelExit,this,
+							panel_pick, panel_places,params));
+		}
+	}
+}
+
+// virtual
+void LLLandmarksPanel::setParcelID(const LLUUID& parcel_id)
+{
+	if (!parcel_id.isNull())
+	{
+		LLRemoteParcelInfoProcessor::getInstance()->addObserver(parcel_id, this);
+		LLRemoteParcelInfoProcessor::getInstance()->sendParcelInfoRequest(parcel_id);
+	}
+}
+
+// virtual
+void LLLandmarksPanel::setErrorStatus(U32 status, const std::string& reason)
+{
+	llerrs<< "Can't handle remote parcel request."<< " Http Status: "<< status << ". Reason : "<< reason<<llendl;
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+// PRIVATE METHODS
+//////////////////////////////////////////////////////////////////////////
+
+void LLLandmarksPanel::initFavoritesInventroyPanel()
+{
+	mFavoritesInventoryPanel = getChild<LLInventorySubTreePanel>("favorites_list");
+
+	initLandmarksPanel(mFavoritesInventoryPanel);
+
+	initAccordion("tab_favorites", mFavoritesInventoryPanel);
+}
+
+void LLLandmarksPanel::initLandmarksInventroyPanel()
+{
+	mLandmarksInventoryPanel = getChild<LLInventorySubTreePanel>("landmarks_list");
+
+	initLandmarksPanel(mLandmarksInventoryPanel);
+
+	mLandmarksInventoryPanel->setShowFolderState(LLInventoryFilter::SHOW_ALL_FOLDERS);
+
+	// subscribe to have auto-rename functionality while creating New Folder
+	mLandmarksInventoryPanel->setSelectCallback(boost::bind(&LLInventoryPanel::onSelectionChange, mLandmarksInventoryPanel, _1, _2));
+
+	initAccordion("tab_landmarks", mLandmarksInventoryPanel);
+}
+
+void LLLandmarksPanel::initMyInventroyPanel()
+{
+	mMyInventoryPanel= getChild<LLInventorySubTreePanel>("my_inventory_list");
+
+	initLandmarksPanel(mMyInventoryPanel);
+
+	initAccordion("tab_inventory", mMyInventoryPanel);
+}
+
+void LLLandmarksPanel::initLibraryInventroyPanel()
+{
+	mLibraryInventoryPanel = getChild<LLInventorySubTreePanel>("library_list");
+
+	initLandmarksPanel(mLibraryInventoryPanel);
+
+	initAccordion("tab_library", mLibraryInventoryPanel);
+}
+
+void LLLandmarksPanel::initLandmarksPanel(LLInventorySubTreePanel* inventory_list)
+{
+	inventory_list->setFilterTypes(0x1 << LLInventoryType::IT_LANDMARK);
+	inventory_list->setSelectCallback(boost::bind(&LLLandmarksPanel::onSelectionChange, this, inventory_list, _1, _2));
+
+	inventory_list->setShowFolderState(LLInventoryFilter::SHOW_NON_EMPTY_FOLDERS);
+	updateSortOrder(inventory_list, mSortByDate);
+
+	LLPlacesFolderView* root_folder = dynamic_cast<LLPlacesFolderView*>(inventory_list->getRootFolder());
+	if (root_folder)
+	{
+		root_folder->setupMenuHandle(LLInventoryType::IT_CATEGORY, mGearFolderMenu->getHandle());
+		root_folder->setupMenuHandle(LLInventoryType::IT_LANDMARK, mGearLandmarkMenu->getHandle());
+	}
+
+	// save initial folder state to avoid incorrect work while switching between Landmarks & Teleport History tabs
+	// See EXT-1609.
+	inventory_list->saveFolderState();
+}
+
+void LLLandmarksPanel::initAccordion(const std::string& accordion_tab_name, LLInventorySubTreePanel* inventory_list)
+{
+	LLAccordionCtrlTab* accordion_tab = getChild<LLAccordionCtrlTab>(accordion_tab_name);
+	mAccordionTabs.push_back(accordion_tab);
+	accordion_tab->setDropDownStateChangedCallback(
+		boost::bind(&LLLandmarksPanel::onAccordionExpandedCollapsed, this, _2, inventory_list));
+}
+
+void LLLandmarksPanel::onAccordionExpandedCollapsed(const LLSD& param, LLInventorySubTreePanel* inventory_list)
+{
+	bool expanded = param.asBoolean();
+
+	if(!expanded && (mCurrentSelectedList == inventory_list))
+	{
+		inventory_list->getRootFolder()->clearSelection();
+
+		mCurrentSelectedList = NULL;
+		updateVerbs();
+	}
+}
+
+void LLLandmarksPanel::deselectOtherThan(const LLInventorySubTreePanel* inventory_list)
+{
+	if (inventory_list != mFavoritesInventoryPanel)
+	{
+		mFavoritesInventoryPanel->getRootFolder()->clearSelection();
+	}
+
+	if (inventory_list != mLandmarksInventoryPanel)
+	{
+		mLandmarksInventoryPanel->getRootFolder()->clearSelection();
+	}
+	if (inventory_list != mMyInventoryPanel)
+	{
+		mMyInventoryPanel->getRootFolder()->clearSelection();
+	}
+	if (inventory_list != mLibraryInventoryPanel)
+	{
+		mLibraryInventoryPanel->getRootFolder()->clearSelection();
+	}
+}
+
+// List Commands Handlers
+void LLLandmarksPanel::initListCommandsHandlers()
+{
+	mListCommands = getChild<LLPanel>("bottom_panel");
+
+	mListCommands->childSetAction(OPTIONS_BUTTON_NAME, boost::bind(&LLLandmarksPanel::onActionsButtonClick, this));
+	mListCommands->childSetAction(TRASH_BUTTON_NAME, boost::bind(&LLLandmarksPanel::onTrashButtonClick, this));
+	mListCommands->getChild<LLButton>(ADD_BUTTON_NAME)->setHeldDownCallback(boost::bind(&LLLandmarksPanel::onAddButtonHeldDown, this));
+	static const LLSD add_landmark_command("add_landmark");
+	mListCommands->childSetAction(ADD_BUTTON_NAME, boost::bind(&LLLandmarksPanel::onAddAction, this, add_landmark_command));
+
+	LLDragAndDropButton* trash_btn = mListCommands->getChild<LLDragAndDropButton>(TRASH_BUTTON_NAME);
+	trash_btn->setDragAndDropHandler(boost::bind(&LLLandmarksPanel::handleDragAndDropToTrash, this
+			,	_4 // BOOL drop
+			,	_5 // EDragAndDropType cargo_type
+			,	_7 // EAcceptance* accept
+			));
+
+	mCommitCallbackRegistrar.add("Places.LandmarksGear.Add.Action", boost::bind(&LLLandmarksPanel::onAddAction, this, _2));
+	mCommitCallbackRegistrar.add("Places.LandmarksGear.CopyPaste.Action", boost::bind(&LLLandmarksPanel::onClipboardAction, this, _2));
+	mCommitCallbackRegistrar.add("Places.LandmarksGear.Custom.Action", boost::bind(&LLLandmarksPanel::onCustomAction, this, _2));
+	mCommitCallbackRegistrar.add("Places.LandmarksGear.Folding.Action", boost::bind(&LLLandmarksPanel::onFoldingAction, this, _2));
+	mEnableCallbackRegistrar.add("Places.LandmarksGear.Check", boost::bind(&LLLandmarksPanel::isActionChecked, this, _2));
+	mEnableCallbackRegistrar.add("Places.LandmarksGear.Enable", boost::bind(&LLLandmarksPanel::isActionEnabled, this, _2));
+	mGearLandmarkMenu = LLUICtrlFactory::getInstance()->createFromFile<LLMenuGL>("menu_places_gear_landmark.xml", gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance());
+	mGearFolderMenu = LLUICtrlFactory::getInstance()->createFromFile<LLMenuGL>("menu_places_gear_folder.xml", gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance());
+	mMenuAdd = LLUICtrlFactory::getInstance()->createFromFile<LLMenuGL>("menu_place_add_button.xml", gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance());
+}
+
+
+void LLLandmarksPanel::updateListCommands()
+{
+	bool add_folder_enabled = isActionEnabled("category");
+	bool trash_enabled = isActionEnabled("delete");
+
+	// keep Options & Add Landmark buttons always enabled
+	mListCommands->childSetEnabled(ADD_FOLDER_BUTTON_NAME, add_folder_enabled);
+	mListCommands->childSetEnabled(TRASH_BUTTON_NAME, trash_enabled);
+}
+
+void LLLandmarksPanel::onActionsButtonClick()
+{
+	LLFolderViewItem* cur_item = NULL;
+	if(mCurrentSelectedList)
+		cur_item = mCurrentSelectedList->getRootFolder()->getCurSelectedItem();
+	
+	if(!cur_item)
+		return;
+	
+	LLFolderViewEventListener* listenerp = cur_item->getListener();
+	
+	LLMenuGL* menu  =NULL;
+	if (listenerp->getInventoryType() == LLInventoryType::IT_LANDMARK)
+	{
+		menu = mGearLandmarkMenu;
+	}
+	else if (listenerp->getInventoryType() == LLInventoryType::IT_CATEGORY)
+	{
+		mGearFolderMenu->getChild<LLMenuItemCallGL>("expand")->setVisible(!cur_item->isOpen());
+		mGearFolderMenu->getChild<LLMenuItemCallGL>("collapse")->setVisible(cur_item->isOpen());
+		menu = mGearFolderMenu;
+	}
+	showActionMenu(menu,OPTIONS_BUTTON_NAME);
+}
+
+void LLLandmarksPanel::onAddButtonHeldDown()
+{
+	showActionMenu(mMenuAdd,ADD_BUTTON_NAME);
+}
+
+void LLLandmarksPanel::showActionMenu(LLMenuGL* menu, std::string spawning_view_name)
+{
+	if (menu)
+	{
+		menu->buildDrawLabels();
+		menu->updateParent(LLMenuGL::sMenuContainer);
+		LLView* spawning_view = getChild<LLView> (spawning_view_name);
+		S32 menu_x, menu_y;
+		//show menu in co-ordinates of panel
+		spawning_view->localPointToOtherView(0, spawning_view->getRect().getHeight(), &menu_x, &menu_y, this);
+		menu_y += menu->getRect().getHeight();
+		LLMenuGL::showPopup(this, menu, menu_x, menu_y);
+	}
+}
+
+void LLLandmarksPanel::onTrashButtonClick() const
+{
+	onClipboardAction("delete");
+}
+
+void LLLandmarksPanel::onAddAction(const LLSD& userdata) const
+{
+	std::string command_name = userdata.asString();
+	if("add_landmark" == command_name)
+	{
+		if(LLLandmarkActions::landmarkAlreadyExists())
+		{
+			std::string location;
+			LLAgentUI::buildLocationString(location, LLAgentUI::LOCATION_FORMAT_FULL);
+			llwarns<<" Landmark already exists at location:  "<< location<<llendl;
+			return;
+		}
+		LLSideTray::getInstance()->showPanel("panel_places", LLSD().insert("type", "create_landmark"));
+	} 
+	else if ("category" == command_name)
+	{
+		LLFolderViewItem* item = getCurSelectedItem();
+		if (item && mCurrentSelectedList == mLandmarksInventoryPanel)
+		{
+			LLFolderViewEventListener* folder_bridge = NULL;
+			if (item-> getListener()->getInventoryType()
+					== LLInventoryType::IT_LANDMARK)
+			{
+				// for a landmark get parent folder bridge
+				folder_bridge = item->getParentFolder()->getListener();
+			}
+			else if (item-> getListener()->getInventoryType()
+					== LLInventoryType::IT_CATEGORY)
+			{
+				// for a folder get its own bridge
+				folder_bridge = item->getListener();
+			}
+
+			menu_create_inventory_item(mCurrentSelectedList->getRootFolder(),
+					dynamic_cast<LLFolderBridge*> (folder_bridge), LLSD(
+							"category"), gInventory.findCategoryUUIDForType(
+							LLAssetType::AT_LANDMARK));
+		}
+	}
+}
+
+void LLLandmarksPanel::onClipboardAction(const LLSD& userdata) const
+{
+	if(!mCurrentSelectedList) 
+		return;
+	std::string command_name = userdata.asString();
+    if("copy_slurl" == command_name)
+	{
+    	LLFolderViewItem* cur_item = getCurSelectedItem();
+		if(cur_item)
+			LLLandmarkActions::copySLURLtoClipboard(cur_item->getListener()->getUUID());
+	}
+	else if ( "paste" == command_name)
+	{
+		mCurrentSelectedList->getRootFolder()->paste();
+	} 
+	else if ( "cut" == command_name)
+	{
+		mCurrentSelectedList->getRootFolder()->cut();
+	}
+	else
+	{
+		mCurrentSelectedList->getRootFolder()->doToSelected(mCurrentSelectedList->getModel(),command_name);
+	}
+}
+
+void LLLandmarksPanel::onFoldingAction(const LLSD& userdata)
+{
+	if(!mCurrentSelectedList) return;
+
+	LLFolderView* root_folder = mCurrentSelectedList->getRootFolder();
+	std::string command_name = userdata.asString();
+
+	if ("expand_all" == command_name)
+	{
+		root_folder->setOpenArrangeRecursively(TRUE, LLFolderViewFolder::RECURSE_DOWN);
+		root_folder->arrangeAll();
+	}
+	else if ("collapse_all" == command_name)
+	{
+		root_folder->closeAllFolders();
+	}
+	else if ( "sort_by_date" == command_name)
+	{
+		mSortByDate = !mSortByDate;
+		updateSortOrder(mLandmarksInventoryPanel, mSortByDate);
+		updateSortOrder(mMyInventoryPanel, mSortByDate);
+		updateSortOrder(mLibraryInventoryPanel, mSortByDate);
+	}
+	else
+	{
+		root_folder->doToSelected(&gInventory, userdata);
+	}
+}
+
+bool LLLandmarksPanel::isActionChecked(const LLSD& userdata) const
+{
+	const std::string command_name = userdata.asString();
+
+	if ( "sort_by_date" == command_name)
+	{
+		return  mSortByDate;
+	}
+
+	return false;
+}
+
+bool LLLandmarksPanel::isActionEnabled(const LLSD& userdata) const
+{
+	std::string command_name = userdata.asString();
+
+
+	LLPlacesFolderView* rootFolderView = mCurrentSelectedList ?
+		static_cast<LLPlacesFolderView*>(mCurrentSelectedList->getRootFolder()) : NULL;
+
+	if (NULL == rootFolderView) return false;
+
+	// disable some commands for multi-selection. EXT-1757
+	if (rootFolderView->getSelectedCount() > 1)
+	{
+		if (   "teleport"		== command_name 
+			|| "more_info"		== command_name
+			|| "rename"			== command_name
+			|| "show_on_map"	== command_name
+			|| "copy_slurl"		== command_name
+			)
+		{
+			return false;
+		}
+
+	}
+
+	// disable some commands for Favorites accordion. EXT-1758
+	if (mCurrentSelectedList == mFavoritesInventoryPanel)
+	{
+		if (   "expand_all"		== command_name
+			|| "collapse_all"	== command_name
+			|| "sort_by_date"	== command_name
+			)
+			return false;
+	}
+
+
+	if("category" == command_name)
+	{
+		// we can add folder only in Landmarks Accordion
+		if (mCurrentSelectedList == mLandmarksInventoryPanel)
+		{
+			// ... but except Received folder
+			return !isReceivedFolderSelected();
+		}
+		else return false;
+	}
+	else if("paste" == command_name || "rename" == command_name || "cut" == command_name || "delete" == command_name)
+	{
+		return canSelectedBeModified(command_name);
+	}
+	else if ( "sort_by_date" == command_name)
+	{
+		return  mSortByDate;
+	}
+	else if("create_pick" == command_name)
+	{
+		return !LLAgentPicksInfo::getInstance()->isPickLimitReached();
+	}
+	else
+	{
+		llwarns << "Unprocessed command has come: " << command_name << llendl;
+	}
+
+	return true;
+}
+
+void LLLandmarksPanel::onCustomAction(const LLSD& userdata)
+{
+	LLFolderViewItem* cur_item = getCurSelectedItem();
+	if(!cur_item)
+		return ;
+	std::string command_name = userdata.asString();
+	if("more_info" == command_name)
+	{
+		cur_item->getListener()->performAction(mCurrentSelectedList->getRootFolder(),mCurrentSelectedList->getModel(),"about");
+	}
+	else if ("teleport" == command_name)
+	{
+		onTeleport();
+	}
+	else if ("show_on_map" == command_name)
+	{
+		onShowOnMap();
+	}
+	else if ("create_pick" == command_name)
+	{
+		LLLandmark* landmark = getCurSelectedLandmark();
+		if(!landmark) return;
+		
+		LLViewerRegion* region = gAgent.getRegion();
+		if (!region) return;
+
+		LLGlobalVec pos_global;
+		LLUUID region_id;
+		landmark->getGlobalPos(pos_global);
+		landmark->getRegionID(region_id);
+		LLVector3 region_pos((F32)fmod(pos_global.mdV[VX], (F64)REGION_WIDTH_METERS),
+						  (F32)fmod(pos_global.mdV[VY], (F64)REGION_WIDTH_METERS),
+						  (F32)pos_global.mdV[VZ]);
+
+		LLSD body;
+		std::string url = region->getCapability("RemoteParcelRequest");
+		if (!url.empty())
+		{
+			body["location"] = ll_sd_from_vector3(region_pos);
+			if (!region_id.isNull())
+			{
+				body["region_id"] = region_id;
+			}
+			if (!pos_global.isExactlyZero())
+			{
+				U64 region_handle = to_region_handle(pos_global);
+				body["region_handle"] = ll_sd_from_U64(region_handle);
+			}
+			LLHTTPClient::post(url, body, new LLRemoteParcelRequestResponder(getObserverHandle()));
+		}
+		else 
+		{
+			llwarns << "Can't create pick for landmark for region" << region_id 
+					<< ". Region: "	<< region->getName() 
+					<< " does not support RemoteParcelRequest" << llendl; 
+		}
+	}
+}
+
+/*
+Processes such actions: cut/rename/delete/paste actions
+
+Rules:
+ 1. We can't perform any action in Library
+ 2. For Landmarks we can:
+	- cut/rename/delete in any other accordions
+	- paste - only in Favorites, Landmarks accordions
+ 3. For Folders we can: perform any action in Landmarks accordion, except Received folder
+ 4. We can not paste folders from Clipboard (processed by LLFolderView::canPaste())
+ 5. Check LLFolderView/Inventory Bridges rules
+ */
+bool LLLandmarksPanel::canSelectedBeModified(const std::string& command_name) const
+{
+	// validate own rules first
+
+	// nothing can be modified in Library
+	if (mLibraryInventoryPanel == mCurrentSelectedList) return false;
+
+	bool can_be_modified = false;
+
+	// landmarks can be modified in any other accordion...
+	if (isLandmarkSelected())
+	{
+		can_be_modified = true;
+
+		// we can modify landmarks anywhere except paste to My Inventory
+		if ("paste" == command_name)
+		{
+			can_be_modified = (mCurrentSelectedList != mMyInventoryPanel);
+		}
+	}
+	else
+	{
+		// ...folders only in the Landmarks accordion...
+		can_be_modified = mLandmarksInventoryPanel == mCurrentSelectedList;
+
+		// ...except "Received" folder
+		can_be_modified &= !isReceivedFolderSelected();
+	}
+
+	// then ask LLFolderView permissions
+	if (can_be_modified)
+	{
+		if ("cut" == command_name)
+		{
+			can_be_modified = mCurrentSelectedList->getRootFolder()->canCut();
+		}
+		else if ("rename" == command_name)
+		{
+			can_be_modified = getCurSelectedItem()->getListener()->isItemRenameable();
+		}
+		else if ("delete" == command_name)
+		{
+			can_be_modified = getCurSelectedItem()->getListener()->isItemRemovable();
+		}
+		else if("paste" == command_name)
+		{
+			return mCurrentSelectedList->getRootFolder()->canPaste();
+		}
+		else
+		{
+			llwarns << "Unprocessed command has come: " << command_name << llendl;
+		}
+	}
+
+	return can_be_modified;
+}
+
+void LLLandmarksPanel::onPickPanelExit( LLPanelPickEdit* pick_panel, LLView* owner, const LLSD& params)
+{
+	pick_panel->setVisible(FALSE);
+	owner->removeChild(pick_panel);
+	//we need remove  observer to  avoid  processParcelInfo in the future.
+	LLRemoteParcelInfoProcessor::getInstance()->removeObserver(params["parcel_id"].asUUID(), this);
+
+	delete pick_panel;
+	pick_panel = NULL;
+}
+
+bool LLLandmarksPanel::handleDragAndDropToTrash(BOOL drop, EDragAndDropType cargo_type, EAcceptance* accept)
+{
+	*accept = ACCEPT_NO;
+
+	switch (cargo_type)
+	{
+
+	case DAD_LANDMARK:
+	case DAD_CATEGORY:
+		{
+			bool is_enabled = isActionEnabled("delete");
+
+			if (is_enabled) *accept = ACCEPT_YES_MULTI;
+
+			if (is_enabled && drop)
+			{
+				onClipboardAction("delete");
+			}
+		}
+		break;
+	default:
+		break;
+	}
+
+	return true;
+}
+
+
+void LLLandmarksPanel::doIdle(void* landmarks_panel)
+{
+	LLLandmarksPanel* panel = (LLLandmarksPanel* ) landmarks_panel;
+
+	if (panel->mDirtyFilter)
+	{
+		panel->updateFilteredAccordions();
+	}
+
+}
+
+void LLLandmarksPanel::updateFilteredAccordions()
+{
+	LLInventoryPanel* inventory_list = NULL;
+	LLAccordionCtrlTab* accordion_tab = NULL;
+	for (accordion_tabs_t::const_iterator iter = mAccordionTabs.begin(); iter != mAccordionTabs.end(); ++iter)
+	{
+		accordion_tab = *iter;
+		inventory_list = dynamic_cast<LLInventorySubTreePanel*> (accordion_tab->getAccordionView());
+		if (NULL == inventory_list) continue;
+		LLFolderView* fv = inventory_list->getRootFolder();
+
+		bool has_visible_children = fv->hasVisibleChildren();
+
+		accordion_tab->setVisible(has_visible_children);
+	}
+
+	// we have to arrange accordion tabs for cases when filter string is less restrictive but 
+	// all items are still filtered.
+	static LLAccordionCtrl* accordion = getChild<LLAccordionCtrl>("landmarks_accordion");
+	accordion->arrange();
+
+	// now filter state is applied to accordion tabs
+	mDirtyFilter = false;
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+// HELPER FUNCTIONS
+//////////////////////////////////////////////////////////////////////////
+static void filter_list(LLInventorySubTreePanel* inventory_list, const std::string& string)
+{
+	if (string == "")
+	{
+		inventory_list->setFilterSubString(LLStringUtil::null);
+
+		// re-open folders that were initially open
+		inventory_list->restoreFolderState();
+	}
+
+	gInventory.startBackgroundFetch();
+
+	if (inventory_list->getFilterSubString().empty() && string.empty())
+	{
+		// current filter and new filter empty, do nothing
+		return;
+	}
+
+	// save current folder open state if no filter currently applied
+	if (inventory_list->getRootFolder()->getFilterSubString().empty())
+	{
+		inventory_list->saveFolderState();
+	}
+
+	// set new filter string
+	inventory_list->setFilterSubString(string);
+}
+// EOF
diff --git a/indra/newview/llpanelmaininventory.cpp b/indra/newview/llpanelmaininventory.cpp
new file mode 100644
index 00000000000..ca567018e7a
--- /dev/null
+++ b/indra/newview/llpanelmaininventory.cpp
@@ -0,0 +1,818 @@
+/** 
+ * @file llsidepanelmaininventory.cpp
+ * @brief Implementation of llsidepanelmaininventory.
+ *
+ * $LicenseInfo:firstyear=2001&license=viewergpl$
+ * 
+ * Copyright (c) 2001-2009, Linden Research, Inc.
+ * 
+ * Second Life Viewer Source Code
+ * The source code in this file ("Source Code") is provided by Linden Lab
+ * to you under the terms of the GNU General Public License, version 2.0
+ * ("GPL"), unless you have obtained a separate licensing agreement
+ * ("Other License"), formally executed by you and Linden Lab.  Terms of
+ * the GPL can be found in doc/GPL-license.txt in this distribution, or
+ * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
+ * 
+ * There are special exceptions to the terms and conditions of the GPL as
+ * it is applied to this Source Code. View the full text of the exception
+ * in the file doc/FLOSS-exception.txt in this software distribution, or
+ * online at
+ * http://secondlifegrid.net/programs/open_source/licensing/flossexception
+ * 
+ * By copying, modifying or distributing this software, you acknowledge
+ * that you have read and understood your obligations described above,
+ * and agree to abide by those obligations.
+ * 
+ * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
+ * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
+ * COMPLETENESS OR PERFORMANCE.
+ * $/LicenseInfo$
+ */
+
+#include "llviewerprecompiledheaders.h"
+#include "llpanelmaininventory.h"
+
+#include "llfloaterinventory.h"
+#include "llinventorybridge.h"
+#include "llinventoryfunctions.h"
+#include "llinventorypanel.h"
+#include "llfiltereditor.h"
+#include "llfloaterreg.h"
+#include "llscrollcontainer.h"
+#include "llsdserialize.h"
+#include "llspinctrl.h"
+#include "lltooldraganddrop.h"
+
+static LLRegisterPanelClassWrapper<LLPanelMainInventory> t_inventory("panel_main_inventory"); // Seraph is this redundant with constructor?
+
+///----------------------------------------------------------------------------
+/// LLFloaterInventoryFinder
+///----------------------------------------------------------------------------
+
+class LLFloaterInventoryFinder : public LLFloater
+{
+public:
+	LLFloaterInventoryFinder( LLPanelMainInventory* inventory_view);
+	virtual void draw();
+	/*virtual*/	BOOL	postBuild();
+	void changeFilter(LLInventoryFilter* filter);
+	void updateElementsFromFilter();
+	BOOL getCheckShowEmpty();
+	BOOL getCheckSinceLogoff();
+
+	static void onTimeAgo(LLUICtrl*, void *);
+	static void onCheckSinceLogoff(LLUICtrl*, void *);
+	static void onCloseBtn(void* user_data);
+	static void selectAllTypes(void* user_data);
+	static void selectNoTypes(void* user_data);
+private:
+	LLPanelMainInventory*	mPanelInventoryDecorated;
+	LLSpinCtrl*			mSpinSinceDays;
+	LLSpinCtrl*			mSpinSinceHours;
+	LLInventoryFilter*	mFilter;
+};
+
+///----------------------------------------------------------------------------
+/// LLPanelMainInventory
+///----------------------------------------------------------------------------
+
+LLPanelMainInventory::LLPanelMainInventory()
+	: LLPanel()
+{
+	LLMemType mt(LLMemType::MTYPE_INVENTORY_VIEW_INIT);
+	// Menu Callbacks (non contex menus)
+	mCommitCallbackRegistrar.add("Inventory.DoToSelected", boost::bind(&LLPanelMainInventory::doToSelected, this, _2));
+	mCommitCallbackRegistrar.add("Inventory.CloseAllFolders", boost::bind(&LLPanelMainInventory::closeAllFolders, this));
+	mCommitCallbackRegistrar.add("Inventory.EmptyTrash", boost::bind(&LLInventoryModel::emptyFolderType, &gInventory, "ConfirmEmptyTrash", LLAssetType::AT_TRASH));
+	mCommitCallbackRegistrar.add("Inventory.EmptyLostAndFound", boost::bind(&LLInventoryModel::emptyFolderType, &gInventory, "ConfirmEmptyLostAndFound", LLAssetType::AT_LOST_AND_FOUND));
+	mCommitCallbackRegistrar.add("Inventory.DoCreate", boost::bind(&LLPanelMainInventory::doCreate, this, _2));
+ 	mCommitCallbackRegistrar.add("Inventory.NewWindow", boost::bind(&LLPanelMainInventory::newWindow, this));
+	mCommitCallbackRegistrar.add("Inventory.ShowFilters", boost::bind(&LLPanelMainInventory::toggleFindOptions, this));
+	mCommitCallbackRegistrar.add("Inventory.ResetFilters", boost::bind(&LLPanelMainInventory::resetFilters, this));
+	mCommitCallbackRegistrar.add("Inventory.SetSortBy", boost::bind(&LLPanelMainInventory::setSortBy, this, _2));
+
+	// Controls
+	// *TODO: Just use persistant settings for each of these
+	U32 sort_order = gSavedSettings.getU32("InventorySortOrder");
+	BOOL sort_by_name = ! ( sort_order & LLInventoryFilter::SO_DATE );
+	BOOL sort_folders_by_name = ( sort_order & LLInventoryFilter::SO_FOLDERS_BY_NAME );
+	BOOL sort_system_folders_to_top = ( sort_order & LLInventoryFilter::SO_SYSTEM_FOLDERS_TO_TOP );
+	
+	gSavedSettings.declareBOOL("Inventory.SortByName", sort_by_name, "Declared in code", FALSE);
+	gSavedSettings.declareBOOL("Inventory.SortByDate", !sort_by_name, "Declared in code", FALSE);
+	gSavedSettings.declareBOOL("Inventory.FoldersAlwaysByName", sort_folders_by_name, "Declared in code", FALSE);
+	gSavedSettings.declareBOOL("Inventory.SystemFoldersToTop", sort_system_folders_to_top, "Declared in code", FALSE);
+	
+	mSavedFolderState = new LLSaveFolderState();
+	mSavedFolderState->setApply(FALSE);
+}
+
+BOOL LLPanelMainInventory::postBuild()
+{
+	gInventory.addObserver(this);
+	
+	mFilterTabs = getChild<LLTabContainer>("inventory filter tabs");
+	mFilterTabs->setCommitCallback(boost::bind(&LLPanelMainInventory::onFilterSelected, this));
+	
+	//panel->getFilter()->markDefault();
+
+	// Set up the default inv. panel/filter settings.
+	mActivePanel = getChild<LLInventoryPanel>("All Items");
+	if (mActivePanel)
+	{
+		// "All Items" is the previous only view, so it gets the InventorySortOrder
+		mActivePanel->setSortOrder(gSavedSettings.getU32("InventorySortOrder"));
+		mActivePanel->getFilter()->markDefault();
+		mActivePanel->getRootFolder()->applyFunctorRecursively(*mSavedFolderState);
+		mActivePanel->setSelectCallback(boost::bind(&LLInventoryPanel::onSelectionChange, mActivePanel, _1, _2));
+	}
+	LLInventoryPanel* recent_items_panel = getChild<LLInventoryPanel>("Recent Items");
+	if (recent_items_panel)
+	{
+		recent_items_panel->setSinceLogoff(TRUE);
+		recent_items_panel->setSortOrder(LLInventoryFilter::SO_DATE);
+		recent_items_panel->setShowFolderState(LLInventoryFilter::SHOW_NON_EMPTY_FOLDERS);
+		recent_items_panel->getFilter()->markDefault();
+		recent_items_panel->setSelectCallback(boost::bind(&LLInventoryPanel::onSelectionChange, recent_items_panel, _1, _2));
+	}
+
+	// Now load the stored settings from disk, if available.
+	std::ostringstream filterSaveName;
+	filterSaveName << gDirUtilp->getExpandedFilename(LL_PATH_PER_SL_ACCOUNT, "filters.xml");
+	llinfos << "LLPanelMainInventory::init: reading from " << filterSaveName << llendl;
+	llifstream file(filterSaveName.str());
+	LLSD savedFilterState;
+	if (file.is_open())
+	{
+		LLSDSerialize::fromXML(savedFilterState, file);
+		file.close();
+
+		// Load the persistent "Recent Items" settings.
+		// Note that the "All Items" settings do not persist.
+		if(recent_items_panel)
+		{
+			if(savedFilterState.has(recent_items_panel->getFilter()->getName()))
+			{
+				LLSD recent_items = savedFilterState.get(
+					recent_items_panel->getFilter()->getName());
+				recent_items_panel->getFilter()->fromLLSD(recent_items);
+			}
+		}
+
+	}
+
+
+	mFilterEditor = getChild<LLFilterEditor>("inventory search editor");
+	if (mFilterEditor)
+	{
+		mFilterEditor->setCommitCallback(boost::bind(&LLPanelMainInventory::onFilterEdit, this, _2));
+	}
+
+	// *TODO:Get the cost info from the server
+	const std::string upload_cost("10");
+	childSetLabelArg("Upload Image", "[COST]", upload_cost);
+	childSetLabelArg("Upload Sound", "[COST]", upload_cost);
+	childSetLabelArg("Upload Animation", "[COST]", upload_cost);
+	childSetLabelArg("Bulk Upload", "[COST]", upload_cost);
+	
+	return TRUE;
+}
+
+// Destroys the object
+LLPanelMainInventory::~LLPanelMainInventory( void )
+{
+	// Save the filters state.
+	LLSD filterRoot;
+	LLInventoryPanel* all_items_panel = getChild<LLInventoryPanel>("All Items");
+	if (all_items_panel)
+	{
+		LLInventoryFilter* filter = all_items_panel->getFilter();
+		if (filter)
+		{
+			LLSD filterState;
+			filter->toLLSD(filterState);
+			filterRoot[filter->getName()] = filterState;
+		}
+	}
+
+	LLInventoryPanel* recent_items_panel = getChild<LLInventoryPanel>("Recent Items");
+	if (recent_items_panel)
+	{
+		LLInventoryFilter* filter = recent_items_panel->getFilter();
+		if (filter)
+		{
+			LLSD filterState;
+			filter->toLLSD(filterState);
+			filterRoot[filter->getName()] = filterState;
+		}
+	}
+
+	std::ostringstream filterSaveName;
+	filterSaveName << gDirUtilp->getExpandedFilename(LL_PATH_PER_SL_ACCOUNT, "filters.xml");
+	llofstream filtersFile(filterSaveName.str());
+	if(!LLSDSerialize::toPrettyXML(filterRoot, filtersFile))
+	{
+		llwarns << "Could not write to filters save file " << filterSaveName << llendl;
+	}
+	else
+		filtersFile.close();
+
+	gInventory.removeObserver(this);
+	delete mSavedFolderState;
+}
+
+void LLPanelMainInventory::startSearch()
+{
+	// this forces focus to line editor portion of search editor
+	if (mFilterEditor)
+	{
+		mFilterEditor->focusFirstItem(TRUE);
+	}
+}
+
+BOOL LLPanelMainInventory::handleKeyHere(KEY key, MASK mask)
+{
+	LLFolderView* root_folder = mActivePanel ? mActivePanel->getRootFolder() : NULL;
+	if (root_folder)
+	{
+		// first check for user accepting current search results
+		if (mFilterEditor 
+			&& mFilterEditor->hasFocus()
+		    && (key == KEY_RETURN 
+		    	|| key == KEY_DOWN)
+		    && mask == MASK_NONE)
+		{
+			// move focus to inventory proper
+			mActivePanel->setFocus(TRUE);
+			root_folder->scrollToShowSelection();
+			return TRUE;
+		}
+
+		if (mActivePanel->hasFocus() && key == KEY_UP)
+		{
+			startSearch();
+		}
+	}
+
+	return LLPanel::handleKeyHere(key, mask);
+
+}
+
+//----------------------------------------------------------------------------
+// menu callbacks
+
+void LLPanelMainInventory::doToSelected(const LLSD& userdata)
+{
+	getPanel()->getRootFolder()->doToSelected(&gInventory, userdata);
+}
+
+void LLPanelMainInventory::closeAllFolders()
+{
+	getPanel()->getRootFolder()->closeAllFolders();
+}
+
+void LLPanelMainInventory::newWindow()
+{
+	LLFloaterInventory::showAgentInventory();
+}
+
+void LLPanelMainInventory::doCreate(const LLSD& userdata)
+{
+	menu_create_inventory_item(getPanel()->getRootFolder(), NULL, userdata);
+}
+
+void LLPanelMainInventory::resetFilters()
+{
+	LLFloaterInventoryFinder *finder = getFinder();
+	getActivePanel()->getFilter()->resetDefault();
+	if (finder)
+	{
+		finder->updateElementsFromFilter();
+	}
+
+	setFilterTextFromFilter();
+}
+
+void LLPanelMainInventory::setSortBy(const LLSD& userdata)
+{
+	std::string sort_field = userdata.asString();
+	if (sort_field == "name")
+	{
+		U32 order = getActivePanel()->getSortOrder();
+		getActivePanel()->setSortOrder( order & ~LLInventoryFilter::SO_DATE );
+			
+		gSavedSettings.setBOOL("Inventory.SortByName", TRUE );
+		gSavedSettings.setBOOL("Inventory.SortByDate", FALSE );
+	}
+	else if (sort_field == "date")
+	{
+		U32 order = getActivePanel()->getSortOrder();
+		getActivePanel()->setSortOrder( order | LLInventoryFilter::SO_DATE );
+
+		gSavedSettings.setBOOL("Inventory.SortByName", FALSE );
+		gSavedSettings.setBOOL("Inventory.SortByDate", TRUE );
+	}
+	else if (sort_field == "foldersalwaysbyname")
+	{
+		U32 order = getActivePanel()->getSortOrder();
+		if ( order & LLInventoryFilter::SO_FOLDERS_BY_NAME )
+		{
+			order &= ~LLInventoryFilter::SO_FOLDERS_BY_NAME;
+
+			gSavedSettings.setBOOL("Inventory.FoldersAlwaysByName", FALSE );
+		}
+		else
+		{
+			order |= LLInventoryFilter::SO_FOLDERS_BY_NAME;
+
+			gSavedSettings.setBOOL("Inventory.FoldersAlwaysByName", TRUE );
+		}
+		getActivePanel()->setSortOrder( order );
+	}
+	else if (sort_field == "systemfolderstotop")
+	{
+		U32 order = getActivePanel()->getSortOrder();
+		if ( order & LLInventoryFilter::SO_SYSTEM_FOLDERS_TO_TOP )
+		{
+			order &= ~LLInventoryFilter::SO_SYSTEM_FOLDERS_TO_TOP;
+
+			gSavedSettings.setBOOL("Inventory.SystemFoldersToTop", FALSE );
+		}
+		else
+		{
+			order |= LLInventoryFilter::SO_SYSTEM_FOLDERS_TO_TOP;
+
+			gSavedSettings.setBOOL("Inventory.SystemFoldersToTop", TRUE );
+		}
+		getActivePanel()->setSortOrder( order );
+	}
+}
+
+// static
+BOOL LLPanelMainInventory::filtersVisible(void* user_data)
+{
+	LLPanelMainInventory* self = (LLPanelMainInventory*)user_data;
+	if(!self) return FALSE;
+
+	return self->getFinder() != NULL;
+}
+
+void LLPanelMainInventory::onClearSearch()
+{
+	LLFloater *finder = getFinder();
+	if (mActivePanel)
+	{
+		mActivePanel->setFilterSubString(LLStringUtil::null);
+		mActivePanel->setFilterTypes(0xffffffff);
+	}
+
+	if (finder)
+	{
+		LLFloaterInventoryFinder::selectAllTypes(finder);
+	}
+
+	// re-open folders that were initially open
+	if (mActivePanel)
+	{
+		mSavedFolderState->setApply(TRUE);
+		mActivePanel->getRootFolder()->applyFunctorRecursively(*mSavedFolderState);
+		LLOpenFoldersWithSelection opener;
+		mActivePanel->getRootFolder()->applyFunctorRecursively(opener);
+		mActivePanel->getRootFolder()->scrollToShowSelection();
+	}
+}
+
+void LLPanelMainInventory::onFilterEdit(const std::string& search_string )
+{
+	if (search_string == "")
+	{
+		onClearSearch();
+	}
+	if (!mActivePanel)
+	{
+		return;
+	}
+
+	gInventory.startBackgroundFetch();
+
+	std::string uppercase_search_string = search_string;
+	LLStringUtil::toUpper(uppercase_search_string);
+	if (mActivePanel->getFilterSubString().empty() && uppercase_search_string.empty())
+	{
+			// current filter and new filter empty, do nothing
+			return;
+	}
+
+	// save current folder open state if no filter currently applied
+	if (!mActivePanel->getRootFolder()->isFilterModified())
+	{
+		mSavedFolderState->setApply(FALSE);
+		mActivePanel->getRootFolder()->applyFunctorRecursively(*mSavedFolderState);
+	}
+
+	// set new filter string
+	mActivePanel->setFilterSubString(uppercase_search_string);
+}
+
+
+ //static
+ BOOL LLPanelMainInventory::incrementalFind(LLFolderViewItem* first_item, const char *find_text, BOOL backward)
+ {
+ 	LLPanelMainInventory* active_view = NULL;
+	
+	LLFloaterReg::const_instance_list_t& inst_list = LLFloaterReg::getFloaterList("inventory");
+	for (LLFloaterReg::const_instance_list_t::const_iterator iter = inst_list.begin(); iter != inst_list.end(); ++iter)
+	{
+		LLPanelMainInventory* iv = dynamic_cast<LLPanelMainInventory*>(*iter);
+		if (iv)
+		{
+			if (gFocusMgr.childHasKeyboardFocus(iv))
+			{
+				active_view = iv;
+				break;
+			}
+ 		}
+ 	}
+
+ 	if (!active_view)
+ 	{
+ 		return FALSE;
+ 	}
+
+ 	std::string search_string(find_text);
+
+ 	if (search_string.empty())
+ 	{
+ 		return FALSE;
+ 	}
+
+ 	if (active_view->getPanel() &&
+ 		active_view->getPanel()->getRootFolder()->search(first_item, search_string, backward))
+ 	{
+ 		return TRUE;
+ 	}
+
+ 	return FALSE;
+ }
+
+void LLPanelMainInventory::onFilterSelected()
+{
+	// Find my index
+	mActivePanel = (LLInventoryPanel*)childGetVisibleTab("inventory filter tabs");
+
+	if (!mActivePanel)
+	{
+		return;
+	}
+	LLInventoryFilter* filter = mActivePanel->getFilter();
+	LLFloaterInventoryFinder *finder = getFinder();
+	if (finder)
+	{
+		finder->changeFilter(filter);
+	}
+	if (filter->isActive())
+	{
+		// If our filter is active we may be the first thing requiring a fetch so we better start it here.
+		gInventory.startBackgroundFetch();
+	}
+	setFilterTextFromFilter();
+}
+
+const std::string LLPanelMainInventory::getFilterSubString() 
+{ 
+	return mActivePanel->getFilterSubString(); 
+}
+
+void LLPanelMainInventory::setFilterSubString(const std::string& string) 
+{ 
+	mActivePanel->setFilterSubString(string); 
+}
+
+BOOL LLPanelMainInventory::handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop,
+										 EDragAndDropType cargo_type,
+										 void* cargo_data,
+										 EAcceptance* accept,
+										 std::string& tooltip_msg)
+{
+	// Check to see if we are auto scrolling from the last frame
+	LLInventoryPanel* panel = (LLInventoryPanel*)this->getActivePanel();
+	BOOL needsToScroll = panel->getScrollableContainer()->autoScroll(x, y);
+	if(mFilterTabs)
+	{
+		if(needsToScroll)
+		{
+			mFilterTabs->startDragAndDropDelayTimer();
+		}
+	}
+	
+	BOOL handled = LLPanel::handleDragAndDrop(x, y, mask, drop, cargo_type, cargo_data, accept, tooltip_msg);
+
+	return handled;
+}
+
+void LLPanelMainInventory::changed(U32 mask)
+{
+}
+
+
+void LLPanelMainInventory::setFilterTextFromFilter() 
+{ 
+	mFilterText = mActivePanel->getFilter()->getFilterText(); 
+}
+
+void LLPanelMainInventory::toggleFindOptions()
+{
+	LLMemType mt(LLMemType::MTYPE_INVENTORY_VIEW_TOGGLE);
+	LLFloater *floater = getFinder();
+	if (!floater)
+	{
+		LLFloaterInventoryFinder * finder = new LLFloaterInventoryFinder(this);
+		mFinderHandle = finder->getHandle();
+		finder->openFloater();
+
+		LLFloater* parent_floater = gFloaterView->getParentFloater(this);
+		if (parent_floater) // Seraph: Fix this, shouldn't be null even for sidepanel
+			parent_floater->addDependentFloater(mFinderHandle);
+		// start background fetch of folders
+		gInventory.startBackgroundFetch();
+	}
+	else
+	{
+		floater->closeFloater();
+	}
+}
+
+void LLPanelMainInventory::setSelectCallback(const LLFolderView::signal_t::slot_type& cb)
+{
+	getChild<LLInventoryPanel>("All Items")->setSelectCallback(cb);
+	getChild<LLInventoryPanel>("Recent Items")->setSelectCallback(cb);
+}
+
+///----------------------------------------------------------------------------
+/// LLFloaterInventoryFinder
+///----------------------------------------------------------------------------
+
+LLFloaterInventoryFinder* LLPanelMainInventory::getFinder() 
+{ 
+	return (LLFloaterInventoryFinder*)mFinderHandle.get();
+}
+
+
+LLFloaterInventoryFinder::LLFloaterInventoryFinder(LLPanelMainInventory* inventory_view) :	
+	LLFloater(LLSD()),
+	mPanelInventoryDecorated(inventory_view),
+	mFilter(inventory_view->getPanel()->getFilter())
+{
+	LLUICtrlFactory::getInstance()->buildFloater(this, "floater_inventory_view_finder.xml", NULL);
+	updateElementsFromFilter();
+}
+
+
+void LLFloaterInventoryFinder::onCheckSinceLogoff(LLUICtrl *ctrl, void *user_data)
+{
+	LLFloaterInventoryFinder *self = (LLFloaterInventoryFinder *)user_data;
+	if (!self) return;
+
+	bool since_logoff= self->childGetValue("check_since_logoff");
+	
+	if (!since_logoff && 
+	    !(  self->mSpinSinceDays->get() ||  self->mSpinSinceHours->get() ) )
+	{
+		self->mSpinSinceHours->set(1.0f);
+	}	
+}
+BOOL LLFloaterInventoryFinder::postBuild()
+{
+	const LLRect& viewrect = mPanelInventoryDecorated->getRect();
+	setRect(LLRect(viewrect.mLeft - getRect().getWidth(), viewrect.mTop, viewrect.mLeft, viewrect.mTop - getRect().getHeight()));
+
+	childSetAction("All", selectAllTypes, this);
+	childSetAction("None", selectNoTypes, this);
+
+	mSpinSinceHours = getChild<LLSpinCtrl>("spin_hours_ago");
+	childSetCommitCallback("spin_hours_ago", onTimeAgo, this);
+
+	mSpinSinceDays = getChild<LLSpinCtrl>("spin_days_ago");
+	childSetCommitCallback("spin_days_ago", onTimeAgo, this);
+
+	//	mCheckSinceLogoff   = getChild<LLSpinCtrl>("check_since_logoff");
+	childSetCommitCallback("check_since_logoff", onCheckSinceLogoff, this);
+
+	childSetAction("Close", onCloseBtn, this);
+
+	updateElementsFromFilter();
+	return TRUE;
+}
+void LLFloaterInventoryFinder::onTimeAgo(LLUICtrl *ctrl, void *user_data)
+{
+	LLFloaterInventoryFinder *self = (LLFloaterInventoryFinder *)user_data;
+	if (!self) return;
+	
+	bool since_logoff=true;
+	if ( self->mSpinSinceDays->get() ||  self->mSpinSinceHours->get() )
+	{
+		since_logoff = false;
+	}
+	self->childSetValue("check_since_logoff", since_logoff);
+}
+
+void LLFloaterInventoryFinder::changeFilter(LLInventoryFilter* filter)
+{
+	mFilter = filter;
+	updateElementsFromFilter();
+}
+
+void LLFloaterInventoryFinder::updateElementsFromFilter()
+{
+	if (!mFilter)
+		return;
+
+	// Get data needed for filter display
+	U32 filter_types = mFilter->getFilterTypes();
+	std::string filter_string = mFilter->getFilterSubString();
+	LLInventoryFilter::EFolderShow show_folders = mFilter->getShowFolderState();
+	U32 hours = mFilter->getHoursAgo();
+
+	// update the ui elements
+	setTitle(mFilter->getName());
+
+	childSetValue("check_animation", (S32) (filter_types & 0x1 << LLInventoryType::IT_ANIMATION));
+
+	childSetValue("check_calling_card", (S32) (filter_types & 0x1 << LLInventoryType::IT_CALLINGCARD));
+	childSetValue("check_clothing", (S32) (filter_types & 0x1 << LLInventoryType::IT_WEARABLE));
+	childSetValue("check_gesture", (S32) (filter_types & 0x1 << LLInventoryType::IT_GESTURE));
+	childSetValue("check_landmark", (S32) (filter_types & 0x1 << LLInventoryType::IT_LANDMARK));
+	childSetValue("check_notecard", (S32) (filter_types & 0x1 << LLInventoryType::IT_NOTECARD));
+	childSetValue("check_object", (S32) (filter_types & 0x1 << LLInventoryType::IT_OBJECT));
+	childSetValue("check_script", (S32) (filter_types & 0x1 << LLInventoryType::IT_LSL));
+	childSetValue("check_sound", (S32) (filter_types & 0x1 << LLInventoryType::IT_SOUND));
+	childSetValue("check_texture", (S32) (filter_types & 0x1 << LLInventoryType::IT_TEXTURE));
+	childSetValue("check_snapshot", (S32) (filter_types & 0x1 << LLInventoryType::IT_SNAPSHOT));
+	childSetValue("check_show_empty", show_folders == LLInventoryFilter::SHOW_ALL_FOLDERS);
+	childSetValue("check_since_logoff", mFilter->isSinceLogoff());
+	mSpinSinceHours->set((F32)(hours % 24));
+	mSpinSinceDays->set((F32)(hours / 24));
+}
+
+void LLFloaterInventoryFinder::draw()
+{
+	LLMemType mt(LLMemType::MTYPE_INVENTORY_DRAW);
+	U32 filter = 0xffffffff;
+	BOOL filtered_by_all_types = TRUE;
+
+	if (!childGetValue("check_animation"))
+	{
+		filter &= ~(0x1 << LLInventoryType::IT_ANIMATION);
+		filtered_by_all_types = FALSE;
+	}
+
+
+	if (!childGetValue("check_calling_card"))
+	{
+		filter &= ~(0x1 << LLInventoryType::IT_CALLINGCARD);
+		filtered_by_all_types = FALSE;
+	}
+
+	if (!childGetValue("check_clothing"))
+	{
+		filter &= ~(0x1 << LLInventoryType::IT_WEARABLE);
+		filtered_by_all_types = FALSE;
+	}
+
+	if (!childGetValue("check_gesture"))
+	{
+		filter &= ~(0x1 << LLInventoryType::IT_GESTURE);
+		filtered_by_all_types = FALSE;
+	}
+
+	if (!childGetValue("check_landmark"))
+
+
+	{
+		filter &= ~(0x1 << LLInventoryType::IT_LANDMARK);
+		filtered_by_all_types = FALSE;
+	}
+
+	if (!childGetValue("check_notecard"))
+	{
+		filter &= ~(0x1 << LLInventoryType::IT_NOTECARD);
+		filtered_by_all_types = FALSE;
+	}
+
+	if (!childGetValue("check_object"))
+	{
+		filter &= ~(0x1 << LLInventoryType::IT_OBJECT);
+		filter &= ~(0x1 << LLInventoryType::IT_ATTACHMENT);
+		filtered_by_all_types = FALSE;
+	}
+
+	if (!childGetValue("check_script"))
+	{
+		filter &= ~(0x1 << LLInventoryType::IT_LSL);
+		filtered_by_all_types = FALSE;
+	}
+
+	if (!childGetValue("check_sound"))
+	{
+		filter &= ~(0x1 << LLInventoryType::IT_SOUND);
+		filtered_by_all_types = FALSE;
+	}
+
+	if (!childGetValue("check_texture"))
+	{
+		filter &= ~(0x1 << LLInventoryType::IT_TEXTURE);
+		filtered_by_all_types = FALSE;
+	}
+
+	if (!childGetValue("check_snapshot"))
+	{
+		filter &= ~(0x1 << LLInventoryType::IT_SNAPSHOT);
+		filtered_by_all_types = FALSE;
+	}
+
+	if (!filtered_by_all_types)
+	{
+		// don't include folders in filter, unless I've selected everything
+		filter &= ~(0x1 << LLInventoryType::IT_CATEGORY);
+	}
+
+	// update the panel, panel will update the filter
+	mPanelInventoryDecorated->getPanel()->setShowFolderState(getCheckShowEmpty() ?
+		LLInventoryFilter::SHOW_ALL_FOLDERS : LLInventoryFilter::SHOW_NON_EMPTY_FOLDERS);
+	mPanelInventoryDecorated->getPanel()->setFilterTypes(filter);
+	if (getCheckSinceLogoff())
+	{
+		mSpinSinceDays->set(0);
+		mSpinSinceHours->set(0);
+	}
+	U32 days = (U32)mSpinSinceDays->get();
+	U32 hours = (U32)mSpinSinceHours->get();
+	if (hours > 24)
+	{
+		days += hours / 24;
+		hours = (U32)hours % 24;
+		mSpinSinceDays->set((F32)days);
+		mSpinSinceHours->set((F32)hours);
+	}
+	hours += days * 24;
+	mPanelInventoryDecorated->getPanel()->setHoursAgo(hours);
+	mPanelInventoryDecorated->getPanel()->setSinceLogoff(getCheckSinceLogoff());
+	mPanelInventoryDecorated->setFilterTextFromFilter();
+
+	LLPanel::draw();
+}
+
+BOOL LLFloaterInventoryFinder::getCheckShowEmpty()
+{
+	return childGetValue("check_show_empty");
+}
+
+BOOL LLFloaterInventoryFinder::getCheckSinceLogoff()
+{
+	return childGetValue("check_since_logoff");
+}
+
+void LLFloaterInventoryFinder::onCloseBtn(void* user_data)
+{
+	LLFloaterInventoryFinder* finderp = (LLFloaterInventoryFinder*)user_data;
+	finderp->closeFloater();
+}
+
+// static
+void LLFloaterInventoryFinder::selectAllTypes(void* user_data)
+{
+	LLFloaterInventoryFinder* self = (LLFloaterInventoryFinder*)user_data;
+	if(!self) return;
+
+	self->childSetValue("check_animation", TRUE);
+	self->childSetValue("check_calling_card", TRUE);
+	self->childSetValue("check_clothing", TRUE);
+	self->childSetValue("check_gesture", TRUE);
+	self->childSetValue("check_landmark", TRUE);
+	self->childSetValue("check_notecard", TRUE);
+	self->childSetValue("check_object", TRUE);
+	self->childSetValue("check_script", TRUE);
+	self->childSetValue("check_sound", TRUE);
+	self->childSetValue("check_texture", TRUE);
+	self->childSetValue("check_snapshot", TRUE);
+}
+
+//static
+void LLFloaterInventoryFinder::selectNoTypes(void* user_data)
+{
+	LLFloaterInventoryFinder* self = (LLFloaterInventoryFinder*)user_data;
+	if(!self) return;
+
+	self->childSetValue("check_animation", FALSE);
+	self->childSetValue("check_calling_card", FALSE);
+	self->childSetValue("check_clothing", FALSE);
+	self->childSetValue("check_gesture", FALSE);
+	self->childSetValue("check_landmark", FALSE);
+	self->childSetValue("check_notecard", FALSE);
+	self->childSetValue("check_object", FALSE);
+	self->childSetValue("check_script", FALSE);
+	self->childSetValue("check_sound", FALSE);
+	self->childSetValue("check_texture", FALSE);
+	self->childSetValue("check_snapshot", FALSE);
+}
diff --git a/indra/newview/llpanelmaininventory.h b/indra/newview/llpanelmaininventory.h
new file mode 100644
index 00000000000..75526a3c98f
--- /dev/null
+++ b/indra/newview/llpanelmaininventory.h
@@ -0,0 +1,125 @@
+/** 
+ * @file llpanelmaininventory.h
+ * @brief llpanelmaininventory.h
+ * class definition
+ *
+ * $LicenseInfo:firstyear=2001&license=viewergpl$
+ * 
+ * Copyright (c) 2001-2009, Linden Research, Inc.
+ * 
+ * Second Life Viewer Source Code
+ * The source code in this file ("Source Code") is provided by Linden Lab
+ * to you under the terms of the GNU General Public License, version 2.0
+ * ("GPL"), unless you have obtained a separate licensing agreement
+ * ("Other License"), formally executed by you and Linden Lab.  Terms of
+ * the GPL can be found in doc/GPL-license.txt in this distribution, or
+ * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
+ * 
+ * There are special exceptions to the terms and conditions of the GPL as
+ * it is applied to this Source Code. View the full text of the exception
+ * in the file doc/FLOSS-exception.txt in this software distribution, or
+ * online at
+ * http://secondlifegrid.net/programs/open_source/licensing/flossexception
+ * 
+ * By copying, modifying or distributing this software, you acknowledge
+ * that you have read and understood your obligations described above,
+ * and agree to abide by those obligations.
+ * 
+ * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
+ * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
+ * COMPLETENESS OR PERFORMANCE.
+ * $/LicenseInfo$
+ */
+
+#ifndef LL_LLPANELMAININVENTORY_H
+#define LL_LLPANELMAININVENTORY_H
+
+#include "llpanel.h"
+#include "llinventorymodel.h"
+#include "llfolderview.h"
+
+class LLFolderViewItem;
+class LLInventoryPanel;
+class LLSaveFolderState;
+class LLFilterEditor;
+class LLTabContainer;
+class LLFloaterInventoryFinder;
+
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+// Class LLPanelMainInventory
+//
+// This is a panel used to view and control an agent's inventory,
+// including all the fixin's (e.g. AllItems/RecentItems tabs, filter floaters).
+//
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+class LLPanelMainInventory : public LLPanel, LLInventoryObserver
+{
+public:
+	friend class LLFloaterInventoryFinder;
+
+	LLPanelMainInventory();
+	~LLPanelMainInventory();
+
+	BOOL postBuild();
+
+	virtual BOOL handleKeyHere(KEY key, MASK mask);
+
+	// Inherited functionality
+	/*virtual*/ BOOL handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop,
+									   EDragAndDropType cargo_type,
+									   void* cargo_data,
+									   EAcceptance* accept,
+									   std::string& tooltip_msg);
+	/*virtual*/ void changed(U32 mask);
+
+	LLInventoryPanel* getPanel() { return mActivePanel; }
+	LLInventoryPanel* getActivePanel() { return mActivePanel; }
+
+	const std::string& getFilterText() const { return mFilterText; }
+	
+	void setSelectCallback(const LLFolderView::signal_t::slot_type& cb);
+
+protected:
+	//
+	// Misc functions
+	//
+	void setFilterTextFromFilter();
+	void startSearch();
+	
+	void toggleFindOptions();
+
+	static BOOL filtersVisible(void* user_data);
+	void onClearSearch();
+	static void onFoldersByName(void *user_data);
+	static BOOL checkFoldersByName(void *user_data);
+	void onFilterEdit(const std::string& search_string );
+	static BOOL incrementalFind(LLFolderViewItem* first_item, const char *find_text, BOOL backward);
+	void onFilterSelected();
+
+	const std::string getFilterSubString();
+	void setFilterSubString(const std::string& string);
+	
+	// menu callbacks
+	void doToSelected(const LLSD& userdata);
+	void closeAllFolders();
+	void newWindow();
+	void doCreate(const LLSD& userdata);
+	void resetFilters();
+	void setSortBy(const LLSD& userdata);
+	
+private:
+	LLFloaterInventoryFinder* getFinder();
+
+	LLFilterEditor*				mFilterEditor;
+	LLTabContainer*				mFilterTabs;
+	LLHandle<LLFloater>			mFinderHandle;
+	LLInventoryPanel*			mActivePanel;
+	LLSaveFolderState*			mSavedFolderState;
+
+	std::string					mFilterText;
+};
+
+#endif // LL_LLPANELMAININVENTORY_H
+
+
+
diff --git a/indra/newview/llpanelobject.h b/indra/newview/llpanelobject.h
index 1ab4ff581ee..58d9fe9b76e 100644
--- a/indra/newview/llpanelobject.h
+++ b/indra/newview/llpanelobject.h
@@ -45,7 +45,6 @@ class LLUICtrl;
 class LLButton;
 class LLViewerObject;
 class LLComboBox;
-class LLPanelInventory;
 class LLColorSwatchCtrl;
 class LLTextureCtrl;
 class LLInventoryItem;
diff --git a/indra/newview/llpanelobjectinventory.cpp b/indra/newview/llpanelobjectinventory.cpp
new file mode 100644
index 00000000000..365a6e632fa
--- /dev/null
+++ b/indra/newview/llpanelobjectinventory.cpp
@@ -0,0 +1,1905 @@
+/**
+ * @file llsidepanelinventory.cpp
+ * @brief LLPanelObjectInventory class implementation
+ *
+ * $LicenseInfo:firstyear=2002&license=viewergpl$
+ * 
+ * Copyright (c) 2002-2009, Linden Research, Inc.
+ * 
+ * Second Life Viewer Source Code
+ * The source code in this file ("Source Code") is provided by Linden Lab
+ * to you under the terms of the GNU General Public License, version 2.0
+ * ("GPL"), unless you have obtained a separate licensing agreement
+ * ("Other License"), formally executed by you and Linden Lab.  Terms of
+ * the GPL can be found in doc/GPL-license.txt in this distribution, or
+ * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
+ * 
+ * There are special exceptions to the terms and conditions of the GPL as
+ * it is applied to this Source Code. View the full text of the exception
+ * in the file doc/FLOSS-exception.txt in this software distribution, or
+ * online at
+ * http://secondlifegrid.net/programs/open_source/licensing/flossexception
+ * 
+ * By copying, modifying or distributing this software, you acknowledge
+ * that you have read and understood your obligations described above,
+ * and agree to abide by those obligations.
+ * 
+ * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
+ * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
+ * COMPLETENESS OR PERFORMANCE.
+ * $/LicenseInfo$
+ */
+
+//*****************************************************************************
+//
+// Implementation of the panel inventory - used to view and control a
+// task's inventory.
+//
+//*****************************************************************************
+
+#include "llviewerprecompiledheaders.h"
+
+#include "llpanelobjectinventory.h"
+
+#include "roles_constants.h"
+
+#include "llagent.h"
+#include "llcallbacklist.h"
+#include "llfloaterbuycurrency.h"
+#include "llfloaterreg.h"
+#include "llinventorybridge.h"
+#include "llinventoryfunctions.h"
+#include "llpreviewanim.h"
+#include "llpreviewgesture.h"
+#include "llpreviewnotecard.h"
+#include "llpreviewscript.h"
+#include "llpreviewsound.h"
+#include "llpreviewtexture.h"
+#include "llscrollcontainer.h"
+#include "llselectmgr.h"
+#include "llstatusbar.h"
+#include "lltrans.h"
+#include "llviewerregion.h"
+#include "llviewerobjectlist.h"
+#include "llviewermessage.h"
+
+
+///----------------------------------------------------------------------------
+/// Class LLTaskInvFVBridge
+///----------------------------------------------------------------------------
+
+class LLTaskInvFVBridge : public LLFolderViewEventListener
+{
+protected:
+	LLUUID mUUID;
+	std::string mName;
+	mutable std::string mDisplayName;
+	LLPanelObjectInventory* mPanel;
+	U32 mFlags;
+
+	LLInventoryItem* findItem() const;
+
+public:
+	LLTaskInvFVBridge(
+		LLPanelObjectInventory* panel,
+		const LLUUID& uuid,
+		const std::string& name,
+		U32 flags=0);
+	virtual ~LLTaskInvFVBridge( void ) {}
+
+	virtual LLFontGL::StyleFlags getLabelStyle() const { return LLFontGL::NORMAL; }
+	virtual std::string getLabelSuffix() const { return LLStringUtil::null; }
+
+	static LLTaskInvFVBridge* createObjectBridge(LLPanelObjectInventory* panel,
+												 LLInventoryObject* object);
+	void showProperties();
+	void buyItem();
+	S32 getPrice();
+	static bool commitBuyItem(const LLSD& notification, const LLSD& response);
+
+	// LLFolderViewEventListener functionality
+	virtual const std::string& getName() const;
+	virtual const std::string& getDisplayName() const;
+	virtual PermissionMask getPermissionMask() const { return PERM_NONE; }
+	/*virtual*/ LLAssetType::EType getPreferredType() const { return LLAssetType::AT_NONE; }
+	virtual const LLUUID& getUUID() const { return mUUID; }
+	virtual time_t getCreationDate() const;
+	virtual LLUIImagePtr getIcon() const;
+	virtual void openItem();
+	virtual void closeItem() {}
+	virtual void previewItem();
+	virtual void selectItem() {}
+	virtual BOOL isItemRenameable() const;
+	virtual BOOL renameItem(const std::string& new_name);
+	virtual BOOL isItemMovable() const;
+	virtual BOOL isItemRemovable();
+	virtual BOOL removeItem();
+	virtual void removeBatch(LLDynamicArray<LLFolderViewEventListener*>& batch);
+	virtual void move(LLFolderViewEventListener* parent_listener);
+	virtual BOOL isItemCopyable() const;
+	virtual BOOL copyToClipboard() const;
+	virtual void cutToClipboard();
+	virtual BOOL isClipboardPasteable() const;
+	virtual void pasteFromClipboard();
+	virtual void pasteLinkFromClipboard();
+	virtual void buildContextMenu(LLMenuGL& menu, U32 flags);
+	virtual void performAction(LLFolderView* folder, LLInventoryModel* model, std::string action);
+	virtual BOOL isUpToDate() const { return TRUE; }
+	virtual BOOL hasChildren() const { return FALSE; }
+	virtual LLInventoryType::EType getInventoryType() const { return LLInventoryType::IT_NONE; }
+	// LLDragAndDropBridge functionality
+	virtual BOOL startDrag(EDragAndDropType* type, LLUUID* id) const;
+	virtual BOOL dragOrDrop(MASK mask, BOOL drop,
+							EDragAndDropType cargo_type,
+							void* cargo_data);
+};
+
+LLTaskInvFVBridge::LLTaskInvFVBridge(
+	LLPanelObjectInventory* panel,
+	const LLUUID& uuid,
+	const std::string& name,
+	U32 flags):
+	mUUID(uuid),
+	mName(name),
+	mPanel(panel),
+	mFlags(flags)
+{
+
+}
+
+LLInventoryItem* LLTaskInvFVBridge::findItem() const
+{
+	LLViewerObject* object = gObjectList.findObject(mPanel->getTaskUUID());
+	if(object)
+	{
+		return (LLInventoryItem*)(object->getInventoryObject(mUUID));
+	}
+	return NULL;
+}
+
+void LLTaskInvFVBridge::showProperties()
+{
+	LLFloaterProperties* floater = LLFloaterReg::showTypedInstance<LLFloaterProperties>("properties", mUUID);
+	if (floater)
+	{
+		floater->setObjectID(mPanel->getTaskUUID());
+	}
+}
+
+struct LLBuyInvItemData
+{
+	LLUUID mTaskID;
+	LLUUID mItemID;
+	LLAssetType::EType mType;
+
+	LLBuyInvItemData(const LLUUID& task,
+					 const LLUUID& item,
+					 LLAssetType::EType type) :
+		mTaskID(task), mItemID(item), mType(type)
+	{}
+};
+
+void LLTaskInvFVBridge::buyItem()
+{
+	llinfos << "LLTaskInvFVBridge::buyItem()" << llendl;
+	LLInventoryItem* item = findItem();
+	if(!item || !item->getSaleInfo().isForSale()) return;
+	LLBuyInvItemData* inv = new LLBuyInvItemData(mPanel->getTaskUUID(),
+												 mUUID,
+												 item->getType());
+
+	const LLSaleInfo& sale_info = item->getSaleInfo();
+	const LLPermissions& perm = item->getPermissions();
+	const std::string owner_name; // no owner name currently... FIXME?
+
+	LLViewerObject* obj;
+	if( ( obj = gObjectList.findObject( mPanel->getTaskUUID() ) ) && obj->isAttachment() )
+	{
+		LLNotifications::instance().add("Cannot_Purchase_an_Attachment");
+		llinfos << "Attempt to purchase an attachment" << llendl;
+		delete inv;
+	}
+	else
+	{
+        LLSD args;
+        args["PRICE"] = llformat("%d",sale_info.getSalePrice());
+        args["OWNER"] = owner_name;
+        if (sale_info.getSaleType() != LLSaleInfo::FS_CONTENTS)
+        {
+        	U32 next_owner_mask = perm.getMaskNextOwner();
+        	args["MODIFYPERM"] = LLNotifications::instance().getGlobalString((next_owner_mask & PERM_MODIFY) ? "PermYes" : "PermNo");
+        	args["COPYPERM"] = LLNotifications::instance().getGlobalString((next_owner_mask & PERM_COPY) ? "PermYes" : "PermNo");
+        	args["RESELLPERM"] = LLNotifications::instance().getGlobalString((next_owner_mask & PERM_TRANSFER) ? "PermYes" : "PermNo");
+        }
+
+		std::string alertdesc;
+       	switch(sale_info.getSaleType())
+       	{
+       	  case LLSaleInfo::FS_ORIGINAL:
+       		alertdesc = owner_name.empty() ? "BuyOriginalNoOwner" : "BuyOriginal";
+       		break;
+       	  case LLSaleInfo::FS_CONTENTS:
+       		alertdesc = owner_name.empty() ? "BuyContentsNoOwner" : "BuyContents";
+       		break;
+		  case LLSaleInfo::FS_COPY:
+       	  default:
+       		alertdesc = owner_name.empty() ? "BuyCopyNoOwner" : "BuyCopy";
+       		break;
+       	}
+
+		LLSD payload;
+		payload["task_id"] = inv->mTaskID;
+		payload["item_id"] = inv->mItemID;
+		payload["type"] = inv->mType;
+		LLNotifications::instance().add(alertdesc, args, payload, LLTaskInvFVBridge::commitBuyItem);
+	}
+}
+
+S32 LLTaskInvFVBridge::getPrice()
+{
+	LLInventoryItem* item = findItem();
+	if(item)
+	{
+		return item->getSaleInfo().getSalePrice();
+	}
+	else
+	{
+		return -1;
+	}
+}
+
+// static
+bool LLTaskInvFVBridge::commitBuyItem(const LLSD& notification, const LLSD& response)
+{
+	S32 option = LLNotification::getSelectedOption(notification, response);
+	if(0 == option)
+	{
+		LLViewerObject* object = gObjectList.findObject(notification["payload"]["task_id"].asUUID());
+		if(!object || !object->getRegion()) return false;
+
+
+		LLMessageSystem* msg = gMessageSystem;
+		msg->newMessageFast(_PREHASH_BuyObjectInventory);
+		msg->nextBlockFast(_PREHASH_AgentData);
+		msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+		msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+		msg->nextBlockFast(_PREHASH_Data);
+		msg->addUUIDFast(_PREHASH_ObjectID, notification["payload"]["task_id"].asUUID());
+		msg->addUUIDFast(_PREHASH_ItemID, notification["payload"]["item_id"].asUUID());
+		msg->addUUIDFast(_PREHASH_FolderID,
+			gInventory.findCategoryUUIDForType((LLAssetType::EType)notification["payload"]["type"].asInteger()));
+		msg->sendReliable(object->getRegion()->getHost());
+	}
+	return false;
+}
+
+const std::string& LLTaskInvFVBridge::getName() const
+{
+	return mName;
+}
+
+const std::string& LLTaskInvFVBridge::getDisplayName() const
+{
+	LLInventoryItem* item = findItem();
+	if(item)
+	{
+		mDisplayName.assign(item->getName());
+
+		const LLPermissions& perm(item->getPermissions());
+		BOOL copy = gAgent.allowOperation(PERM_COPY, perm, GP_OBJECT_MANIPULATE);
+		BOOL mod  = gAgent.allowOperation(PERM_MODIFY, perm, GP_OBJECT_MANIPULATE);
+		BOOL xfer = gAgent.allowOperation(PERM_TRANSFER, perm, GP_OBJECT_MANIPULATE);
+
+		if(!copy)
+		{
+			mDisplayName.append(" (no copy)");
+		}
+		if(!mod)
+		{
+			mDisplayName.append(" (no modify)");
+		}
+		if(!xfer)
+		{
+			mDisplayName.append(" (no transfer)");
+		}
+	}
+
+	return mDisplayName;
+}
+
+// BUG: No creation dates for task inventory
+time_t LLTaskInvFVBridge::getCreationDate() const
+{
+	return 0;
+}
+
+LLUIImagePtr LLTaskInvFVBridge::getIcon() const
+{
+	BOOL item_is_multi = FALSE;
+	if ( mFlags & LLInventoryItem::II_FLAGS_OBJECT_HAS_MULTIPLE_ITEMS )
+	{
+		item_is_multi = TRUE;
+	}
+
+	return get_item_icon(LLAssetType::AT_OBJECT, LLInventoryType::IT_OBJECT, 0, item_is_multi );
+}
+
+void LLTaskInvFVBridge::openItem()
+{
+	// no-op.
+	lldebugs << "LLTaskInvFVBridge::openItem()" << llendl;
+}
+
+void LLTaskInvFVBridge::previewItem()
+{
+	openItem();
+}
+
+BOOL LLTaskInvFVBridge::isItemRenameable() const
+{
+	if(gAgent.isGodlike()) return TRUE;
+	LLViewerObject* object = gObjectList.findObject(mPanel->getTaskUUID());
+	if(object)
+	{
+		LLInventoryItem* item;
+		item = (LLInventoryItem*)(object->getInventoryObject(mUUID));
+		if(item && gAgent.allowOperation(PERM_MODIFY, item->getPermissions(),
+										 GP_OBJECT_MANIPULATE, GOD_LIKE))
+		{
+			return TRUE;
+		}
+	}
+	return FALSE;
+}
+
+BOOL LLTaskInvFVBridge::renameItem(const std::string& new_name)
+{
+	LLViewerObject* object = gObjectList.findObject(mPanel->getTaskUUID());
+	if(object)
+	{
+		LLViewerInventoryItem* item = NULL;
+		item = (LLViewerInventoryItem*)object->getInventoryObject(mUUID);
+		if(item && (gAgent.allowOperation(PERM_MODIFY, item->getPermissions(),
+										GP_OBJECT_MANIPULATE, GOD_LIKE)))
+		{
+			LLPointer<LLViewerInventoryItem> new_item = new LLViewerInventoryItem(item);
+			new_item->rename(new_name);
+			object->updateInventory(
+				new_item,
+				TASK_INVENTORY_ITEM_KEY,
+				false);
+		}
+	}
+	return TRUE;
+}
+
+BOOL LLTaskInvFVBridge::isItemMovable() const
+{
+	//LLViewerObject* object = gObjectList.findObject(mPanel->getTaskUUID());
+	//if(object && (object->permModify() || gAgent.isGodlike()))
+	//{
+	//	return TRUE;
+	//}
+	//return FALSE;
+	return TRUE;
+}
+
+BOOL LLTaskInvFVBridge::isItemRemovable()
+{
+	LLViewerObject* object = gObjectList.findObject(mPanel->getTaskUUID());
+	if(object
+	   && (object->permModify() || object->permYouOwner()))
+	{
+		return TRUE;
+	}
+	return FALSE;
+}
+
+bool remove_task_inventory_callback(const LLSD& notification, const LLSD& response, LLPanelObjectInventory* panel)
+{
+	S32 option = LLNotification::getSelectedOption(notification, response);
+	LLViewerObject* object = gObjectList.findObject(notification["payload"]["task_id"].asUUID());
+	if(option == 0 && object)
+	{
+		// yes
+		LLSD::array_const_iterator list_end = notification["payload"]["inventory_ids"].endArray();
+		for (LLSD::array_const_iterator list_it = notification["payload"]["inventory_ids"].beginArray();
+			list_it != list_end; 
+			++list_it)
+		{
+			object->removeInventory(list_it->asUUID());
+		}
+
+		// refresh the UI.
+		panel->refresh();
+	}
+	return false;
+}
+
+// helper for remove
+// ! REFACTOR ! two_uuids_list_t is also defined in llinevntorybridge.h, but differently.
+typedef std::pair<LLUUID, std::list<LLUUID> > panel_two_uuids_list_t;
+typedef std::pair<LLPanelObjectInventory*, panel_two_uuids_list_t> remove_data_t;
+BOOL LLTaskInvFVBridge::removeItem()
+{
+	if(isItemRemovable() && mPanel)
+	{
+		LLViewerObject* object = gObjectList.findObject(mPanel->getTaskUUID());
+		if(object)
+		{
+			if(object->permModify())
+			{
+				// just do it.
+				object->removeInventory(mUUID);
+				return TRUE;
+			}
+			else
+			{
+				remove_data_t* data = new remove_data_t;
+				data->first = mPanel;
+				data->second.first = mPanel->getTaskUUID();
+				data->second.second.push_back(mUUID);
+				LLSD payload;
+				payload["task_id"] = mPanel->getTaskUUID();
+				payload["inventory_ids"].append(mUUID);
+				LLNotifications::instance().add("RemoveItemWarn", LLSD(), payload, boost::bind(&remove_task_inventory_callback, _1, _2, mPanel));
+				return FALSE;
+			}
+		}
+	}
+	return FALSE;
+}
+
+void LLTaskInvFVBridge::removeBatch(LLDynamicArray<LLFolderViewEventListener*>& batch)
+{
+	if (!mPanel)
+	{
+		return;
+	}
+
+	LLViewerObject* object = gObjectList.findObject(mPanel->getTaskUUID());
+	if (!object)
+	{
+		return;
+	}
+
+	if (!object->permModify())
+	{
+		LLSD payload;
+		payload["task_id"] = mPanel->getTaskUUID();
+		for (S32 i = 0; i < (S32)batch.size(); i++)
+		{
+			LLTaskInvFVBridge* itemp = (LLTaskInvFVBridge*)batch[i];
+			payload["inventory_ids"].append(itemp->getUUID());
+		}
+		LLNotifications::instance().add("RemoveItemWarn", LLSD(), payload, boost::bind(&remove_task_inventory_callback, _1, _2, mPanel));
+		
+	}
+	else
+	{
+		for (S32 i = 0; i < (S32)batch.size(); i++)
+		{
+			LLTaskInvFVBridge* itemp = (LLTaskInvFVBridge*)batch[i];
+
+			if(itemp->isItemRemovable())
+			{
+				// just do it.
+				object->removeInventory(itemp->getUUID());
+			}
+		}
+	}
+}
+
+void LLTaskInvFVBridge::move(LLFolderViewEventListener* parent_listener)
+{
+}
+
+BOOL LLTaskInvFVBridge::isItemCopyable() const
+{
+	LLInventoryItem* item = findItem();
+	if(!item) return FALSE;
+	return gAgent.allowOperation(PERM_COPY, item->getPermissions(),
+								GP_OBJECT_MANIPULATE);
+}
+
+BOOL LLTaskInvFVBridge::copyToClipboard() const
+{
+	return FALSE;
+}
+
+void LLTaskInvFVBridge::cutToClipboard()
+{
+}
+
+BOOL LLTaskInvFVBridge::isClipboardPasteable() const
+{
+	return FALSE;
+}
+
+void LLTaskInvFVBridge::pasteFromClipboard()
+{
+}
+
+void LLTaskInvFVBridge::pasteLinkFromClipboard()
+{
+}
+
+BOOL LLTaskInvFVBridge::startDrag(EDragAndDropType* type, LLUUID* id) const
+{
+	//llinfos << "LLTaskInvFVBridge::startDrag()" << llendl;
+	if(mPanel)
+	{
+		LLViewerObject* object = gObjectList.findObject(mPanel->getTaskUUID());
+		if(object)
+		{
+			LLInventoryItem* inv = NULL;
+			if((inv = (LLInventoryItem*)object->getInventoryObject(mUUID)))
+			{
+				const LLPermissions& perm = inv->getPermissions();
+				bool can_copy = gAgent.allowOperation(PERM_COPY, perm,
+														GP_OBJECT_MANIPULATE);
+				if (object->isAttachment() && !can_copy)
+				{
+                    //RN: no copy contents of attachments cannot be dragged out
+                    // due to a race condition and possible exploit where
+                    // attached objects do not update their inventory items
+                    // when their contents are manipulated
+                    return FALSE;
+				}
+				if((can_copy && perm.allowTransferTo(gAgent.getID()))
+				   || object->permYouOwner())
+//				   || gAgent.isGodlike())
+
+				{
+					*type = LLAssetType::lookupDragAndDropType(inv->getType());
+
+					*id = inv->getUUID();
+					return TRUE;
+				}
+			}
+		}
+	}
+	return FALSE;
+}
+
+BOOL LLTaskInvFVBridge::dragOrDrop(MASK mask, BOOL drop,
+								   EDragAndDropType cargo_type,
+								   void* cargo_data)
+{
+	//llinfos << "LLTaskInvFVBridge::dragOrDrop()" << llendl;
+	return FALSE;
+}
+
+// virtual
+void LLTaskInvFVBridge::performAction(LLFolderView* folder, LLInventoryModel* model, std::string action)
+{
+	if (action == "task_buy")
+	{
+		// Check the price of the item.
+		S32 price = getPrice();
+		if (-1 == price)
+		{
+			llwarns << "label_buy_task_bridged_item: Invalid price" << llendl;
+		}
+		else
+		{
+			if (price > 0 && price > gStatusBar->getBalance())
+			{
+				LLFloaterBuyCurrency::buyCurrency("This costs", price);
+			}
+			else
+			{
+				buyItem();
+			}
+		}
+	}
+	else if (action == "task_open")
+	{
+		openItem();
+	}
+	else if (action == "task_properties")
+	{
+		showProperties();
+	}
+}
+
+void LLTaskInvFVBridge::buildContextMenu(LLMenuGL& menu, U32 flags)
+{
+	LLInventoryItem* item = findItem();
+	std::vector<std::string> items;
+	std::vector<std::string> disabled_items;
+	
+	if (!item)
+	{
+		hide_context_entries(menu, items, disabled_items);
+		return;
+	}
+
+	if(gAgent.allowOperation(PERM_OWNER, item->getPermissions(),
+							 GP_OBJECT_MANIPULATE)
+	   && item->getSaleInfo().isForSale())
+	{
+		items.push_back(std::string("Task Buy"));
+
+		std::string label= LLTrans::getString("Buy");
+		// Check the price of the item.
+		S32 price = getPrice();
+		if (-1 == price)
+		{
+			llwarns << "label_buy_task_bridged_item: Invalid price" << llendl;
+		}
+		else
+		{
+			std::ostringstream info;
+			info << LLTrans::getString("BuyforL$") << price;
+			label.assign(info.str());
+		}
+
+		const LLView::child_list_t *list = menu.getChildList();
+		LLView::child_list_t::const_iterator itor;
+		for (itor = list->begin(); itor != list->end(); ++itor)
+		{
+			std::string name = (*itor)->getName();
+			LLMenuItemCallGL* menu_itemp = dynamic_cast<LLMenuItemCallGL*>(*itor);
+			if (name == "Task Buy" && menu_itemp)
+			{
+				menu_itemp->setLabel(label);
+			}
+		}
+	}
+	else
+	{
+		items.push_back(std::string("Task Open"));
+		if (!isItemCopyable())
+		{
+			disabled_items.push_back(std::string("Task Open"));
+		}
+	}
+	items.push_back(std::string("Task Properties"));
+	if(isItemRenameable())
+	{
+		items.push_back(std::string("Task Rename"));
+	}
+	if(isItemRemovable())
+	{
+		items.push_back(std::string("Task Remove"));
+	}
+
+	hide_context_entries(menu, items, disabled_items);
+}
+
+
+///----------------------------------------------------------------------------
+/// Class LLTaskFolderBridge
+///----------------------------------------------------------------------------
+
+class LLTaskCategoryBridge : public LLTaskInvFVBridge
+{
+public:
+	LLTaskCategoryBridge(
+		LLPanelObjectInventory* panel,
+		const LLUUID& uuid,
+		const std::string& name);
+
+	virtual LLUIImagePtr getIcon() const;
+	virtual const std::string& getDisplayName() const { return getName(); }
+	virtual BOOL isItemRenameable() const;
+	virtual BOOL renameItem(const std::string& new_name);
+	virtual BOOL isItemRemovable();
+	virtual void buildContextMenu(LLMenuGL& menu, U32 flags);
+	virtual BOOL hasChildren() const;
+	virtual BOOL startDrag(EDragAndDropType* type, LLUUID* id) const;
+	virtual BOOL dragOrDrop(MASK mask, BOOL drop,
+							EDragAndDropType cargo_type,
+							void* cargo_data);
+};
+
+LLTaskCategoryBridge::LLTaskCategoryBridge(
+	LLPanelObjectInventory* panel,
+	const LLUUID& uuid,
+	const std::string& name) :
+	LLTaskInvFVBridge(panel, uuid, name)
+{
+}
+
+LLUIImagePtr LLTaskCategoryBridge::getIcon() const
+{
+	return LLUI::getUIImage("Inv_FolderClosed");
+}
+
+BOOL LLTaskCategoryBridge::isItemRenameable() const
+{
+	return FALSE;
+}
+
+BOOL LLTaskCategoryBridge::renameItem(const std::string& new_name)
+{
+	return FALSE;
+}
+
+BOOL LLTaskCategoryBridge::isItemRemovable()
+{
+	return FALSE;
+}
+
+void LLTaskCategoryBridge::buildContextMenu(LLMenuGL& menu, U32 flags)
+{
+	std::vector<std::string> items;
+	std::vector<std::string> disabled_items;
+	items.push_back(std::string("Task Open"));
+	hide_context_entries(menu, items, disabled_items);
+}
+
+BOOL LLTaskCategoryBridge::hasChildren() const
+{
+	// return TRUE if we have or do know know if we have children.
+	// *FIX: For now, return FALSE - we will know for sure soon enough.
+	return FALSE;
+}
+
+BOOL LLTaskCategoryBridge::startDrag(EDragAndDropType* type, LLUUID* id) const
+{
+	//llinfos << "LLTaskInvFVBridge::startDrag()" << llendl;
+	if(mPanel)
+	{
+		LLViewerObject* object = gObjectList.findObject(mPanel->getTaskUUID());
+		if(object)
+		{
+			LLInventoryItem* inv = NULL;
+			if((inv = (LLInventoryItem*)object->getInventoryObject(mUUID)))
+			{
+				const LLPermissions& perm = inv->getPermissions();
+				bool can_copy = gAgent.allowOperation(PERM_COPY, perm,
+														GP_OBJECT_MANIPULATE);
+				if((can_copy && perm.allowTransferTo(gAgent.getID()))
+				   || object->permYouOwner())
+//				   || gAgent.isGodlike())
+
+				{
+					*type = LLAssetType::lookupDragAndDropType(inv->getType());
+
+					*id = inv->getUUID();
+					return TRUE;
+				}
+			}
+		}
+	}
+	return FALSE;
+}
+
+BOOL LLTaskCategoryBridge::dragOrDrop(MASK mask, BOOL drop,
+									  EDragAndDropType cargo_type,
+									  void* cargo_data)
+{
+	//llinfos << "LLTaskCategoryBridge::dragOrDrop()" << llendl;
+	BOOL accept = FALSE;
+	LLViewerObject* object = gObjectList.findObject(mPanel->getTaskUUID());
+	if(object)
+	{
+		switch(cargo_type)
+		{
+		case DAD_CATEGORY:
+			accept = LLToolDragAndDrop::getInstance()->dadUpdateInventoryCategory(object,drop);
+			break;
+		case DAD_TEXTURE:
+		case DAD_SOUND:
+		case DAD_LANDMARK:
+		case DAD_OBJECT:
+		case DAD_NOTECARD:
+		case DAD_CLOTHING:
+		case DAD_BODYPART:
+		case DAD_ANIMATION:
+		case DAD_GESTURE:
+		case DAD_CALLINGCARD:
+			accept = LLToolDragAndDrop::isInventoryDropAcceptable(object, (LLViewerInventoryItem*)cargo_data);
+			if(accept && drop)
+			{
+				LLToolDragAndDrop::dropInventory(object,
+												 (LLViewerInventoryItem*)cargo_data,
+												 LLToolDragAndDrop::getInstance()->getSource(),
+												 LLToolDragAndDrop::getInstance()->getSourceID());
+			}
+			break;
+		case DAD_SCRIPT:
+			// *HACK: In order to resolve SL-22177, we need to block
+			// drags from notecards and objects onto other
+			// objects. uncomment the simpler version when we have
+			// that right.
+			//accept = LLToolDragAndDrop::isInventoryDropAcceptable(object, (LLViewerInventoryItem*)cargo_data);
+			if(LLToolDragAndDrop::isInventoryDropAcceptable(
+				   object, (LLViewerInventoryItem*)cargo_data)
+			   && (LLToolDragAndDrop::SOURCE_WORLD != LLToolDragAndDrop::getInstance()->getSource())
+			   && (LLToolDragAndDrop::SOURCE_NOTECARD != LLToolDragAndDrop::getInstance()->getSource()))
+			{
+				accept = TRUE;
+			}
+			if(accept && drop)
+			{
+				LLViewerInventoryItem* item = (LLViewerInventoryItem*)cargo_data;
+				// rez in the script active by default, rez in
+				// inactive if the control key is being held down.
+				BOOL active = ((mask & MASK_CONTROL) == 0);
+				LLToolDragAndDrop::dropScript(object, item, active,
+											  LLToolDragAndDrop::getInstance()->getSource(),
+											  LLToolDragAndDrop::getInstance()->getSourceID());
+			}
+			break;
+		default:
+			break;
+		}
+	}
+	return accept;
+}
+
+///----------------------------------------------------------------------------
+/// Class LLTaskTextureBridge
+///----------------------------------------------------------------------------
+
+class LLTaskTextureBridge : public LLTaskInvFVBridge
+{
+public:
+	LLTaskTextureBridge(
+		LLPanelObjectInventory* panel,
+		const LLUUID& uuid,
+		const std::string& name,
+		LLInventoryType::EType it);
+
+	virtual LLUIImagePtr getIcon() const;
+	virtual void openItem();
+protected:
+	LLInventoryType::EType mInventoryType;
+};
+
+LLTaskTextureBridge::LLTaskTextureBridge(
+	LLPanelObjectInventory* panel,
+	const LLUUID& uuid,
+	const std::string& name,
+	LLInventoryType::EType it) :
+	LLTaskInvFVBridge(panel, uuid, name),
+	mInventoryType(it)
+{
+}
+
+LLUIImagePtr LLTaskTextureBridge::getIcon() const
+{
+	return get_item_icon(LLAssetType::AT_TEXTURE, mInventoryType, 0, FALSE);
+}
+
+void LLTaskTextureBridge::openItem()
+{
+	llinfos << "LLTaskTextureBridge::openItem()" << llendl;
+	LLPreviewTexture* preview = LLFloaterReg::showTypedInstance<LLPreviewTexture>("preview_texture", LLSD(mUUID), TAKE_FOCUS_YES);
+	if(preview)
+	{
+		preview->setObjectID(mPanel->getTaskUUID());
+	}
+}
+
+
+///----------------------------------------------------------------------------
+/// Class LLTaskSoundBridge
+///----------------------------------------------------------------------------
+
+class LLTaskSoundBridge : public LLTaskInvFVBridge
+{
+public:
+	LLTaskSoundBridge(
+		LLPanelObjectInventory* panel,
+		const LLUUID& uuid,
+		const std::string& name);
+
+	virtual LLUIImagePtr getIcon() const;
+	virtual void openItem();
+	virtual void performAction(LLFolderView* folder, LLInventoryModel* model, std::string action);
+	virtual void buildContextMenu(LLMenuGL& menu, U32 flags);
+	static void openSoundPreview(void* data);
+};
+
+LLTaskSoundBridge::LLTaskSoundBridge(
+	LLPanelObjectInventory* panel,
+	const LLUUID& uuid,
+	const std::string& name) :
+	LLTaskInvFVBridge(panel, uuid, name)
+{
+}
+
+LLUIImagePtr LLTaskSoundBridge::getIcon() const
+{
+	return get_item_icon(LLAssetType::AT_SOUND, LLInventoryType::IT_SOUND, 0, FALSE);
+}
+
+void LLTaskSoundBridge::openItem()
+{
+	openSoundPreview((void*)this);
+}
+
+void LLTaskSoundBridge::openSoundPreview(void* data)
+{
+	LLTaskSoundBridge* self = (LLTaskSoundBridge*)data;
+	if(!self)
+		return;
+
+	LLPreviewSound* preview = LLFloaterReg::showTypedInstance<LLPreviewSound>("preview_sound", LLSD(self->mUUID), TAKE_FOCUS_YES);
+	if (preview)
+	{
+		preview->setObjectID(self->mPanel->getTaskUUID());
+	}
+}
+
+// virtual
+void LLTaskSoundBridge::performAction(LLFolderView* folder, LLInventoryModel* model, std::string action)
+{
+	if (action == "task_play")
+	{
+		LLInventoryItem* item = findItem();
+		if(item)
+		{
+			send_sound_trigger(item->getAssetUUID(), 1.0);
+		}
+	}
+	LLTaskInvFVBridge::performAction(folder, model, action);
+}
+
+void LLTaskSoundBridge::buildContextMenu(LLMenuGL& menu, U32 flags)
+{
+	LLInventoryItem* item = findItem();
+	if(!item) return;
+	std::vector<std::string> items;
+	std::vector<std::string> disabled_items;
+
+	if(item->getPermissions().getOwner() != gAgent.getID()
+	   && item->getSaleInfo().isForSale())
+	{
+		items.push_back(std::string("Task Buy"));
+
+		std::string label= LLTrans::getString("Buy");
+		// Check the price of the item.
+		S32 price = getPrice();
+		if (-1 == price)
+		{
+			llwarns << "label_buy_task_bridged_item: Invalid price" << llendl;
+		}
+		else
+		{
+			std::ostringstream info;
+			info <<  LLTrans::getString("BuyforL$") << price;
+			label.assign(info.str());
+		}
+
+		const LLView::child_list_t *list = menu.getChildList();
+		LLView::child_list_t::const_iterator itor;
+		for (itor = list->begin(); itor != list->end(); ++itor)
+		{
+			std::string name = (*itor)->getName();
+			LLMenuItemCallGL* menu_itemp = dynamic_cast<LLMenuItemCallGL*>(*itor);
+			if (name == "Task Buy" && menu_itemp)
+			{
+				menu_itemp->setLabel(label);
+			}
+		}
+	}
+	else
+	{
+		items.push_back(std::string("Task Open")); 
+		if (!isItemCopyable())
+		{
+			disabled_items.push_back(std::string("Task Open"));
+		}
+	}
+	items.push_back(std::string("Task Properties"));
+	if(isItemRenameable())
+	{
+		items.push_back(std::string("Task Rename"));
+	}
+	if(isItemRemovable())
+	{
+		items.push_back(std::string("Task Remove"));
+	}
+
+	items.push_back(std::string("Task Play"));
+
+
+	hide_context_entries(menu, items, disabled_items);
+}
+
+///----------------------------------------------------------------------------
+/// Class LLTaskLandmarkBridge
+///----------------------------------------------------------------------------
+
+class LLTaskLandmarkBridge : public LLTaskInvFVBridge
+{
+public:
+	LLTaskLandmarkBridge(
+		LLPanelObjectInventory* panel,
+		const LLUUID& uuid,
+		const std::string& name);
+
+	virtual LLUIImagePtr getIcon() const;
+};
+
+LLTaskLandmarkBridge::LLTaskLandmarkBridge(
+	LLPanelObjectInventory* panel,
+	const LLUUID& uuid,
+	const std::string& name) :
+	LLTaskInvFVBridge(panel, uuid, name)
+{
+}
+
+LLUIImagePtr LLTaskLandmarkBridge::getIcon() const
+{
+	return get_item_icon(LLAssetType::AT_LANDMARK, LLInventoryType::IT_LANDMARK, 0, FALSE);
+}
+
+
+///----------------------------------------------------------------------------
+/// Class LLTaskCallingCardBridge
+///----------------------------------------------------------------------------
+
+class LLTaskCallingCardBridge : public LLTaskInvFVBridge
+{
+public:
+	LLTaskCallingCardBridge(
+		LLPanelObjectInventory* panel,
+		const LLUUID& uuid,
+		const std::string& name);
+
+	virtual LLUIImagePtr getIcon() const;
+	virtual BOOL isItemRenameable() const;
+	virtual BOOL renameItem(const std::string& new_name);
+};
+
+LLTaskCallingCardBridge::LLTaskCallingCardBridge(
+	LLPanelObjectInventory* panel,
+	const LLUUID& uuid,
+	const std::string& name) :
+	LLTaskInvFVBridge(panel, uuid, name)
+{
+}
+
+LLUIImagePtr LLTaskCallingCardBridge::getIcon() const
+{
+	return get_item_icon(LLAssetType::AT_CALLINGCARD, LLInventoryType::IT_CALLINGCARD, 0, FALSE);
+}
+
+BOOL LLTaskCallingCardBridge::isItemRenameable() const
+{
+	return FALSE;
+}
+
+BOOL LLTaskCallingCardBridge::renameItem(const std::string& new_name)
+{
+	return FALSE;
+}
+
+
+///----------------------------------------------------------------------------
+/// Class LLTaskScriptBridge
+///----------------------------------------------------------------------------
+
+class LLTaskScriptBridge : public LLTaskInvFVBridge
+{
+public:
+	LLTaskScriptBridge(
+		LLPanelObjectInventory* panel,
+		const LLUUID& uuid,
+		const std::string& name);
+
+	virtual LLUIImagePtr getIcon() const;
+	//static BOOL enableIfCopyable( void* userdata );
+};
+
+LLTaskScriptBridge::LLTaskScriptBridge(
+	LLPanelObjectInventory* panel,
+	const LLUUID& uuid,
+	const std::string& name) :
+	LLTaskInvFVBridge(panel, uuid, name)
+{
+}
+
+LLUIImagePtr LLTaskScriptBridge::getIcon() const
+{
+	return get_item_icon(LLAssetType::AT_SCRIPT, LLInventoryType::IT_LSL, 0, FALSE);
+}
+
+
+class LLTaskLSLBridge : public LLTaskScriptBridge
+{
+public:
+	LLTaskLSLBridge(
+		LLPanelObjectInventory* panel,
+		const LLUUID& uuid,
+		const std::string& name);
+
+	virtual void openItem();
+	virtual BOOL removeItem();
+	//virtual void buildContextMenu(LLMenuGL& menu);
+
+	//static void copyToInventory(void* userdata);
+};
+
+LLTaskLSLBridge::LLTaskLSLBridge(
+	LLPanelObjectInventory* panel,
+	const LLUUID& uuid,
+	const std::string& name) :
+	LLTaskScriptBridge(panel, uuid, name)
+{
+}
+
+void LLTaskLSLBridge::openItem()
+{
+	llinfos << "LLTaskLSLBridge::openItem() " << mUUID << llendl;
+	LLViewerObject* object = gObjectList.findObject(mPanel->getTaskUUID());
+	if(!object || object->isInventoryPending())
+	{
+		return;
+	}
+	LLLiveLSLEditor* preview = LLFloaterReg::showTypedInstance<LLLiveLSLEditor>("preview_scriptedit", LLSD(mUUID), TAKE_FOCUS_YES);
+	if (preview && (object->permModify() || gAgent.isGodlike()))
+	{
+		preview->setObjectID(mPanel->getTaskUUID());
+	}
+}
+
+BOOL LLTaskLSLBridge::removeItem()
+{
+	LLFloaterReg::hideInstance("preview_scriptedit", LLSD(mUUID));
+	return LLTaskInvFVBridge::removeItem();
+}
+
+///----------------------------------------------------------------------------
+/// Class LLTaskObjectBridge
+///----------------------------------------------------------------------------
+
+class LLTaskObjectBridge : public LLTaskInvFVBridge
+{
+public:
+	LLTaskObjectBridge(
+		LLPanelObjectInventory* panel,
+		const LLUUID& uuid,
+		const std::string& name);
+
+	virtual LLUIImagePtr getIcon() const;
+};
+
+LLTaskObjectBridge::LLTaskObjectBridge(
+	LLPanelObjectInventory* panel,
+	const LLUUID& uuid,
+	const std::string& name) :
+	LLTaskInvFVBridge(panel, uuid, name)
+{
+}
+
+LLUIImagePtr LLTaskObjectBridge::getIcon() const
+{
+	BOOL item_is_multi = FALSE;
+	if ( mFlags & LLInventoryItem::II_FLAGS_OBJECT_HAS_MULTIPLE_ITEMS )
+	{
+		item_is_multi = TRUE;
+	}
+
+	return get_item_icon(LLAssetType::AT_OBJECT, LLInventoryType::IT_OBJECT, 0, item_is_multi);
+}
+
+///----------------------------------------------------------------------------
+/// Class LLTaskNotecardBridge
+///----------------------------------------------------------------------------
+
+class LLTaskNotecardBridge : public LLTaskInvFVBridge
+{
+public:
+	LLTaskNotecardBridge(
+		LLPanelObjectInventory* panel,
+		const LLUUID& uuid,
+		const std::string& name);
+
+	virtual LLUIImagePtr getIcon() const;
+	virtual void openItem();
+	virtual BOOL removeItem();
+};
+
+LLTaskNotecardBridge::LLTaskNotecardBridge(
+	LLPanelObjectInventory* panel,
+	const LLUUID& uuid,
+	const std::string& name) :
+	LLTaskInvFVBridge(panel, uuid, name)
+{
+}
+
+LLUIImagePtr LLTaskNotecardBridge::getIcon() const
+{
+	return get_item_icon(LLAssetType::AT_NOTECARD, LLInventoryType::IT_NOTECARD, 0, FALSE);
+}
+
+void LLTaskNotecardBridge::openItem()
+{
+	LLViewerObject* object = gObjectList.findObject(mPanel->getTaskUUID());
+	if(!object || object->isInventoryPending())
+	{
+		return;
+	}
+	if(object->permModify() || gAgent.isGodlike())
+	{
+		LLPreviewNotecard* preview = LLFloaterReg::showTypedInstance<LLPreviewNotecard>("preview_notecard", LLSD(mUUID), TAKE_FOCUS_YES);
+		if (preview)
+		{
+			preview->setObjectID(mPanel->getTaskUUID());
+		}
+	}
+}
+
+BOOL LLTaskNotecardBridge::removeItem()
+{
+	LLFloaterReg::hideInstance("preview_notecard", LLSD(mUUID));
+	return LLTaskInvFVBridge::removeItem();
+}
+
+///----------------------------------------------------------------------------
+/// Class LLTaskGestureBridge
+///----------------------------------------------------------------------------
+
+class LLTaskGestureBridge : public LLTaskInvFVBridge
+{
+public:
+	LLTaskGestureBridge(
+		LLPanelObjectInventory* panel,
+		const LLUUID& uuid,
+		const std::string& name);
+
+	virtual LLUIImagePtr getIcon() const;
+	virtual void openItem();
+	virtual BOOL removeItem();
+};
+
+LLTaskGestureBridge::LLTaskGestureBridge(
+	LLPanelObjectInventory* panel,
+	const LLUUID& uuid,
+	const std::string& name) :
+	LLTaskInvFVBridge(panel, uuid, name)
+{
+}
+
+LLUIImagePtr LLTaskGestureBridge::getIcon() const
+{
+	return get_item_icon(LLAssetType::AT_GESTURE, LLInventoryType::IT_GESTURE, 0, FALSE);
+}
+
+void LLTaskGestureBridge::openItem()
+{
+	LLViewerObject* object = gObjectList.findObject(mPanel->getTaskUUID());
+	if(!object || object->isInventoryPending())
+	{
+		return;
+	}
+	LLPreviewGesture::show(mUUID, mPanel->getTaskUUID());
+}
+
+BOOL LLTaskGestureBridge::removeItem()
+{
+	// Don't need to deactivate gesture because gestures inside objects can never be active.
+	LLFloaterReg::hideInstance("preview_gesture", LLSD(mUUID));
+	return LLTaskInvFVBridge::removeItem();
+}
+
+///----------------------------------------------------------------------------
+/// Class LLTaskAnimationBridge
+///----------------------------------------------------------------------------
+
+class LLTaskAnimationBridge : public LLTaskInvFVBridge
+{
+public:
+	LLTaskAnimationBridge(
+		LLPanelObjectInventory* panel,
+		const LLUUID& uuid,
+		const std::string& name);
+
+	virtual LLUIImagePtr getIcon() const;
+	virtual void openItem();
+	virtual BOOL removeItem();
+};
+
+LLTaskAnimationBridge::LLTaskAnimationBridge(
+	LLPanelObjectInventory* panel,
+	const LLUUID& uuid,
+	const std::string& name) :
+	LLTaskInvFVBridge(panel, uuid, name)
+{
+}
+
+LLUIImagePtr LLTaskAnimationBridge::getIcon() const
+{
+	return get_item_icon(LLAssetType::AT_ANIMATION, LLInventoryType::IT_ANIMATION, 0, FALSE);
+}
+
+void LLTaskAnimationBridge::openItem()
+{
+	LLViewerObject* object = gObjectList.findObject(mPanel->getTaskUUID());
+	if(!object || object->isInventoryPending())
+	{
+		return;
+	}
+
+	LLPreviewAnim* preview = LLFloaterReg::showTypedInstance<LLPreviewAnim>("preview_anim", LLSD(mUUID), TAKE_FOCUS_YES);
+	if (preview && (object->permModify() || gAgent.isGodlike()))
+	{
+		preview->setObjectID(mPanel->getTaskUUID());
+	}
+}
+
+BOOL LLTaskAnimationBridge::removeItem()
+{
+	LLFloaterReg::hideInstance("preview_anim", LLSD(mUUID));
+	return LLTaskInvFVBridge::removeItem();
+}
+
+///----------------------------------------------------------------------------
+/// Class LLTaskWearableBridge
+///----------------------------------------------------------------------------
+
+class LLTaskWearableBridge : public LLTaskInvFVBridge
+{
+public:
+	LLTaskWearableBridge(
+		LLPanelObjectInventory* panel,
+		const LLUUID& uuid,
+		const std::string& name,
+		LLAssetType::EType asset_type,
+		U32 flags);
+
+	virtual LLUIImagePtr getIcon() const;
+
+protected:
+	LLAssetType::EType		mAssetType;
+};
+
+LLTaskWearableBridge::LLTaskWearableBridge(
+	LLPanelObjectInventory* panel,
+	const LLUUID& uuid,
+	const std::string& name,
+	LLAssetType::EType asset_type,
+	U32 flags) :
+	LLTaskInvFVBridge(panel, uuid, name, flags),
+	mAssetType( asset_type )
+{
+}
+
+LLUIImagePtr LLTaskWearableBridge::getIcon() const
+{
+	return get_item_icon(mAssetType, LLInventoryType::IT_WEARABLE, mFlags, FALSE );
+}
+
+
+///----------------------------------------------------------------------------
+/// LLTaskInvFVBridge impl
+//----------------------------------------------------------------------------
+
+LLTaskInvFVBridge* LLTaskInvFVBridge::createObjectBridge(LLPanelObjectInventory* panel,
+														 LLInventoryObject* object)
+{
+	LLTaskInvFVBridge* new_bridge = NULL;
+	LLAssetType::EType type = object->getType();
+	LLInventoryItem* item = NULL;
+	switch(type)
+	{
+	case LLAssetType::AT_TEXTURE:
+		item = (LLInventoryItem*)object;
+		new_bridge = new LLTaskTextureBridge(panel,
+											 object->getUUID(),
+											 object->getName(),
+											 item->getInventoryType());
+		break;
+	case LLAssetType::AT_SOUND:
+		new_bridge = new LLTaskSoundBridge(panel,
+										   object->getUUID(),
+										   object->getName());
+		break;
+	case LLAssetType::AT_LANDMARK:
+		new_bridge = new LLTaskLandmarkBridge(panel,
+											  object->getUUID(),
+											  object->getName());
+		break;
+	case LLAssetType::AT_CALLINGCARD:
+		new_bridge = new LLTaskCallingCardBridge(panel,
+												 object->getUUID(),
+												 object->getName());
+		break;
+	case LLAssetType::AT_SCRIPT:
+		// OLD SCRIPTS DEPRECATED - JC
+		llwarns << "Old script" << llendl;
+		//new_bridge = new LLTaskOldScriptBridge(panel,
+		//									   object->getUUID(),
+		//									   object->getName());
+		break;
+	case LLAssetType::AT_OBJECT:
+		new_bridge = new LLTaskObjectBridge(panel,
+											object->getUUID(),
+											object->getName());
+		break;
+	case LLAssetType::AT_NOTECARD:
+		new_bridge = new LLTaskNotecardBridge(panel,
+											  object->getUUID(),
+											  object->getName());
+		break;
+	case LLAssetType::AT_ANIMATION:
+		new_bridge = new LLTaskAnimationBridge(panel,
+											  object->getUUID(),
+											  object->getName());
+		break;
+	case LLAssetType::AT_GESTURE:
+		new_bridge = new LLTaskGestureBridge(panel,
+											  object->getUUID(),
+											  object->getName());
+		break;
+	case LLAssetType::AT_CLOTHING:
+	case LLAssetType::AT_BODYPART:
+		item = (LLInventoryItem*)object;
+		new_bridge = new LLTaskWearableBridge(panel,
+											  object->getUUID(),
+											  object->getName(),
+											  type,
+											  item->getFlags());
+		break;
+	case LLAssetType::AT_CATEGORY:
+	case LLAssetType::AT_FAVORITE:
+		new_bridge = new LLTaskCategoryBridge(panel,
+											  object->getUUID(),
+											  object->getName());
+		break;
+	case LLAssetType::AT_LSL_TEXT:
+		new_bridge = new LLTaskLSLBridge(panel,
+										 object->getUUID(),
+										 object->getName());
+		break;
+	
+		break;
+	default:
+		llinfos << "Unhandled inventory type (llassetstorage.h): "
+				<< (S32)type << llendl;
+		break;
+	}
+	return new_bridge;
+}
+
+
+///----------------------------------------------------------------------------
+/// Class LLPanelObjectInventory
+///----------------------------------------------------------------------------
+
+static LLDefaultChildRegistry::Register<LLPanelObjectInventory> r("panel_inventory_object");
+
+void do_nothing()
+{
+}
+
+// Default constructor
+LLPanelObjectInventory::LLPanelObjectInventory(const LLPanelObjectInventory::Params& p) :
+	LLPanel(p),
+	mScroller(NULL),
+	mFolders(NULL),
+	mHaveInventory(FALSE),
+	mIsInventoryEmpty(TRUE),
+	mInventoryNeedsUpdate(FALSE)
+{
+	// Setup context menu callbacks
+	mCommitCallbackRegistrar.add("Inventory.DoToSelected", boost::bind(&LLPanelObjectInventory::doToSelected, this, _2));
+	mCommitCallbackRegistrar.add("Inventory.EmptyTrash", boost::bind(&LLInventoryModel::emptyFolderType, &gInventory, "ConfirmEmptyTrash", LLAssetType::AT_TRASH));
+	mCommitCallbackRegistrar.add("Inventory.EmptyLostAndFound", boost::bind(&LLInventoryModel::emptyFolderType, &gInventory, "ConfirmEmptyLostAndFound", LLAssetType::AT_LOST_AND_FOUND));
+	mCommitCallbackRegistrar.add("Inventory.DoCreate", boost::bind(&do_nothing));
+	mCommitCallbackRegistrar.add("Inventory.AttachObject", boost::bind(&do_nothing));
+	mCommitCallbackRegistrar.add("Inventory.BeginIMSession", boost::bind(&do_nothing));
+}
+
+// Destroys the object
+LLPanelObjectInventory::~LLPanelObjectInventory()
+{
+	if (!gIdleCallbacks.deleteFunction(idle, this))
+	{
+		llwarns << "LLPanelObjectInventory::~LLPanelObjectInventory() failed to delete callback" << llendl;
+	}
+}
+
+BOOL LLPanelObjectInventory::postBuild()
+{
+	// clear contents and initialize menus, sets up mFolders
+	reset();
+
+	// Register an idle update callback
+	gIdleCallbacks.addFunction(idle, this);
+
+	return TRUE;
+}
+
+void LLPanelObjectInventory::doToSelected(const LLSD& userdata)
+{
+	mFolders->doToSelected(&gInventory, userdata);
+}
+
+void LLPanelObjectInventory::clearContents()
+{
+	mHaveInventory = FALSE;
+	mIsInventoryEmpty = TRUE;
+	if (LLToolDragAndDrop::getInstance() && LLToolDragAndDrop::getInstance()->getSource() == LLToolDragAndDrop::SOURCE_WORLD)
+	{
+		LLToolDragAndDrop::getInstance()->endDrag();
+	}
+
+	if( mScroller )
+	{
+		// removes mFolders
+		removeChild( mScroller ); //*TODO: Really shouldn't do this during draw()/refresh()
+		mScroller->die();
+		mScroller = NULL;
+		mFolders = NULL;
+	}
+}
+
+
+void LLPanelObjectInventory::reset()
+{
+	clearContents();
+
+	setBorderVisible(FALSE);
+	
+	mCommitCallbackRegistrar.pushScope(); // push local callbacks
+	
+	LLRect dummy_rect(0, 1, 1, 0);
+	LLFolderView::Params p;
+	p.name = "task inventory";
+	p.task_id = getTaskUUID();
+	p.parent_panel = this;
+	mFolders = LLUICtrlFactory::create<LLFolderView>(p);
+	// this ensures that we never say "searching..." or "no items found"
+	mFolders->getFilter()->setShowFolderState(LLInventoryFilter::SHOW_ALL_FOLDERS);
+	mFolders->setCallbackRegistrar(&mCommitCallbackRegistrar);
+
+	LLRect scroller_rect(0, getRect().getHeight(), getRect().getWidth(), 0);
+	LLScrollContainer::Params scroll_p;
+	scroll_p.name("task inventory scroller");
+	scroll_p.rect(scroller_rect);
+	scroll_p.follows.flags(FOLLOWS_ALL);
+	mScroller = LLUICtrlFactory::create<LLScrollContainer>(scroll_p);
+	addChild(mScroller);
+	mScroller->addChild(mFolders);
+	
+	mFolders->setScrollContainer( mScroller );
+	
+	mCommitCallbackRegistrar.popScope();
+}
+
+void LLPanelObjectInventory::inventoryChanged(LLViewerObject* object,
+										InventoryObjectList* inventory,
+										S32 serial_num,
+										void* data)
+{
+	if(!object) return;
+
+	//llinfos << "invetnory arrived: \n"
+	//		<< " panel UUID: " << panel->mTaskUUID << "\n"
+	//		<< " task  UUID: " << object->mID << llendl;
+	if(mTaskUUID == object->mID)
+	{
+		mInventoryNeedsUpdate = TRUE;
+	}
+
+	// refresh any properties floaters that are hanging around.
+	if(inventory)
+	{
+		for (InventoryObjectList::const_iterator iter = inventory->begin();
+			 iter != inventory->end(); )
+		{
+			LLInventoryObject* item = *iter++;
+			LLFloaterProperties* floater = LLFloaterReg::findTypedInstance<LLFloaterProperties>("properites", item->getUUID());
+			if(floater)
+			{
+				floater->refresh();
+			}
+		}
+	}
+}
+
+void LLPanelObjectInventory::updateInventory()
+{
+	//llinfos << "inventory arrived: \n"
+	//		<< " panel UUID: " << panel->mTaskUUID << "\n"
+	//		<< " task  UUID: " << object->mID << llendl;
+	// We're still interested in this task's inventory.
+	std::set<LLUUID> selected_items;
+	BOOL inventory_has_focus = FALSE;
+	if (mHaveInventory && mFolders->getNumSelectedDescendants())
+	{
+		mFolders->getSelectionList(selected_items);
+		inventory_has_focus = gFocusMgr.childHasKeyboardFocus(mFolders);
+	}
+
+	reset();
+
+	LLViewerObject* objectp = gObjectList.findObject(mTaskUUID);
+	if (objectp)
+	{
+		LLInventoryObject* inventory_root = objectp->getInventoryRoot();
+		InventoryObjectList contents;
+		objectp->getInventoryContents(contents);
+		if (inventory_root)
+		{
+			createFolderViews(inventory_root, contents);
+			mHaveInventory = TRUE;
+			mIsInventoryEmpty = FALSE;
+			mFolders->setEnabled(TRUE);
+		}
+		else
+		{
+			// TODO: create an empty inventory
+			mIsInventoryEmpty = TRUE;
+			mHaveInventory = TRUE;
+		}
+	}
+	else
+	{
+		// TODO: create an empty inventory
+		mIsInventoryEmpty = TRUE;
+		mHaveInventory = TRUE;
+	}
+
+	// restore previous selection
+	std::set<LLUUID>::iterator selection_it;
+	BOOL first_item = TRUE;
+	for (selection_it = selected_items.begin(); selection_it != selected_items.end(); ++selection_it)
+	{
+		LLFolderViewItem* selected_item = mFolders->getItemByID(*selection_it);
+		if (selected_item)
+		{
+			//HACK: "set" first item then "change" each other one to get keyboard focus right
+			if (first_item)
+			{
+				mFolders->setSelection(selected_item, TRUE, inventory_has_focus);
+				first_item = FALSE;
+			}
+			else
+			{
+				mFolders->changeSelection(selected_item, TRUE);
+			}
+		}
+	}
+
+	mFolders->requestArrange();
+	mInventoryNeedsUpdate = FALSE;
+}
+
+// *FIX: This is currently a very expensive operation, because we have
+// to iterate through the inventory one time for each category. This
+// leads to an N^2 based on the category count. This could be greatly
+// speeded with an efficient multimap implementation, but we don't
+// have that in our current arsenal.
+void LLPanelObjectInventory::createFolderViews(LLInventoryObject* inventory_root, InventoryObjectList& contents)
+{
+	if (!inventory_root)
+	{
+		return;
+	}
+	// Create a visible root category.
+	LLTaskInvFVBridge* bridge = NULL;
+	bridge = LLTaskInvFVBridge::createObjectBridge(this, inventory_root);
+	if(bridge)
+	{
+		LLFolderViewFolder* new_folder = NULL;
+		LLFolderViewFolder::Params p;
+		p.name = inventory_root->getName();
+		p.icon = LLUI::getUIImage("Inv_FolderClosed");
+		p.icon_open = LLUI::getUIImage("Inv_FolderOpen");
+		p.root = mFolders;
+		p.listener = bridge;
+		new_folder = LLUICtrlFactory::create<LLFolderViewFolder>(p);
+		new_folder->addToFolder(mFolders, mFolders);
+		new_folder->toggleOpen();
+
+		createViewsForCategory(&contents, inventory_root, new_folder);
+	}
+}
+
+typedef std::pair<LLInventoryObject*, LLFolderViewFolder*> obj_folder_pair;
+
+void LLPanelObjectInventory::createViewsForCategory(InventoryObjectList* inventory, 
+											  LLInventoryObject* parent,
+											  LLFolderViewFolder* folder)
+{
+	// Find all in the first pass
+	LLDynamicArray<obj_folder_pair*> child_categories;
+	LLTaskInvFVBridge* bridge;
+	LLFolderViewItem* view;
+
+	InventoryObjectList::iterator it = inventory->begin();
+	InventoryObjectList::iterator end = inventory->end();
+	for( ; it != end; ++it)
+	{
+		LLInventoryObject* obj = *it;
+
+		if(parent->getUUID() == obj->getParentUUID())
+		{
+			bridge = LLTaskInvFVBridge::createObjectBridge(this, obj);
+			if(!bridge)
+			{
+				continue;
+			}
+			if(LLAssetType::AT_CATEGORY == obj->getType())
+			{
+				LLFolderViewFolder::Params p;
+				p.name = obj->getName();
+				p.icon = LLUI::getUIImage("Inv_FolderClosed");
+				p.icon_open = LLUI::getUIImage("Inv_FolderOpen");
+				p.root = mFolders;
+				p.listener = bridge;
+				view = LLUICtrlFactory::create<LLFolderViewFolder>(p);
+				child_categories.put(new obj_folder_pair(obj,
+														 (LLFolderViewFolder*)view));
+			}
+			else
+			{
+				LLFolderViewItem::Params params;
+				params.name(obj->getName());
+				params.icon(bridge->getIcon());
+				params.creation_date(bridge->getCreationDate());
+				params.root(mFolders);
+				params.listener(bridge);
+				params.rect(LLRect());
+				view = LLUICtrlFactory::create<LLFolderViewItem> (params);
+			}
+			view->addToFolder(folder, mFolders);
+		}
+	}
+
+	// now, for each category, do the second pass
+	for(S32 i = 0; i < child_categories.count(); i++)
+	{
+		createViewsForCategory(inventory, child_categories[i]->first,
+							   child_categories[i]->second );
+		delete child_categories[i];
+	}
+}
+
+void LLPanelObjectInventory::refresh()
+{
+	//llinfos << "LLPanelObjectInventory::refresh()" << llendl;
+	BOOL has_inventory = FALSE;
+	const BOOL non_root_ok = TRUE;
+	LLSelectNode* node = LLSelectMgr::getInstance()->getSelection()->getFirstRootNode(NULL, non_root_ok);
+	if(node)
+	{
+		LLViewerObject* object = node->getObject();
+		if(object && ((LLSelectMgr::getInstance()->getSelection()->getRootObjectCount() == 1)
+					  || (LLSelectMgr::getInstance()->getSelection()->getObjectCount() == 1)))
+		{
+			// determine if we need to make a request. Start with a
+			// default based on if we have inventory at all.
+			BOOL make_request = !mHaveInventory;
+
+			// If the task id is different than what we've stored,
+			// then make the request.
+			if(mTaskUUID != object->mID)
+			{
+				mTaskUUID = object->mID;
+				make_request = TRUE;
+
+				// This is a new object so pre-emptively clear the contents
+				// Otherwise we show the old stuff until the update comes in
+				clearContents();
+
+				// Register for updates from this object,
+				registerVOInventoryListener(object,NULL);
+			}
+
+			// Based on the node information, we may need to dirty the
+			// object inventory and get it again.
+			if(node->mValid)
+			{
+				if(node->mInventorySerial != object->getInventorySerial() || object->isInventoryDirty())
+				{
+					make_request = TRUE;
+				}
+			}
+
+			// do the request if necessary.
+			if(make_request)
+			{
+				requestVOInventory();
+			}
+			has_inventory = TRUE;
+		}
+	}
+	if(!has_inventory)
+	{
+		mTaskUUID = LLUUID::null;
+		removeVOInventoryListener();
+		clearContents();
+	}
+	//llinfos << "LLPanelObjectInventory::refresh() " << mTaskUUID << llendl;
+}
+
+void LLPanelObjectInventory::removeSelectedItem()
+{
+	if(mFolders)
+	{
+		mFolders->removeSelectedItems();
+	}
+}
+
+void LLPanelObjectInventory::startRenamingSelectedItem()
+{
+	if(mFolders)
+	{
+		mFolders->startRenamingSelectedItem();
+	}
+}
+
+void LLPanelObjectInventory::draw()
+{
+	LLPanel::draw();
+
+	if(mIsInventoryEmpty)
+	{
+		if((LLUUID::null != mTaskUUID) && (!mHaveInventory))
+		{
+			LLFontGL::getFontSansSerif()->renderUTF8(LLTrans::getString("LoadingContents"), 0,
+													 (S32)(getRect().getWidth() * 0.5f),
+													 10,
+													 LLColor4( 1, 1, 1, 1 ),
+													 LLFontGL::HCENTER,
+													 LLFontGL::BOTTOM);
+		}
+		else if(mHaveInventory)
+		{
+			LLFontGL::getFontSansSerif()->renderUTF8(LLTrans::getString("NoContents"), 0,
+													 (S32)(getRect().getWidth() * 0.5f),
+													 10,
+													 LLColor4( 1, 1, 1, 1 ),
+													 LLFontGL::HCENTER,
+													 LLFontGL::BOTTOM);
+		}
+	}
+}
+
+void LLPanelObjectInventory::deleteAllChildren()
+{
+	mScroller = NULL;
+	mFolders = NULL;
+	LLView::deleteAllChildren();
+}
+
+BOOL LLPanelObjectInventory::handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop, EDragAndDropType cargo_type, void *cargo_data, EAcceptance *accept, std::string& tooltip_msg)
+{
+	if (mFolders && mHaveInventory)
+	{
+		LLFolderViewItem* folderp = mFolders->getNextFromChild(NULL);
+		if (!folderp)
+		{
+			return FALSE;
+		}
+		// Try to pass on unmodified mouse coordinates
+		S32 local_x = x - mFolders->getRect().mLeft;
+		S32 local_y = y - mFolders->getRect().mBottom;
+
+		if (mFolders->pointInView(local_x, local_y))
+		{
+			return mFolders->handleDragAndDrop(local_x, local_y, mask, drop, cargo_type, cargo_data, accept, tooltip_msg);
+		}
+		else
+		{
+			//force mouse coordinates to be inside folder rectangle
+			return mFolders->handleDragAndDrop(5, 1, mask, drop, cargo_type, cargo_data, accept, tooltip_msg);
+		}
+	}
+	else
+	{
+		return FALSE;
+	}
+}
+
+//static
+void LLPanelObjectInventory::idle(void* user_data)
+{
+	LLPanelObjectInventory* self = (LLPanelObjectInventory*)user_data;
+
+
+	if (self->mInventoryNeedsUpdate)
+	{
+		self->updateInventory();
+	}
+}
diff --git a/indra/newview/llpanelobjectinventory.h b/indra/newview/llpanelobjectinventory.h
new file mode 100644
index 00000000000..7a39d8fabc4
--- /dev/null
+++ b/indra/newview/llpanelobjectinventory.h
@@ -0,0 +1,102 @@
+/** 
+ * @file llpanelobjectinventory.h
+ * @brief LLPanelObjectInventory class definition
+ *
+ * $LicenseInfo:firstyear=2002&license=viewergpl$
+ * 
+ * Copyright (c) 2002-2009, Linden Research, Inc.
+ * 
+ * Second Life Viewer Source Code
+ * The source code in this file ("Source Code") is provided by Linden Lab
+ * to you under the terms of the GNU General Public License, version 2.0
+ * ("GPL"), unless you have obtained a separate licensing agreement
+ * ("Other License"), formally executed by you and Linden Lab.  Terms of
+ * the GPL can be found in doc/GPL-license.txt in this distribution, or
+ * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
+ * 
+ * There are special exceptions to the terms and conditions of the GPL as
+ * it is applied to this Source Code. View the full text of the exception
+ * in the file doc/FLOSS-exception.txt in this software distribution, or
+ * online at
+ * http://secondlifegrid.net/programs/open_source/licensing/flossexception
+ * 
+ * By copying, modifying or distributing this software, you acknowledge
+ * that you have read and understood your obligations described above,
+ * and agree to abide by those obligations.
+ * 
+ * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
+ * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
+ * COMPLETENESS OR PERFORMANCE.
+ * $/LicenseInfo$
+ */
+
+#ifndef LL_LLPANELOBJECTINVENTORY_H
+#define LL_LLPANELOBJECTINVENTORY_H
+
+#include "llvoinventorylistener.h"
+#include "llpanel.h"
+
+#include "llinventory.h"
+
+class LLScrollContainer;
+class LLFolderView;
+class LLFolderViewFolder;
+class LLViewerObject;
+
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+// Class LLPanelObjectInventory
+//
+// This class represents the panel used to view and control a
+// particular task's inventory.
+//
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+class LLPanelObjectInventory : public LLPanel, public LLVOInventoryListener
+{
+public:
+	// dummy param block for template registration purposes
+	struct Params : public LLPanel::Params {};
+
+	LLPanelObjectInventory(const Params&);
+	virtual ~LLPanelObjectInventory();
+	
+	virtual BOOL postBuild();
+
+	void doToSelected(const LLSD& userdata);
+	
+	void refresh();
+	const LLUUID& getTaskUUID() { return mTaskUUID;}
+	void removeSelectedItem();
+	void startRenamingSelectedItem();
+
+	LLFolderView* getRootFolder() const { return mFolders; }
+
+	virtual void draw();
+	virtual void deleteAllChildren();
+	virtual BOOL handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop, EDragAndDropType cargo_type, void *cargo_data, EAcceptance *accept, std::string& tooltip_msg);
+	
+	static void idle(void* user_data);
+
+protected:
+	void reset();
+	/*virtual*/ void inventoryChanged(LLViewerObject* object,
+								 InventoryObjectList* inventory,
+								 S32 serial_num,
+								 void* user_data);
+	void updateInventory();
+	void createFolderViews(LLInventoryObject* inventory_root, InventoryObjectList& contents);
+	void createViewsForCategory(InventoryObjectList* inventory,
+								LLInventoryObject* parent,
+								LLFolderViewFolder* folder);
+	void clearContents();
+
+private:
+	LLScrollContainer* mScroller;
+	LLFolderView* mFolders;
+	
+	LLUUID mTaskUUID;
+	BOOL mHaveInventory;
+	BOOL mIsInventoryEmpty;
+	BOOL mInventoryNeedsUpdate;
+};
+
+#endif // LL_LLPANELOBJECTINVENTORY_H
diff --git a/indra/newview/llpanelvolume.cpp b/indra/newview/llpanelvolume.cpp
index 4ac109bf3d2..5a70842a733 100644
--- a/indra/newview/llpanelvolume.cpp
+++ b/indra/newview/llpanelvolume.cpp
@@ -57,7 +57,6 @@
 #include "llfirstuse.h"
 #include "llfocusmgr.h"
 #include "llmanipscale.h"
-#include "llpanelinventory.h"
 #include "llpreviewscript.h"
 #include "llresmgr.h"
 #include "llselectmgr.h"
diff --git a/indra/newview/llpanelvolume.h b/indra/newview/llpanelvolume.h
index 9d197aafa58..7bc935f986f 100644
--- a/indra/newview/llpanelvolume.h
+++ b/indra/newview/llpanelvolume.h
@@ -45,7 +45,6 @@ class LLUICtrl;
 class LLButton;
 class LLViewerObject;
 class LLComboBox;
-class LLPanelInventory;
 class LLColorSwatchCtrl;
 
 class LLPanelVolume : public LLPanel
diff --git a/indra/newview/llplacesinventorybridge.cpp b/indra/newview/llplacesinventorybridge.cpp
index b3b48577278..83443687c92 100644
--- a/indra/newview/llplacesinventorybridge.cpp
+++ b/indra/newview/llplacesinventorybridge.cpp
@@ -38,6 +38,7 @@
 
 #include "llfloaterinventory.h" // for LLInventoryPanel
 #include "llfolderview.h" // for FIRST_SELECTED_ITEM
+#include "llinventorypanel.h"
 
 
 static const std::string LANDMARKS_INVENTORY_LIST_NAME("landmarks_list");
@@ -83,7 +84,7 @@ void LLPlacesLandmarkBridge::buildContextMenu(LLMenuGL& menu, U32 flags)
 		// they should be synchronized with Places/My Landmarks/Gear menu. See EXT-1601 
 	}
 
-	hideContextEntries(menu, items, disabled_items);
+	hide_context_entries(menu, items, disabled_items);
 }
 
 
@@ -116,7 +117,7 @@ void LLPlacesFolderBridge::buildContextMenu(LLMenuGL& menu, U32 flags)
 		// repeat parent functionality
  		sSelf = this; // necessary for "New Folder" functionality
 
-		hideContextEntries(menu, items, disabled_items);
+		hide_context_entries(menu, items, disabled_items);
 	}
 }
 
diff --git a/indra/newview/llpreviewscript.cpp b/indra/newview/llpreviewscript.cpp
index ac7abf14485..a6f5465e1b4 100644
--- a/indra/newview/llpreviewscript.cpp
+++ b/indra/newview/llpreviewscript.cpp
@@ -89,7 +89,6 @@
 #include "lltrans.h"
 #include "llviewercontrol.h"
 #include "llappviewer.h"
-#include "llpanelinventory.h"
 
 const std::string HELLO_LSL =
 	"default\n"
diff --git a/indra/newview/llsidepanelinventory.cpp b/indra/newview/llsidepanelinventory.cpp
new file mode 100644
index 00000000000..8a1b97695d1
--- /dev/null
+++ b/indra/newview/llsidepanelinventory.cpp
@@ -0,0 +1,276 @@
+/**
+ * @file LLSidepanelInventory.cpp
+ * @brief Side Bar "Inventory" panel
+ *
+ * $LicenseInfo:firstyear=2009&license=viewergpl$
+ *
+ * Copyright (c) 2004-2009, Linden Research, Inc.
+ *
+ * Second Life Viewer Source Code
+ * The source code in this file ("Source Code") is provided by Linden Lab
+ * to you under the terms of the GNU General Public License, version 2.0
+ * ("GPL"), unless you have obtained a separate licensing agreement
+ * ("Other License"), formally executed by you and Linden Lab.  Terms of
+ * the GPL can be found in doc/GPL-license.txt in this distribution, or
+ * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
+ *
+ * There are special exceptions to the terms and conditions of the GPL as
+ * it is applied to this Source Code. View the full text of the exception
+ * in the file doc/FLOSS-exception.txt in this software distribution, or
+ * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception
+ *
+ * By copying, modifying or distributing this software, you acknowledge
+ * that you have read and understood your obligations described above,
+ * and agree to abide by those obligations.
+ *
+ * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
+ * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
+ * COMPLETENESS OR PERFORMANCE.
+ * $/LicenseInfo$
+ */
+
+#include "llviewerprecompiledheaders.h"
+#include "llsidepanelinventory.h"
+
+#include "llagent.h"
+#include "llbutton.h"
+#include "llinventorybridge.h"
+#include "llinventorypanel.h"
+#include "llpanelmaininventory.h"
+#include "llsidepanelobjectinfo.h"
+#include "lltabcontainer.h"
+
+static const S32 LANDMARK_FOLDERS_MENU_WIDTH = 250;
+static const std::string AGENT_INFO_TYPE			= "agent";
+static const std::string CREATE_LANDMARK_INFO_TYPE	= "create_landmark";
+static const std::string LANDMARK_INFO_TYPE			= "landmark";
+static const std::string REMOTE_PLACE_INFO_TYPE		= "remote_place";
+static const std::string TELEPORT_HISTORY_INFO_TYPE	= "teleport_history";
+
+// Helper functions
+static void setAllChildrenVisible(LLView* view, BOOL visible);
+
+static LLRegisterPanelClassWrapper<LLSidepanelInventory> t_inventory("sidepanel_inventory");
+
+LLSidepanelInventory::LLSidepanelInventory()
+	:	LLPanel(),
+		mSidepanelObjectInfo(NULL),
+		mItem(NULL)
+{
+
+	//LLUICtrlFactory::getInstance()->buildPanel(this, "panel_inventory.xml"); // Called from LLRegisterPanelClass::defaultPanelClassBuilder()
+}
+
+LLSidepanelInventory::~LLSidepanelInventory()
+{
+}
+
+BOOL LLSidepanelInventory::postBuild()
+{
+	mInfoBtn = getChild<LLButton>("info_btn");
+	mInfoBtn->setClickedCallback(boost::bind(&LLSidepanelInventory::onInfoButtonClicked, this));
+
+	mShareBtn = getChild<LLButton>("share_btn");
+	mShareBtn->setClickedCallback(boost::bind(&LLSidepanelInventory::onShareButtonClicked, this));
+
+	mShareBtn = getChild<LLButton>("share_btn");
+	mShareBtn->setClickedCallback(boost::bind(&LLSidepanelInventory::onShareButtonClicked, this));
+
+	mWearBtn = getChild<LLButton>("wear_btn");
+	mWearBtn->setClickedCallback(boost::bind(&LLSidepanelInventory::onWearButtonClicked, this));
+
+	mPlayBtn = getChild<LLButton>("play_btn");
+	mPlayBtn->setClickedCallback(boost::bind(&LLSidepanelInventory::onPlayButtonClicked, this));
+
+	mTeleportBtn = getChild<LLButton>("teleport_btn");
+	mTeleportBtn->setClickedCallback(boost::bind(&LLSidepanelInventory::onTeleportButtonClicked, this));
+
+	mOverflowBtn = getChild<LLButton>("overflow_btn");
+	mOverflowBtn->setClickedCallback(boost::bind(&LLSidepanelInventory::onOverflowButtonClicked, this));
+
+	mTabContainer = getChild<LLTabContainer>("Inventory Tabs");
+	mSidepanelObjectInfo = getChild<LLSidepanelObjectInfo>("sidepanel_object_info");
+
+	mPanelMainInventory = getChild<LLPanelMainInventory>("panel_main_inventory");
+	mPanelMainInventory->setSelectCallback(boost::bind(&LLSidepanelInventory::onSelectionChange, this, _1, _2));
+
+	LLButton* back_btn = mSidepanelObjectInfo->getChild<LLButton>("back_btn");
+	back_btn->setClickedCallback(boost::bind(&LLSidepanelInventory::onBackButtonClicked, this));
+
+	return TRUE;
+}
+
+void LLSidepanelInventory::onOpen(const LLSD& key)
+{
+	if(mSidepanelObjectInfo == NULL || key.size() == 0)
+		return;
+
+	mItem = NULL;
+
+	LLInventoryItem* item = gInventory.getItem(key["id"].asUUID());
+	if (!item)
+	{
+		return;
+	}
+	setItem(item);
+	toggleObjectInfoPanel(TRUE);
+}
+
+void LLSidepanelInventory::setItem(LLInventoryItem* item)
+{
+	if (!mSidepanelObjectInfo || !item)
+		return;
+
+	mItem = item;
+
+	LLAssetType::EType item_type = mItem->getActualType();
+	if (item_type == LLAssetType::AT_LINK)
+	{
+		mItem = gInventory.getItem(mItem->getLinkedUUID());
+		if (mItem.isNull())
+			return;
+	}
+
+	// Check if item is in agent's inventory and he has the permission to modify it.
+	BOOL is_object_editable = gInventory.isObjectDescendentOf(mItem->getUUID(), gInventory.getRootFolderID()) &&
+		mItem->getPermissions().allowModifyBy(gAgent.getID());
+
+	mInfoBtn->setEnabled(is_object_editable);
+	// mSaveBtn->setEnabled(is_object_editable);
+
+	mSidepanelObjectInfo->displayItemInfo(mItem);
+}
+
+void LLSidepanelInventory::onInfoButtonClicked()
+{
+	LLInventoryItem *item = getSelectedItem();
+	if (item)
+	{
+		setItem(item);
+		toggleObjectInfoPanel(TRUE);
+	}
+}
+
+void LLSidepanelInventory::onShareButtonClicked()
+{
+}
+
+void LLSidepanelInventory::performActionOnSelection(const std::string &action)
+{
+	LLInventoryPanel *panel = mPanelMainInventory->getActivePanel();
+	LLFolderViewItem* current_item = panel->getRootFolder()->getCurSelectedItem();
+	if (!current_item)
+	{
+		return;
+	}
+	current_item->getListener()->performAction(panel->getRootFolder(), panel->getModel(), action);
+}
+
+void LLSidepanelInventory::onWearButtonClicked()
+{
+	performActionOnSelection("wear");
+	performActionOnSelection("attach");
+}
+
+void LLSidepanelInventory::onPlayButtonClicked()
+{
+	performActionOnSelection("activate");
+}
+
+void LLSidepanelInventory::onTeleportButtonClicked()
+{
+	performActionOnSelection("teleport");
+}
+
+void LLSidepanelInventory::onOverflowButtonClicked()
+{
+}
+
+void LLSidepanelInventory::onBackButtonClicked()
+{
+	if (!mSidepanelObjectInfo)
+		return;
+	
+	toggleObjectInfoPanel(FALSE);
+
+	
+	updateVerbs();
+}
+
+void LLSidepanelInventory::onSelectionChange(const std::deque<LLFolderViewItem*> &items, BOOL user_action)
+{
+	updateVerbs();
+}
+
+void LLSidepanelInventory::toggleObjectInfoPanel(BOOL visible)
+{
+	if (!mSidepanelObjectInfo)
+		return;
+
+	mSidepanelObjectInfo->setVisible(visible);
+	mTabContainer->setVisible(!visible);
+
+	if (visible)
+	{
+		mSidepanelObjectInfo->reset();
+		mSidepanelObjectInfo->setEditMode(FALSE);
+
+		LLRect rect = getRect();
+		LLRect new_rect = LLRect(rect.mLeft, rect.mTop, rect.mRight, mTabContainer->getRect().mBottom);
+		mSidepanelObjectInfo->reshape(new_rect.getWidth(),new_rect.getHeight());
+	}
+}
+
+void LLSidepanelInventory::updateVerbs()
+{
+	mInfoBtn->setEnabled(FALSE);
+	mShareBtn->setEnabled(FALSE);
+
+	mWearBtn->setVisible(FALSE);
+	mWearBtn->setEnabled(FALSE);
+	mPlayBtn->setVisible(FALSE);
+	mPlayBtn->setEnabled(FALSE);
+ 	mTeleportBtn->setVisible(FALSE);
+ 	mTeleportBtn->setEnabled(FALSE);
+	
+	const LLInventoryItem *item = getSelectedItem();
+	if (!item)
+		return;
+
+	mInfoBtn->setEnabled(TRUE);
+	mShareBtn->setEnabled(TRUE);
+
+	switch(item->getInventoryType())
+	{
+		case LLInventoryType::IT_WEARABLE:
+		case LLInventoryType::IT_OBJECT:
+		case LLInventoryType::IT_ATTACHMENT:
+			mWearBtn->setVisible(TRUE);
+			mWearBtn->setEnabled(TRUE);
+			break;
+		case LLInventoryType::IT_SOUND:
+		case LLInventoryType::IT_GESTURE:
+		case LLInventoryType::IT_ANIMATION:
+			mPlayBtn->setVisible(TRUE);
+			mPlayBtn->setEnabled(TRUE);
+			break;
+		case LLInventoryType::IT_LANDMARK:
+			mTeleportBtn->setVisible(TRUE);
+			mTeleportBtn->setEnabled(TRUE);
+			break;
+		default:
+			break;
+	}
+}
+
+LLInventoryItem *LLSidepanelInventory::getSelectedItem()
+{
+	LLFolderViewItem* current_item = mPanelMainInventory->getActivePanel()->getRootFolder()->getCurSelectedItem();
+	if (!current_item)
+	{
+		return NULL;
+	}
+	const LLUUID &item_id = current_item->getListener()->getUUID();
+	LLInventoryItem *item = gInventory.getItem(item_id);
+	return item;
+}
diff --git a/indra/newview/llsidepanelinventory.h b/indra/newview/llsidepanelinventory.h
new file mode 100644
index 00000000000..784f5e43b7c
--- /dev/null
+++ b/indra/newview/llsidepanelinventory.h
@@ -0,0 +1,85 @@
+/** 
+ * @file LLSidepanelInventory.h
+ * @brief Side Bar "Inventory" panel
+ *
+ * $LicenseInfo:firstyear=2009&license=viewergpl$
+ * 
+ * Copyright (c) 2004-2009, Linden Research, Inc.
+ * 
+ * Second Life Viewer Source Code
+ * The source code in this file ("Source Code") is provided by Linden Lab
+ * to you under the terms of the GNU General Public License, version 2.0
+ * ("GPL"), unless you have obtained a separate licensing agreement
+ * ("Other License"), formally executed by you and Linden Lab.  Terms of
+ * the GPL can be found in doc/GPL-license.txt in this distribution, or
+ * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
+ * 
+ * There are special exceptions to the terms and conditions of the GPL as
+ * it is applied to this Source Code. View the full text of the exception
+ * in the file doc/FLOSS-exception.txt in this software distribution, or
+ * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception
+ * 
+ * By copying, modifying or distributing this software, you acknowledge
+ * that you have read and understood your obligations described above,
+ * and agree to abide by those obligations.
+ * 
+ * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
+ * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
+ * COMPLETENESS OR PERFORMANCE.
+ * $/LicenseInfo$
+ */
+
+#ifndef LL_LLSIDEPANELINVENTORY_H
+#define LL_LLSIDEPANELINVENTORY_H
+
+#include "llpanel.h"
+
+class LLInventoryItem;
+class LLSidepanelObjectInfo;
+class LLTabContainer;
+class LLPanelMainInventory;
+class LLFolderViewItem;
+
+class LLSidepanelInventory : public LLPanel
+{
+public:
+	LLSidepanelInventory();
+	virtual ~LLSidepanelInventory();
+
+	/*virtual*/ BOOL postBuild();
+	/*virtual*/ void onOpen(const LLSD& key);
+
+	void setItem(LLInventoryItem* item);
+
+protected:
+	LLInventoryItem *getSelectedItem();
+	void onSelectionChange(const std::deque<LLFolderViewItem*> &items, BOOL user_action);
+	void onTabSelected();
+	void toggleObjectInfoPanel(BOOL visible);
+	void updateVerbs();
+	void performActionOnSelection(const std::string &action);
+
+	LLTabContainer*				mTabContainer;
+	LLSidepanelObjectInfo*		mSidepanelObjectInfo;
+	LLPanelMainInventory*		mPanelMainInventory;
+
+	void 						onInfoButtonClicked();
+	void 						onShareButtonClicked();
+	void 						onWearButtonClicked();
+	void 						onPlayButtonClicked();
+	void 						onTeleportButtonClicked();
+	void 						onOverflowButtonClicked();
+	void 						onBackButtonClicked();
+	
+	LLButton*					mInfoBtn;
+	LLButton*					mShareBtn;
+	LLButton*					mWearBtn;
+	LLButton*					mPlayBtn;
+	LLButton*					mTeleportBtn;
+	LLButton*					mOverflowBtn;
+
+	// Pointer to a item
+	LLPointer<LLInventoryItem>	mItem;
+};
+
+#endif //LL_LLSIDEPANELINVENTORY_H
diff --git a/indra/newview/lltexturectrl.cpp b/indra/newview/lltexturectrl.cpp
index b5aec1b80bc..9f0e2057125 100644
--- a/indra/newview/lltexturectrl.cpp
+++ b/indra/newview/lltexturectrl.cpp
@@ -47,7 +47,9 @@
 #include "llfolderview.h"
 #include "llfoldervieweventlistener.h"
 #include "llinventory.h"
+#include "llinventoryfunctions.h"
 #include "llinventorymodel.h"
+#include "llinventorypanel.h"
 #include "llfloaterinventory.h"
 #include "lllineeditor.h"
 #include "llui.h"
diff --git a/indra/newview/lltoastgroupnotifypanel.cpp b/indra/newview/lltoastgroupnotifypanel.cpp
index e26a0776ff4..e78737fe0d5 100644
--- a/indra/newview/lltoastgroupnotifypanel.cpp
+++ b/indra/newview/lltoastgroupnotifypanel.cpp
@@ -38,6 +38,7 @@
 
 #include "llbutton.h"
 #include "lliconctrl.h"
+#include "llinventoryfunctions.h"
 #include "llnotify.h"
 #include "lltextbox.h"
 
diff --git a/indra/newview/llviewerinventory.cpp b/indra/newview/llviewerinventory.cpp
index 366e5602bd8..470739baa90 100644
--- a/indra/newview/llviewerinventory.cpp
+++ b/indra/newview/llviewerinventory.cpp
@@ -38,6 +38,7 @@
 
 #include "llagent.h"
 #include "llfoldertype.h"
+#include "llfolderview.h"
 #include "llviewercontrol.h"
 #include "llconsole.h"
 #include "llinventorymodel.h"
diff --git a/indra/newview/llviewermenu.cpp b/indra/newview/llviewermenu.cpp
index 864cf9d57bb..a2b0923df0c 100644
--- a/indra/newview/llviewermenu.cpp
+++ b/indra/newview/llviewermenu.cpp
@@ -50,6 +50,7 @@
 #include "llfocusmgr.h"
 #include "llfontgl.h"
 #include "llinstantmessage.h"
+#include "llinventorypanel.h"
 #include "llpermissionsflags.h"
 #include "llrect.h"
 #include "llsecondlifeurls.h"
diff --git a/indra/newview/llviewermessage.cpp b/indra/newview/llviewermessage.cpp
index 320f0f83ff9..0a30b0069e1 100644
--- a/indra/newview/llviewermessage.cpp
+++ b/indra/newview/llviewermessage.cpp
@@ -1,5722 +1,5723 @@
-/** 
- * @file llviewermessage.cpp
- * @brief Dumping ground for viewer-side message system callbacks.
- *
- * $LicenseInfo:firstyear=2002&license=viewergpl$
- * 
- * Copyright (c) 2002-2009, Linden Research, Inc.
- * 
- * Second Life Viewer Source Code
- * The source code in this file ("Source Code") is provided by Linden Lab
- * to you under the terms of the GNU General Public License, version 2.0
- * ("GPL"), unless you have obtained a separate licensing agreement
- * ("Other License"), formally executed by you and Linden Lab.  Terms of
- * the GPL can be found in doc/GPL-license.txt in this distribution, or
- * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
- * 
- * There are special exceptions to the terms and conditions of the GPL as
- * it is applied to this Source Code. View the full text of the exception
- * in the file doc/FLOSS-exception.txt in this software distribution, or
- * online at
- * http://secondlifegrid.net/programs/open_source/licensing/flossexception
- * 
- * By copying, modifying or distributing this software, you acknowledge
- * that you have read and understood your obligations described above,
- * and agree to abide by those obligations.
- * 
- * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
- * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
- * COMPLETENESS OR PERFORMANCE.
- * $/LicenseInfo$
- */
-
-#include "llviewerprecompiledheaders.h"
-
-#include "llviewermessage.h"
-
-#include <deque>
-
-#include "llaudioengine.h" 
-#include "indra_constants.h"
-#include "lscript_byteformat.h"
-#include "mean_collision_data.h"
-#include "llfloaterbump.h"
-#include "llassetstorage.h"
-#include "llcachename.h"
-#include "llchat.h"
-#include "lldbstrings.h"
-#include "lleconomy.h"
-#include "llfilepicker.h"
-#include "llfloaterreg.h"
-#include "llfocusmgr.h"
-#include "llfollowcamparams.h"
-#include "llinstantmessage.h"
-#include "llquantize.h"
-#include "llregionflags.h"
-#include "llregionhandle.h"
-#include "llsdserialize.h"
-#include "llstring.h"
-#include "llteleportflags.h"
-#include "lltracker.h"
-#include "lltransactionflags.h"
-#include "llxfermanager.h"
-#include "message.h"
-#include "sound_ids.h"
-#include "lltimer.h"
-#include "llmd5.h"
-
-#include "llagent.h"
-#include "llcallingcard.h"
-#include "llconsole.h"
-#include "llvieweraudio.h"
-#include "llviewercontrol.h"
-#include "lldrawpool.h"
-#include "llfirstuse.h"
-#include "llfloateranimpreview.h"
-#include "llfloaterbuycurrency.h"
-#include "llfloaterbuyland.h"
-#include "llfloaterchat.h"
-#include "llfloaterimagepreview.h"
-#include "llfloaterland.h"
-#include "llfloaterregioninfo.h"
-#include "llfloaterlandholdings.h"
-#include "llurldispatcher.h"
-#include "llfloaterpostcard.h"
-#include "llfloaterpreference.h"
-#include "llfollowcam.h"
-#include "llgroupnotify.h"
-#include "llhudeffect.h"
-#include "llhudeffecttrail.h"
-#include "llhudmanager.h"
-#include "llimpanel.h"
-#include "llinventorymodel.h"
-#include "llfloaterinventory.h"
-#include "llmenugl.h"
-#include "llmoveview.h"
-#include "llmutelist.h"
-#include "llnearbychat.h"
-#include "llnotifications.h"
-#include "llnotify.h"
-#include "llpanelgrouplandmoney.h"
-#include "llpanelplaces.h"
-#include "llrecentpeople.h"
-#include "llselectmgr.h"
-#include "llsidetray.h"
-#include "llstartup.h"
-#include "llsky.h"
-#include "llslurl.h"
-#include "llstatenums.h"
-#include "llstatusbar.h"
-#include "llimview.h"
-#include "lltool.h"
-#include "lltoolbar.h"
-#include "lltoolmgr.h"
-#include "lltrans.h"
-#include "llui.h"			// for make_ui_sound
-#include "lluploaddialog.h"
-#include "llviewercamera.h"
-#include "llviewergenericmessage.h"
-#include "llviewerinventory.h"
-#include "llviewermenu.h"
-#include "llviewerobject.h"
-#include "llviewerobjectlist.h"
-#include "llviewerparcelmgr.h"
-#include "llviewerpartsource.h"
-#include "llviewerregion.h"
-#include "llviewerstats.h"
-#include "llviewertexteditor.h"
-#include "llviewerthrottle.h"
-#include "llviewerwindow.h"
-#include "llvlmanager.h"
-#include "llvoavatarself.h"
-#include "llvotextbubble.h"
-#include "llweb.h"
-#include "llworld.h"
-#include "pipeline.h"
-#include "llappviewer.h"
-#include "llfloaterworldmap.h"
-#include "llviewerdisplay.h"
-#include "llkeythrottle.h"
-#include "llgroupactions.h"
-#include "llagentui.h"
-#include "llpanelblockedlist.h"
-#include "llpanelplaceinfo.h"
-
-#include <boost/tokenizer.hpp>
-#include <boost/algorithm/string/split.hpp>
-
-#if LL_WINDOWS // For Windows specific error handler
-#include "llwindebug.h"	// For the invalid message handler
-#endif
-
-//#include "llnearbychathistory.h"
-#include "llnotificationmanager.h"
-
-//
-// Constants
-//
-const F32 BIRD_AUDIBLE_RADIUS = 32.0f;
-const F32 SIT_DISTANCE_FROM_TARGET = 0.25f;
-static const F32 LOGOUT_REPLY_TIME = 3.f;	// Wait this long after LogoutReply before quitting.
-
-// Determine how quickly residents' scripts can issue question dialogs
-// Allow bursts of up to 5 dialogs in 10 seconds. 10*2=20 seconds recovery if throttle kicks in
-static const U32 LLREQUEST_PERMISSION_THROTTLE_LIMIT	= 5;     // requests
-static const F32 LLREQUEST_PERMISSION_THROTTLE_INTERVAL	= 10.0f; // seconds
-
-extern BOOL gDebugClicks;
-
-// function prototypes
-void open_offer(const std::vector<LLUUID>& items, const std::string& from_name);
-bool check_offer_throttle(const std::string& from_name, bool check_only);
-
-//inventory offer throttle globals
-LLFrameTimer gThrottleTimer;
-const U32 OFFER_THROTTLE_MAX_COUNT=5; //number of items per time period
-const F32 OFFER_THROTTLE_TIME=10.f; //time period in seconds
-
-//script permissions
-const std::string SCRIPT_QUESTIONS[SCRIPT_PERMISSION_EOF] = 
-	{ 
-		"ScriptTakeMoney",
-		"ActOnControlInputs",
-		"RemapControlInputs",
-		"AnimateYourAvatar",
-		"AttachToYourAvatar",
-		"ReleaseOwnership",
-		"LinkAndDelink",
-		"AddAndRemoveJoints",
-		"ChangePermissions",
-		"TrackYourCamera",
-		"ControlYourCamera"
-	};
-
-const BOOL SCRIPT_QUESTION_IS_CAUTION[SCRIPT_PERMISSION_EOF] = 
-{
-	TRUE,	// ScriptTakeMoney,
-	FALSE,	// ActOnControlInputs
-	FALSE,	// RemapControlInputs
-	FALSE,	// AnimateYourAvatar
-	FALSE,	// AttachToYourAvatar
-	FALSE,	// ReleaseOwnership,
-	FALSE,	// LinkAndDelink,
-	FALSE,	// AddAndRemoveJoints
-	FALSE,	// ChangePermissions
-	FALSE,	// TrackYourCamera,
-	FALSE	// ControlYourCamera
-};
-
-bool friendship_offer_callback(const LLSD& notification, const LLSD& response)
-{
-	S32 option = LLNotification::getSelectedOption(notification, response);
-	LLUUID fid;
-	LLMessageSystem* msg = gMessageSystem;
-	const LLSD& payload = notification["payload"];
-
-	// add friend to recent people list
-	LLRecentPeople::instance().add(payload["from_id"]);
-
-	switch(option)
-	{
-	case 0:
-		// accept
-		LLAvatarTracker::formFriendship(payload["from_id"]);
-
-		fid = gInventory.findCategoryUUIDForType(LLAssetType::AT_CALLINGCARD);
-
-		// This will also trigger an onlinenotification if the user is online
-		msg->newMessageFast(_PREHASH_AcceptFriendship);
-		msg->nextBlockFast(_PREHASH_AgentData);
-		msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-		msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-		msg->nextBlockFast(_PREHASH_TransactionBlock);
-		msg->addUUIDFast(_PREHASH_TransactionID, payload["session_id"]);
-		msg->nextBlockFast(_PREHASH_FolderData);
-		msg->addUUIDFast(_PREHASH_FolderID, fid);
-		msg->sendReliable(LLHost(payload["sender"].asString()));
-		break;
-	case 1:
-		// decline
-		// We no longer notify other viewers, but we DO still send
-		// the rejection to the simulator to delete the pending userop.
-		msg->newMessageFast(_PREHASH_DeclineFriendship);
-		msg->nextBlockFast(_PREHASH_AgentData);
-		msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-		msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-		msg->nextBlockFast(_PREHASH_TransactionBlock);
-		msg->addUUIDFast(_PREHASH_TransactionID, payload["session_id"]);
-		msg->sendReliable(LLHost(payload["sender"].asString()));
-		break;
-	default:
-		// close button probably, possibly timed out
-		break;
-	}
-
-	return false;
-}
-static LLNotificationFunctorRegistration friendship_offer_callback_reg("OfferFriendship", friendship_offer_callback);
-static LLNotificationFunctorRegistration friendship_offer_callback_reg_nm("OfferFriendshipNoMessage", friendship_offer_callback);
-
-//const char BUSY_AUTO_RESPONSE[] =	"The Resident you messaged is in 'busy mode' which means they have "
-//									"requested not to be disturbed. Your message will still be shown in their IM "
-//									"panel for later viewing.";
-
-//
-// Functions
-//
-
-void give_money(const LLUUID& uuid, LLViewerRegion* region, S32 amount, BOOL is_group,
-				S32 trx_type, const std::string& desc)
-{
-	if(0 == amount || !region) return;
-	amount = abs(amount);
-	LL_INFOS("Messaging") << "give_money(" << uuid << "," << amount << ")"<< LL_ENDL;
-	if(can_afford_transaction(amount))
-	{
-//		gStatusBar->debitBalance(amount);
-		LLMessageSystem* msg = gMessageSystem;
-		msg->newMessageFast(_PREHASH_MoneyTransferRequest);
-		msg->nextBlockFast(_PREHASH_AgentData);
-		msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-        msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-		msg->nextBlockFast(_PREHASH_MoneyData);
-		msg->addUUIDFast(_PREHASH_SourceID, gAgent.getID() );
-		msg->addUUIDFast(_PREHASH_DestID, uuid);
-		msg->addU8Fast(_PREHASH_Flags, pack_transaction_flags(FALSE, is_group));
-		msg->addS32Fast(_PREHASH_Amount, amount);
-		msg->addU8Fast(_PREHASH_AggregatePermNextOwner, (U8)LLAggregatePermissions::AP_EMPTY);
-		msg->addU8Fast(_PREHASH_AggregatePermInventory, (U8)LLAggregatePermissions::AP_EMPTY);
-		msg->addS32Fast(_PREHASH_TransactionType, trx_type );
-		msg->addStringFast(_PREHASH_Description, desc);
-		msg->sendReliable(region->getHost());
-	}
-	else
-	{
-		LLFloaterBuyCurrency::buyCurrency("Giving", amount);
-	}
-}
-
-void send_complete_agent_movement(const LLHost& sim_host)
-{
-	LLMessageSystem* msg = gMessageSystem;
-	msg->newMessageFast(_PREHASH_CompleteAgentMovement);
-	msg->nextBlockFast(_PREHASH_AgentData);
-	msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-	msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-	msg->addU32Fast(_PREHASH_CircuitCode, msg->mOurCircuitCode);
-	msg->sendReliable(sim_host);
-}
-
-void process_logout_reply(LLMessageSystem* msg, void**)
-{
-	// The server has told us it's ok to quit.
-	LL_DEBUGS("Messaging") << "process_logout_reply" << LL_ENDL;
-
-	LLUUID agent_id;
-	msg->getUUID("AgentData", "AgentID", agent_id);
-	LLUUID session_id;
-	msg->getUUID("AgentData", "SessionID", session_id);
-	if((agent_id != gAgent.getID()) || (session_id != gAgent.getSessionID()))
-	{
-		LL_WARNS("Messaging") << "Bogus Logout Reply" << LL_ENDL;
-	}
-
-	LLInventoryModel::update_map_t parents;
-	S32 count = msg->getNumberOfBlocksFast( _PREHASH_InventoryData );
-	for(S32 i = 0; i < count; ++i)
-	{
-		LLUUID item_id;
-		msg->getUUIDFast(_PREHASH_InventoryData, _PREHASH_ItemID, item_id, i);
-
-		if( (1 == count) && item_id.isNull() )
-		{
-			// Detect dummy item.  Indicates an empty list.
-			break;
-		}
-
-		// We do not need to track the asset ids, just account for an
-		// updated inventory version.
-		LL_INFOS("Messaging") << "process_logout_reply itemID=" << item_id << LL_ENDL;
-		LLInventoryItem* item = gInventory.getItem( item_id );
-		if( item )
-		{
-			parents[item->getParentUUID()] = 0;
-			gInventory.addChangedMask(LLInventoryObserver::INTERNAL, item_id);
-		}
-		else
-		{
-			LL_INFOS("Messaging") << "process_logout_reply item not found: " << item_id << LL_ENDL;
-		}
-	}
-    LLAppViewer::instance()->forceQuit();
-}
-
-void process_layer_data(LLMessageSystem *mesgsys, void **user_data)
-{
-	LLViewerRegion *regionp = LLWorld::getInstance()->getRegion(mesgsys->getSender());
-
-	if (!regionp || gNoRender)
-	{
-		return;
-	}
-
-
-	S32 size;
-	S8 type;
-
-	mesgsys->getS8Fast(_PREHASH_LayerID, _PREHASH_Type, type);
-	size = mesgsys->getSizeFast(_PREHASH_LayerData, _PREHASH_Data);
-	if (0 == size)
-	{
-		LL_WARNS("Messaging") << "Layer data has zero size." << LL_ENDL;
-		return;
-	}
-	if (size < 0)
-	{
-		// getSizeFast() is probably trying to tell us about an error
-		LL_WARNS("Messaging") << "getSizeFast() returned negative result: "
-			<< size
-			<< LL_ENDL;
-		return;
-	}
-	U8 *datap = new U8[size];
-	mesgsys->getBinaryDataFast(_PREHASH_LayerData, _PREHASH_Data, datap, size);
-	LLVLData *vl_datap = new LLVLData(regionp, type, datap, size);
-	if (mesgsys->getReceiveCompressedSize())
-	{
-		gVLManager.addLayerData(vl_datap, mesgsys->getReceiveCompressedSize());
-	}
-	else
-	{
-		gVLManager.addLayerData(vl_datap, mesgsys->getReceiveSize());
-	}
-}
-
-// S32 exported_object_count = 0;
-// S32 exported_image_count = 0;
-// S32 current_object_count = 0;
-// S32 current_image_count = 0;
-
-// extern LLNotifyBox *gExporterNotify;
-// extern LLUUID gExporterRequestID;
-// extern std::string gExportDirectory;
-
-// extern LLUploadDialog *gExportDialog;
-
-// std::string gExportedFile;
-
-// std::map<LLUUID, std::string> gImageChecksums;
-
-// void export_complete()
-// {
-// 		LLUploadDialog::modalUploadFinished();
-// 		gExporterRequestID.setNull();
-// 		gExportDirectory = "";
-
-// 		LLFILE* fXML = LLFile::fopen(gExportedFile, "rb");		/* Flawfinder: ignore */
-// 		fseek(fXML, 0, SEEK_END);
-// 		long length = ftell(fXML);
-// 		fseek(fXML, 0, SEEK_SET);
-// 		U8 *buffer = new U8[length + 1];
-// 		size_t nread = fread(buffer, 1, length, fXML);
-// 		if (nread < (size_t) length)
-// 		{
-// 			LL_WARNS("Messaging") << "Short read" << LL_ENDL;
-// 		}
-// 		buffer[nread] = '\0';
-// 		fclose(fXML);
-
-// 		char *pos = (char *)buffer;
-// 		while ((pos = strstr(pos+1, "<sl:image ")) != 0)
-// 		{
-// 			char *pos_check = strstr(pos, "checksum=\"");
-
-// 			if (pos_check)
-// 			{
-// 				char *pos_uuid = strstr(pos_check, "\">");
-
-// 				if (pos_uuid)
-// 				{
-// 					char image_uuid_str[UUID_STR_SIZE];		/* Flawfinder: ignore */
-// 					memcpy(image_uuid_str, pos_uuid+2, UUID_STR_SIZE-1);		/* Flawfinder: ignore */
-// 					image_uuid_str[UUID_STR_SIZE-1] = 0;
-					
-// 					LLUUID image_uuid(image_uuid_str);
-
-// 					LL_INFOS("Messaging") << "Found UUID: " << image_uuid << LL_ENDL;
-
-// 					std::map<LLUUID, std::string>::iterator itor = gImageChecksums.find(image_uuid);
-// 					if (itor != gImageChecksums.end())
-// 					{
-// 						LL_INFOS("Messaging") << "Replacing with checksum: " << itor->second << LL_ENDL;
-// 						if (!itor->second.empty())
-// 						{
-// 							memcpy(&pos_check[10], itor->second.c_str(), 32);		/* Flawfinder: ignore */
-// 						}
-// 					}
-// 				}
-// 			}
-// 		}
-
-// 		LLFILE* fXMLOut = LLFile::fopen(gExportedFile, "wb");		/* Flawfinder: ignore */
-// 		if (fwrite(buffer, 1, length, fXMLOut) != length)
-// 		{
-// 			LL_WARNS("Messaging") << "Short write" << LL_ENDL;
-// 		}
-// 		fclose(fXMLOut);
-
-// 		delete [] buffer;
-// }
-
-
-// void exported_item_complete(const LLTSCode status, void *user_data)
-// {
-// 	//std::string *filename = (std::string *)user_data;
-
-// 	if (status < LLTS_OK)
-// 	{
-// 		LL_WARNS("Messaging") << "Export failed!" << LL_ENDL;
-// 	}
-// 	else
-// 	{
-// 		++current_object_count;
-// 		if (current_image_count == exported_image_count && current_object_count == exported_object_count)
-// 		{
-// 			LL_INFOS("Messaging") << "*** Export complete ***" << LL_ENDL;
-
-// 			export_complete();
-// 		}
-// 		else
-// 		{
-// 			gExportDialog->setMessage(llformat("Exported %d/%d object files, %d/%d textures.", current_object_count, exported_object_count, current_image_count, exported_image_count));
-// 		}
-// 	}
-// }
-
-// struct exported_image_info
-// {
-// 	LLUUID image_id;
-// 	std::string filename;
-// 	U32 image_num;
-// };
-
-// void exported_j2c_complete(const LLTSCode status, void *user_data)
-// {
-// 	exported_image_info *info = (exported_image_info *)user_data;
-// 	LLUUID image_id = info->image_id;
-// 	U32 image_num = info->image_num;
-// 	std::string filename = info->filename;
-// 	delete info;
-
-// 	if (status < LLTS_OK)
-// 	{
-// 		LL_WARNS("Messaging") << "Image download failed!" << LL_ENDL;
-// 	}
-// 	else
-// 	{
-// 		LLFILE* fIn = LLFile::fopen(filename, "rb");		/* Flawfinder: ignore */
-// 		if (fIn) 
-// 		{
-// 			LLPointer<LLImageJ2C> ImageUtility = new LLImageJ2C;
-// 			LLPointer<LLImageTGA> TargaUtility = new LLImageTGA;
-
-// 			fseek(fIn, 0, SEEK_END);
-// 			S32 length = ftell(fIn);
-// 			fseek(fIn, 0, SEEK_SET);
-// 			U8 *buffer = ImageUtility->allocateData(length);
-// 			if (fread(buffer, 1, length, fIn) != length)
-// 			{
-// 				LL_WARNS("Messaging") << "Short read" << LL_ENDL;
-// 			}
-// 			fclose(fIn);
-// 			LLFile::remove(filename);
-
-// 			// Convert to TGA
-// 			LLPointer<LLImageRaw> image = new LLImageRaw();
-
-// 			ImageUtility->updateData();
-// 			ImageUtility->decode(image, 100000.0f);
-			
-// 			TargaUtility->encode(image);
-// 			U8 *data = TargaUtility->getData();
-// 			S32 data_size = TargaUtility->getDataSize();
-
-// 			std::string file_path = gDirUtilp->getDirName(filename);
-			
-// 			std::string output_file = llformat("%s/image-%03d.tga", file_path.c_str(), image_num);//filename;
-// 			//S32 name_len = output_file.length();
-// 			//strcpy(&output_file[name_len-3], "tga");
-// 			LLFILE* fOut = LLFile::fopen(output_file, "wb");		/* Flawfinder: ignore */
-// 			char md5_hash_string[33];		/* Flawfinder: ignore */
-// 			strcpy(md5_hash_string, "00000000000000000000000000000000");		/* Flawfinder: ignore */
-// 			if (fOut)
-// 			{
-// 				if (fwrite(data, 1, data_size, fOut) != data_size)
-// 				{
-// 					LL_WARNS("Messaging") << "Short write" << LL_ENDL;
-// 				}
-// 				fseek(fOut, 0, SEEK_SET);
-// 				fclose(fOut);
-// 				fOut = LLFile::fopen(output_file, "rb");		/* Flawfinder: ignore */
-// 				LLMD5 my_md5_hash(fOut);
-// 				my_md5_hash.hex_digest(md5_hash_string);
-// 			}
-
-// 			gImageChecksums.insert(std::pair<LLUUID, std::string>(image_id, md5_hash_string));
-// 		}
-// 	}
-
-// 	++current_image_count;
-// 	if (current_image_count == exported_image_count && current_object_count == exported_object_count)
-// 	{
-// 		LL_INFOS("Messaging") << "*** Export textures complete ***" << LL_ENDL;
-// 			export_complete();
-// 	}
-// 	else
-// 	{
-// 		gExportDialog->setMessage(llformat("Exported %d/%d object files, %d/%d textures.", current_object_count, exported_object_count, current_image_count, exported_image_count));
-// 	}
-//}
-
-void process_derez_ack(LLMessageSystem*, void**)
-{
-	if(gViewerWindow) gViewerWindow->getWindow()->decBusyCount();
-}
-
-void process_places_reply(LLMessageSystem* msg, void** data)
-{
-	LLUUID query_id;
-
-	msg->getUUID("AgentData", "QueryID", query_id);
-	if (query_id.isNull())
-	{
-		LLFloaterLandHoldings::processPlacesReply(msg, data);
-	}
-	else if(gAgent.isInGroup(query_id))
-	{
-		LLPanelGroupLandMoney::processPlacesReply(msg, data);
-	}
-	else
-	{
-		LL_WARNS("Messaging") << "Got invalid PlacesReply message" << LL_ENDL;
-	}
-}
-
-void send_sound_trigger(const LLUUID& sound_id, F32 gain)
-{
-	if (sound_id.isNull() || gAgent.getRegion() == NULL)
-	{
-		// disconnected agent or zero guids don't get sent (no sound)
-		return;
-	}
-
-	LLMessageSystem* msg = gMessageSystem;
-	msg->newMessageFast(_PREHASH_SoundTrigger);
-	msg->nextBlockFast(_PREHASH_SoundData);
-	msg->addUUIDFast(_PREHASH_SoundID, sound_id);
-	// Client untrusted, ids set on sim
-	msg->addUUIDFast(_PREHASH_OwnerID, LLUUID::null );
-	msg->addUUIDFast(_PREHASH_ObjectID, LLUUID::null );
-	msg->addUUIDFast(_PREHASH_ParentID, LLUUID::null );
-
-	msg->addU64Fast(_PREHASH_Handle, gAgent.getRegion()->getHandle());
-
-	LLVector3 position = gAgent.getPositionAgent();
-	msg->addVector3Fast(_PREHASH_Position, position);
-	msg->addF32Fast(_PREHASH_Gain, gain);
-
-	gAgent.sendMessage();
-}
-
-bool join_group_response(const LLSD& notification, const LLSD& response)
-{
-	S32 option = LLNotification::getSelectedOption(notification, response);
-	BOOL delete_context_data = TRUE;
-	bool accept_invite = false;
-
-	LLUUID group_id = notification["payload"]["group_id"].asUUID();
-	LLUUID transaction_id = notification["payload"]["transaction_id"].asUUID();
-	std::string name = notification["payload"]["name"].asString();
-	std::string message = notification["payload"]["message"].asString();
-	S32 fee = notification["payload"]["fee"].asInteger();
-
-	if (option == 2 && !group_id.isNull())
-	{
-		LLGroupActions::show(group_id);
-		LLSD args;
-		args["MESSAGE"] = message;
-		LLNotifications::instance().add("JoinGroup", args, notification["payload"]);
-		return false;
-	}
-	if(option == 0 && !group_id.isNull())
-	{
-		// check for promotion or demotion.
-		S32 max_groups = MAX_AGENT_GROUPS;
-		if(gAgent.isInGroup(group_id)) ++max_groups;
-
-		if(gAgent.mGroups.count() < max_groups)
-		{
-			accept_invite = true;
-		}
-		else
-		{
-			delete_context_data = FALSE;
-			LLSD args;
-			args["NAME"] = name;
-			args["INVITE"] = message;
-			LLNotifications::instance().add("JoinedTooManyGroupsMember", args, notification["payload"]);
-		}
-	}
-
-	if (accept_invite)
-	{
-		// If there is a fee to join this group, make
-		// sure the user is sure they want to join.
-		if (fee > 0)
-		{
-			delete_context_data = FALSE;
-			LLSD args;
-			args["COST"] = llformat("%d", fee);
-			// Set the fee for next time to 0, so that we don't keep
-			// asking about a fee.
-			LLSD next_payload = notification["payload"];
-			next_payload["fee"] = 0;
-			LLNotifications::instance().add("JoinGroupCanAfford",
-									args,
-									next_payload);
-		}
-		else
-		{
-			send_improved_im(group_id,
-							 std::string("name"),
-							 std::string("message"),
-							IM_ONLINE,
-							IM_GROUP_INVITATION_ACCEPT,
-							transaction_id);
-		}
-	}
-	else
-	{
-		send_improved_im(group_id,
-						 std::string("name"),
-						 std::string("message"),
-						IM_ONLINE,
-						IM_GROUP_INVITATION_DECLINE,
-						transaction_id);
-	}
-
-	return false;
-}
-static LLNotificationFunctorRegistration jgr_1("JoinGroup", join_group_response);
-static LLNotificationFunctorRegistration jgr_2("JoinedTooManyGroupsMember", join_group_response);
-static LLNotificationFunctorRegistration jgr_3("JoinGroupCanAfford", join_group_response);
-
-
-//-----------------------------------------------------------------------------
-// Instant Message
-//-----------------------------------------------------------------------------
-class LLOpenAgentOffer : public LLInventoryFetchObserver
-{
-public:
-	LLOpenAgentOffer(const std::string& from_name) : mFromName(from_name) {}
-	/*virtual*/ void done()
-	{
-		open_offer(mComplete, mFromName);
-		gInventory.removeObserver(this);
-		delete this;
-	}
-private:
-	std::string mFromName;
-};
-
-//unlike the FetchObserver for AgentOffer, we only make one 
-//instance of the AddedObserver for TaskOffers
-//and it never dies.  We do this because we don't know the UUID of 
-//task offers until they are accepted, so we don't wouldn't 
-//know what to watch for, so instead we just watch for all additions.
-class LLOpenTaskOffer : public LLInventoryAddedObserver
-{
-protected:
-	/*virtual*/ void done()
-	{
-		open_offer(mAdded, "");
-		mAdded.clear();
-	}
- };
-
-//one global instance to bind them
-LLOpenTaskOffer* gNewInventoryObserver=NULL;
-
-void start_new_inventory_observer()
-{
-	if (!gNewInventoryObserver) //task offer observer 
-	{
-		// Observer is deleted by gInventory
-		gNewInventoryObserver = new LLOpenTaskOffer;
-		gInventory.addObserver(gNewInventoryObserver);
-	}
-}
-
-class LLDiscardAgentOffer : public LLInventoryFetchComboObserver
-{
-public:
-	LLDiscardAgentOffer(const LLUUID& folder_id, const LLUUID& object_id) :
-		mFolderID(folder_id),
-		mObjectID(object_id) {}
-	virtual ~LLDiscardAgentOffer() {}
-	virtual void done()
-	{
-		LL_DEBUGS("Messaging") << "LLDiscardAgentOffer::done()" << LL_ENDL;
-		LLUUID trash_id;
-		trash_id = gInventory.findCategoryUUIDForType(LLAssetType::AT_TRASH);
-		bool notify = false;
-		if(trash_id.notNull() && mObjectID.notNull())
-		{
-			LLInventoryModel::update_list_t update;
-			LLInventoryModel::LLCategoryUpdate old_folder(mFolderID, -1);
-			update.push_back(old_folder);
-			LLInventoryModel::LLCategoryUpdate new_folder(trash_id, 1);
-			update.push_back(new_folder);
-			gInventory.accountForUpdate(update);
-			gInventory.moveObject(mObjectID, trash_id);
-			LLInventoryObject* obj = gInventory.getObject(mObjectID);
-			if(obj)
-			{
-				// no need to restamp since this is already a freshly
-				// stamped item.
-				obj->updateParentOnServer(FALSE);
-				notify = true;
-			}
-		}
-		else
-		{
-			LL_WARNS("Messaging") << "DiscardAgentOffer unable to find: "
-					<< (trash_id.isNull() ? "trash " : "")
-					<< (mObjectID.isNull() ? "object" : "") << LL_ENDL;
-		}
-		gInventory.removeObserver(this);
-		if(notify)
-		{
-			gInventory.notifyObservers();
-		}
-		delete this;
-	}
-protected:
-	LLUUID mFolderID;
-	LLUUID mObjectID;
-};
-
-
-//Returns TRUE if we are OK, FALSE if we are throttled
-//Set check_only true if you want to know the throttle status 
-//without registering a hit
-bool check_offer_throttle(const std::string& from_name, bool check_only)
-{
-	static U32 throttle_count;
-	static bool throttle_logged;
-	LLChat chat;
-	std::string log_message;
-
-	if (!gSavedSettings.getBOOL("ShowNewInventory"))
-		return false;
-
-	if (check_only)
-	{
-		return gThrottleTimer.hasExpired();
-	}
-	
-	if(gThrottleTimer.checkExpirationAndReset(OFFER_THROTTLE_TIME))
-	{
-		LL_DEBUGS("Messaging") << "Throttle Expired" << LL_ENDL;
-		throttle_count=1;
-		throttle_logged=false;
-		return true;
-	}
-	else //has not expired
-	{
-		LL_DEBUGS("Messaging") << "Throttle Not Expired, Count: " << throttle_count << LL_ENDL;
-		// When downloading the initial inventory we get a lot of new items
-		// coming in and can't tell that from spam.
-		if (LLStartUp::getStartupState() >= STATE_STARTED
-			&& throttle_count >= OFFER_THROTTLE_MAX_COUNT)
-		{
-			if (!throttle_logged)
-			{
-				// Use the name of the last item giver, who is probably the person
-				// spamming you.
-				std::ostringstream message;
-				message << LLAppViewer::instance()->getSecondLifeTitle();
-				if (!from_name.empty())
-				{
-					message << ": Items coming in too fast from " << from_name;
-				}
-				else
-				{
-					message << ": Items coming in too fast";
-				}
-				message << ", automatic preview disabled for "
-					<< OFFER_THROTTLE_TIME << " seconds.";
-				chat.mText = message.str();
-				//this is kinda important, so actually put it on screen
-				LLFloaterChat::addChat(chat, FALSE, FALSE);
-				throttle_logged=true;
-			}
-			return false;
-		}
-		else
-		{
-			throttle_count++;
-			return true;
-		}
-	}
-}
- 
-void open_offer(const std::vector<LLUUID>& items, const std::string& from_name)
-{
-	std::vector<LLUUID>::const_iterator it = items.begin();
-	std::vector<LLUUID>::const_iterator end = items.end();
-	LLUUID trash_id(gInventory.findCategoryUUIDForType(LLAssetType::AT_TRASH));
-	LLInventoryItem* item;
-	for(; it != end; ++it)
-	{
-		const LLUUID& id = *it;
-		item = gInventory.getItem(id);
-		if(!item)
-		{
-			LL_WARNS("Messaging") << "Unable to show inventory item: " << id << LL_ENDL;
-			continue;
-		}
-		if(gInventory.isObjectDescendentOf(id, trash_id))
-		{
-			continue;
-		}
-		LLAssetType::EType asset_type = item->getType();
-
-		//if we are throttled, don't display them
-		if (check_offer_throttle(from_name, false))
-		{
-			// If we opened this ourselves, focus it
-			BOOL take_focus = from_name.empty() ? TAKE_FOCUS_YES : TAKE_FOCUS_NO;
-			switch(asset_type)
-			{
-			  case LLAssetType::AT_NOTECARD:
-				LLFloaterReg::showInstance("preview_notecard", LLSD(id), take_focus);
-				break;
-			  case LLAssetType::AT_LANDMARK:
-			  	{
-					LLInventoryCategory* parent_folder = gInventory.getCategory(item->getParentUUID());
-					LLSD args;
-					args["LANDMARK_NAME"] = item->getName();
-					args["FOLDER_NAME"] = std::string(parent_folder ? parent_folder->getName() : "unknown");
-					LLNotifications::instance().add("LandmarkCreated", args);
-
-					// Created landmark is passed to Places panel to allow its editing.
-					LLPanelPlaces *panel = dynamic_cast<LLPanelPlaces*>(LLSideTray::getInstance()->showPanel("panel_places", LLSD()));
-					if (panel)
-					{
-						panel->setItem(item);
-					}
-			  	}
-				break;
-			  case LLAssetType::AT_TEXTURE:
-				LLFloaterReg::showInstance("preview_texture", LLSD(id), take_focus);
-				break;
-			  default:
-				break;
-			}
-		}
-		//highlight item, if it's not in the trash or lost+found
-		
-		// Don't auto-open the inventory floater
-		LLFloaterInventory* view = NULL;
-		if(gSavedSettings.getBOOL("ShowInInventory") &&
-		   asset_type != LLAssetType::AT_CALLINGCARD &&
-		   item->getInventoryType() != LLInventoryType::IT_ATTACHMENT &&
-		   !from_name.empty())
-		{
-			view = LLFloaterInventory::showAgentInventory();
-		}
-		else
-		{
-			view = LLFloaterInventory::getActiveInventory();
-		}
-		if(!view)
-		{
-			return;
-		}
-
-		//Trash Check
-		LLUUID trash_id;
-		trash_id = gInventory.findCategoryUUIDForType(LLAssetType::AT_TRASH);
-		if(gInventory.isObjectDescendentOf(item->getUUID(), trash_id))
-		{
-			return;
-		}
-		LLUUID lost_and_found_id = gInventory.findCategoryUUIDForType(LLAssetType::AT_LOST_AND_FOUND);
-		//BOOL inventory_has_focus = gFocusMgr.childHasKeyboardFocus(view);
-		BOOL user_is_away = gAwayTimer.getStarted();
-
-		// don't select lost and found items if the user is active
-		if (gInventory.isObjectDescendentOf(item->getUUID(), lost_and_found_id)
-			&& !user_is_away)
-		{
-			return;
-		}
-
-		//Not sure about this check.  Could make it easy to miss incoming items.
-		//don't dick with highlight while the user is working
-		//if(inventory_has_focus && !user_is_away)
-		//	break;
-		LL_DEBUGS("Messaging") << "Highlighting" << item->getUUID()  << LL_ENDL;
-		//highlight item
-
-		if (view->getPanel())
-		{
-			LLFocusableElement* focus_ctrl = gFocusMgr.getKeyboardFocus();
-			view->getPanel()->setSelection(item->getUUID(), TAKE_FOCUS_NO);
-			gFocusMgr.setKeyboardFocus(focus_ctrl);
-		}
-	}
-}
-
-void inventory_offer_mute_callback(const LLUUID& blocked_id,
-								   const std::string& first_name,
-								   const std::string& last_name,
-								   BOOL is_group)
-{
-	std::string from_name;
-	LLMute::EType type;
-
-	if (is_group)
-	{
-		type = LLMute::GROUP;
-		from_name = first_name;
-	}
-	else
-	{
-		type = LLMute::AGENT;
-		from_name = first_name + " " + last_name;
-	}
-
-	LLMute mute(blocked_id, from_name, type);
-	if (LLMuteList::getInstance()->add(mute))
-	{
-		LLPanelBlockedList::showPanelAndSelect(blocked_id);
-	}
-
-	// purge the message queue of any previously queued inventory offers from the same source.
-	class OfferMatcher : public LLNotifyBoxView::Matcher
-	{
-	public:
-		OfferMatcher(const LLUUID& to_block) : blocked_id(to_block) {}
-		BOOL matches(const LLNotificationPtr notification) const
-		{
-			if(notification->getName() == "ObjectGiveItem" 
-				|| notification->getName() == "ObjectGiveItemUnknownUser"
-				|| notification->getName() == "UserGiveItem")
-			{
-				return (notification->getPayload()["from_id"].asUUID() == blocked_id);
-			}
-			return FALSE;
-		}
-	private:
-		const LLUUID& blocked_id;
-	};
-	gNotifyBoxView->purgeMessagesMatching(OfferMatcher(blocked_id));
-}
-
-LLOfferInfo::LLOfferInfo(const LLSD& sd)
-{
-	mIM = (EInstantMessage)sd["im_type"].asInteger();
-	mFromID = sd["from_id"].asUUID();
-	mFromGroup = sd["from_group"].asBoolean();
-	mFromObject = sd["from_object"].asBoolean();
-	mTransactionID = sd["transaction_id"].asUUID();
-	mFolderID = sd["folder_id"].asUUID();
-	mObjectID = sd["object_id"].asUUID();
-	mType = LLAssetType::lookup(sd["type"].asString().c_str());
-	mFromName = sd["from_name"].asString();
-	mDesc = sd["description"].asString();
-	mHost = LLHost(sd["sender"].asString());
-}
-
-LLSD LLOfferInfo::asLLSD()
-{
-	LLSD sd;
-	sd["im_type"] = mIM;
-	sd["from_id"] = mFromID;
-	sd["from_group"] = mFromGroup;
-	sd["from_object"] = mFromObject;
-	sd["transaction_id"] = mTransactionID;
-	sd["folder_id"] = mFolderID;
-	sd["object_id"] = mObjectID;
-	sd["type"] = LLAssetType::lookup(mType);
-	sd["from_name"] = mFromName;
-	sd["description"] = mDesc;
-	sd["sender"] = mHost.getIPandPort();
-	return sd;
-}
-
-bool LLOfferInfo::inventory_offer_callback(const LLSD& notification, const LLSD& response)
- {
-	LLChat chat;
-	std::string log_message;
-	S32 button = LLNotification::getSelectedOption(notification, response);
-
-	// For muting, we need to add the mute, then decline the offer.
-	// This must be done here because:
-	// * callback may be called immediately,
-	// * adding the mute sends a message,
-	// * we can't build two messages at once.
-	if (2 == button)
-	{
-		gCacheName->get(mFromID, mFromGroup, &inventory_offer_mute_callback);
-	}
-
-	LLMessageSystem* msg = gMessageSystem;
-	msg->newMessageFast(_PREHASH_ImprovedInstantMessage);
-	msg->nextBlockFast(_PREHASH_AgentData);
-	msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-	msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-	msg->nextBlockFast(_PREHASH_MessageBlock);
-	msg->addBOOLFast(_PREHASH_FromGroup, FALSE);
-	msg->addUUIDFast(_PREHASH_ToAgentID, mFromID);
-	msg->addU8Fast(_PREHASH_Offline, IM_ONLINE);
-	msg->addUUIDFast(_PREHASH_ID, mTransactionID);
-	msg->addU32Fast(_PREHASH_Timestamp, NO_TIMESTAMP); // no timestamp necessary
-	std::string name;
-	LLAgentUI::buildFullname(name);
-	msg->addStringFast(_PREHASH_FromAgentName, name);
-	msg->addStringFast(_PREHASH_Message, ""); 
-	msg->addU32Fast(_PREHASH_ParentEstateID, 0);
-	msg->addUUIDFast(_PREHASH_RegionID, LLUUID::null);
-	msg->addVector3Fast(_PREHASH_Position, gAgent.getPositionAgent());
-	LLInventoryObserver* opener = NULL;
-	LLViewerInventoryCategory* catp = NULL;
-	catp = (LLViewerInventoryCategory*)gInventory.getCategory(mObjectID);
-	LLViewerInventoryItem* itemp = NULL;
-	if(!catp)
-	{
-		itemp = (LLViewerInventoryItem*)gInventory.getItem(mObjectID);
-	}
-
-	std::string from_string; // Used in the pop-up.
-	std::string chatHistory_string;  // Used in chat history.
-	if (mFromObject == TRUE)
-	{
-		if (mFromGroup)
-		{
-			std::string group_name;
-			if (gCacheName->getGroupName(mFromID, group_name))
-			{
-				from_string = LLTrans::getString("InvOfferAnObjectNamed") + " "+"'" 
-							+ mFromName + LLTrans::getString("'") +" " + LLTrans::getString("InvOfferOwnedByGroup") 
-				            + " "+ "'" + group_name + "'";
-				
-				chatHistory_string = mFromName + " " + LLTrans::getString("InvOfferOwnedByGroup") 
-								   + " " + group_name + "'";
-			}
-			else
-			{
-				from_string = LLTrans::getString("InvOfferAnObjectNamed") + " "+"'"
-				            + mFromName +"'"+ " " + LLTrans::getString("InvOfferOwnedByUnknownGroup");
-				chatHistory_string = mFromName + " " + LLTrans::getString("InvOfferOwnedByUnknownGroup");
-			}
-		}
-		else
-		{
-			std::string first_name, last_name;
-			if (gCacheName->getName(mFromID, first_name, last_name))
-			{
-				from_string = LLTrans::getString("InvOfferAnObjectNamed") + " "+ LLTrans::getString("'") + mFromName 
-							+ LLTrans::getString("'")+" " + LLTrans::getString("InvOfferOwnedBy") + first_name + " " + last_name;
-				chatHistory_string = mFromName + " " + LLTrans::getString("InvOfferOwnedBy") + " " + first_name + " " + last_name;
-			}
-			else
-			{
-				from_string = LLTrans::getString("InvOfferAnObjectNamed") + " "+LLTrans::getString("'") 
-				            + mFromName + LLTrans::getString("'")+" " + LLTrans::getString("InvOfferOwnedByUnknownUser");
-				chatHistory_string = mFromName + " " + LLTrans::getString("InvOfferOwnedByUnknownUser");
-			}
-		}
-	}
-	else
-	{
-		from_string = chatHistory_string = mFromName;
-	}
-	
-	bool busy=FALSE;
-	
-	switch(button)
-	{
-	case IOR_ACCEPT:
-		// ACCEPT. The math for the dialog works, because the accept
-		// for inventory_offered, task_inventory_offer or
-		// group_notice_inventory is 1 greater than the offer integer value.
-		// Generates IM_INVENTORY_ACCEPTED, IM_TASK_INVENTORY_ACCEPTED, 
-		// or IM_GROUP_NOTICE_INVENTORY_ACCEPTED
-		msg->addU8Fast(_PREHASH_Dialog, (U8)(mIM + 1));
-		msg->addBinaryDataFast(_PREHASH_BinaryBucket, &(mFolderID.mData),
-					 sizeof(mFolderID.mData));
-		// send the message
-		msg->sendReliable(mHost);
-
-		//don't spam them if they are getting flooded
-		if (check_offer_throttle(mFromName, true))
-		{
-			log_message = chatHistory_string + " " + LLTrans::getString("InvOfferGaveYou") + " " + mDesc + LLTrans::getString(".");
- 			chat.mText = log_message;
- 			LLFloaterChat::addChatHistory(chat);
-		}
-
-		// we will want to open this item when it comes back.
-		LL_DEBUGS("Messaging") << "Initializing an opener for tid: " << mTransactionID
-				 << LL_ENDL;
-		switch (mIM)
-		{
-		case IM_INVENTORY_OFFERED:
-		{
-			// This is an offer from an agent. In this case, the back
-			// end has already copied the items into your inventory,
-			// so we can fetch it out of our inventory.
-			LLInventoryFetchObserver::item_ref_t items;
-			items.push_back(mObjectID);
-			LLOpenAgentOffer* open_agent_offer = new LLOpenAgentOffer(from_string);
-			open_agent_offer->fetchItems(items);
-			if(catp || (itemp && itemp->isComplete()))
-			{
-				open_agent_offer->done();
-			}
-			else
-			{
-				opener = open_agent_offer;
-			}
-		}
-			break;
-		case IM_TASK_INVENTORY_OFFERED:
-		case IM_GROUP_NOTICE:
-		case IM_GROUP_NOTICE_REQUESTED:
-		{
-			// This is an offer from a task or group.
-			// We don't use a new instance of an opener
-			// We instead use the singular observer gOpenTaskOffer
-			// Since it already exists, we don't need to actually do anything
-		}
-		break;
-		default:
-			LL_WARNS("Messaging") << "inventory_offer_callback: unknown offer type" << LL_ENDL;
-			break;
-		}	// end switch (mIM)
-		break;
-
-	case IOR_BUSY:
-		//Busy falls through to decline.  Says to make busy message.
-		busy=TRUE;
-	case IOR_MUTE:
-		// MUTE falls through to decline
-	case IOR_DECLINE:
-		// DECLINE. The math for the dialog works, because the decline
-		// for inventory_offered, task_inventory_offer or
-		// group_notice_inventory is 2 greater than the offer integer value.
-		// Generates IM_INVENTORY_DECLINED, IM_TASK_INVENTORY_DECLINED,
-		// or IM_GROUP_NOTICE_INVENTORY_DECLINED
-	default:
-		// close button probably (or any of the fall-throughs from above)
-		msg->addU8Fast(_PREHASH_Dialog, (U8)(mIM + 2));
-		msg->addBinaryDataFast(_PREHASH_BinaryBucket, EMPTY_BINARY_BUCKET, EMPTY_BINARY_BUCKET_SIZE);
-		// send the message
-		msg->sendReliable(mHost);
-
-		log_message = LLTrans::getString("InvOfferYouDecline") + " " + mDesc + " " + LLTrans::getString("InvOfferFrom") + " " + mFromName +".";
-		chat.mText = log_message;
-		if( LLMuteList::getInstance()->isMuted(mFromID ) && ! LLMuteList::getInstance()->isLinden(mFromName) )  // muting for SL-42269
-		{
-			chat.mMuted = TRUE;
-		}
-		LLFloaterChat::addChatHistory(chat);
-
-		// If it's from an agent, we have to fetch the item to throw
-		// it away. If it's from a task or group, just denying the 
-		// request will suffice to discard the item.
-		if(IM_INVENTORY_OFFERED == mIM)
-		{
-			LLInventoryFetchComboObserver::folder_ref_t folders;
-			LLInventoryFetchComboObserver::item_ref_t items;
-			items.push_back(mObjectID);
-			LLDiscardAgentOffer* discard_agent_offer;
-			discard_agent_offer = new LLDiscardAgentOffer(mFolderID, mObjectID);
-			discard_agent_offer->fetch(folders, items);
-			if(catp || (itemp && itemp->isComplete()))
-			{
-				discard_agent_offer->done();
-			}
-			else
-			{
-				opener = discard_agent_offer;
-			}
-			
-		}
-		if (busy &&	(!mFromGroup && !mFromObject))
-		{
-			busy_message(msg,mFromID);
-		}
-		break;
-	}
-
-	if(IM_INVENTORY_OFFERED == mIM)
-	{
-		// add buddy to recent people list
-		LLRecentPeople::instance().add(mFromID);
-	}
-
-	if(opener)
-	{
-		gInventory.addObserver(opener);
-	}
-
-	delete this;
-	return false;
-}
-
-
-void inventory_offer_handler(LLOfferInfo* info, BOOL from_task)
-{
-	//Until throttling is implmented, busy mode should reject inventory instead of silently
-	//accepting it.  SEE SL-39554
-	if (gAgent.getBusy())
-	{
-		info->forceResponse(IOR_BUSY);
-		return;
-	}
-	
-	//If muted, don't even go through the messaging stuff.  Just curtail the offer here.
-	if (LLMuteList::getInstance()->isMuted(info->mFromID, info->mFromName))
-	{
-		info->forceResponse(IOR_MUTE);
-		return;
-	}
-
-	// Avoid the Accept/Discard dialog if the user so desires. JC
-	if (gSavedSettings.getBOOL("AutoAcceptNewInventory")
-		&& (info->mType == LLAssetType::AT_NOTECARD
-			|| info->mType == LLAssetType::AT_LANDMARK
-			|| info->mType == LLAssetType::AT_TEXTURE))
-	{
-		// For certain types, just accept the items into the inventory,
-		// and possibly open them on receipt depending upon "ShowNewInventory".
-		info->forceResponse(IOR_ACCEPT);
-		return;
-	}
-
-	// Strip any SLURL from the message display. (DEV-2754)
-	std::string msg = info->mDesc;
-	int indx = msg.find(" ( http://slurl.com/secondlife/");
-	if(indx >= 0)
-	{
-		LLStringUtil::truncate(msg, indx);
-	}
-	
-	LLSD args;
-	args["[OBJECTNAME]"] = msg;
-
-	LLSD payload;
-
-	// must protect against a NULL return from lookupHumanReadable()
-	std::string typestr = ll_safe_string(LLAssetType::lookupHumanReadable(info->mType));
-	if (!typestr.empty())
-	{
-		args["OBJECTTYPE"] = typestr;
-	}
-	else
-	{
-		LL_WARNS("Messaging") << "LLAssetType::lookupHumanReadable() returned NULL - probably bad asset type: " << info->mType << LL_ENDL;
-		args["OBJECTTYPE"] = "";
-
-		// This seems safest, rather than propagating bogosity
-		LL_WARNS("Messaging") << "Forcing an inventory-decline for probably-bad asset type." << LL_ENDL;
-		info->forceResponse(IOR_DECLINE);
-		return;
-	}
-
-	// Name cache callbacks don't store userdata, so can't save
-	// off the LLOfferInfo.  Argh.
-	BOOL name_found = FALSE;
-	if (info->mFromGroup)
-	{
-		std::string group_name;
-		if (gCacheName->getGroupName(info->mFromID, group_name))
-		{
-			args["FIRST"] = group_name;
-			args["LAST"] = "";
-			name_found = TRUE;
-		}
-	}
-	else
-	{
-		std::string first_name, last_name;
-		if (gCacheName->getName(info->mFromID, first_name, last_name))
-		{
-			args["FIRST"] = first_name;
-			args["LAST"] = last_name;
-			name_found = TRUE;
-		}
-	}
-
-	payload["from_id"] = info->mFromID;
-	args["OBJECTFROMNAME"] = info->mFromName;
-	args["NAME"] = info->mFromName;
-
-	LLNotification::Params p("ObjectGiveItem");
-	p.substitutions(args).payload(payload).functor.function(boost::bind(&LLOfferInfo::inventory_offer_callback, info, _1, _2));
-
-	if (from_task)
-	{
-		p.name = name_found ? "ObjectGiveItem" : "ObjectGiveItemUnknownUser";
-	}
-	else
-	{
-		p.name = "UserGiveItem";
-	}
-
-	LLNotifications::instance().add(p);
-}
-
-bool lure_callback(const LLSD& notification, const LLSD& response)
-{
-	S32 option = 0;
-	if (response.isInteger()) 
-	{
-		option = response.asInteger();
-	}
-	else
-	{
-		option = LLNotification::getSelectedOption(notification, response);
-	}
-	
-	LLUUID from_id = notification["payload"]["from_id"].asUUID();
-	LLUUID lure_id = notification["payload"]["lure_id"].asUUID();
-	BOOL godlike = notification["payload"]["godlike"].asBoolean();
-
-	switch(option)
-	{
-	case 0:
-		{
-			// accept
-			gAgent.teleportViaLure(lure_id, godlike);
-		}
-		break;
-	case 1:
-	default:
-		// decline
-		send_simple_im(from_id,
-					   LLStringUtil::null,
-					   IM_LURE_DECLINED,
-					   lure_id);
-		break;
-	}
-	return false;
-}
-static LLNotificationFunctorRegistration lure_callback_reg("TeleportOffered", lure_callback);
-
-bool goto_url_callback(const LLSD& notification, const LLSD& response)
-{
-	std::string url = notification["payload"]["url"].asString();
-	S32 option = LLNotification::getSelectedOption(notification, response);
-	if(1 == option)
-	{
-		LLWeb::loadURL(url);
-	}
-	return false;
-}
-static LLNotificationFunctorRegistration goto_url_callback_reg("GotoURL", goto_url_callback);
-
-void process_improved_im(LLMessageSystem *msg, void **user_data)
-{
-	if (gNoRender)
-	{
-		return;
-	}
-	LLUUID from_id;
-	BOOL from_group;
-	LLUUID to_id;
-	U8 offline;
-	U8 d = 0;
-	LLUUID session_id;
-	U32 timestamp;
-	std::string name;
-	std::string message;
-	U32 parent_estate_id = 0;
-	LLUUID region_id;
-	LLVector3 position;
-	U8 binary_bucket[MTUBYTES];
-	S32 binary_bucket_size;
-	LLChat chat;
-	std::string buffer;
-	
-	// *TODO: Translate - need to fix the full name to first/last (maybe)
-	msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, from_id);
-	msg->getBOOLFast(_PREHASH_MessageBlock, _PREHASH_FromGroup, from_group);
-	msg->getUUIDFast(_PREHASH_MessageBlock, _PREHASH_ToAgentID, to_id);
-	msg->getU8Fast(  _PREHASH_MessageBlock, _PREHASH_Offline, offline);
-	msg->getU8Fast(  _PREHASH_MessageBlock, _PREHASH_Dialog, d);
-	msg->getUUIDFast(_PREHASH_MessageBlock, _PREHASH_ID, session_id);
-	msg->getU32Fast( _PREHASH_MessageBlock, _PREHASH_Timestamp, timestamp);
-	//msg->getData("MessageBlock", "Count",		&count);
-	msg->getStringFast(_PREHASH_MessageBlock, _PREHASH_FromAgentName, name);
-	msg->getStringFast(_PREHASH_MessageBlock, _PREHASH_Message,		message);
-	msg->getU32Fast(_PREHASH_MessageBlock, _PREHASH_ParentEstateID, parent_estate_id);
-	msg->getUUIDFast(_PREHASH_MessageBlock, _PREHASH_RegionID, region_id);
-	msg->getVector3Fast(_PREHASH_MessageBlock, _PREHASH_Position, position);
-	msg->getBinaryDataFast(  _PREHASH_MessageBlock, _PREHASH_BinaryBucket, binary_bucket, 0, 0, MTUBYTES);
-	binary_bucket_size = msg->getSizeFast(_PREHASH_MessageBlock, _PREHASH_BinaryBucket);
-	EInstantMessage dialog = (EInstantMessage)d;
-
-    // make sure that we don't have an empty or all-whitespace name
-	LLStringUtil::trim(name);
-	if (name.empty())
-	{
-        name = LLTrans::getString("Unnamed");
-	}
-
-	BOOL is_busy = gAgent.getBusy();
-	BOOL is_muted = LLMuteList::getInstance()->isMuted(from_id, name, LLMute::flagTextChat);
-	BOOL is_linden = LLMuteList::getInstance()->isLinden(name);
-	BOOL is_owned_by_me = FALSE;
-	BOOL is_friend = (LLAvatarTracker::instance().getBuddyInfo(from_id) == NULL) ? false : true;
-	BOOL accept_im_from_only_friend = gSavedSettings.getBOOL("VoiceCallsFriendsOnly");
-	
-	chat.mMuted = is_muted && !is_linden;
-	chat.mFromID = from_id;
-	chat.mFromName = name;
-	chat.mSourceType = (from_id.isNull() || (name == std::string(SYSTEM_FROM))) ? CHAT_SOURCE_SYSTEM : CHAT_SOURCE_AGENT;
-
-	LLViewerObject *source = gObjectList.findObject(session_id); //Session ID is probably the wrong thing.
-	if (source)
-	{
-		is_owned_by_me = source->permYouOwner();
-	}
-
-	std::string separator_string(": ");
-	int message_offset = 0;
-
-		//Handle IRC styled /me messages.
-	std::string prefix = message.substr(0, 4);
-	if (prefix == "/me " || prefix == "/me'")
-	{
-		separator_string = "";
-		message_offset = 3;
-	}
-
-	LLSD args;
-	switch(dialog)
-	{
-	case IM_CONSOLE_AND_CHAT_HISTORY:
-		// These are used for system messages, hence don't need the name,
-		// as it is always "Second Life".
-	  	// *TODO: Translate
-		args["MESSAGE"] = message;
-
-		// Note: don't put the message in the IM history, even though was sent
-		// via the IM mechanism.
-		LLNotifications::instance().add("SystemMessageTip",args);
-		break;
-
-	case IM_NOTHING_SPECIAL: 
-		// Don't show dialog, just do IM
-		if (!gAgent.isGodlike()
-				&& gAgent.getRegion()->isPrelude() 
-				&& to_id.isNull() )
-		{
-			// do nothing -- don't distract newbies in
-			// Prelude with global IMs
-		}
-		else if (offline == IM_ONLINE && !is_linden && is_busy && name != SYSTEM_FROM)
-		{
-			// return a standard "busy" message, but only do it to online IM 
-			// (i.e. not other auto responses and not store-and-forward IM)
-			if (!gIMMgr->hasSession(session_id))
-			{
-				// if there is not a panel for this conversation (i.e. it is a new IM conversation
-				// initiated by the other party) then...
-				std::string my_name;
-				LLAgentUI::buildFullname(my_name);
-				std::string response = gSavedPerAccountSettings.getString("BusyModeResponse2");
-				pack_instant_message(
-					gMessageSystem,
-					gAgent.getID(),
-					FALSE,
-					gAgent.getSessionID(),
-					from_id,
-					my_name,
-					response,
-					IM_ONLINE,
-					IM_BUSY_AUTO_RESPONSE,
-					session_id);
-				gAgent.sendReliableMessage();
-			}
-
-			// now store incoming IM in chat history
-
-			buffer = message.substr(message_offset);
-	
-			LL_INFOS("Messaging") << "process_improved_im: session_id( " << session_id << " ), from_id( " << from_id << " )" << LL_ENDL;
-
-			// add to IM panel, but do not bother the user
-			gIMMgr->addMessage(
-				session_id,
-				from_id,
-				name,
-				buffer,
-				LLStringUtil::null,
-				dialog,
-				parent_estate_id,
-				region_id,
-				position,
-				true);
-
-			// pretend this is chat generated by self, so it does not show up on screen
-			chat.mText = std::string("IM: ") + name + separator_string + message.substr(message_offset);
-			LLFloaterChat::addChat( chat, TRUE, TRUE );
-		}
-		else if (from_id.isNull())
-		{
-			// Messages from "Second Life" ID don't go to IM history
-			// messages which should be routed to IM window come from a user ID with name=SYSTEM_NAME
-			chat.mText = name + ": " + message;
-			LLFloaterChat::addChat(chat, FALSE, FALSE);
-		}
-		else if (to_id.isNull())
-		{
-			// Message to everyone from GOD
-			args["NAME"] = name;
-			args["MESSAGE"] = message;
-			LLNotifications::instance().add("GodMessage", args);
-
-			// Treat like a system message and put in chat history.
-			// Claim to be from a local agent so it doesn't go into
-			// console.
-			chat.mText = name + separator_string + message.substr(message_offset);
-			BOOL local_agent = TRUE;
-			LLFloaterChat::addChat(chat, FALSE, local_agent);
-		}
-		else
-		{
-			// standard message, not from system
-			std::string saved;
-			if(offline == IM_OFFLINE)
-			{
-				saved = llformat("(Saved %s) ", formatted_time(timestamp).c_str());
-			}
-			buffer = saved + message.substr(message_offset);
-
-			LL_INFOS("Messaging") << "process_improved_im: session_id( " << session_id << " ), from_id( " << from_id << " )" << LL_ENDL;
-
-			bool mute_im = is_muted;
-			if(accept_im_from_only_friend&&!is_friend)
-			{
-				mute_im = true;
-			}
-			if (!mute_im || is_linden) 
-			{
-				gIMMgr->addMessage(
-					session_id,
-					from_id,
-					name,
-					buffer,
-					LLStringUtil::null,
-					dialog,
-					parent_estate_id,
-					region_id,
-					position,
-					true);
-				chat.mText = std::string("IM: ") + name + separator_string + saved + message.substr(message_offset);
-
-				BOOL local_agent = FALSE;
-				LLFloaterChat::addChat( chat, TRUE, local_agent );
-			}
-			else
-			{
-				// muted user, so don't start an IM session, just record line in chat
-				// history.  Pretend the chat is from a local agent,
-				// so it will go into the history but not be shown on screen.
-				chat.mText = buffer;
-				BOOL local_agent = TRUE;
-				LLFloaterChat::addChat( chat, TRUE, local_agent );
-			}
-		}
-		break;
-
-	case IM_TYPING_START:
-		{
-			LLPointer<LLIMInfo> im_info = new LLIMInfo(gMessageSystem);
-			gIMMgr->processIMTypingStart(im_info);
-		}
-		break;
-
-	case IM_TYPING_STOP:
-		{
-			LLPointer<LLIMInfo> im_info = new LLIMInfo(gMessageSystem);
-			gIMMgr->processIMTypingStop(im_info);
-		}
-		break;
-
-	case IM_MESSAGEBOX:
-		{
-			// This is a block, modeless dialog.
-			//*TODO: Translate
-			args["MESSAGE"] = message;
-			LLNotifications::instance().add("SystemMessage", args);
-		}
-		break;
-	case IM_GROUP_NOTICE:
-	case IM_GROUP_NOTICE_REQUESTED:
-		{
-			LL_INFOS("Messaging") << "Received IM_GROUP_NOTICE message." << LL_ENDL;
-			// Read the binary bucket for more information.
-			struct notice_bucket_header_t
-			{
-				U8 has_inventory;
-				U8 asset_type;
-				LLUUID group_id;
-			};
-			struct notice_bucket_full_t
-			{
-				struct notice_bucket_header_t header;
-				U8 item_name[DB_INV_ITEM_NAME_BUF_SIZE];
-			}* notice_bin_bucket;
-
-			// Make sure the binary bucket is big enough to hold the header 
-			// and a null terminated item name.
-			if ( (binary_bucket_size < (S32)((sizeof(notice_bucket_header_t) + sizeof(U8))))
-				|| (binary_bucket[binary_bucket_size - 1] != '\0') )
-			{
-				LL_WARNS("Messaging") << "Malformed group notice binary bucket" << LL_ENDL;
-				break;
-			}
-
-			notice_bin_bucket = (struct notice_bucket_full_t*) &binary_bucket[0];
-			U8 has_inventory = notice_bin_bucket->header.has_inventory;
-			U8 asset_type = notice_bin_bucket->header.asset_type;
-			LLUUID group_id = notice_bin_bucket->header.group_id;
-			std::string item_name = ll_safe_string((const char*) notice_bin_bucket->item_name);
-
-			// If there is inventory, give the user the inventory offer.
-			LLOfferInfo* info = NULL;
-
-			if (has_inventory)
-			{
-				info = new LLOfferInfo;
-				
-				info->mIM = IM_GROUP_NOTICE;
-				info->mFromID = from_id;
-				info->mFromGroup = from_group;
-				info->mTransactionID = session_id;
-				info->mType = (LLAssetType::EType) asset_type;
-				info->mFolderID = gInventory.findCategoryUUIDForType(info->mType);
-				std::string from_name;
-
-				from_name += "A group member named ";
-				from_name += name;
-
-				info->mFromName = from_name;
-				info->mDesc = item_name;
-				info->mHost = msg->getSender();
-			}
-			
-			std::string str(message);
-
-			// Tokenize the string.
-			// TODO: Support escaped tokens ("||" -> "|")
-			typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
-			boost::char_separator<char> sep("|","",boost::keep_empty_tokens);
-			tokenizer tokens(str, sep);
-			tokenizer::iterator iter = tokens.begin();
-
-			std::string subj(*iter++);
-			std::string mes(*iter++);
-
-			// Send the notification down the new path.
-			// For requested notices, we don't want to send the popups.
-			if (dialog != IM_GROUP_NOTICE_REQUESTED)
-			{
-				LLSD payload;
-				payload["subject"] = subj;
-				payload["message"] = mes;
-				payload["sender_name"] = name;
-				payload["group_id"] = group_id;
-				payload["inventory_name"] = item_name;
-				payload["inventory_offer"] = info ? info->asLLSD() : LLSD();
-
-				LLSD args;
-				args["SUBJECT"] = subj;
-				args["MESSAGE"] = mes;
-				LLNotifications::instance().add(LLNotification::Params("GroupNotice").substitutions(args).payload(payload).time_stamp(timestamp));
-			}
-
-			// Also send down the old path for now.
-			if (IM_GROUP_NOTICE_REQUESTED == dialog)
-			{
-				
-				LLPanelGroup::showNotice(subj,mes,group_id,has_inventory,item_name,info);
-			}
-		}
-		break;
-	case IM_GROUP_INVITATION:
-		{
-			//if (!is_linden && (is_busy || is_muted))
-			if ((is_busy || is_muted))
-			{
-				LLMessageSystem *msg = gMessageSystem;
-				busy_message(msg,from_id);
-			}
-			else
-			{
-				LL_INFOS("Messaging") << "Received IM_GROUP_INVITATION message." << LL_ENDL;
-				// Read the binary bucket for more information.
-				struct invite_bucket_t
-				{
-					S32 membership_fee;
-					LLUUID role_id;
-				}* invite_bucket;
-
-				// Make sure the binary bucket is the correct size.
-				if (binary_bucket_size != sizeof(invite_bucket_t))
-				{
-					LL_WARNS("Messaging") << "Malformed group invite binary bucket" << LL_ENDL;
-					break;
-				}
-
-				invite_bucket = (struct invite_bucket_t*) &binary_bucket[0];
-				S32 membership_fee = ntohl(invite_bucket->membership_fee);
-
-				LLSD payload;
-				payload["transaction_id"] = session_id;
-				payload["group_id"] = from_id;
-				payload["name"] = name;
-				payload["message"] = message;
-				payload["fee"] = membership_fee;
-
-				LLSD args;
-				args["MESSAGE"] = message;
-				LLNotifications::instance().add("JoinGroup", args, payload, join_group_response);
-			}
-		}
-		break;
-
-	case IM_INVENTORY_OFFERED:
-	case IM_TASK_INVENTORY_OFFERED:
-		// Someone has offered us some inventory.
-		{
-			LLOfferInfo* info = new LLOfferInfo;
-			bool mute_im = false;
-			if (IM_INVENTORY_OFFERED == dialog)
-			{
-				struct offer_agent_bucket_t
-				{
-					S8		asset_type;
-					LLUUID	object_id;
-				}* bucketp;
-
-				if (sizeof(offer_agent_bucket_t) != binary_bucket_size)
-				{
-					LL_WARNS("Messaging") << "Malformed inventory offer from agent" << LL_ENDL;
-					break;
-				}
-				bucketp = (struct offer_agent_bucket_t*) &binary_bucket[0];
-				info->mType = (LLAssetType::EType) bucketp->asset_type;
-				info->mObjectID = bucketp->object_id;
-				
-				if(accept_im_from_only_friend&&!is_friend)
-				{
-					mute_im = true;
-				}
-			}
-			else
-			{
-				if (sizeof(S8) != binary_bucket_size)
-				{
-					LL_WARNS("Messaging") << "Malformed inventory offer from object" << LL_ENDL;
-					break;
-				}
-				info->mType = (LLAssetType::EType) binary_bucket[0];
-				info->mObjectID = LLUUID::null;
-			}
-
-			info->mIM = dialog;
-			info->mFromID = from_id;
-			info->mFromGroup = from_group;
-			info->mTransactionID = session_id;
-			info->mFolderID = gInventory.findCategoryUUIDForType(info->mType);
-
-			if (dialog == IM_TASK_INVENTORY_OFFERED)
-			{
-				info->mFromObject = TRUE;
-			}
-			else
-			{
-				info->mFromObject = FALSE;
-			}
-			info->mFromName = name;
-			info->mDesc = message;
-			info->mHost = msg->getSender();
-			//if (((is_busy && !is_owned_by_me) || is_muted))
-			if ( is_muted || mute_im)
-			{
-				// Same as closing window
-				info->forceResponse(IOR_DECLINE);
-			}
-			else
-			{
-				inventory_offer_handler(info, dialog == IM_TASK_INVENTORY_OFFERED);
-			}
-		}
-		break;
-
-	case IM_INVENTORY_ACCEPTED:
-	{
-		args["NAME"] = name;
-		LLNotifications::instance().add("InventoryAccepted", args);
-		break;
-	}
-	case IM_INVENTORY_DECLINED:
-	{
-		args["NAME"] = name;
-		LLNotifications::instance().add("InventoryDeclined", args);
-		break;
-	}
-	// TODO: _DEPRECATED suffix as part of vote removal - DEV-24856
-	case IM_GROUP_VOTE:
-		{
-			LL_WARNS("Messaging") << "Received IM: IM_GROUP_VOTE_DEPRECATED" << LL_ENDL;
-		}
-		break;
-
-	case IM_GROUP_ELECTION_DEPRECATED:
-	{
-		LL_WARNS("Messaging") << "Received IM: IM_GROUP_ELECTION_DEPRECATED" << LL_ENDL;
-	}
-	break;
-	
-	case IM_SESSION_SEND:
-	{
-		if (!is_linden && is_busy)
-		{
-			return;
-		}
-
-		// Only show messages if we have a session open (which
-		// should happen after you get an "invitation"
-		if ( !gIMMgr->hasSession(session_id) )
-		{
-			return;
-		}
-
-		// standard message, not from system
-		std::string saved;
-		if(offline == IM_OFFLINE)
-		{
-			saved = llformat("(Saved %s) ", formatted_time(timestamp).c_str());
-		}
-		buffer = saved + message.substr(message_offset);
-		BOOL is_this_agent = FALSE;
-		if(from_id == gAgentID)
-		{
-			is_this_agent = TRUE;
-		}
-		gIMMgr->addMessage(
-			session_id,
-			from_id,
-			name,
-			buffer,
-			ll_safe_string((char*)binary_bucket),
-			IM_SESSION_INVITE,
-			parent_estate_id,
-			region_id,
-			position,
-			true);
-
-		chat.mText = std::string("IM: ") + name + separator_string +  saved + message.substr(message_offset);
-		LLFloaterChat::addChat(chat, TRUE, is_this_agent);
-	}
-	break;
-
-	case IM_FROM_TASK:
-		{
-			if (is_busy && !is_owned_by_me)
-			{
-				return;
-			}
-
-			LLSD substitutions;
-			substitutions["MSG"] = message.substr(message_offset);
-			LLNotifications::instance().add("ServerObjectMessage", substitutions);
-		}
-		break;
-	case IM_FROM_TASK_AS_ALERT:
-		if (is_busy && !is_owned_by_me)
-		{
-			return;
-		}
-		{
-			// Construct a viewer alert for this message.
-			args["NAME"] = name;
-			args["MESSAGE"] = message;
-			LLNotifications::instance().add("ObjectMessage", args);
-		}
-		break;
-	case IM_BUSY_AUTO_RESPONSE:
-		if (is_muted)
-		{
-			LL_DEBUGS("Messaging") << "Ignoring busy response from " << from_id << LL_ENDL;
-			return;
-		}
-		else
-		{
-			// TODO: after LLTrans hits release, get "busy response" into translatable file
-			buffer = llformat("%s (%s): %s", name.c_str(), "busy response", message.substr(message_offset).c_str());
-			gIMMgr->addMessage(session_id, from_id, name, buffer);
-		}
-		break;
-		
-	case IM_LURE_USER:
-		{
-			if (is_muted)
-			{ 
-				return;
-			}
-			else if (is_busy) 
-			{
-				busy_message(msg,from_id);
-			}
-			else
-			{
-				LLSD args;
-				// *TODO: Translate -> [FIRST] [LAST] (maybe)
-				args["NAME"] = name;
-				args["MESSAGE"] = message;
-				LLSD payload;
-				payload["from_id"] = from_id;
-				payload["lure_id"] = session_id;
-				payload["godlike"] = FALSE;
-				LLNotifications::instance().add("TeleportOffered", args, payload);
-			}
-		}
-		break;
-
-	case IM_GODLIKE_LURE_USER:
-		{
-			LLSD payload;
-			payload["from_id"] = from_id;
-			payload["lure_id"] = session_id;
-			payload["godlike"] = TRUE;
-			// do not show a message box, because you're about to be
-			// teleported.
-			LLNotifications::instance().forceResponse(LLNotification::Params("TeleportOffered").payload(payload), 0);
-		}
-		break;
-
-	case IM_GOTO_URL:
-		{
-			LLSD args;
-			// n.b. this is for URLs sent by the system, not for
-			// URLs sent by scripts (i.e. llLoadURL)
-			if (binary_bucket_size <= 0)
-			{
-				LL_WARNS("Messaging") << "bad binary_bucket_size: "
-					<< binary_bucket_size
-					<< " - aborting function." << LL_ENDL;
-				return;
-			}
-
-			std::string url;
-			
-			url.assign((char*)binary_bucket, binary_bucket_size-1);
-			args["MESSAGE"] = message;
-			args["URL"] = url;
-			LLSD payload;
-			payload["url"] = url;
-			LLNotifications::instance().add("GotoURL", args, payload );
-		}
-		break;
-
-	case IM_FRIENDSHIP_OFFERED:
-		{
-			LLSD payload;
-			payload["from_id"] = from_id;
-			payload["session_id"] = session_id;;
-			payload["online"] = (offline == IM_ONLINE);
-			payload["sender"] = msg->getSender().getIPandPort();
-
-			if (is_busy)
-			{
-				busy_message(msg, from_id);
-				LLNotifications::instance().forceResponse(LLNotification::Params("OfferFriendship").payload(payload), 1);
-			}
-			else if (is_muted)
-			{
-				LLNotifications::instance().forceResponse(LLNotification::Params("OfferFriendship").payload(payload), 1);
-			}
-			else
-			{
-				args["[NAME]"] = name;
-				if(message.empty())
-				{
-					//support for frienship offers from clients before July 2008
-				        LLNotifications::instance().add("OfferFriendshipNoMessage", args, payload);
-				}
-				else
-				{
-					args["[MESSAGE]"] = message;
-				        LLNotifications::instance().add("OfferFriendship", args, payload);
-				}
-			}
-		}
-		break;
-
-	case IM_FRIENDSHIP_ACCEPTED:
-		{
-			// In the case of an offline IM, the formFriendship() may be extraneous
-			// as the database should already include the relationship.  But it
-			// doesn't hurt for dupes.
-			LLAvatarTracker::formFriendship(from_id);
-			
-			std::vector<std::string> strings;
-			strings.push_back(from_id.asString());
-			send_generic_message("requestonlinenotification", strings);
-			
-			args["NAME"] = name;
-			LLNotifications::instance().add("FriendshipAccepted", args);
-		}
-		break;
-
-	case IM_FRIENDSHIP_DECLINED_DEPRECATED:
-	default:
-		LL_WARNS("Messaging") << "Instant message calling for unknown dialog "
-				<< (S32)dialog << LL_ENDL;
-		break;
-	}
-
-	LLWindow* viewer_window = gViewerWindow->getWindow();
-	if (viewer_window && viewer_window->getMinimized())
-	{
-		viewer_window->flashIcon(5.f);
-	}
-}
-
-void busy_message (LLMessageSystem* msg, LLUUID from_id) 
-{
-	if (gAgent.getBusy())
-	{
-		std::string my_name;
-		LLAgentUI::buildFullname(my_name);
-		std::string response = gSavedPerAccountSettings.getString("BusyModeResponse2");
-		pack_instant_message(
-			gMessageSystem,
-			gAgent.getID(),
-			FALSE,
-			gAgent.getSessionID(),
-			from_id,
-			my_name,
-			response,
-			IM_ONLINE,
-			IM_BUSY_AUTO_RESPONSE);
-		gAgent.sendReliableMessage();
-	}
-}
-
-bool callingcard_offer_callback(const LLSD& notification, const LLSD& response)
-{
-	S32 option = LLNotification::getSelectedOption(notification, response);
-	LLUUID fid;
-	LLUUID from_id;
-	LLMessageSystem* msg = gMessageSystem;
-	switch(option)
-	{
-	case 0:
-		// accept
-		msg->newMessageFast(_PREHASH_AcceptCallingCard);
-		msg->nextBlockFast(_PREHASH_AgentData);
-		msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-		msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-		msg->nextBlockFast(_PREHASH_TransactionBlock);
-		msg->addUUIDFast(_PREHASH_TransactionID, notification["payload"]["transaction_id"].asUUID());
-		fid = gInventory.findCategoryUUIDForType(LLAssetType::AT_CALLINGCARD);
-		msg->nextBlockFast(_PREHASH_FolderData);
-		msg->addUUIDFast(_PREHASH_FolderID, fid);
-		msg->sendReliable(LLHost(notification["payload"]["sender"].asString()));
-		break;
-	case 1:
-		// decline		
-		msg->newMessageFast(_PREHASH_DeclineCallingCard);
-		msg->nextBlockFast(_PREHASH_AgentData);
-		msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-		msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-		msg->nextBlockFast(_PREHASH_TransactionBlock);
-		msg->addUUIDFast(_PREHASH_TransactionID, notification["payload"]["transaction_id"].asUUID());
-		msg->sendReliable(LLHost(notification["payload"]["sender"].asString()));
-		busy_message(msg, notification["payload"]["source_id"].asUUID());
-		break;
-	default:
-		// close button probably, possibly timed out
-		break;
-	}
-
-	return false;
-}
-static LLNotificationFunctorRegistration callingcard_offer_cb_reg("OfferCallingCard", callingcard_offer_callback);
-
-void process_offer_callingcard(LLMessageSystem* msg, void**)
-{
-	// someone has offered to form a friendship
-	LL_DEBUGS("Messaging") << "callingcard offer" << LL_ENDL;
-
-	LLUUID source_id;
-	msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, source_id);
-	LLUUID tid;
-	msg->getUUIDFast(_PREHASH_AgentBlock, _PREHASH_TransactionID, tid);
-
-	LLSD payload;
-	payload["transaction_id"] = tid;
-	payload["source_id"] = source_id;
-	payload["sender"] = msg->getSender().getIPandPort();
-
-	LLViewerObject* source = gObjectList.findObject(source_id);
-	LLSD args;
-	std::string source_name;
-	if(source && source->isAvatar())
-	{
-		LLNameValue* nvfirst = source->getNVPair("FirstName");
-		LLNameValue* nvlast  = source->getNVPair("LastName");
-		if (nvfirst && nvlast)
-		{
-			args["FIRST"] = nvfirst->getString();
-			args["LAST"] = nvlast->getString();
-			source_name = std::string(nvfirst->getString()) + " " + nvlast->getString();
-		}
-	}
-
-	if(!source_name.empty())
-	{
-		if (gAgent.getBusy() 
-			|| LLMuteList::getInstance()->isMuted(source_id, source_name, LLMute::flagTextChat))
-		{
-			// automatically decline offer
-			LLNotifications::instance().forceResponse(LLNotification::Params("OfferCallingCard").payload(payload), 1);
-		}
-		else
-		{
-			LLNotifications::instance().add("OfferCallingCard", args, payload);
-		}
-	}
-	else
-	{
-		LL_WARNS("Messaging") << "Calling card offer from an unknown source." << LL_ENDL;
-	}
-}
-
-void process_accept_callingcard(LLMessageSystem* msg, void**)
-{
-	LLNotifications::instance().add("CallingCardAccepted");
-}
-
-void process_decline_callingcard(LLMessageSystem* msg, void**)
-{
-	LLNotifications::instance().add("CallingCardDeclined");
-}
-
-
-void process_chat_from_simulator(LLMessageSystem *msg, void **user_data)
-{
-	LLChat		chat;
-	std::string		mesg;
-	std::string		from_name;
-	U8			source_temp;
-	U8			type_temp;
-	U8			audible_temp;
-	LLColor4	color(1.0f, 1.0f, 1.0f, 1.0f);
-	LLUUID		from_id;
-	LLUUID		owner_id;
-	BOOL		is_owned_by_me = FALSE;
-	LLViewerObject*	chatter;
-
-	msg->getString("ChatData", "FromName", from_name);
-	chat.mFromName = from_name;
-	
-	msg->getUUID("ChatData", "SourceID", from_id);
-	chat.mFromID = from_id;
-	
-	// Object owner for objects
-	msg->getUUID("ChatData", "OwnerID", owner_id);
-	
-	msg->getU8Fast(_PREHASH_ChatData, _PREHASH_SourceType, source_temp);
-	chat.mSourceType = (EChatSourceType)source_temp;
-
-	msg->getU8("ChatData", "ChatType", type_temp);
-	chat.mChatType = (EChatType)type_temp;
-
-	msg->getU8Fast(_PREHASH_ChatData, _PREHASH_Audible, audible_temp);
-	chat.mAudible = (EChatAudible)audible_temp;
-	
-	chat.mTime = LLFrameTimer::getElapsedSeconds();
-	
-	BOOL is_busy = gAgent.getBusy();
-
-	BOOL is_muted = FALSE;
-	BOOL is_linden = FALSE;
-	is_muted = LLMuteList::getInstance()->isMuted(
-		from_id,
-		from_name,
-		LLMute::flagTextChat) 
-		|| LLMuteList::getInstance()->isMuted(owner_id, LLMute::flagTextChat);
-	is_linden = chat.mSourceType != CHAT_SOURCE_OBJECT &&
-		LLMuteList::getInstance()->isLinden(from_name);
-
-	BOOL is_audible = (CHAT_AUDIBLE_FULLY == chat.mAudible);
-	chatter = gObjectList.findObject(from_id);
-	if (chatter)
-	{
-		chat.mPosAgent = chatter->getPositionAgent();
-		
-		// Make swirly things only for talking objects. (not script debug messages, though)
-		if (chat.mSourceType == CHAT_SOURCE_OBJECT 
-			&& chat.mChatType != CHAT_TYPE_DEBUG_MSG)
-		{
-			LLPointer<LLViewerPartSourceChat> psc = new LLViewerPartSourceChat(chatter->getPositionAgent());
-			psc->setSourceObject(chatter);
-			psc->setColor(color);
-			//We set the particles to be owned by the object's owner, 
-			//just in case they should be muted by the mute list
-			psc->setOwnerUUID(owner_id);
-			LLViewerPartSim::getInstance()->addPartSource(psc);
-		}
-
-		// record last audible utterance
-		if (is_audible
-			&& (is_linden || (!is_muted && !is_busy)))
-		{
-			if (chat.mChatType != CHAT_TYPE_START 
-				&& chat.mChatType != CHAT_TYPE_STOP)
-			{
-				gAgent.heardChat(chat.mFromID);
-			}
-		}
-
-		is_owned_by_me = chatter->permYouOwner();
-	}
-
-	if (is_audible)
-	{
-		BOOL visible_in_chat_bubble = FALSE;
-		std::string verb;
-
-		color.setVec(1.f,1.f,1.f,1.f);
-		msg->getStringFast(_PREHASH_ChatData, _PREHASH_Message, mesg);
-
-		BOOL ircstyle = FALSE;
-
-		// Look for IRC-style emotes here so chatbubbles work
-		std::string prefix = mesg.substr(0, 4);
-		if (prefix == "/me " || prefix == "/me'")
-		{
-			chat.mText = from_name;
-			chat.mText += mesg.substr(3);
-			ircstyle = TRUE;
-		}
-		else
-		{
-			chat.mText = mesg;
-		}
-
-		// Look for the start of typing so we can put "..." in the bubbles.
-		if (CHAT_TYPE_START == chat.mChatType)
-		{
-			LLLocalSpeakerMgr::getInstance()->setSpeakerTyping(from_id, TRUE);
-
-			// Might not have the avatar constructed yet, eg on login.
-			if (chatter && chatter->isAvatar())
-			{
-				((LLVOAvatar*)chatter)->startTyping();
-			}
-			return;
-		}
-		else if (CHAT_TYPE_STOP == chat.mChatType)
-		{
-			LLLocalSpeakerMgr::getInstance()->setSpeakerTyping(from_id, FALSE);
-
-			// Might not have the avatar constructed yet, eg on login.
-			if (chatter && chatter->isAvatar())
-			{
-				((LLVOAvatar*)chatter)->stopTyping();
-			}
-			return;
-		}
-
-		// We have a real utterance now, so can stop showing "..." and proceed.
-		if (chatter && chatter->isAvatar())
-		{
-			LLLocalSpeakerMgr::getInstance()->setSpeakerTyping(from_id, FALSE);
-			((LLVOAvatar*)chatter)->stopTyping();
-
-			if (!is_muted && !is_busy)
-			{
-				visible_in_chat_bubble = gSavedSettings.getBOOL("UseChatBubbles");
-				((LLVOAvatar*)chatter)->addChat(chat);
-			}
-		}
-
-		// Look for IRC-style emotes
-		if (ircstyle)
-		{
-			// set CHAT_STYLE_IRC to avoid adding Avatar Name as author of message. See EXT-656
-			chat.mChatStyle = CHAT_STYLE_IRC;
-
-			// Do nothing, ircstyle is fixed above for chat bubbles
-		}
-		else
-		{
-			switch(chat.mChatType)
-			{
-			case CHAT_TYPE_WHISPER:
-				verb = "(" + LLTrans::getString("whisper") + ")";
-				break;
-			case CHAT_TYPE_DEBUG_MSG:
-			case CHAT_TYPE_OWNER:
-			case CHAT_TYPE_NORMAL:
-				verb = "";
-				break;
-			case CHAT_TYPE_SHOUT:
-				verb = "(" + LLTrans::getString("shout") + ")";
-				break;
-			case CHAT_TYPE_START:
-			case CHAT_TYPE_STOP:
-				LL_WARNS("Messaging") << "Got chat type start/stop in main chat processing." << LL_ENDL;
-				break;
-			default:
-				LL_WARNS("Messaging") << "Unknown type " << chat.mChatType << " in chat!" << LL_ENDL;
-				verb = "";
-				break;
-			}
-
-
-			chat.mText = "";
-			chat.mText += verb;
-			chat.mText += mesg;
-		}
-		
-		if (chatter)
-		{
-			chat.mPosAgent = chatter->getPositionAgent();
-		}
-
-		// truth table:
-		// LINDEN	BUSY	MUTED	OWNED_BY_YOU	TASK		DISPLAY		STORE IN HISTORY
-		// F		F		F		F				*			Yes			Yes
-		// F		F		F		T				*			Yes			Yes
-		// F		F		T		F				*			No			No
-		// F		F		T		T				*			No			No
-		// F		T		F		F				*			No			Yes
-		// F		T		F		T				*			Yes			Yes
-		// F		T		T		F				*			No			No
-		// F		T		T		T				*			No			No
-		// T		*		*		*				F			Yes			Yes
-
-		chat.mMuted = is_muted && !is_linden;
-
-		if (!visible_in_chat_bubble 
-			&& (is_linden || !is_busy || is_owned_by_me))
-		{
-			// show on screen and add to history
-			LLNotificationsUI::LLNotificationManager::instance().onChat(
-					chat, LLNotificationsUI::NT_NEARBYCHAT);
-
-            // adding temporarily so that communications window chat bar 
-            // works until the new chat window is ready
-			chat.mText = from_name + ": " + chat.mText;
-			LLFloaterChat::addChat(chat, FALSE, FALSE);
-		}
-		else
-		{
-			LLNotificationsUI::LLNotificationManager::instance().onChat(
-					chat, LLNotificationsUI::NT_NEARBYCHAT);
-			// adding temporarily
-			LLFloaterChat::addChatHistory(chat);
-		}
-	}
-}
-
-
-// Simulator we're on is informing the viewer that the agent
-// is starting to teleport (perhaps to another sim, perhaps to the 
-// same sim). If we initiated the teleport process by sending some kind 
-// of TeleportRequest, then this info is redundant, but if the sim 
-// initiated the teleport (via a script call, being killed, etc.) 
-// then this info is news to us.
-void process_teleport_start(LLMessageSystem *msg, void**)
-{
-	U32 teleport_flags = 0x0;
-	msg->getU32("Info", "TeleportFlags", teleport_flags);
-
-	if (teleport_flags & TELEPORT_FLAGS_DISABLE_CANCEL)
-	{
-		gViewerWindow->setProgressCancelButtonVisible(FALSE);
-	}
-	else
-	{
-		gViewerWindow->setProgressCancelButtonVisible(TRUE, LLTrans::getString("Cancel"));
-	}
-
-	// Freeze the UI and show progress bar
-	// Note: could add data here to differentiate between normal teleport and death.
-
-	if( gAgent.getTeleportState() == LLAgent::TELEPORT_NONE )
-	{
-		gTeleportDisplay = TRUE;
-		gAgent.setTeleportState( LLAgent::TELEPORT_START );
-		make_ui_sound("UISndTeleportOut");
-		
-		// Don't call LLFirstUse::useTeleport here because this could be
-		// due to being killed, which would send you home, not to a Telehub
-	}
-}
-
-void process_teleport_progress(LLMessageSystem* msg, void**)
-{
-	LLUUID agent_id;
-	msg->getUUID("AgentData", "AgentID", agent_id);
-	if((gAgent.getID() != agent_id)
-	   || (gAgent.getTeleportState() == LLAgent::TELEPORT_NONE))
-	{
-		LL_WARNS("Messaging") << "Unexpected teleport progress message." << LL_ENDL;
-		return;
-	}
-	U32 teleport_flags = 0x0;
-	msg->getU32("Info", "TeleportFlags", teleport_flags);
-	if (teleport_flags & TELEPORT_FLAGS_DISABLE_CANCEL)
-	{
-		gViewerWindow->setProgressCancelButtonVisible(FALSE);
-	}
-	else
-	{
-		gViewerWindow->setProgressCancelButtonVisible(TRUE, LLTrans::getString("Cancel"));
-	}
-	std::string buffer;
-	msg->getString("Info", "Message", buffer);
-	LL_DEBUGS("Messaging") << "teleport progress: " << buffer << LL_ENDL;
-
-	//Sorta hacky...default to using simulator raw messages
-	//if we don't find the coresponding mapping in our progress mappings
-	std::string message = buffer;
-
-	if (LLAgent::sTeleportProgressMessages.find(buffer) != 
-		LLAgent::sTeleportProgressMessages.end() )
-	{
-		message = LLAgent::sTeleportProgressMessages[buffer];
-	}
-
-	gAgent.setTeleportMessage(LLAgent::sTeleportProgressMessages[message]);
-}
-
-class LLFetchInWelcomeArea : public LLInventoryFetchDescendentsObserver
-{
-public:
-	LLFetchInWelcomeArea() {}
-	virtual void done()
-	{
-		LLIsType is_landmark(LLAssetType::AT_LANDMARK);
-		LLIsType is_card(LLAssetType::AT_CALLINGCARD);
-
-		LLInventoryModel::cat_array_t	card_cats;
-		LLInventoryModel::item_array_t	card_items;
-		LLInventoryModel::cat_array_t	land_cats;
-		LLInventoryModel::item_array_t	land_items;
-
-		folder_ref_t::iterator it = mCompleteFolders.begin();
-		folder_ref_t::iterator end = mCompleteFolders.end();
-		for(; it != end; ++it)
-		{
-			gInventory.collectDescendentsIf(
-				(*it),
-				land_cats,
-				land_items,
-				LLInventoryModel::EXCLUDE_TRASH,
-				is_landmark);
-			gInventory.collectDescendentsIf(
-				(*it),
-				card_cats,
-				card_items,
-				LLInventoryModel::EXCLUDE_TRASH,
-				is_card);
-		}
-		LLSD args;
-		if ( land_items.count() > 0 )
-		{	// Show notification that they can now teleport to landmarks.  Use a random landmark from the inventory
-			S32 random_land = ll_rand( land_items.count() - 1 );
-			args["NAME"] = land_items[random_land]->getName();
-			LLNotifications::instance().add("TeleportToLandmark",args);
-		}
-		if ( card_items.count() > 0 )
-		{	// Show notification that they can now contact people.  Use a random calling card from the inventory
-			S32 random_card = ll_rand( card_items.count() - 1 );
-			args["NAME"] = card_items[random_card]->getName();
-			LLNotifications::instance().add("TeleportToPerson",args);
-		}
-
-		gInventory.removeObserver(this);
-		delete this;
-	}
-};
-
-
-
-class LLPostTeleportNotifiers : public LLEventTimer 
-{
-public:
-	LLPostTeleportNotifiers();
-	virtual ~LLPostTeleportNotifiers();
-
-	//function to be called at the supplied frequency
-	virtual BOOL tick();
-};
-
-LLPostTeleportNotifiers::LLPostTeleportNotifiers() : LLEventTimer( 2.0 )
-{
-};
-
-LLPostTeleportNotifiers::~LLPostTeleportNotifiers()
-{
-}
-
-BOOL LLPostTeleportNotifiers::tick()
-{
-	BOOL all_done = FALSE;
-	if ( gAgent.getTeleportState() == LLAgent::TELEPORT_NONE )
-	{
-		// get callingcards and landmarks available to the user arriving.
-		LLInventoryFetchDescendentsObserver::folder_ref_t folders;
-		LLUUID folder_id;
-		folder_id = gInventory.findCategoryUUIDForType(LLAssetType::AT_CALLINGCARD);
-		if(folder_id.notNull()) 
-			folders.push_back(folder_id);
-		folder_id = gInventory.findCategoryUUIDForType(LLAssetType::AT_LANDMARK);
-		if(folder_id.notNull()) 
-			folders.push_back(folder_id);
-		if(!folders.empty())
-		{
-			LLFetchInWelcomeArea* fetcher = new LLFetchInWelcomeArea;
-			fetcher->fetchDescendents(folders);
-			if(fetcher->isEverythingComplete())
-			{
-				fetcher->done();
-			}
-			else
-			{
-				gInventory.addObserver(fetcher);
-			}
-		}
-		all_done = TRUE;
-	}
-
-	return all_done;
-}
-
-
-
-// Teleport notification from the simulator
-// We're going to pretend to be a new agent
-void process_teleport_finish(LLMessageSystem* msg, void**)
-{
-	LL_DEBUGS("Messaging") << "Got teleport location message" << LL_ENDL;
-	LLUUID agent_id;
-	msg->getUUIDFast(_PREHASH_Info, _PREHASH_AgentID, agent_id);
-	if (agent_id != gAgent.getID())
-	{
-		LL_WARNS("Messaging") << "Got teleport notification for wrong agent!" << LL_ENDL;
-		return;
-	}
-
-	// Do teleport effect for where you're leaving
-	// VEFFECT: TeleportStart
-	LLHUDEffectSpiral *effectp = (LLHUDEffectSpiral *)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_POINT, TRUE);
-	effectp->setPositionGlobal(gAgent.getPositionGlobal());
-	effectp->setColor(LLColor4U(gAgent.getEffectColor()));
-	LLHUDManager::getInstance()->sendEffects();
-
-	U32 location_id;
-	U32 sim_ip;
-	U16 sim_port;
-	LLVector3 pos, look_at;
-	U64 region_handle;
-	msg->getU32Fast(_PREHASH_Info, _PREHASH_LocationID, location_id);
-	msg->getIPAddrFast(_PREHASH_Info, _PREHASH_SimIP, sim_ip);
-	msg->getIPPortFast(_PREHASH_Info, _PREHASH_SimPort, sim_port);
-	//msg->getVector3Fast(_PREHASH_Info, _PREHASH_Position, pos);
-	//msg->getVector3Fast(_PREHASH_Info, _PREHASH_LookAt, look_at);
-	msg->getU64Fast(_PREHASH_Info, _PREHASH_RegionHandle, region_handle);
-	U32 teleport_flags;
-	msg->getU32Fast(_PREHASH_Info, _PREHASH_TeleportFlags, teleport_flags);
-	
-	
-	std::string seedCap;
-	msg->getStringFast(_PREHASH_Info, _PREHASH_SeedCapability, seedCap);
-
-	// update home location if we are teleporting out of prelude - specific to teleporting to welcome area 
-	if((teleport_flags & TELEPORT_FLAGS_SET_HOME_TO_TARGET)
-	   && (!gAgent.isGodlike()))
-	{
-		gAgent.setHomePosRegion(region_handle, pos);
-
-		// Create a timer that will send notices when teleporting is all finished.  Since this is 
-		// based on the LLEventTimer class, it will be managed by that class and not orphaned or leaked.
-		new LLPostTeleportNotifiers();
-	}
-
-	LLHost sim_host(sim_ip, sim_port);
-
-	// Viewer trusts the simulator.
-	gMessageSystem->enableCircuit(sim_host, TRUE);
-	LLViewerRegion* regionp =  LLWorld::getInstance()->addRegion(region_handle, sim_host);
-
-/*
-	// send camera update to new region
-	gAgent.updateCamera();
-
-	// likewise make sure the camera is behind the avatar
-	gAgent.resetView(TRUE);
-	LLVector3 shift_vector = regionp->getPosRegionFromGlobal(gAgent.getRegion()->getOriginGlobal());
-	gAgent.setRegion(regionp);
-	gObjectList.shiftObjects(shift_vector);
-
-	if (gAgent.getAvatarObject())
-	{
-		gAgent.getAvatarObject()->clearChatText();
-		gAgent.slamLookAt(look_at);
-	}
-	gAgent.setPositionAgent(pos);
-	gAssetStorage->setUpstream(sim);
-	gCacheName->setUpstream(sim);
-*/
-
-	// now, use the circuit info to tell simulator about us!
-	LL_INFOS("Messaging") << "process_teleport_finish() Enabling "
-			<< sim_host << " with code " << msg->mOurCircuitCode << LL_ENDL;
-	msg->newMessageFast(_PREHASH_UseCircuitCode);
-	msg->nextBlockFast(_PREHASH_CircuitCode);
-	msg->addU32Fast(_PREHASH_Code, msg->getOurCircuitCode());
-	msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-	msg->addUUIDFast(_PREHASH_ID, gAgent.getID());
-	msg->sendReliable(sim_host);
-
-	send_complete_agent_movement(sim_host);
-	gAgent.setTeleportState( LLAgent::TELEPORT_MOVING );
-	gAgent.setTeleportMessage(LLAgent::sTeleportProgressMessages["contacting"]);
-
-	regionp->setSeedCapability(seedCap);
-
-	// Don't send camera updates to the new region until we're
-	// actually there...
-
-
-	// Now do teleport effect for where you're going.
-	// VEFFECT: TeleportEnd
-	effectp = (LLHUDEffectSpiral *)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_POINT, TRUE);
-	effectp->setPositionGlobal(gAgent.getPositionGlobal());
-
-	effectp->setColor(LLColor4U(gAgent.getEffectColor()));
-	LLHUDManager::getInstance()->sendEffects();
-
-//	gTeleportDisplay = TRUE;
-//	gTeleportDisplayTimer.reset();
-//	gViewerWindow->setShowProgress(TRUE);
-}
-
-// stuff we have to do every time we get an AvatarInitComplete from a sim
-/*
-void process_avatar_init_complete(LLMessageSystem* msg, void**)
-{
-	LLVector3 agent_pos;
-	msg->getVector3Fast(_PREHASH_AvatarData, _PREHASH_Position, agent_pos);
-	agent_movement_complete(msg->getSender(), agent_pos);
-}
-*/
-
-void process_agent_movement_complete(LLMessageSystem* msg, void**)
-{
-	gAgentMovementCompleted = true;
-
-	LLUUID agent_id;
-	msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, agent_id);
-	LLUUID session_id;
-	msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_SessionID, session_id);
-	if((gAgent.getID() != agent_id) || (gAgent.getSessionID() != session_id))
-	{
-		LL_WARNS("Messaging") << "Incorrect id in process_agent_movement_complete()"
-				<< LL_ENDL;
-		return;
-	}
-
-	LL_DEBUGS("Messaging") << "process_agent_movement_complete()" << LL_ENDL;
-
-	// *TODO: check timestamp to make sure the movement compleation
-	// makes sense.
-	LLVector3 agent_pos;
-	msg->getVector3Fast(_PREHASH_Data, _PREHASH_Position, agent_pos);
-	LLVector3 look_at;
-	msg->getVector3Fast(_PREHASH_Data, _PREHASH_LookAt, look_at);
-	U64 region_handle;
-	msg->getU64Fast(_PREHASH_Data, _PREHASH_RegionHandle, region_handle);
-	
-	std::string version_channel;
-	msg->getString("SimData", "ChannelVersion", version_channel);
-
-	LLVOAvatar* avatarp = gAgent.getAvatarObject();
-	if (!avatarp)
-	{
-		// Could happen if you were immediately god-teleported away on login,
-		// maybe other cases.  Continue, but warn.
-		LL_WARNS("Messaging") << "agent_movement_complete() with NULL avatarp." << LL_ENDL;
-	}
-
-	F32 x, y;
-	from_region_handle(region_handle, &x, &y);
-	LLViewerRegion* regionp = LLWorld::getInstance()->getRegionFromHandle(region_handle);
-	if (!regionp)
-	{
-		if (gAgent.getRegion())
-		{
-			LL_WARNS("Messaging") << "current region " << gAgent.getRegion()->getOriginGlobal() << LL_ENDL;
-		}
-
-		LL_WARNS("Messaging") << "Agent being sent to invalid home region: " 
-			<< x << ":" << y 
-			<< " current pos " << gAgent.getPositionGlobal()
-			<< LL_ENDL;
-		LLAppViewer::instance()->forceDisconnect("You were sent to an invalid region.");
-		return;
-
-	}
-
-	LL_INFOS("Messaging") << "Changing home region to " << x << ":" << y << LL_ENDL;
-
-	// set our upstream host the new simulator and shuffle things as
-	// appropriate.
-	LLVector3 shift_vector = regionp->getPosRegionFromGlobal(
-		gAgent.getRegion()->getOriginGlobal());
-	gAgent.setRegion(regionp);
-	gObjectList.shiftObjects(shift_vector);
-	gAssetStorage->setUpstream(msg->getSender());
-	gCacheName->setUpstream(msg->getSender());
-	gViewerThrottle.sendToSim();
-	gViewerWindow->sendShapeToSim();
-
-	bool is_teleport = gAgent.getTeleportState() == LLAgent::TELEPORT_MOVING;
-
-	if( is_teleport )
-	{
-		// Force the camera back onto the agent, don't animate.
-		gAgent.setFocusOnAvatar(TRUE, FALSE);
-		gAgent.slamLookAt(look_at);
-		gAgent.updateCamera();
-
-		gAgent.setTeleportState( LLAgent::TELEPORT_START_ARRIVAL );
-
-		// set the appearance on teleport since the new sim does not
-		// know what you look like.
-		gAgent.sendAgentSetAppearance();
-
-		if (avatarp)
-		{
-			// Chat the "back" SLURL. (DEV-4907)
-			LLChat chat("Teleport completed from " + gAgent.getTeleportSourceSLURL());
-			chat.mSourceType = CHAT_SOURCE_SYSTEM;
- 			LLFloaterChat::addChatHistory(chat);
-
-			// Set the new position
-			avatarp->setPositionAgent(agent_pos);
-			avatarp->clearChat();
-			avatarp->slamPosition();
-		}
-	}
-	else
-	{
-		// This is likely just the initial logging in phase.
-		gAgent.setTeleportState( LLAgent::TELEPORT_NONE );
-	}
-
-	if ( LLTracker::isTracking(NULL) )
-	{
-		// Check distance to beacon, if < 5m, remove beacon
-		LLVector3d beacon_pos = LLTracker::getTrackedPositionGlobal();
-		LLVector3 beacon_dir(agent_pos.mV[VX] - (F32)fmod(beacon_pos.mdV[VX], 256.0), agent_pos.mV[VY] - (F32)fmod(beacon_pos.mdV[VY], 256.0), 0);
-		if (beacon_dir.magVecSquared() < 25.f)
-		{
-			LLTracker::stopTracking(NULL);
-		}
-		else if ( is_teleport )
-		{
-			//look at the beacon
-			LLVector3 global_agent_pos = agent_pos;
-			global_agent_pos[0] += x;
-			global_agent_pos[1] += y;
-			look_at = (LLVector3)beacon_pos - global_agent_pos;
-			look_at.normVec();
-			gAgent.slamLookAt(look_at);
-		}
-	}
-
-	// TODO: Put back a check for flying status! DK 12/19/05
-	// Sim tells us whether the new position is off the ground
-	/*
-	if (teleport_flags & TELEPORT_FLAGS_IS_FLYING)
-	{
-		gAgent.setFlying(TRUE);
-	}
-	else
-	{
-		gAgent.setFlying(FALSE);
-	}
-	*/
-
-	send_agent_update(TRUE, TRUE);
-
-	if (gAgent.getRegion()->getBlockFly())
-	{
-		gAgent.setFlying(gAgent.canFly());
-	}
-
-	// force simulator to recognize busy state
-	if (gAgent.getBusy())
-	{
-		gAgent.setBusy();
-	}
-	else
-	{
-		gAgent.clearBusy();
-	}
-
-	if (avatarp)
-	{
-		avatarp->mFootPlane.clearVec();
-	}
-	
-	// send walk-vs-run status
-	gAgent.sendWalkRun(gAgent.getRunning() || gAgent.getAlwaysRun());
-
-	// If the server version has changed, display an info box and offer
-	// to display the release notes, unless this is the initial log in.
-	if (gLastVersionChannel == version_channel)
-	{
-		return;
-	}
-
-	if (!gLastVersionChannel.empty())
-	{
-		LLSD payload;
-		payload["message"] = version_channel;
-		LLNotifications::instance().add("ServerVersionChanged", LLSD(), payload, server_version_changed_callback);
-	}
-
-	gLastVersionChannel = version_channel;
-}
-
-bool server_version_changed_callback(const LLSD& notification, const LLSD& response)
-{
-	if(notification["payload"]["message"].asString() =="")
-		return false;
-	std::string url ="http://wiki.secondlife.com/wiki/Release_Notes/";
-	//parse the msg string
-	std::string server_version = notification["payload"]["message"].asString();
-	std::vector<std::string> s_vect;
-	boost::algorithm::split(s_vect, server_version, isspace);
-	for(U32 i = 0; i < s_vect.size(); i++)
-	{
-    	if (i != (s_vect.size() - 1))
-		{
-			if(i != (s_vect.size() - 2))
-			{
-			   url += s_vect[i] + "_";
-			}
-			else
-			{
-				url += s_vect[i] + "/";
-			}
-		}
-		else
-		{
-			url += s_vect[i].substr(0,4);
-		}
-	}
-	
-	LLWeb::loadURL(url);
-	return false;
-}
-
-
-void process_crossed_region(LLMessageSystem* msg, void**)
-{
-	LLUUID agent_id;
-	msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, agent_id);
-	LLUUID session_id;
-	msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_SessionID, session_id);
-	if((gAgent.getID() != agent_id) || (gAgent.getSessionID() != session_id))
-	{
-		LL_WARNS("Messaging") << "Incorrect id in process_crossed_region()"
-				<< LL_ENDL;
-		return;
-	}
-	LL_INFOS("Messaging") << "process_crossed_region()" << LL_ENDL;
-
-	U32 sim_ip;
-	msg->getIPAddrFast(_PREHASH_RegionData, _PREHASH_SimIP, sim_ip);
-	U16 sim_port;
-	msg->getIPPortFast(_PREHASH_RegionData, _PREHASH_SimPort, sim_port);
-	LLHost sim_host(sim_ip, sim_port);
-	U64 region_handle;
-	msg->getU64Fast(_PREHASH_RegionData, _PREHASH_RegionHandle, region_handle);
-	
-	std::string seedCap;
-	msg->getStringFast(_PREHASH_RegionData, _PREHASH_SeedCapability, seedCap);
-
-	send_complete_agent_movement(sim_host);
-
-	LLViewerRegion* regionp = LLWorld::getInstance()->addRegion(region_handle, sim_host);
-	regionp->setSeedCapability(seedCap);
-}
-
-
-
-// Sends avatar and camera information to simulator.
-// Sent roughly once per frame, or 20 times per second, whichever is less often
-
-const F32 THRESHOLD_HEAD_ROT_QDOT = 0.9997f;	// ~= 2.5 degrees -- if its less than this we need to update head_rot
-const F32 MAX_HEAD_ROT_QDOT = 0.99999f;			// ~= 0.5 degrees -- if its greater than this then no need to update head_rot
-												// between these values we delay the updates (but no more than one second)
-
-
-void send_agent_update(BOOL force_send, BOOL send_reliable)
-{
-	if (gAgent.getTeleportState() != LLAgent::TELEPORT_NONE)
-	{
-		// We don't care if they want to send an agent update, they're not allowed to until the simulator
-		// that's the target is ready to receive them (after avatar_init_complete is received)
-		return;
-	}
-
-	// We have already requested to log out.  Don't send agent updates.
-	if(LLAppViewer::instance()->logoutRequestSent())
-	{
-		return;
-	}
-
-	// no region to send update to
-	if(gAgent.getRegion() == NULL)
-	{
-		return;
-	}
-
-	const F32 TRANSLATE_THRESHOLD = 0.01f;
-
-	// NOTA BENE: This is (intentionally?) using the small angle sine approximation to test for rotation
-	//			  Plus, there is an extra 0.5 in the mix since the perpendicular between last_camera_at and getAtAxis() bisects cam_rot_change
-	//			  Thus, we're actually testing against 0.2 degrees
-	const F32 ROTATION_THRESHOLD = 0.1f * 2.f*F_PI/360.f;			//  Rotation thresh 0.2 deg, see note above
-
-	const U8 DUP_MSGS = 1;				//  HACK!  number of times to repeat data on motionless agent
-
-	//  Store data on last sent update so that if no changes, no send
-	static LLVector3 last_camera_pos_agent, 
-					 last_camera_at, 
-					 last_camera_left,
-					 last_camera_up;
-	
-	static LLVector3 cam_center_chg,
-					 cam_rot_chg;
-
-	static LLQuaternion last_head_rot;
-	static U32 last_control_flags = 0;
-	static U8 last_render_state;
-	static U8 duplicate_count = 0;
-	static F32 head_rot_chg = 1.0;
-	static U8 last_flags;
-
-	LLMessageSystem	*msg = gMessageSystem;
-	LLVector3		camera_pos_agent;				// local to avatar's region
-	U8				render_state;
-
-	LLQuaternion body_rotation = gAgent.getFrameAgent().getQuaternion();
-	LLQuaternion head_rotation = gAgent.getHeadRotation();
-
-	camera_pos_agent = gAgent.getCameraPositionAgent();
-
-	render_state = gAgent.getRenderState();
-
-	U32		control_flag_change = 0;
-	U8		flag_change = 0;
-
-	cam_center_chg = last_camera_pos_agent - camera_pos_agent;
-	cam_rot_chg = last_camera_at - LLViewerCamera::getInstance()->getAtAxis();
-
-	// If a modifier key is held down, turn off
-	// LBUTTON and ML_LBUTTON so that using the camera (alt-key) doesn't
-	// trigger a control event.
-	U32 control_flags = gAgent.getControlFlags();
-	MASK	key_mask = gKeyboard->currentMask(TRUE);
-	if (key_mask & MASK_ALT || key_mask & MASK_CONTROL)
-	{
-		control_flags &= ~(	AGENT_CONTROL_LBUTTON_DOWN |
-							AGENT_CONTROL_ML_LBUTTON_DOWN );
-		control_flags |= 	AGENT_CONTROL_LBUTTON_UP |
-							AGENT_CONTROL_ML_LBUTTON_UP ;
-	}
-
-	control_flag_change = last_control_flags ^ control_flags;
-
-	U8 flags = AU_FLAGS_NONE;
-	if (gAgent.isGroupTitleHidden())
-	{
-		flags |= AU_FLAGS_HIDETITLE;
-	}
-	if (gAgent.getAutoPilot())
-	{
-		flags |= AU_FLAGS_CLIENT_AUTOPILOT;
-	}
-
-	flag_change = last_flags ^ flags;
-
-	head_rot_chg = dot(last_head_rot, head_rotation);
-
-	if (force_send || 
-		(cam_center_chg.magVec() > TRANSLATE_THRESHOLD) || 
-		(head_rot_chg < THRESHOLD_HEAD_ROT_QDOT) ||	
-		(last_render_state != render_state) ||
-		(cam_rot_chg.magVec() > ROTATION_THRESHOLD) ||
-		control_flag_change != 0 ||
-		flag_change != 0)  
-	{
-/*
-		if (head_rot_chg < THRESHOLD_HEAD_ROT_QDOT)
-		{
-			//LL_INFOS("Messaging") << "head rot " << head_rotation << LL_ENDL;
-			LL_INFOS("Messaging") << "head_rot_chg = " << head_rot_chg << LL_ENDL;
-		}
-		if (cam_rot_chg.magVec() > ROTATION_THRESHOLD) 
-		{
-			LL_INFOS("Messaging") << "cam rot " <<  cam_rot_chg.magVec() << LL_ENDL;
-		}
-		if (cam_center_chg.magVec() > TRANSLATE_THRESHOLD)
-		{
-			LL_INFOS("Messaging") << "cam center " << cam_center_chg.magVec() << LL_ENDL;
-		}
-//		if (drag_delta_chg.magVec() > TRANSLATE_THRESHOLD)
-//		{
-//			LL_INFOS("Messaging") << "drag delta " << drag_delta_chg.magVec() << LL_ENDL;
-//		}
-		if (control_flag_change)
-		{
-			LL_INFOS("Messaging") << "dcf = " << control_flag_change << LL_ENDL;
-		}
-*/
-
-		duplicate_count = 0;
-	}
-	else
-	{
-		duplicate_count++;
-
-		if (head_rot_chg < MAX_HEAD_ROT_QDOT  &&  duplicate_count < AGENT_UPDATES_PER_SECOND)
-		{
-			// The head_rotation is sent for updating things like attached guns.
-			// We only trigger a new update when head_rotation deviates beyond
-			// some threshold from the last update, however this can break fine
-			// adjustments when trying to aim an attached gun, so what we do here
-			// (where we would normally skip sending an update when nothing has changed)
-			// is gradually reduce the threshold to allow a better update to 
-			// eventually get sent... should update to within 0.5 degrees in less 
-			// than a second.
-			if (head_rot_chg < THRESHOLD_HEAD_ROT_QDOT + (MAX_HEAD_ROT_QDOT - THRESHOLD_HEAD_ROT_QDOT) * duplicate_count / AGENT_UPDATES_PER_SECOND)
-			{
-				duplicate_count = 0;
-			}
-			else
-			{
-				return;
-			}
-		}
-		else
-		{
-			return;
-		}
-	}
-
-	if (duplicate_count < DUP_MSGS && !gDisconnected)
-	{
-		// Build the message
-		msg->newMessageFast(_PREHASH_AgentUpdate);
-		msg->nextBlockFast(_PREHASH_AgentData);
-		msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-		msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-		msg->addQuatFast(_PREHASH_BodyRotation, body_rotation);
-		msg->addQuatFast(_PREHASH_HeadRotation, head_rotation);
-		msg->addU8Fast(_PREHASH_State, render_state);
-		msg->addU8Fast(_PREHASH_Flags, flags);
-
-//		if (camera_pos_agent.mV[VY] > 255.f)
-//		{
-//			LL_INFOS("Messaging") << "Sending camera center " << camera_pos_agent << LL_ENDL;
-//		}
-		
-		msg->addVector3Fast(_PREHASH_CameraCenter, camera_pos_agent);
-		msg->addVector3Fast(_PREHASH_CameraAtAxis, LLViewerCamera::getInstance()->getAtAxis());
-		msg->addVector3Fast(_PREHASH_CameraLeftAxis, LLViewerCamera::getInstance()->getLeftAxis());
-		msg->addVector3Fast(_PREHASH_CameraUpAxis, LLViewerCamera::getInstance()->getUpAxis());
-		msg->addF32Fast(_PREHASH_Far, gAgent.mDrawDistance);
-		
-		msg->addU32Fast(_PREHASH_ControlFlags, control_flags);
-
-		if (gDebugClicks)
-		{
-			if (control_flags & AGENT_CONTROL_LBUTTON_DOWN)
-			{
-				LL_INFOS("Messaging") << "AgentUpdate left button down" << LL_ENDL;
-			}
-
-			if (control_flags & AGENT_CONTROL_LBUTTON_UP)
-			{
-				LL_INFOS("Messaging") << "AgentUpdate left button up" << LL_ENDL;
-			}
-		}
-
-		gAgent.enableControlFlagReset();
-
-		if (!send_reliable)
-		{
-			gAgent.sendMessage();
-		}
-		else
-		{
-			gAgent.sendReliableMessage();
-		}
-
-//		LL_DEBUGS("Messaging") << "agent " << avatar_pos_agent << " cam " << camera_pos_agent << LL_ENDL;
-
-		// Copy the old data 
-		last_head_rot = head_rotation;
-		last_render_state = render_state;
-		last_camera_pos_agent = camera_pos_agent;
-		last_camera_at = LLViewerCamera::getInstance()->getAtAxis();
-		last_camera_left = LLViewerCamera::getInstance()->getLeftAxis();
-		last_camera_up = LLViewerCamera::getInstance()->getUpAxis();
-		last_control_flags = control_flags;
-		last_flags = flags;
-	}
-}
-
-
-
-// *TODO: Remove this dependency, or figure out a better way to handle
-// this hack.
-extern U32 gObjectBits;
-
-void process_object_update(LLMessageSystem *mesgsys, void **user_data)
-{	
-	LLMemType mt(LLMemType::MTYPE_OBJECT);
-	// Update the data counters
-	if (mesgsys->getReceiveCompressedSize())
-	{
-		gObjectBits += mesgsys->getReceiveCompressedSize() * 8;
-	}
-	else
-	{
-		gObjectBits += mesgsys->getReceiveSize() * 8;
-	}
-
-	// Update the object...
-	gObjectList.processObjectUpdate(mesgsys, user_data, OUT_FULL);
-}
-
-void process_compressed_object_update(LLMessageSystem *mesgsys, void **user_data)
-{
-	LLMemType mt(LLMemType::MTYPE_OBJECT);
-	// Update the data counters
-	if (mesgsys->getReceiveCompressedSize())
-	{
-		gObjectBits += mesgsys->getReceiveCompressedSize() * 8;
-	}
-	else
-	{
-		gObjectBits += mesgsys->getReceiveSize() * 8;
-	}
-
-	// Update the object...
-	gObjectList.processCompressedObjectUpdate(mesgsys, user_data, OUT_FULL_COMPRESSED);
-}
-
-void process_cached_object_update(LLMessageSystem *mesgsys, void **user_data)
-{
-	LLMemType mt(LLMemType::MTYPE_OBJECT);
-	// Update the data counters
-	if (mesgsys->getReceiveCompressedSize())
-	{
-		gObjectBits += mesgsys->getReceiveCompressedSize() * 8;
-	}
-	else
-	{
-		gObjectBits += mesgsys->getReceiveSize() * 8;
-	}
-
-	// Update the object...
-	gObjectList.processCachedObjectUpdate(mesgsys, user_data, OUT_FULL_CACHED);
-}
-
-
-void process_terse_object_update_improved(LLMessageSystem *mesgsys, void **user_data)
-{
-	LLMemType mt(LLMemType::MTYPE_OBJECT);
-	if (mesgsys->getReceiveCompressedSize())
-	{
-		gObjectBits += mesgsys->getReceiveCompressedSize() * 8;
-	}
-	else
-	{
-		gObjectBits += mesgsys->getReceiveSize() * 8;
-	}
-
-	gObjectList.processCompressedObjectUpdate(mesgsys, user_data, OUT_TERSE_IMPROVED);
-}
-
-static LLFastTimer::DeclareTimer FTM_PROCESS_OBJECTS("Process Objects");
-
-
-void process_kill_object(LLMessageSystem *mesgsys, void **user_data)
-{
-	LLFastTimer t(FTM_PROCESS_OBJECTS);
-
-	LLUUID		id;
-	U32			local_id;
-	S32			i;
-	S32			num_objects;
-
-	num_objects = mesgsys->getNumberOfBlocksFast(_PREHASH_ObjectData);
-
-	for (i = 0; i < num_objects; i++)
-	{
-		mesgsys->getU32Fast(_PREHASH_ObjectData, _PREHASH_ID, local_id, i);
-
-		LLViewerObjectList::getUUIDFromLocal(id,
-											local_id,
-											gMessageSystem->getSenderIP(),
-											gMessageSystem->getSenderPort());
-		if (id == LLUUID::null)
-		{
-			LL_DEBUGS("Messaging") << "Unknown kill for local " << local_id << LL_ENDL;
-			gObjectList.mNumUnknownKills++;
-			continue;
-		}
-		else
-		{
-			LL_DEBUGS("Messaging") << "Kill message for local " << local_id << LL_ENDL;
-		}
-
-		LLSelectMgr::getInstance()->removeObjectFromSelections(id);
-
-		// ...don't kill the avatar
-		if (!(id == gAgentID))
-		{
-			LLViewerObject *objectp = gObjectList.findObject(id);
-			if (objectp)
-			{
-				// Display green bubble on kill
-				if ( gShowObjectUpdates )
-				{
-					LLViewerObject* newobject;
-					newobject = gObjectList.createObjectViewer(LL_PCODE_LEGACY_TEXT_BUBBLE, objectp->getRegion());
-
-					LLVOTextBubble* bubble = (LLVOTextBubble*) newobject;
-
-					bubble->mColor.setVec(0.f, 1.f, 0.f, 1.f);
-					bubble->setScale( 2.0f * bubble->getScale() );
-					bubble->setPositionGlobal(objectp->getPositionGlobal());
-					gPipeline.addObject(bubble);
-				}
-
-				// Do the kill
-				gObjectList.killObject(objectp);
-			}
-			else
-			{
-				LL_WARNS("Messaging") << "Object in UUID lookup, but not on object list in kill!" << LL_ENDL;
-				gObjectList.mNumUnknownKills++;
-			}
-		}
-	}
-}
-
-void process_time_synch(LLMessageSystem *mesgsys, void **user_data)
-{
-	LLVector3 sun_direction;
-	LLVector3 sun_ang_velocity;
-	F32 phase;
-	U64	space_time_usec;
-
-    U32 seconds_per_day;
-    U32 seconds_per_year;
-
-	// "SimulatorViewerTimeMessage"
-	mesgsys->getU64Fast(_PREHASH_TimeInfo, _PREHASH_UsecSinceStart, space_time_usec);
-	mesgsys->getU32Fast(_PREHASH_TimeInfo, _PREHASH_SecPerDay, seconds_per_day);
-	mesgsys->getU32Fast(_PREHASH_TimeInfo, _PREHASH_SecPerYear, seconds_per_year);
-
-	// This should eventually be moved to an "UpdateHeavenlyBodies" message
-	mesgsys->getF32Fast(_PREHASH_TimeInfo, _PREHASH_SunPhase, phase);
-	mesgsys->getVector3Fast(_PREHASH_TimeInfo, _PREHASH_SunDirection, sun_direction);
-	mesgsys->getVector3Fast(_PREHASH_TimeInfo, _PREHASH_SunAngVelocity, sun_ang_velocity);
-
-	LLWorld::getInstance()->setSpaceTimeUSec(space_time_usec);
-
-	//LL_DEBUGS("Messaging") << "time_synch() - " << sun_direction << ", " << sun_ang_velocity
-	//		 << ", " << phase << LL_ENDL;
-
-	gSky.setSunPhase(phase);
-	gSky.setSunTargetDirection(sun_direction, sun_ang_velocity);
-	if (!gNoRender && !(gSavedSettings.getBOOL("SkyOverrideSimSunPosition") || gSky.getOverrideSun()))
-	{
-		gSky.setSunDirection(sun_direction, sun_ang_velocity);
-	}
-}
-
-void process_sound_trigger(LLMessageSystem *msg, void **)
-{
-	if (!gAudiop) return;
-
-	U64		region_handle = 0;
-	F32		gain = 0;
-	LLUUID	sound_id;
-	LLUUID	owner_id;
-	LLUUID	object_id;
-	LLUUID	parent_id;
-	LLVector3	pos_local;
-
-	msg->getUUIDFast(_PREHASH_SoundData, _PREHASH_SoundID, sound_id);
-	msg->getUUIDFast(_PREHASH_SoundData, _PREHASH_OwnerID, owner_id);
-	msg->getUUIDFast(_PREHASH_SoundData, _PREHASH_ObjectID, object_id);
-	msg->getUUIDFast(_PREHASH_SoundData, _PREHASH_ParentID, parent_id);
-	msg->getU64Fast(_PREHASH_SoundData, _PREHASH_Handle, region_handle);
-	msg->getVector3Fast(_PREHASH_SoundData, _PREHASH_Position, pos_local);
-	msg->getF32Fast(_PREHASH_SoundData, _PREHASH_Gain, gain);
-
-	// adjust sound location to true global coords
-	LLVector3d	pos_global = from_region_handle(region_handle);
-	pos_global.mdV[VX] += pos_local.mV[VX];
-	pos_global.mdV[VY] += pos_local.mV[VY];
-	pos_global.mdV[VZ] += pos_local.mV[VZ];
-
-	// Don't play a trigger sound if you can't hear it due
-	// to parcel "local audio only" settings.
-	if (!LLViewerParcelMgr::getInstance()->canHearSound(pos_global)) return;
-
-	// Don't play sounds triggered by someone you muted.
-	if (LLMuteList::getInstance()->isMuted(owner_id, LLMute::flagObjectSounds)) return;
-	
-	// Don't play sounds from an object you muted
-	if (LLMuteList::getInstance()->isMuted(object_id)) return;
-
-	// Don't play sounds from an object whose parent you muted
-	if (parent_id.notNull()
-		&& LLMuteList::getInstance()->isMuted(parent_id))
-	{
-		return;
-	}
-
-	// Don't play sounds from a region with maturity above current agent maturity
-	if( !gAgent.canAccessMaturityInRegion( region_handle ) )
-	{
-		return;
-	}
-		
-	gAudiop->triggerSound(sound_id, owner_id, gain, LLAudioEngine::AUDIO_TYPE_SFX, pos_global);
-}
-
-void process_preload_sound(LLMessageSystem *msg, void **user_data)
-{
-	if (!gAudiop)
-	{
-		return;
-	}
-
-	LLUUID sound_id;
-	LLUUID object_id;
-	LLUUID owner_id;
-
-	msg->getUUIDFast(_PREHASH_DataBlock, _PREHASH_SoundID, sound_id);
-	msg->getUUIDFast(_PREHASH_DataBlock, _PREHASH_ObjectID, object_id);
-	msg->getUUIDFast(_PREHASH_DataBlock, _PREHASH_OwnerID, owner_id);
-
-	LLViewerObject *objectp = gObjectList.findObject(object_id);
-	if (!objectp) return;
-
-	if (LLMuteList::getInstance()->isMuted(object_id)) return;
-	if (LLMuteList::getInstance()->isMuted(owner_id, LLMute::flagObjectSounds)) return;
-	
-	LLAudioSource *sourcep = objectp->getAudioSource(owner_id);
-	if (!sourcep) return;
-	
-	LLAudioData *datap = gAudiop->getAudioData(sound_id);
-
-	// Note that I don't actually do any loading of the
-	// audio data into a buffer at this point, as it won't actually
-	// help us out.
-
-	// Don't play sounds from a region with maturity above current agent maturity
-	LLVector3d pos_global = objectp->getPositionGlobal();
-	if( !gAgent.canAccessMaturityAtGlobal( pos_global ) )
-	{
-		return;
-	}
-	
-	// Add audioData starts a transfer internally.
-	sourcep->addAudioData(datap, FALSE);
-}
-
-void process_attached_sound(LLMessageSystem *msg, void **user_data)
-{
-	F32 gain = 0;
-	LLUUID sound_id;
-	LLUUID object_id;
-	LLUUID owner_id;
-	U8 flags;
-
-	msg->getUUIDFast(_PREHASH_DataBlock, _PREHASH_SoundID, sound_id);
-	msg->getUUIDFast(_PREHASH_DataBlock, _PREHASH_ObjectID, object_id);
-	msg->getUUIDFast(_PREHASH_DataBlock, _PREHASH_OwnerID, owner_id);
-	msg->getF32Fast(_PREHASH_DataBlock, _PREHASH_Gain, gain);
-	msg->getU8Fast(_PREHASH_DataBlock, _PREHASH_Flags, flags);
-
-	LLViewerObject *objectp = gObjectList.findObject(object_id);
-	if (!objectp)
-	{
-		// we don't know about this object, just bail
-		return;
-	}
-	
-	if (LLMuteList::getInstance()->isMuted(object_id)) return;
-	
-	if (LLMuteList::getInstance()->isMuted(owner_id, LLMute::flagObjectSounds)) return;
-
-	
-	// Don't play sounds from a region with maturity above current agent maturity
-	LLVector3d pos = objectp->getPositionGlobal();
-	if( !gAgent.canAccessMaturityAtGlobal(pos) )
-	{
-		return;
-	}
-	
-	objectp->setAttachedSound(sound_id, owner_id, gain, flags);
-}
-
-
-void process_attached_sound_gain_change(LLMessageSystem *mesgsys, void **user_data)
-{
-	F32 gain = 0;
-	LLUUID object_guid;
-	LLViewerObject *objectp = NULL;
-
-	mesgsys->getUUIDFast(_PREHASH_DataBlock, _PREHASH_ObjectID, object_guid);
-
-	if (!((objectp = gObjectList.findObject(object_guid))))
-	{
-		// we don't know about this object, just bail
-		return;
-	}
-
- 	mesgsys->getF32Fast(_PREHASH_DataBlock, _PREHASH_Gain, gain);
-
-	objectp->adjustAudioGain(gain);
-}
-
-
-void process_health_message(LLMessageSystem *mesgsys, void **user_data)
-{
-	F32 health;
-
-	mesgsys->getF32Fast(_PREHASH_HealthData, _PREHASH_Health, health);
-
-	if (gStatusBar)
-	{
-		gStatusBar->setHealth((S32)health);
-	}
-}
-
-
-void process_sim_stats(LLMessageSystem *msg, void **user_data)
-{	
-	S32 count = msg->getNumberOfBlocks("Stat");
-	for (S32 i = 0; i < count; ++i)
-	{
-		U32 stat_id;
-		F32 stat_value;
-		msg->getU32("Stat", "StatID", stat_id, i);
-		msg->getF32("Stat", "StatValue", stat_value, i);
-		switch (stat_id)
-		{
-		case LL_SIM_STAT_TIME_DILATION:
-			LLViewerStats::getInstance()->mSimTimeDilation.addValue(stat_value);
-			break;
-		case LL_SIM_STAT_FPS:
-			LLViewerStats::getInstance()->mSimFPS.addValue(stat_value);
-			break;
-		case LL_SIM_STAT_PHYSFPS:
-			LLViewerStats::getInstance()->mSimPhysicsFPS.addValue(stat_value);
-			break;
-		case LL_SIM_STAT_AGENTUPS:
-			LLViewerStats::getInstance()->mSimAgentUPS.addValue(stat_value);
-			break;
-		case LL_SIM_STAT_FRAMEMS:
-			LLViewerStats::getInstance()->mSimFrameMsec.addValue(stat_value);
-			break;
-		case LL_SIM_STAT_NETMS:
-			LLViewerStats::getInstance()->mSimNetMsec.addValue(stat_value);
-			break;
-		case LL_SIM_STAT_SIMOTHERMS:
-			LLViewerStats::getInstance()->mSimSimOtherMsec.addValue(stat_value);
-			break;
-		case LL_SIM_STAT_SIMPHYSICSMS:
-			LLViewerStats::getInstance()->mSimSimPhysicsMsec.addValue(stat_value);
-			break;
-		case LL_SIM_STAT_AGENTMS:
-			LLViewerStats::getInstance()->mSimAgentMsec.addValue(stat_value);
-			break;
-		case LL_SIM_STAT_IMAGESMS:
-			LLViewerStats::getInstance()->mSimImagesMsec.addValue(stat_value);
-			break;
-		case LL_SIM_STAT_SCRIPTMS:
-			LLViewerStats::getInstance()->mSimScriptMsec.addValue(stat_value);
-			break;
-		case LL_SIM_STAT_NUMTASKS:
-			LLViewerStats::getInstance()->mSimObjects.addValue(stat_value);
-			break;
-		case LL_SIM_STAT_NUMTASKSACTIVE:
-			LLViewerStats::getInstance()->mSimActiveObjects.addValue(stat_value);
-			break;
-		case LL_SIM_STAT_NUMAGENTMAIN:
-			LLViewerStats::getInstance()->mSimMainAgents.addValue(stat_value);
-			break;
-		case LL_SIM_STAT_NUMAGENTCHILD:
-			LLViewerStats::getInstance()->mSimChildAgents.addValue(stat_value);
-			break;
-		case LL_SIM_STAT_NUMSCRIPTSACTIVE:
-			LLViewerStats::getInstance()->mSimActiveScripts.addValue(stat_value);
-			break;
-		case LL_SIM_STAT_SCRIPT_EPS:
-			LLViewerStats::getInstance()->mSimScriptEPS.addValue(stat_value);
-			break;
-		case LL_SIM_STAT_INPPS:
-			LLViewerStats::getInstance()->mSimInPPS.addValue(stat_value);
-			break;
-		case LL_SIM_STAT_OUTPPS:
-			LLViewerStats::getInstance()->mSimOutPPS.addValue(stat_value);
-			break;
-		case LL_SIM_STAT_PENDING_DOWNLOADS:
-			LLViewerStats::getInstance()->mSimPendingDownloads.addValue(stat_value);
-			break;
-		case LL_SIM_STAT_PENDING_UPLOADS:
-			LLViewerStats::getInstance()->mSimPendingUploads.addValue(stat_value);
-			break;
-		case LL_SIM_STAT_PENDING_LOCAL_UPLOADS:
-			LLViewerStats::getInstance()->mSimPendingLocalUploads.addValue(stat_value);
-			break;
-		case LL_SIM_STAT_TOTAL_UNACKED_BYTES:
-			LLViewerStats::getInstance()->mSimTotalUnackedBytes.addValue(stat_value / 1024.f);
-			break;
-		case LL_SIM_STAT_PHYSICS_PINNED_TASKS:
-			LLViewerStats::getInstance()->mPhysicsPinnedTasks.addValue(stat_value);
-			break;
-		case LL_SIM_STAT_PHYSICS_LOD_TASKS:
-			LLViewerStats::getInstance()->mPhysicsLODTasks.addValue(stat_value);
-			break;
-		case LL_SIM_STAT_SIMPHYSICSSTEPMS:
-			LLViewerStats::getInstance()->mSimSimPhysicsStepMsec.addValue(stat_value);
-			break;
-		case LL_SIM_STAT_SIMPHYSICSSHAPEMS:
-			LLViewerStats::getInstance()->mSimSimPhysicsShapeUpdateMsec.addValue(stat_value);
-			break;
-		case LL_SIM_STAT_SIMPHYSICSOTHERMS:
-			LLViewerStats::getInstance()->mSimSimPhysicsOtherMsec.addValue(stat_value);
-			break;
-		case LL_SIM_STAT_SIMPHYSICSMEMORY:
-			LLViewerStats::getInstance()->mPhysicsMemoryAllocated.addValue(stat_value);
-			break;
-		case LL_SIM_STAT_SIMSPARETIME:
-			LLViewerStats::getInstance()->mSimSpareMsec.addValue(stat_value);
-			break;
-		case LL_SIM_STAT_SIMSLEEPTIME:
-			LLViewerStats::getInstance()->mSimSleepMsec.addValue(stat_value);
-			break;
-		case LL_SIM_STAT_IOPUMPTIME:
-			LLViewerStats::getInstance()->mSimPumpIOMsec.addValue(stat_value);
-			break;
-		default:
-			// Used to be a commented out warning.
- 			LL_DEBUGS("Messaging") << "Unknown stat id" << stat_id << LL_ENDL;
-		  break;
-		}
-	}
-
-	/*
-	msg->getF32Fast(_PREHASH_Statistics, _PREHASH_PhysicsTimeDilation, time_dilation);
-	LLViewerStats::getInstance()->mSimTDStat.addValue(time_dilation);
-
-	// Process information
-	//	{	CpuUsage			F32				}
-	//	{	SimMemTotal			F32				}
-	//	{	SimMemRSS			F32				}
-	//	{	ProcessUptime		F32				}
-	F32 cpu_usage;
-	F32 sim_mem_total;
-	F32 sim_mem_rss;
-	F32 process_uptime;
-	msg->getF32Fast(_PREHASH_Statistics, _PREHASH_CpuUsage, cpu_usage);
-	msg->getF32Fast(_PREHASH_Statistics, _PREHASH_SimMemTotal, sim_mem_total);
-	msg->getF32Fast(_PREHASH_Statistics, _PREHASH_SimMemRSS, sim_mem_rss);
-	msg->getF32Fast(_PREHASH_Statistics, _PREHASH_ProcessUptime, process_uptime);
-	LLViewerStats::getInstance()->mSimCPUUsageStat.addValue(cpu_usage);
-	LLViewerStats::getInstance()->mSimMemTotalStat.addValue(sim_mem_total);
-	LLViewerStats::getInstance()->mSimMemRSSStat.addValue(sim_mem_rss);
-	*/
-
-	//
-	// Various hacks that aren't statistics, but are being handled here.
-	//
-	U32 max_tasks_per_region;
-	U32 region_flags;
-	msg->getU32("Region", "ObjectCapacity", max_tasks_per_region);
-	msg->getU32("Region", "RegionFlags", region_flags);
-
-	LLViewerRegion* regionp = gAgent.getRegion();
-	if (regionp)
-	{
-		BOOL was_flying = gAgent.getFlying();
-		regionp->setRegionFlags(region_flags);
-		regionp->setMaxTasks(max_tasks_per_region);
-		// HACK: This makes agents drop from the sky if the region is 
-		// set to no fly while people are still in the sim.
-		if (was_flying && regionp->getBlockFly())
-		{
-			gAgent.setFlying(gAgent.canFly());
-		}
-	}
-}
-
-
-
-void process_avatar_animation(LLMessageSystem *mesgsys, void **user_data)
-{
-	LLUUID	animation_id;
-	LLUUID	uuid;
-	S32		anim_sequence_id;
-	LLVOAvatar *avatarp;
-	
-	mesgsys->getUUIDFast(_PREHASH_Sender, _PREHASH_ID, uuid);
-
-	//clear animation flags
-	avatarp = (LLVOAvatar *)gObjectList.findObject(uuid);
-
-	if (!avatarp)
-	{
-		// no agent by this ID...error?
-		LL_WARNS("Messaging") << "Received animation state for unknown avatar" << uuid << LL_ENDL;
-		return;
-	}
-
-	S32 num_blocks = mesgsys->getNumberOfBlocksFast(_PREHASH_AnimationList);
-	S32 num_source_blocks = mesgsys->getNumberOfBlocksFast(_PREHASH_AnimationSourceList);
-
-	avatarp->mSignaledAnimations.clear();
-	
-	if (avatarp->isSelf())
-	{
-		LLUUID object_id;
-
-		for( S32 i = 0; i < num_blocks; i++ )
-		{
-			mesgsys->getUUIDFast(_PREHASH_AnimationList, _PREHASH_AnimID, animation_id, i);
-			mesgsys->getS32Fast(_PREHASH_AnimationList, _PREHASH_AnimSequenceID, anim_sequence_id, i);
-
-			LL_DEBUGS("Messaging") << "Anim sequence ID: " << anim_sequence_id << LL_ENDL;
-
-			avatarp->mSignaledAnimations[animation_id] = anim_sequence_id;
-
-			if (i < num_source_blocks)
-			{
-				mesgsys->getUUIDFast(_PREHASH_AnimationSourceList, _PREHASH_ObjectID, object_id, i);
-			
-				LLViewerObject* object = gObjectList.findObject(object_id);
-				if (object)
-				{
-					object->mFlags |= FLAGS_ANIM_SOURCE;
-
-					BOOL anim_found = FALSE;
-					LLVOAvatar::AnimSourceIterator anim_it = avatarp->mAnimationSources.find(object_id);
-					for (;anim_it != avatarp->mAnimationSources.end(); ++anim_it)
-					{
-						if (anim_it->second == animation_id)
-						{
-							anim_found = TRUE;
-							break;
-						}
-					}
-
-					if (!anim_found)
-					{
-						avatarp->mAnimationSources.insert(LLVOAvatar::AnimationSourceMap::value_type(object_id, animation_id));
-					}
-				}
-			}
-		}
-	}
-	else
-	{
-		for( S32 i = 0; i < num_blocks; i++ )
-		{
-			mesgsys->getUUIDFast(_PREHASH_AnimationList, _PREHASH_AnimID, animation_id, i);
-			mesgsys->getS32Fast(_PREHASH_AnimationList, _PREHASH_AnimSequenceID, anim_sequence_id, i);
-			avatarp->mSignaledAnimations[animation_id] = anim_sequence_id;
-		}
-	}
-
-	if (num_blocks)
-	{
-		avatarp->processAnimationStateChanges();
-	}
-}
-
-void process_avatar_appearance(LLMessageSystem *mesgsys, void **user_data)
-{
-	LLUUID uuid;
-	mesgsys->getUUIDFast(_PREHASH_Sender, _PREHASH_ID, uuid);
-
-	LLVOAvatar* avatarp = (LLVOAvatar *)gObjectList.findObject(uuid);
-	if( avatarp )
-	{
-		avatarp->processAvatarAppearance( mesgsys );
-	}
-	else
-	{
-		LL_WARNS("Messaging") << "avatar_appearance sent for unknown avatar " << uuid << LL_ENDL;
-	}
-}
-
-void process_camera_constraint(LLMessageSystem *mesgsys, void **user_data)
-{
-	LLVector4 cameraCollidePlane;
-	mesgsys->getVector4Fast(_PREHASH_CameraCollidePlane, _PREHASH_Plane, cameraCollidePlane);
-
-	gAgent.setCameraCollidePlane(cameraCollidePlane);
-}
-
-void near_sit_object(BOOL success, void *data)
-{
-	if (success)
-	{
-		// Send message to sit on object
-		gMessageSystem->newMessageFast(_PREHASH_AgentSit);
-		gMessageSystem->nextBlockFast(_PREHASH_AgentData);
-		gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-		gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-		gAgent.sendReliableMessage();
-	}
-}
-
-void process_avatar_sit_response(LLMessageSystem *mesgsys, void **user_data)
-{
-	LLVector3 sitPosition;
-	LLQuaternion sitRotation;
-	LLUUID sitObjectID;
-	BOOL use_autopilot;
-	mesgsys->getUUIDFast(_PREHASH_SitObject, _PREHASH_ID, sitObjectID);
-	mesgsys->getBOOLFast(_PREHASH_SitTransform, _PREHASH_AutoPilot, use_autopilot);
-	mesgsys->getVector3Fast(_PREHASH_SitTransform, _PREHASH_SitPosition, sitPosition);
-	mesgsys->getQuatFast(_PREHASH_SitTransform, _PREHASH_SitRotation, sitRotation);
-	LLVector3 camera_eye;
-	mesgsys->getVector3Fast(_PREHASH_SitTransform, _PREHASH_CameraEyeOffset, camera_eye);
-	LLVector3 camera_at;
-	mesgsys->getVector3Fast(_PREHASH_SitTransform, _PREHASH_CameraAtOffset, camera_at);
-	BOOL force_mouselook;
-	mesgsys->getBOOLFast(_PREHASH_SitTransform, _PREHASH_ForceMouselook, force_mouselook);
-
-	LLVOAvatar* avatar = gAgent.getAvatarObject();
-
-	if (avatar && dist_vec_squared(camera_eye, camera_at) > 0.0001f)
-	{
-		gAgent.setSitCamera(sitObjectID, camera_eye, camera_at);
-	}
-	
-	gAgent.setForceMouselook(force_mouselook);
-
-	LLViewerObject* object = gObjectList.findObject(sitObjectID);
-	if (object)
-	{
-		LLVector3 sit_spot = object->getPositionAgent() + (sitPosition * object->getRotation());
-		if (!use_autopilot || (avatar && avatar->isSitting() && avatar->getRoot() == object->getRoot()))
-		{
-			//we're already sitting on this object, so don't autopilot
-		}
-		else
-		{
-			gAgent.startAutoPilotGlobal(gAgent.getPosGlobalFromAgent(sit_spot), "Sit", &sitRotation, near_sit_object, NULL, 0.5f);
-		}
-	}
-	else
-	{
-		LL_WARNS("Messaging") << "Received sit approval for unknown object " << sitObjectID << LL_ENDL;
-	}
-}
-
-void process_clear_follow_cam_properties(LLMessageSystem *mesgsys, void **user_data)
-{
-	LLUUID		source_id;
-
-	mesgsys->getUUIDFast(_PREHASH_ObjectData, _PREHASH_ObjectID, source_id);
-
-	LLFollowCamMgr::removeFollowCamParams(source_id);
-}
-
-void process_set_follow_cam_properties(LLMessageSystem *mesgsys, void **user_data)
-{
-	S32			type;
-	F32			value;
-	bool		settingPosition = false;
-	bool		settingFocus	= false;
-	bool		settingFocusOffset = false;
-	LLVector3	position;
-	LLVector3	focus;
-	LLVector3	focus_offset;
-
-	LLUUID		source_id;
-
-	mesgsys->getUUIDFast(_PREHASH_ObjectData, _PREHASH_ObjectID, source_id);
-
-	LLViewerObject* objectp = gObjectList.findObject(source_id);
-	if (objectp)
-	{
-		objectp->mFlags |= FLAGS_CAMERA_SOURCE;
-	}
-
-	S32 num_objects = mesgsys->getNumberOfBlocks("CameraProperty");
-	for (S32 block_index = 0; block_index < num_objects; block_index++)
-	{
-		mesgsys->getS32("CameraProperty", "Type", type, block_index);
-		mesgsys->getF32("CameraProperty", "Value", value, block_index);
-		switch(type)
-		{
-		case FOLLOWCAM_PITCH:
-			LLFollowCamMgr::setPitch(source_id, value);
-			break;
-		case FOLLOWCAM_FOCUS_OFFSET_X:
-			focus_offset.mV[VX] = value;
-			settingFocusOffset = true;
-			break;
-		case FOLLOWCAM_FOCUS_OFFSET_Y:
-			focus_offset.mV[VY] = value;
-			settingFocusOffset = true;
-			break;
-		case FOLLOWCAM_FOCUS_OFFSET_Z:
-			focus_offset.mV[VZ] = value;
-			settingFocusOffset = true;
-			break;
-		case FOLLOWCAM_POSITION_LAG:
-			LLFollowCamMgr::setPositionLag(source_id, value);
-			break;
-		case FOLLOWCAM_FOCUS_LAG:
-			LLFollowCamMgr::setFocusLag(source_id, value);
-			break;
-		case FOLLOWCAM_DISTANCE:
-			LLFollowCamMgr::setDistance(source_id, value);
-			break;
-		case FOLLOWCAM_BEHINDNESS_ANGLE:
-			LLFollowCamMgr::setBehindnessAngle(source_id, value);
-			break;
-		case FOLLOWCAM_BEHINDNESS_LAG:
-			LLFollowCamMgr::setBehindnessLag(source_id, value);
-			break;
-		case FOLLOWCAM_POSITION_THRESHOLD:
-			LLFollowCamMgr::setPositionThreshold(source_id, value);
-			break;
-		case FOLLOWCAM_FOCUS_THRESHOLD:
-			LLFollowCamMgr::setFocusThreshold(source_id, value);
-			break;
-		case FOLLOWCAM_ACTIVE:
-			//if 1, set using followcam,. 
-			LLFollowCamMgr::setCameraActive(source_id, value != 0.f);
-			break;
-		case FOLLOWCAM_POSITION_X:
-			settingPosition = true;
-			position.mV[ 0 ] = value;
-			break;
-		case FOLLOWCAM_POSITION_Y:
-			settingPosition = true;
-			position.mV[ 1 ] = value;
-			break;
-		case FOLLOWCAM_POSITION_Z:
-			settingPosition = true;
-			position.mV[ 2 ] = value;
-			break;
-		case FOLLOWCAM_FOCUS_X:
-			settingFocus = true;
-			focus.mV[ 0 ] = value;
-			break;
-		case FOLLOWCAM_FOCUS_Y:
-			settingFocus = true;
-			focus.mV[ 1 ] = value;
-			break;
-		case FOLLOWCAM_FOCUS_Z:
-			settingFocus = true;
-			focus.mV[ 2 ] = value;
-			break;
-		case FOLLOWCAM_POSITION_LOCKED:
-			LLFollowCamMgr::setPositionLocked(source_id, value != 0.f);
-			break;
-		case FOLLOWCAM_FOCUS_LOCKED:
-			LLFollowCamMgr::setFocusLocked(source_id, value != 0.f);
-			break;
-
-		default:
-			break;
-		}
-	}
-
-	if ( settingPosition )
-	{
-		LLFollowCamMgr::setPosition(source_id, position);
-	}
-	if ( settingFocus )
-	{
-		LLFollowCamMgr::setFocus(source_id, focus);
-	}
-	if ( settingFocusOffset )
-	{
-		LLFollowCamMgr::setFocusOffset(source_id, focus_offset);
-	}
-}
-//end Ventrella 
-
-
-// Culled from newsim lltask.cpp
-void process_name_value(LLMessageSystem *mesgsys, void **user_data)
-{
-	std::string	temp_str;
-	LLUUID	id;
-	S32		i, num_blocks;
-
-	mesgsys->getUUIDFast(_PREHASH_TaskData, _PREHASH_ID, id);
-
-	LLViewerObject* object = gObjectList.findObject(id);
-
-	if (object)
-	{
-		num_blocks = mesgsys->getNumberOfBlocksFast(_PREHASH_NameValueData);
-		for (i = 0; i < num_blocks; i++)
-		{
-			mesgsys->getStringFast(_PREHASH_NameValueData, _PREHASH_NVPair, temp_str, i);
-			LL_INFOS("Messaging") << "Added to object Name Value: " << temp_str << LL_ENDL;
-			object->addNVPair(temp_str);
-		}
-	}
-	else
-	{
-		LL_INFOS("Messaging") << "Can't find object " << id << " to add name value pair" << LL_ENDL;
-	}
-}
-
-void process_remove_name_value(LLMessageSystem *mesgsys, void **user_data)
-{
-	std::string	temp_str;
-	LLUUID	id;
-	S32		i, num_blocks;
-
-	mesgsys->getUUIDFast(_PREHASH_TaskData, _PREHASH_ID, id);
-
-	LLViewerObject* object = gObjectList.findObject(id);
-
-	if (object)
-	{
-		num_blocks = mesgsys->getNumberOfBlocksFast(_PREHASH_NameValueData);
-		for (i = 0; i < num_blocks; i++)
-		{
-			mesgsys->getStringFast(_PREHASH_NameValueData, _PREHASH_NVPair, temp_str, i);
-			LL_INFOS("Messaging") << "Removed from object Name Value: " << temp_str << LL_ENDL;
-			object->removeNVPair(temp_str);
-		}
-	}
-	else
-	{
-		LL_INFOS("Messaging") << "Can't find object " << id << " to remove name value pair" << LL_ENDL;
-	}
-}
-
-void process_kick_user(LLMessageSystem *msg, void** /*user_data*/)
-{
-	std::string message;
-
-	msg->getStringFast(_PREHASH_UserInfo, _PREHASH_Reason, message);
-
-	LLAppViewer::instance()->forceDisconnect(message);
-}
-
-
-/*
-void process_user_list_reply(LLMessageSystem *msg, void **user_data)
-{
-	LLUserList::processUserListReply(msg, user_data);
-	return;
-	char	firstname[MAX_STRING+1];
-	char	lastname[MAX_STRING+1];
-	U8		status;
-	S32		user_count;
-
-	user_count = msg->getNumberOfBlocks("UserBlock");
-
-	for (S32 i = 0; i < user_count; i++)
-	{
-		msg->getData("UserBlock", i, "FirstName", firstname);
-		msg->getData("UserBlock", i, "LastName", lastname);
-		msg->getData("UserBlock", i, "Status", &status);
-
-		if (status & 0x01)
-		{
-			dialog_friends_add_friend(buffer, TRUE);
-		}
-		else
-		{
-			dialog_friends_add_friend(buffer, FALSE);
-		}
-	}
-
-	dialog_friends_done_adding();
-}
-*/
-
-// this is not handled in processUpdateMessage
-/*
-void process_time_dilation(LLMessageSystem *msg, void **user_data)
-{
-	// get the time_dilation
-	U16 foo;
-	msg->getData("TimeDilation", "TimeDilation", &foo);
-	F32 time_dilation = ((F32) foo) / 65535.f;
-
-	// get the pointer to the right region
-	U32 ip = msg->getSenderIP();
-	U32 port = msg->getSenderPort();
-	LLViewerRegion *regionp = LLWorld::getInstance()->getRegion(ip, port);
-	if (regionp)
-	{
-		regionp->setTimeDilation(time_dilation);
-	}
-}
-*/
-
-
-
-void process_money_balance_reply( LLMessageSystem* msg, void** )
-{
-	S32 balance = 0;
-	S32 credit = 0;
-	S32 committed = 0;
-	std::string desc;
-
-	msg->getS32("MoneyData", "MoneyBalance", balance);
-	msg->getS32("MoneyData", "SquareMetersCredit", credit);
-	msg->getS32("MoneyData", "SquareMetersCommitted", committed);
-	msg->getStringFast(_PREHASH_MoneyData, _PREHASH_Description, desc);
-	LL_INFOS("Messaging") << "L$, credit, committed: " << balance << " " << credit << " "
-			<< committed << LL_ENDL;
-
-	if (gStatusBar)
-	{
-		S32 old_balance = gStatusBar->getBalance();
-
-		// This is an update, not the first transmission of balance
-		if (old_balance != 0)
-		{
-			// this is actually an update
-			if (balance > old_balance)
-			{
-				LLFirstUse::useBalanceIncrease(balance - old_balance);
-			}
-			else if (balance < old_balance)
-			{
-				LLFirstUse::useBalanceDecrease(balance - old_balance);
-			}
-		}
-
-		gStatusBar->setBalance(balance);
-		gStatusBar->setLandCredit(credit);
-		gStatusBar->setLandCommitted(committed);
-	}
-
-	LLUUID tid;
-	msg->getUUID("MoneyData", "TransactionID", tid);
-	static std::deque<LLUUID> recent;
-	if(!desc.empty() && gSavedSettings.getBOOL("NotifyMoneyChange")
-	   && (std::find(recent.rbegin(), recent.rend(), tid) == recent.rend()))
-	{
-		// Make the user confirm the transaction, since they might
-		// have missed something during an event.
-		// *TODO: Translate
-		LLSD args;
-		args["MESSAGE"] = desc;
-		LLNotifications::instance().add("SystemMessage", args);
-
-		// Once the 'recent' container gets large enough, chop some
-		// off the beginning.
-		const U32 MAX_LOOKBACK = 30;
-		const S32 POP_FRONT_SIZE = 12;
-		if(recent.size() > MAX_LOOKBACK)
-		{
-			LL_DEBUGS("Messaging") << "Removing oldest transaction records" << LL_ENDL;
-			recent.erase(recent.begin(), recent.begin() + POP_FRONT_SIZE);
-		}
-		//LL_DEBUGS("Messaging") << "Pushing back transaction " << tid << LL_ENDL;
-		recent.push_back(tid);
-	}
-}
-
-bool handle_special_notification_callback(const LLSD& notification, const LLSD& response)
-{
-	S32 option = LLNotification::getSelectedOption(notification, response);
-	
-	if (0 == option)
-	{
-		// set the preference to the maturity of the region we're calling
-		int preferredMaturity = notification["payload"]["_region_access"].asInteger();
-		gSavedSettings.setU32("PreferredMaturity", preferredMaturity);
-		gAgent.sendMaturityPreferenceToServer(preferredMaturity);
-
-	}
-	
-	return false;
-}
-
-// some of the server notifications need special handling. This is where we do that.
-bool handle_special_notification(std::string notificationID, LLSD& llsdBlock)
-{
-	int regionAccess = llsdBlock["_region_access"].asInteger();
-	llsdBlock["REGIONMATURITY"] = LLViewerRegion::accessToString(regionAccess);
-	
-	// we're going to throw the LLSD in there in case anyone ever wants to use it
-	LLNotifications::instance().add(notificationID+"_Notify", llsdBlock);
-	
-	if (regionAccess == SIM_ACCESS_MATURE)
-	{
-		if (gAgent.isTeen())
-		{
-			LLNotifications::instance().add(notificationID+"_KB", llsdBlock);
-			return true;
-		}
-		else if (gAgent.prefersPG())
-		{
-			LLNotifications::instance().add(notificationID+"_Change", llsdBlock, llsdBlock, handle_special_notification_callback);
-			return true;
-		}
-	}
-	else if (regionAccess == SIM_ACCESS_ADULT)
-	{
-		if (!gAgent.isAdult())
-		{
-			LLNotifications::instance().add(notificationID+"_KB", llsdBlock);
-			return true;
-		}
-		else if (gAgent.prefersPG() || gAgent.prefersMature())
-		{
-			LLNotifications::instance().add(notificationID+"_Change", llsdBlock, llsdBlock, handle_special_notification_callback);
-			return true;
-		}
-	}
-	return false;
-}
-
-bool attempt_standard_notification(LLMessageSystem* msgsystem)
-{
-	// if we have additional alert data
-	if (msgsystem->has(_PREHASH_AlertInfo) && msgsystem->getNumberOfBlocksFast(_PREHASH_AlertInfo) > 0)
-	{
-		// notification was specified using the new mechanism, so we can just handle it here
-		std::string notificationID;
-		std::string llsdRaw;
-		LLSD llsdBlock;
-		msgsystem->getStringFast(_PREHASH_AlertInfo, _PREHASH_Message, notificationID);
-		msgsystem->getStringFast(_PREHASH_AlertInfo, _PREHASH_ExtraParams, llsdRaw);
-		if (llsdRaw.length())
-		{
-			std::istringstream llsdData(llsdRaw);
-			if (!LLSDSerialize::deserialize(llsdBlock, llsdData, llsdRaw.length()))
-			{
-				llwarns << "attempt_standard_notification: Attempted to read notification parameter data into LLSD but failed:" << llsdRaw << llendl;
-			}
-		}
-		
-		if (
-			(notificationID == "RegionEntryAccessBlocked") ||
-			(notificationID == "LandClaimAccessBlocked") ||
-			(notificationID == "LandBuyAccessBlocked")
-		   )
-		{
-			/*---------------------------------------------------------------------
-			 (Commented so a grep will find the notification strings, since
-			 we construct them on the fly; if you add additional notifications,
-			 please update the comment.)
-			 
-			 Could throw any of the following notifications:
-			 
-				RegionEntryAccessBlocked
-				RegionEntryAccessBlocked_Notify
-				RegionEntryAccessBlocked_Change
-				RegionEntryAccessBlocked_KB
-				LandClaimAccessBlocked 
-				LandClaimAccessBlocked_Notify 
-				LandClaimAccessBlocked_Change 
-				LandClaimAccessBlocked_KB 
-				LandBuyAccessBlocked
-				LandBuyAccessBlocked_Notify
-				LandBuyAccessBlocked_Change
-				LandBuyAccessBlocked_KB
-			 
-			-----------------------------------------------------------------------*/ 
-			if (handle_special_notification(notificationID, llsdBlock))
-			{
-				return true;
-			}
-		}
-		
-		LLNotifications::instance().add(notificationID, llsdBlock);
-		return true;
-	}	
-	return false;
-}
-
-
-void process_agent_alert_message(LLMessageSystem* msgsystem, void** user_data)
-{
-	// make sure the cursor is back to the usual default since the
-	// alert is probably due to some kind of error.
-	gViewerWindow->getWindow()->resetBusyCount();
-	
-	if (!attempt_standard_notification(msgsystem))
-	{
-		BOOL modal = FALSE;
-		msgsystem->getBOOL("AlertData", "Modal", modal);
-		std::string buffer;
-		msgsystem->getStringFast(_PREHASH_AlertData, _PREHASH_Message, buffer);
-		process_alert_core(buffer, modal);
-	}
-}
-
-// The only difference between this routine and the previous is the fact that
-// for this routine, the modal parameter is always false. Sadly, for the message
-// handled by this routine, there is no "Modal" parameter on the message, and
-// there's no API to tell if a message has the given parameter or not.
-// So we can't handle the messages with the same handler.
-void process_alert_message(LLMessageSystem *msgsystem, void **user_data)
-{
-	// make sure the cursor is back to the usual default since the
-	// alert is probably due to some kind of error.
-	gViewerWindow->getWindow()->resetBusyCount();
-		
-	if (!attempt_standard_notification(msgsystem))
-	{
-		BOOL modal = FALSE;
-		std::string buffer;
-		msgsystem->getStringFast(_PREHASH_AlertData, _PREHASH_Message, buffer);
-		process_alert_core(buffer, modal);
-	}
-}
-
-void process_alert_core(const std::string& message, BOOL modal)
-{
-	// HACK -- handle callbacks for specific alerts
-	if ( message == "You died and have been teleported to your home location")
-	{
-		LLViewerStats::getInstance()->incStat(LLViewerStats::ST_KILLED_COUNT);
-	}
-	else if( message == "Home position set." )
-	{
-		// save the home location image to disk
-		std::string snap_filename = gDirUtilp->getLindenUserDir();
-		snap_filename += gDirUtilp->getDirDelimiter();
-		snap_filename += SCREEN_HOME_FILENAME;
-		gViewerWindow->saveSnapshot(snap_filename, gViewerWindow->getWindowDisplayWidth(), gViewerWindow->getWindowDisplayHeight(), FALSE, FALSE);
-	}
-
-	const std::string ALERT_PREFIX("ALERT: ");
-	const std::string NOTIFY_PREFIX("NOTIFY: ");
-	if (message.find(ALERT_PREFIX) == 0)
-	{
-		// Allow the server to spawn a named alert so that server alerts can be
-		// translated out of English.
-		std::string alert_name(message.substr(ALERT_PREFIX.length()));
-		LLNotifications::instance().add(alert_name);
-	}
-	else if (message.find(NOTIFY_PREFIX) == 0)
-	{
-		// Allow the server to spawn a named notification so that server notifications can be
-		// translated out of English.
-		std::string notify_name(message.substr(NOTIFY_PREFIX.length()));
-		LLNotifications::instance().add(notify_name);
-	}
-	else if (message[0] == '/')
-	{
-		// System message is important, show in upper-right box not tip
-		std::string text(message.substr(1));
-		LLSD args;
-		if (text.substr(0,17) == "RESTART_X_MINUTES")
-		{
-			S32 mins = 0;
-			LLStringUtil::convertToS32(text.substr(18), mins);
-			args["MINUTES"] = llformat("%d",mins);
-			LLNotifications::instance().add("RegionRestartMinutes", args);
-		}
-		else if (text.substr(0,17) == "RESTART_X_SECONDS")
-		{
-			S32 secs = 0;
-			LLStringUtil::convertToS32(text.substr(18), secs);
-			args["SECONDS"] = llformat("%d",secs);
-			LLNotifications::instance().add("RegionRestartSeconds", args);
-		}
-		else
-		{
-			std::string new_msg =LLNotifications::instance().getGlobalString(text);
-			args["MESSAGE"] = new_msg;
-			LLNotifications::instance().add("SystemMessage", args);
-		}
-	}
-	else if (modal)
-	{
-		LLSD args;
-		std::string new_msg =LLNotifications::instance().getGlobalString(message);
-		args["ERROR_MESSAGE"] = new_msg;
-		LLNotifications::instance().add("ErrorMessage", args);
-	}
-	else
-	{
-		LLSD args;
-		std::string new_msg =LLNotifications::instance().getGlobalString(message);
-		args["MESSAGE"] = new_msg;
-		LLNotifications::instance().add("SystemMessageTip", args);
-	}
-}
-
-mean_collision_list_t				gMeanCollisionList;
-time_t								gLastDisplayedTime = 0;
-
-void handle_show_mean_events(void *)
-{
-	if (gNoRender)
-	{
-		return;
-	}
-	LLFloaterReg::showInstance("bumps");
-	//LLFloaterBump::showInstance();
-}
-
-void mean_name_callback(const LLUUID &id, const std::string& first, const std::string& last, BOOL always_false)
-{
-	if (gNoRender)
-	{
-		return;
-	}
-
-	static const U32 max_collision_list_size = 20;
-	if (gMeanCollisionList.size() > max_collision_list_size)
-	{
-		mean_collision_list_t::iterator iter = gMeanCollisionList.begin();
-		for (U32 i=0; i<max_collision_list_size; i++) iter++;
-		for_each(iter, gMeanCollisionList.end(), DeletePointer());
-		gMeanCollisionList.erase(iter, gMeanCollisionList.end());
-	}
-
-	for (mean_collision_list_t::iterator iter = gMeanCollisionList.begin();
-		 iter != gMeanCollisionList.end(); ++iter)
-	{
-		LLMeanCollisionData *mcd = *iter;
-		if (mcd->mPerp == id)
-		{
-			mcd->mFirstName = first;
-			mcd->mLastName = last;
-		}
-	}
-}
-
-void process_mean_collision_alert_message(LLMessageSystem *msgsystem, void **user_data)
-{
-	if (gAgent.inPrelude())
-	{
-		// In prelude, bumping is OK.  This dialog is rather confusing to 
-		// newbies, so we don't show it.  Drop the packet on the floor.
-		return;
-	}
-
-	// make sure the cursor is back to the usual default since the
-	// alert is probably due to some kind of error.
-	gViewerWindow->getWindow()->resetBusyCount();
-
-	LLUUID perp;
-	U32	   time;
-	U8	   u8type;
-	EMeanCollisionType	   type;
-	F32    mag;
-
-	S32 i, num = msgsystem->getNumberOfBlocks(_PREHASH_MeanCollision);
-
-	for (i = 0; i < num; i++)
-	{
-		msgsystem->getUUIDFast(_PREHASH_MeanCollision, _PREHASH_Perp, perp);
-		msgsystem->getU32Fast(_PREHASH_MeanCollision, _PREHASH_Time, time);
-		msgsystem->getF32Fast(_PREHASH_MeanCollision, _PREHASH_Mag, mag);
-		msgsystem->getU8Fast(_PREHASH_MeanCollision, _PREHASH_Type, u8type);
-
-		type = (EMeanCollisionType)u8type;
-
-		BOOL b_found = FALSE;
-
-		for (mean_collision_list_t::iterator iter = gMeanCollisionList.begin();
-			 iter != gMeanCollisionList.end(); ++iter)
-		{
-			LLMeanCollisionData *mcd = *iter;
-			if ((mcd->mPerp == perp) && (mcd->mType == type))
-			{
-				mcd->mTime = time;
-				mcd->mMag = mag;
-				b_found = TRUE;
-				break;
-			}
-		}
-
-		if (!b_found)
-		{
-			LLMeanCollisionData *mcd = new LLMeanCollisionData(gAgentID, perp, time, type, mag);
-			gMeanCollisionList.push_front(mcd);
-			const BOOL is_group = FALSE;
-			gCacheName->get(perp, is_group, &mean_name_callback);
-		}
-	}
-}
-
-void process_frozen_message(LLMessageSystem *msgsystem, void **user_data)
-{
-	// make sure the cursor is back to the usual default since the
-	// alert is probably due to some kind of error.
-	gViewerWindow->getWindow()->resetBusyCount();
-	BOOL b_frozen;
-	
-	msgsystem->getBOOL("FrozenData", "Data", b_frozen);
-
-	// TODO: make being frozen change view
-	if (b_frozen)
-	{
-	}
-	else
-	{
-	}
-}
-
-// do some extra stuff once we get our economy data
-void process_economy_data(LLMessageSystem *msg, void** /*user_data*/)
-{
-	LLGlobalEconomy::processEconomyData(msg, LLGlobalEconomy::Singleton::getInstance());
-
-	S32 upload_cost = LLGlobalEconomy::Singleton::getInstance()->getPriceUpload();
-
-	LL_INFOS_ONCE("Messaging") << "EconomyData message arrived; upload cost is L$" << upload_cost << LL_ENDL;
-
-	gMenuHolder->childSetLabelArg("Upload Image", "[COST]", llformat("%d", upload_cost));
-	gMenuHolder->childSetLabelArg("Upload Sound", "[COST]", llformat("%d", upload_cost));
-	gMenuHolder->childSetLabelArg("Upload Animation", "[COST]", llformat("%d", upload_cost));
-	gMenuHolder->childSetLabelArg("Bulk Upload", "[COST]", llformat("%d", upload_cost));
-}
-
-void notify_cautioned_script_question(const LLSD& notification, const LLSD& response, S32 orig_questions, BOOL granted)
-{
-	// only continue if at least some permissions were requested
-	if (orig_questions)
-	{
-		// check to see if the person we are asking
-
-		// "'[OBJECTNAME]', an object owned by '[OWNERNAME]', 
-		// located in [REGIONNAME] at [REGIONPOS], 
-		// has been <granted|denied> permission to: [PERMISSIONS]."
-
-		LLUIString notice(LLTrans::getString(granted ? "ScriptQuestionCautionChatGranted" : "ScriptQuestionCautionChatDenied"));
-
-		// always include the object name and owner name 
-		notice.setArg("[OBJECTNAME]", notification["payload"]["object_name"].asString());
-		notice.setArg("[OWNERNAME]", notification["payload"]["owner_name"].asString());
-
-		// try to lookup viewerobject that corresponds to the object that
-		// requested permissions (here, taskid->requesting object id)
-		BOOL foundpos = FALSE;
-		LLViewerObject* viewobj = gObjectList.findObject(notification["payload"]["task_id"].asUUID());
-		if (viewobj)
-		{
-			// found the viewerobject, get it's position in its region
-			LLVector3 objpos(viewobj->getPosition());
-			
-			// try to lookup the name of the region the object is in
-			LLViewerRegion* viewregion = viewobj->getRegion();
-			if (viewregion)
-			{
-				// got the region, so include the region and 3d coordinates of the object
-				notice.setArg("[REGIONNAME]", viewregion->getName());				
-				std::string formatpos = llformat("%.1f, %.1f,%.1f", objpos[VX], objpos[VY], objpos[VZ]);
-				notice.setArg("[REGIONPOS]", formatpos);
-
-				foundpos = TRUE;
-			}
-		}
-
-		if (!foundpos)
-		{
-			// unable to determine location of the object
-			notice.setArg("[REGIONNAME]", "(unknown region)");
-			notice.setArg("[REGIONPOS]", "(unknown position)");
-		}
-
-		// check each permission that was requested, and list each 
-		// permission that has been flagged as a caution permission
-		BOOL caution = FALSE;
-		S32 count = 0;
-		std::string perms;
-		for (S32 i = 0; i < SCRIPT_PERMISSION_EOF; i++)
-		{
-			if ((orig_questions & LSCRIPTRunTimePermissionBits[i]) && SCRIPT_QUESTION_IS_CAUTION[i])
-			{
-				count++;
-				caution = TRUE;
-
-				// add a comma before the permission description if it is not the first permission
-				// added to the list or the last permission to check
-				if ((count > 1) && (i < SCRIPT_PERMISSION_EOF))
-				{
-					perms.append(", ");
-				}
-
-				perms.append(LLTrans::getString(SCRIPT_QUESTIONS[i]));
-			}
-		}
-
-		notice.setArg("[PERMISSIONS]", perms);
-
-		// log a chat message as long as at least one requested permission
-		// is a caution permission
-		if (caution)
-		{
-			LLChat chat(notice.getString());
-			LLFloaterChat::addChat(chat, FALSE, FALSE);
-		}
-	}
-}
-
-bool script_question_cb(const LLSD& notification, const LLSD& response)
-{
-	S32 option = LLNotification::getSelectedOption(notification, response);
-	LLMessageSystem *msg = gMessageSystem;
-	S32 orig = notification["payload"]["questions"].asInteger();
-	S32 new_questions = orig;
-
-	// check whether permissions were granted or denied
-	BOOL allowed = TRUE;
-	// the "yes/accept" button is the first button in the template, making it button 0
-	// if any other button was clicked, the permissions were denied
-	if (option != 0)
-	{
-		new_questions = 0;
-		allowed = FALSE;
-	}	
-
-	LLUUID task_id = notification["payload"]["task_id"].asUUID();
-	LLUUID item_id = notification["payload"]["item_id"].asUUID();
-
-	// reply with the permissions granted or denied
-	msg->newMessageFast(_PREHASH_ScriptAnswerYes);
-	msg->nextBlockFast(_PREHASH_AgentData);
-	msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-	msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-	msg->nextBlockFast(_PREHASH_Data);
-	msg->addUUIDFast(_PREHASH_TaskID, task_id);
-	msg->addUUIDFast(_PREHASH_ItemID, item_id);
-	msg->addS32Fast(_PREHASH_Questions, new_questions);
-	msg->sendReliable(LLHost(notification["payload"]["sender"].asString()));
-
-	// only log a chat message if caution prompts are enabled
-	if (gSavedSettings.getBOOL("PermissionsCautionEnabled"))
-	{
-		// log a chat message, if appropriate
-		notify_cautioned_script_question(notification, response, orig, allowed);
-	}
-
-	if ( response["Mute"] ) // mute
-	{
-		LLMuteList::getInstance()->add(LLMute(item_id, notification["payload"]["object_name"].asString(), LLMute::OBJECT));
-
-		// purge the message queue of any previously queued requests from the same source. DEV-4879
-		class OfferMatcher : public LLNotifyBoxView::Matcher
-		{
-		public:
-			OfferMatcher(const LLUUID& to_block) : blocked_id(to_block) {}
-			BOOL matches(const LLNotificationPtr notification) const
-			{
-				if (notification->getName() == "ScriptQuestionCaution"
-					|| notification->getName() == "ScriptQuestion")
-				{
-					return (notification->getPayload()["item_id"].asUUID() == blocked_id);
-				}
-				return FALSE;
-			}
-		private:
-			const LLUUID& blocked_id;
-		};
-		// should do this via the channel
-		gNotifyBoxView->purgeMessagesMatching(OfferMatcher(item_id));
-	}
-
-	if (response["Details"])
-	{
-		// respawn notification...
-		LLNotifications::instance().add(notification["name"], notification["substitutions"], notification["payload"]);
-
-		// ...with description on top
-		LLNotifications::instance().add("DebitPermissionDetails");
-	}
-	return false;
-}
-static LLNotificationFunctorRegistration script_question_cb_reg_1("ScriptQuestion", script_question_cb);
-static LLNotificationFunctorRegistration script_question_cb_reg_2("ScriptQuestionCaution", script_question_cb);
-
-void process_script_question(LLMessageSystem *msg, void **user_data)
-{
-	// *TODO: Translate owner name -> [FIRST] [LAST]
-
-	LLHost sender = msg->getSender();
-
-	LLUUID taskid;
-	LLUUID itemid;
-	S32		questions;
-	std::string object_name;
-	std::string owner_name;
-
-	// taskid -> object key of object requesting permissions
-	msg->getUUIDFast(_PREHASH_Data, _PREHASH_TaskID, taskid );
-	// itemid -> script asset key of script requesting permissions
-	msg->getUUIDFast(_PREHASH_Data, _PREHASH_ItemID, itemid );
-	msg->getStringFast(_PREHASH_Data, _PREHASH_ObjectName, object_name);
-	msg->getStringFast(_PREHASH_Data, _PREHASH_ObjectOwner, owner_name);
-	msg->getS32Fast(_PREHASH_Data, _PREHASH_Questions, questions );
-
-	// Special case. If the objects are owned by this agent, throttle per-object instead
-	// of per-owner. It's common for residents to reset a ton of scripts that re-request
-	// permissions, as with tier boxes. UUIDs can't be valid agent names and vice-versa,
-	// so we'll reuse the same namespace for both throttle types.
-	std::string throttle_name = owner_name;
-	std::string self_name;
-	LLAgentUI::buildName( self_name );
-	if( owner_name == self_name )
-	{
-		throttle_name = taskid.getString();
-	}
-	
-	// don't display permission requests if this object is muted
-	if (LLMuteList::getInstance()->isMuted(taskid)) return;
-	
-	// throttle excessive requests from any specific user's scripts
-	typedef LLKeyThrottle<std::string> LLStringThrottle;
-	static LLStringThrottle question_throttle( LLREQUEST_PERMISSION_THROTTLE_LIMIT, LLREQUEST_PERMISSION_THROTTLE_INTERVAL );
-
-	switch (question_throttle.noteAction(throttle_name))
-	{
-		case LLStringThrottle::THROTTLE_NEWLY_BLOCKED:
-			LL_INFOS("Messaging") << "process_script_question throttled"
-					<< " owner_name:" << owner_name
-					<< LL_ENDL;
-			// Fall through
-
-		case LLStringThrottle::THROTTLE_BLOCKED:
-			// Escape altogether until we recover
-			return;
-
-		case LLStringThrottle::THROTTLE_OK:
-			break;
-	}
-
-	std::string script_question;
-	if (questions)
-	{
-		BOOL caution = FALSE;
-		S32 count = 0;
-		LLSD args;
-		args["OBJECTNAME"] = object_name;
-		args["NAME"] = owner_name;
-
-		// check the received permission flags against each permission
-		for (S32 i = 0; i < SCRIPT_PERMISSION_EOF; i++)
-		{
-			if (questions & LSCRIPTRunTimePermissionBits[i])
-			{
-				count++;
-				script_question += "    " + LLTrans::getString(SCRIPT_QUESTIONS[i]) + "\n";
-
-				// check whether permission question should cause special caution dialog
-				caution |= (SCRIPT_QUESTION_IS_CAUTION[i]);
-			}
-		}
-		args["QUESTIONS"] = script_question;
-
-		LLSD payload;
-		payload["task_id"] = taskid;
-		payload["item_id"] = itemid;
-		payload["sender"] = sender.getIPandPort();
-		payload["questions"] = questions;
-		payload["object_name"] = object_name;
-		payload["owner_name"] = owner_name;
-
-		// check whether cautions are even enabled or not
-		if (gSavedSettings.getBOOL("PermissionsCautionEnabled"))
-		{
-			// display the caution permissions prompt
-			LLNotifications::instance().add(caution ? "ScriptQuestionCaution" : "ScriptQuestion", args, payload);
-		}
-		else
-		{
-			// fall back to default behavior if cautions are entirely disabled
-			LLNotifications::instance().add("ScriptQuestion", args, payload);
-		}
-
-	}
-}
-
-
-void process_derez_container(LLMessageSystem *msg, void**)
-{
-	LL_WARNS("Messaging") << "call to deprecated process_derez_container" << LL_ENDL;
-}
-
-void container_inventory_arrived(LLViewerObject* object,
-								 InventoryObjectList* inventory,
-								 S32 serial_num,
-								 void* data)
-{
-	LL_DEBUGS("Messaging") << "container_inventory_arrived()" << LL_ENDL;
-	if( gAgent.cameraMouselook() )
-	{
-		gAgent.changeCameraToDefault();
-	}
-
-	LLFloaterInventory* view = LLFloaterInventory::getActiveInventory();
-
-	if (inventory->size() > 2)
-	{
-		// create a new inventory category to put this in
-		LLUUID cat_id;
-		cat_id = gInventory.createNewCategory(gInventory.getRootFolderID(),
-											  LLAssetType::AT_NONE,
-											  LLTrans::getString("AcquiredItems"));
-
-		InventoryObjectList::const_iterator it = inventory->begin();
-		InventoryObjectList::const_iterator end = inventory->end();
-		for ( ; it != end; ++it)
-		{
-			if ((*it)->getType() != LLAssetType::AT_CATEGORY &&
-				(*it)->getType() != LLAssetType::AT_ROOT_CATEGORY)
-			{
-				LLInventoryObject* obj = (LLInventoryObject*)(*it);
-				LLInventoryItem* item = (LLInventoryItem*)(obj);
-				LLUUID item_id;
-				item_id.generate();
-				time_t creation_date_utc = time_corrected();
-				LLPointer<LLViewerInventoryItem> new_item
-					= new LLViewerInventoryItem(item_id,
-												cat_id,
-												item->getPermissions(),
-												item->getAssetUUID(),
-												item->getType(),
-												item->getInventoryType(),
-												item->getName(),
-												item->getDescription(),
-												LLSaleInfo::DEFAULT,
-												item->getFlags(),
-												creation_date_utc);
-				new_item->updateServer(TRUE);
-				gInventory.updateItem(new_item);
-			}
-		}
-		gInventory.notifyObservers();
-		if(view)
-		{
-			view->getPanel()->setSelection(cat_id, TAKE_FOCUS_NO);
-		}
-	}
-	else if (inventory->size() == 2)
-	{
-		// we're going to get one fake root category as well as the
-		// one actual object
-		InventoryObjectList::iterator it = inventory->begin();
-
-		if ((*it)->getType() == LLAssetType::AT_CATEGORY ||
-			(*it)->getType() == LLAssetType::AT_ROOT_CATEGORY)
-		{
-			++it;
-		}
-
-		LLInventoryItem* item = (LLInventoryItem*)((LLInventoryObject*)(*it));
-		LLUUID category = gInventory.findCategoryUUIDForType(item->getType());
-
-		LLUUID item_id;
-		item_id.generate();
-		time_t creation_date_utc = time_corrected();
-		LLPointer<LLViewerInventoryItem> new_item
-			= new LLViewerInventoryItem(item_id, category,
-										item->getPermissions(),
-										item->getAssetUUID(),
-										item->getType(),
-										item->getInventoryType(),
-										item->getName(),
-										item->getDescription(),
-										LLSaleInfo::DEFAULT,
-										item->getFlags(),
-										creation_date_utc);
-		new_item->updateServer(TRUE);
-		gInventory.updateItem(new_item);
-		gInventory.notifyObservers();
-		if(view)
-		{
-			view->getPanel()->setSelection(item_id, TAKE_FOCUS_NO);
-		}
-	}
-
-	// we've got the inventory, now delete this object if this was a take
-	BOOL delete_object = (BOOL)(intptr_t)data;
-	LLViewerRegion *region = gAgent.getRegion();
-	if (delete_object && region)
-	{
-		gMessageSystem->newMessageFast(_PREHASH_ObjectDelete);
-		gMessageSystem->nextBlockFast(_PREHASH_AgentData);
-		gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-		gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-		const U8 NO_FORCE = 0;
-		gMessageSystem->addU8Fast(_PREHASH_Force, NO_FORCE);
-		gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
-		gMessageSystem->addU32Fast(_PREHASH_ObjectLocalID, object->getLocalID());
-		gMessageSystem->sendReliable(region->getHost());
-	}
-}
-
-// method to format the time.
-std::string formatted_time(const time_t& the_time)
-{
-	std::string dateStr = "["+LLTrans::getString("LTimeWeek")+"] ["
-						+LLTrans::getString("LTimeMonth")+"] ["
-						+LLTrans::getString("LTimeDay")+"] ["
-						+LLTrans::getString("LTimeHour")+"]:["
-						+LLTrans::getString("LTimeMin")+"]:["
-						+LLTrans::getString("LTimeSec")+"] ["
-						+LLTrans::getString("LTimeYear")+"]";
-
-	LLSD substitution;
-	substitution["datetime"] = (S32) the_time;
-	LLStringUtil::format (dateStr, substitution);
-	return dateStr;
-}
-
-
-void process_teleport_failed(LLMessageSystem *msg, void**)
-{
-	std::string reason;
-	std::string big_reason;
-	LLSD args;
-
-	// if we have additional alert data
-	if (msg->has(_PREHASH_AlertInfo) && msg->getSizeFast(_PREHASH_AlertInfo, _PREHASH_Message) > 0)
-	{
-		// Get the message ID
-		msg->getStringFast(_PREHASH_AlertInfo, _PREHASH_Message, reason);
-		big_reason = LLAgent::sTeleportErrorMessages[reason];
-		if ( big_reason.size() > 0 )
-		{	// Substitute verbose reason from the local map
-			args["REASON"] = big_reason;
-		}
-		else
-		{	// Nothing found in the map - use what the server returned in the original message block
-			msg->getStringFast(_PREHASH_Info, _PREHASH_Reason, reason);
-			args["REASON"] = reason;
-		}
-
-		LLSD llsd_block;
-		std::string llsd_raw;
-		msg->getStringFast(_PREHASH_AlertInfo, _PREHASH_ExtraParams, llsd_raw);
-		if (llsd_raw.length())
-		{
-			std::istringstream llsd_data(llsd_raw);
-			if (!LLSDSerialize::deserialize(llsd_block, llsd_data, llsd_raw.length()))
-			{
-				llwarns << "process_teleport_failed: Attempted to read alert parameter data into LLSD but failed:" << llsd_raw << llendl;
-			}
-			else
-			{
-				// change notification name in this special case
-				if (handle_special_notification("RegionEntryAccessBlocked", llsd_block))
-				{
-					if( gAgent.getTeleportState() != LLAgent::TELEPORT_NONE )
-					{
-						gAgent.setTeleportState( LLAgent::TELEPORT_NONE );
-					}
-					return;
-				}
-			}
-		}
-
-	}
-	else
-	{
-		msg->getStringFast(_PREHASH_Info, _PREHASH_Reason, reason);
-
-		big_reason = LLAgent::sTeleportErrorMessages[reason];
-		if ( big_reason.size() > 0 )
-		{	// Substitute verbose reason from the local map
-			args["REASON"] = big_reason;
-		}
-		else
-		{	// Nothing found in the map - use what the server returned
-			args["REASON"] = reason;
-		}
-	}
-
-	LLNotifications::instance().add("CouldNotTeleportReason", args);
-
-	// Let the interested parties know that teleport failed.
-	LLViewerParcelMgr::getInstance()->onTeleportFailed();
-
-	if( gAgent.getTeleportState() != LLAgent::TELEPORT_NONE )
-	{
-		gAgent.setTeleportState( LLAgent::TELEPORT_NONE );
-	}
-}
-
-void process_teleport_local(LLMessageSystem *msg,void**)
-{
-	LLUUID agent_id;
-	msg->getUUIDFast(_PREHASH_Info, _PREHASH_AgentID, agent_id);
-	if (agent_id != gAgent.getID())
-	{
-		LL_WARNS("Messaging") << "Got teleport notification for wrong agent!" << LL_ENDL;
-		return;
-	}
-
-	U32 location_id;
-	LLVector3 pos, look_at;
-	U32 teleport_flags;
-	msg->getU32Fast(_PREHASH_Info, _PREHASH_LocationID, location_id);
-	msg->getVector3Fast(_PREHASH_Info, _PREHASH_Position, pos);
-	msg->getVector3Fast(_PREHASH_Info, _PREHASH_LookAt, look_at);
-	msg->getU32Fast(_PREHASH_Info, _PREHASH_TeleportFlags, teleport_flags);
-
-	if( gAgent.getTeleportState() != LLAgent::TELEPORT_NONE )
-	{
-		gAgent.setTeleportState( LLAgent::TELEPORT_NONE );
-	}
-
-	// Sim tells us whether the new position is off the ground
-	if (teleport_flags & TELEPORT_FLAGS_IS_FLYING)
-	{
-		gAgent.setFlying(TRUE);
-	}
-	else
-	{
-		gAgent.setFlying(FALSE);
-	}
-
-	gAgent.setPositionAgent(pos);
-	gAgent.slamLookAt(look_at);
-
-	// likewise make sure the camera is behind the avatar
-	gAgent.resetView(TRUE, TRUE);
-
-	// send camera update to new region
-	gAgent.updateCamera();
-
-	send_agent_update(TRUE, TRUE);
-
-	// Let the interested parties know we've teleported.
-	// Vadim *HACK: Agent position seems to get reset (to render position?)
-	//              on each frame, so we have to pass the new position manually.
-	LLViewerParcelMgr::getInstance()->onTeleportFinished(true, gAgent.getPosGlobalFromAgent(pos));
-}
-
-void send_simple_im(const LLUUID& to_id,
-					const std::string& message,
-					EInstantMessage dialog,
-					const LLUUID& id)
-{
-	std::string my_name;
-	LLAgentUI::buildFullname(my_name);
-	send_improved_im(to_id,
-					 my_name,
-					 message,
-					 IM_ONLINE,
-					 dialog,
-					 id,
-					 NO_TIMESTAMP,
-					 (U8*)EMPTY_BINARY_BUCKET,
-					 EMPTY_BINARY_BUCKET_SIZE);
-}
-
-void send_group_notice(const LLUUID& group_id,
-					   const std::string& subject,
-					   const std::string& message,
-					   const LLInventoryItem* item)
-{
-	// Put this notice into an instant message form.
-	// This will mean converting the item to a binary bucket,
-	// and the subject/message into a single field.
-	std::string my_name;
-	LLAgentUI::buildFullname(my_name);
-
-	// Combine subject + message into a single string.
-	std::ostringstream subject_and_message;
-	// TODO: turn all existing |'s into ||'s in subject and message.
-	subject_and_message << subject << "|" << message;
-
-	// Create an empty binary bucket.
-	U8 bin_bucket[MAX_INVENTORY_BUFFER_SIZE];
-	U8* bucket_to_send = bin_bucket;
-	bin_bucket[0] = '\0';
-	S32 bin_bucket_size = EMPTY_BINARY_BUCKET_SIZE;
-	// If there is an item being sent, pack it into the binary bucket.
-	if (item)
-	{
-		LLSD item_def;
-		item_def["item_id"] = item->getUUID();
-		item_def["owner_id"] = item->getPermissions().getOwner();
-		std::ostringstream ostr;
-		LLSDSerialize::serialize(item_def, ostr, LLSDSerialize::LLSD_XML);
-		bin_bucket_size = ostr.str().copy(
-			(char*)bin_bucket, ostr.str().size());
-		bin_bucket[bin_bucket_size] = '\0';
-	}
-	else
-	{
-		bucket_to_send = (U8*) EMPTY_BINARY_BUCKET;
-	}
-   
-
-	send_improved_im(
-			group_id,
-			my_name,
-			subject_and_message.str(),
-			IM_ONLINE,
-			IM_GROUP_NOTICE,
-			LLUUID::null,
-			NO_TIMESTAMP,
-			bucket_to_send,
-			bin_bucket_size);
-}
-
-bool handle_lure_callback(const LLSD& notification, const LLSD& response)
-{
-	std::string text = response["message"].asString();
-	S32 option = LLNotification::getSelectedOption(notification, response);
-
-	if(0 == option)
-	{
-		LLMessageSystem* msg = gMessageSystem;
-		msg->newMessageFast(_PREHASH_StartLure);
-		msg->nextBlockFast(_PREHASH_AgentData);
-		msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-		msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-		msg->nextBlockFast(_PREHASH_Info);
-		msg->addU8Fast(_PREHASH_LureType, (U8)0); // sim will fill this in.
-		msg->addStringFast(_PREHASH_Message, text);
-		for(LLSD::array_const_iterator it = notification["payload"]["ids"].beginArray();
-			it != notification["payload"]["ids"].endArray();
-			++it)
-		{
-			msg->nextBlockFast(_PREHASH_TargetData);
-			msg->addUUIDFast(_PREHASH_TargetID, it->asUUID());
-		}
-		gAgent.sendReliableMessage();
-	}
-
-	return false;
-}
-
-void handle_lure(const LLUUID& invitee)
-{
-	LLDynamicArray<LLUUID> ids;
-	ids.push_back(invitee);
-	handle_lure(ids);
-}
-
-// Prompt for a message to the invited user.
-void handle_lure(const std::vector<LLUUID>& ids)
-{
-	LLSD edit_args;
-	edit_args["REGION"] = gAgent.getRegion()->getName();
-
-	LLSD payload;
-	for (LLDynamicArray<LLUUID>::const_iterator it = ids.begin();
-		it != ids.end();
-		++it)
-	{
-		payload["ids"].append(*it);
-	}
-	if (gAgent.isGodlike())
-	{
-		LLNotifications::instance().add("OfferTeleportFromGod", edit_args, payload, handle_lure_callback);
-	}
-	else
-	{
-		LLNotifications::instance().add("OfferTeleport", edit_args, payload, handle_lure_callback);
-	}
-}
-
-
-void send_improved_im(const LLUUID& to_id,
-							const std::string& name,
-							const std::string& message,
-							U8 offline,
-							EInstantMessage dialog,
-							const LLUUID& id,
-							U32 timestamp, 
-							const U8* binary_bucket,
-							S32 binary_bucket_size)
-{
-	pack_instant_message(
-		gMessageSystem,
-		gAgent.getID(),
-		FALSE,
-		gAgent.getSessionID(),
-		to_id,
-		name,
-		message,
-		offline,
-		dialog,
-		id,
-		0,
-		LLUUID::null,
-		gAgent.getPositionAgent(),
-		timestamp,
-		binary_bucket,
-		binary_bucket_size);
-	gAgent.sendReliableMessage();
-}
-
-
-void send_places_query(const LLUUID& query_id,
-					   const LLUUID& trans_id,
-					   const std::string& query_text,
-					   U32 query_flags,
-					   S32 category,
-					   const std::string& sim_name)
-{
-	LLMessageSystem* msg = gMessageSystem;
-
-	msg->newMessage("PlacesQuery");
-	msg->nextBlock("AgentData");
-	msg->addUUID("AgentID", gAgent.getID());
-	msg->addUUID("SessionID", gAgent.getSessionID());
-	msg->addUUID("QueryID", query_id);
-	msg->nextBlock("TransactionData");
-	msg->addUUID("TransactionID", trans_id);
-	msg->nextBlock("QueryData");
-	msg->addString("QueryText", query_text);
-	msg->addU32("QueryFlags", query_flags);
-	msg->addS8("Category", (S8)category);
-	msg->addString("SimName", sim_name);
-	gAgent.sendReliableMessage();
-}
-
-
-void process_user_info_reply(LLMessageSystem* msg, void**)
-{
-	LLUUID agent_id;
-	msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, agent_id);
-	if(agent_id != gAgent.getID())
-	{
-		LL_WARNS("Messaging") << "process_user_info_reply - "
-				<< "wrong agent id." << LL_ENDL;
-	}
-	
-	BOOL im_via_email;
-	msg->getBOOLFast(_PREHASH_UserData, _PREHASH_IMViaEMail, im_via_email);
-	std::string email;
-	msg->getStringFast(_PREHASH_UserData, _PREHASH_EMail, email);
-	std::string dir_visibility;
-	msg->getString( "UserData", "DirectoryVisibility", dir_visibility);
-
-	LLFloaterPreference::updateUserInfo(dir_visibility, im_via_email, email);
-	LLFloaterPostcard::updateUserInfo(email);
-}
-
-
-//---------------------------------------------------------------------------
-// Script Dialog
-//---------------------------------------------------------------------------
-
-const S32 SCRIPT_DIALOG_MAX_BUTTONS = 12;
-const S32 SCRIPT_DIALOG_BUTTON_STR_SIZE = 24;
-const S32 SCRIPT_DIALOG_MAX_MESSAGE_SIZE = 512;
-const char* SCRIPT_DIALOG_HEADER = "Script Dialog:\n";
-
-bool callback_script_dialog(const LLSD& notification, const LLSD& response)
-{
-	LLNotificationForm form(notification["form"]);
-	std::string button = LLNotification::getSelectedOptionName(response);
-	S32 button_idx = LLNotification::getSelectedOption(notification, response);
-	// Didn't click "Ignore"
-	if (button_idx != -1)
-	{
-		LLMessageSystem* msg = gMessageSystem;
-		msg->newMessage("ScriptDialogReply");
-		msg->nextBlock("AgentData");
-		msg->addUUID("AgentID", gAgent.getID());
-		msg->addUUID("SessionID", gAgent.getSessionID());
-		msg->nextBlock("Data");
-		msg->addUUID("ObjectID", notification["payload"]["object_id"].asUUID());
-		msg->addS32("ChatChannel", notification["payload"]["chat_channel"].asInteger());
-		msg->addS32("ButtonIndex", button_idx);
-		msg->addString("ButtonLabel", button);
-		msg->sendReliable(LLHost(notification["payload"]["sender"].asString()));
-	}
-
-	return false;
-}
-static LLNotificationFunctorRegistration callback_script_dialog_reg_1("ScriptDialog", callback_script_dialog);
-static LLNotificationFunctorRegistration callback_script_dialog_reg_2("ScriptDialogGroup", callback_script_dialog);
-
-void process_script_dialog(LLMessageSystem* msg, void**)
-{
-	S32 i;
-	LLSD payload;
-
-	LLUUID object_id;
-	msg->getUUID("Data", "ObjectID", object_id);
-
-	if (LLMuteList::getInstance()->isMuted(object_id))
-	{
-		return;
-	}
-
-	std::string message; 
-	std::string first_name;
-	std::string last_name;
-	std::string title;
-
-	S32 chat_channel;
-	msg->getString("Data", "FirstName", first_name);
-	msg->getString("Data", "LastName", last_name);
-	msg->getString("Data", "ObjectName", title);
-	msg->getString("Data", "Message", message);
-	msg->getS32("Data", "ChatChannel", chat_channel);
-
-		// unused for now
-	LLUUID image_id;
-	msg->getUUID("Data", "ImageID", image_id);
-
-	payload["sender"] = msg->getSender().getIPandPort();
-	payload["object_id"] = object_id;
-	payload["chat_channel"] = chat_channel;
-
-	// build up custom form
-	S32 button_count = msg->getNumberOfBlocks("Buttons");
-	if (button_count > SCRIPT_DIALOG_MAX_BUTTONS)
-	{
-		llwarns << "Too many script dialog buttons - omitting some" << llendl;
-		button_count = SCRIPT_DIALOG_MAX_BUTTONS;
-	}
-
-	LLNotificationForm form;
-	for (i = 0; i < button_count; i++)
-	{
-		std::string tdesc;
-		msg->getString("Buttons", "ButtonLabel", tdesc, i);
-		form.addElement("button", std::string(tdesc));
-	}
-
-	LLSD args;
-	args["TITLE"] = title;
-	args["MESSAGE"] = message;
-	LLNotificationPtr notification;
-	if (!first_name.empty())
-	{
-		args["FIRST"] = first_name;
-		args["LAST"] = last_name;
-		notification = LLNotifications::instance().add(
-			LLNotification::Params("ScriptDialog").substitutions(args).payload(payload).form_elements(form.asLLSD()));
-	}
-	else
-	{
-		args["GROUPNAME"] = last_name;
-		notification = LLNotifications::instance().add(
-			LLNotification::Params("ScriptDialogGroup").substitutions(args).payload(payload).form_elements(form.asLLSD()));
-	}
-}
-
-//---------------------------------------------------------------------------
-
-
-std::vector<LLSD> gLoadUrlList;
-
-bool callback_load_url(const LLSD& notification, const LLSD& response)
-{
-	S32 option = LLNotification::getSelectedOption(notification, response);
-
-	if (0 == option)
-	{
-		LLWeb::loadURL(notification["payload"]["url"].asString());
-	}
-
-	return false;
-}
-static LLNotificationFunctorRegistration callback_load_url_reg("LoadWebPage", callback_load_url);
-
-
-// We've got the name of the person who owns the object hurling the url.
-// Display confirmation dialog.
-void callback_load_url_name(const LLUUID& id, const std::string& first, const std::string& last, BOOL is_group)
-{
-	std::vector<LLSD>::iterator it;
-	for (it = gLoadUrlList.begin(); it != gLoadUrlList.end(); )
-	{
-		LLSD load_url_info = *it;
-		if (load_url_info["owner_id"].asUUID() == id)
-		{
-			it = gLoadUrlList.erase(it);
-
-			std::string owner_name;
-			if (is_group)
-			{
-				owner_name = first + LLTrans::getString("Group");
-			}
-			else
-			{
-				owner_name = first + " " + last;
-			}
-
-			// For legacy name-only mutes.
-			if (LLMuteList::getInstance()->isMuted(LLUUID::null, owner_name))
-			{
-				continue;
-			}
-			LLSD args;
-			args["URL"] = load_url_info["url"].asString();
-			args["MESSAGE"] = load_url_info["message"].asString();;
-			args["OBJECTNAME"] = load_url_info["object_name"].asString();
-			args["NAME"] = owner_name;
-
-			LLNotifications::instance().add("LoadWebPage", args, load_url_info);
-		}
-		else
-		{
-			++it;
-		}
-	}
-}
-
-void process_load_url(LLMessageSystem* msg, void**)
-{
-	LLUUID object_id;
-	LLUUID owner_id;
-	BOOL owner_is_group;
-	char object_name[256];		/* Flawfinder: ignore */
-	char message[256];		/* Flawfinder: ignore */
-	char url[256];		/* Flawfinder: ignore */
-
-	msg->getString("Data", "ObjectName", 256, object_name);
-	msg->getUUID(  "Data", "ObjectID", object_id);
-	msg->getUUID(  "Data", "OwnerID", owner_id);
-	msg->getBOOL(  "Data", "OwnerIsGroup", owner_is_group);
-	msg->getString("Data", "Message", 256, message);
-	msg->getString("Data", "URL", 256, url);
-
-	LLSD payload;
-	payload["object_id"] = object_id;
-	payload["owner_id"] = owner_id;
-	payload["owner_is_group"] = owner_is_group;
-	payload["object_name"] = object_name;
-	payload["message"] = message;
-	payload["url"] = url;
-
-	// URL is safety checked in load_url above
-
-	// Check if object or owner is muted
-	if (LLMuteList::getInstance()->isMuted(object_id, object_name) ||
-	    LLMuteList::getInstance()->isMuted(owner_id))
-	{
-		LL_INFOS("Messaging")<<"Ignoring load_url from muted object/owner."<<LL_ENDL;
-		return;
-	}
-
-	// Add to list of pending name lookups
-	gLoadUrlList.push_back(payload);
-
-	gCacheName->get(owner_id, owner_is_group, &callback_load_url_name);
-}
-
-
-void callback_download_complete(void** data, S32 result, LLExtStat ext_status)
-{
-	std::string* filepath = (std::string*)data;
-	LLSD args;
-	args["DOWNLOAD_PATH"] = *filepath;
-	LLNotifications::instance().add("FinishedRawDownload", args);
-	delete filepath;
-}
-
-
-void process_initiate_download(LLMessageSystem* msg, void**)
-{
-	LLUUID agent_id;
-	msg->getUUID("AgentData", "AgentID", agent_id);
-	if (agent_id != gAgent.getID())
-	{
-		LL_WARNS("Messaging") << "Initiate download for wrong agent" << LL_ENDL;
-		return;
-	}
-
-	std::string sim_filename;
-	std::string viewer_filename;
-	msg->getString("FileData", "SimFilename", sim_filename);
-	msg->getString("FileData", "ViewerFilename", viewer_filename);
-
-	if (!gXferManager->validateFileForRequest(viewer_filename))
-	{
-		llwarns << "SECURITY: Unauthorized download to local file " << viewer_filename << llendl;
-		return;
-	}
-	gXferManager->requestFile(viewer_filename,
-		sim_filename,
-		LL_PATH_NONE,
-		msg->getSender(),
-		FALSE,	// don't delete remote
-		callback_download_complete,
-		(void**)new std::string(viewer_filename));
-}
-
-
-void process_script_teleport_request(LLMessageSystem* msg, void**)
-{
-	std::string object_name;
-	std::string sim_name;
-	LLVector3 pos;
-	LLVector3 look_at;
-
-	msg->getString("Data", "ObjectName", object_name);
-	msg->getString("Data", "SimName", sim_name);
-	msg->getVector3("Data", "SimPosition", pos);
-	msg->getVector3("Data", "LookAt", look_at);
-
-	LLFloaterWorldMap* instance = LLFloaterWorldMap::getInstance();
-	if(instance)
-	{
-		instance->trackURL(
-						   sim_name, (S32)pos.mV[VX], (S32)pos.mV[VY], (S32)pos.mV[VZ]);
-		LLFloaterReg::showInstance("world_map", "center");
-	}
-	
-	// remove above two lines and replace with below line
-	// to re-enable parcel browser for llMapDestination()
-	// LLURLDispatcher::dispatch(LLSLURL::buildSLURL(sim_name, (S32)pos.mV[VX], (S32)pos.mV[VY], (S32)pos.mV[VZ]), FALSE);
-	
-}
-
-void process_covenant_reply(LLMessageSystem* msg, void**)
-{
-	LLUUID covenant_id, estate_owner_id;
-	std::string estate_name;
-	U32 covenant_timestamp;
-	msg->getUUID("Data", "CovenantID", covenant_id);
-	msg->getU32("Data", "CovenantTimestamp", covenant_timestamp);
-	msg->getString("Data", "EstateName", estate_name);
-	msg->getUUID("Data", "EstateOwnerID", estate_owner_id);
-
-	LLPanelEstateCovenant::updateEstateName(estate_name);
-	LLPanelLandCovenant::updateEstateName(estate_name);
-	LLFloaterBuyLand::updateEstateName(estate_name);
-
-	std::string owner_name =
-		LLSLURL::buildCommand("agent", estate_owner_id, "inspect");
-	LLPanelEstateCovenant::updateEstateOwnerName(owner_name);
-	LLPanelLandCovenant::updateEstateOwnerName(owner_name);
-	LLFloaterBuyLand::updateEstateOwnerName(owner_name);
-
-	LLPanelPlaceInfo* panel = LLSideTray::getInstance()->findChild<LLPanelPlaceInfo>("panel_place_info");
-	if (panel)
-	{
-		panel->updateEstateName(estate_name);
-		panel->updateEstateOwnerName(owner_name);
-	}
-
-	// standard message, not from system
-	std::string last_modified;
-	if (covenant_timestamp == 0)
-	{
-		last_modified = LLTrans::getString("covenant_last_modified")+LLTrans::getString("never_text");
-	}
-	else
-	{
-		last_modified = LLTrans::getString("covenant_last_modified")+"["
-						+LLTrans::getString("LTimeWeek")+"] ["
-						+LLTrans::getString("LTimeMonth")+"] ["
-						+LLTrans::getString("LTimeDay")+"] ["
-						+LLTrans::getString("LTimeHour")+"]:["
-						+LLTrans::getString("LTimeMin")+"]:["
-						+LLTrans::getString("LTimeSec")+"] ["
-						+LLTrans::getString("LTimeYear")+"]";
-		LLSD substitution;
-		substitution["datetime"] = (S32) covenant_timestamp;
-		LLStringUtil::format (last_modified, substitution);
-	}
-
-	LLPanelEstateCovenant::updateLastModified(last_modified);
-	LLPanelLandCovenant::updateLastModified(last_modified);
-	LLFloaterBuyLand::updateLastModified(last_modified);
-
-	// load the actual covenant asset data
-	const BOOL high_priority = TRUE;
-	if (covenant_id.notNull())
-	{
-		gAssetStorage->getEstateAsset(gAgent.getRegionHost(),
-									gAgent.getID(),
-									gAgent.getSessionID(),
-									covenant_id,
-                                    LLAssetType::AT_NOTECARD,
-									ET_Covenant,
-                                    onCovenantLoadComplete,
-									NULL,
-									high_priority);
-	}
-	else
-	{
-		std::string covenant_text;
-		if (estate_owner_id.isNull())
-		{
-			// mainland
-			covenant_text = LLTrans::getString("RegionNoCovenant");
-		}
-		else
-		{
-			covenant_text = LLTrans::getString("RegionNoCovenantOtherOwner");
-		}
-		LLPanelEstateCovenant::updateCovenantText(covenant_text, covenant_id);
-		LLPanelLandCovenant::updateCovenantText(covenant_text);
-		LLFloaterBuyLand::updateCovenantText(covenant_text, covenant_id);
-		if (panel)
-		{
-			panel->updateCovenantText(covenant_text);
-		}
-	}
-}
-
-void onCovenantLoadComplete(LLVFS *vfs,
-					const LLUUID& asset_uuid,
-					LLAssetType::EType type,
-					void* user_data, S32 status, LLExtStat ext_status)
-{
-	LL_DEBUGS("Messaging") << "onCovenantLoadComplete()" << LL_ENDL;
-	std::string covenant_text;
-	if(0 == status)
-	{
-		LLVFile file(vfs, asset_uuid, type, LLVFile::READ);
-		
-		S32 file_length = file.getSize();
-		
-		std::vector<char> buffer(file_length+1);
-		file.read((U8*)&buffer[0], file_length);		
-		// put a EOS at the end
-		buffer[file_length] = '\0';
-		
-		if( (file_length > 19) && !strncmp( &buffer[0], "Linden text version", 19 ) )
-		{
-			LLViewerTextEditor::Params params;
-			params.name("temp");
-			params.max_text_length(file_length+1);
-			LLViewerTextEditor * editor = LLUICtrlFactory::create<LLViewerTextEditor> (params);
-			if( !editor->importBuffer( &buffer[0], file_length+1 ) )
-			{
-				LL_WARNS("Messaging") << "Problem importing estate covenant." << LL_ENDL;
-				covenant_text = "Problem importing estate covenant.";
-			}
-			else
-			{
-				// Version 0 (just text, doesn't include version number)
-				covenant_text = editor->getText();
-			}
-			delete editor;
-		}
-		else
-		{
-			LL_WARNS("Messaging") << "Problem importing estate covenant: Covenant file format error." << LL_ENDL;
-			covenant_text = "Problem importing estate covenant: Covenant file format error.";
-		}
-	}
-	else
-	{
-		LLViewerStats::getInstance()->incStat( LLViewerStats::ST_DOWNLOAD_FAILED );
-		
-		if( LL_ERR_ASSET_REQUEST_NOT_IN_DATABASE == status ||
-		    LL_ERR_FILE_EMPTY == status)
-		{
-			covenant_text = "Estate covenant notecard is missing from database.";
-		}
-		else if (LL_ERR_INSUFFICIENT_PERMISSIONS == status)
-		{
-			covenant_text = "Insufficient permissions to view estate covenant.";
-		}
-		else
-		{
-			covenant_text = "Unable to load estate covenant at this time.";
-		}
-		
-		LL_WARNS("Messaging") << "Problem loading notecard: " << status << LL_ENDL;
-	}
-	LLPanelEstateCovenant::updateCovenantText(covenant_text, asset_uuid);
-	LLPanelLandCovenant::updateCovenantText(covenant_text);
-	LLFloaterBuyLand::updateCovenantText(covenant_text, asset_uuid);
-
-	LLPanelPlaceInfo* panel = LLSideTray::getInstance()->findChild<LLPanelPlaceInfo>("panel_place_info");
-	if (panel)
-	{
-		panel->updateCovenantText(covenant_text);
-	}
-}
-
-
-void process_feature_disabled_message(LLMessageSystem* msg, void**)
-{
-	// Handle Blacklisted feature simulator response...
-	LLUUID	agentID;
-	LLUUID	transactionID;
-	std::string	messageText;
-	msg->getStringFast(_PREHASH_FailureInfo,_PREHASH_ErrorMessage, messageText,0);
-	msg->getUUIDFast(_PREHASH_FailureInfo,_PREHASH_AgentID,agentID);
-	msg->getUUIDFast(_PREHASH_FailureInfo,_PREHASH_TransactionID,transactionID);
-	
-	LL_WARNS("Messaging") << "Blacklisted Feature Response:" << messageText << LL_ENDL;
-}
-
-// ------------------------------------------------------------
-// Message system exception callbacks
-// ------------------------------------------------------------
-
-void invalid_message_callback(LLMessageSystem* msg,
-								   void*,
-								   EMessageException exception)
-{
-    LLAppViewer::instance()->badNetworkHandler();
-}
-
-// Please do not add more message handlers here. This file is huge.
-// Put them in a file related to the functionality you are implementing.
-
-void LLOfferInfo::forceResponse(InventoryOfferResponse response)
-{
-	LLNotification::Params params("UserGiveItem");
-	params.functor.function(boost::bind(&LLOfferInfo::inventory_offer_callback, this, _1, _2));
-	LLNotifications::instance().forceResponse(params, response);
-}
+/** 
+ * @file llviewermessage.cpp
+ * @brief Dumping ground for viewer-side message system callbacks.
+ *
+ * $LicenseInfo:firstyear=2002&license=viewergpl$
+ * 
+ * Copyright (c) 2002-2009, Linden Research, Inc.
+ * 
+ * Second Life Viewer Source Code
+ * The source code in this file ("Source Code") is provided by Linden Lab
+ * to you under the terms of the GNU General Public License, version 2.0
+ * ("GPL"), unless you have obtained a separate licensing agreement
+ * ("Other License"), formally executed by you and Linden Lab.  Terms of
+ * the GPL can be found in doc/GPL-license.txt in this distribution, or
+ * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
+ * 
+ * There are special exceptions to the terms and conditions of the GPL as
+ * it is applied to this Source Code. View the full text of the exception
+ * in the file doc/FLOSS-exception.txt in this software distribution, or
+ * online at
+ * http://secondlifegrid.net/programs/open_source/licensing/flossexception
+ * 
+ * By copying, modifying or distributing this software, you acknowledge
+ * that you have read and understood your obligations described above,
+ * and agree to abide by those obligations.
+ * 
+ * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
+ * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
+ * COMPLETENESS OR PERFORMANCE.
+ * $/LicenseInfo$
+ */
+
+#include "llviewerprecompiledheaders.h"
+
+#include "llviewermessage.h"
+
+#include <deque>
+
+#include "llaudioengine.h" 
+#include "indra_constants.h"
+#include "lscript_byteformat.h"
+#include "mean_collision_data.h"
+#include "llfloaterbump.h"
+#include "llassetstorage.h"
+#include "llcachename.h"
+#include "llchat.h"
+#include "lldbstrings.h"
+#include "lleconomy.h"
+#include "llfilepicker.h"
+#include "llfloaterreg.h"
+#include "llfocusmgr.h"
+#include "llfollowcamparams.h"
+#include "llinstantmessage.h"
+#include "llquantize.h"
+#include "llregionflags.h"
+#include "llregionhandle.h"
+#include "llsdserialize.h"
+#include "llstring.h"
+#include "llteleportflags.h"
+#include "lltracker.h"
+#include "lltransactionflags.h"
+#include "llxfermanager.h"
+#include "message.h"
+#include "sound_ids.h"
+#include "lltimer.h"
+#include "llmd5.h"
+
+#include "llagent.h"
+#include "llcallingcard.h"
+#include "llconsole.h"
+#include "llvieweraudio.h"
+#include "llviewercontrol.h"
+#include "lldrawpool.h"
+#include "llfirstuse.h"
+#include "llfloateranimpreview.h"
+#include "llfloaterbuycurrency.h"
+#include "llfloaterbuyland.h"
+#include "llfloaterchat.h"
+#include "llfloaterimagepreview.h"
+#include "llfloaterland.h"
+#include "llfloaterregioninfo.h"
+#include "llfloaterlandholdings.h"
+#include "llurldispatcher.h"
+#include "llfloaterpostcard.h"
+#include "llfloaterpreference.h"
+#include "llfollowcam.h"
+#include "llgroupnotify.h"
+#include "llhudeffect.h"
+#include "llhudeffecttrail.h"
+#include "llhudmanager.h"
+#include "llimpanel.h"
+#include "llinventorymodel.h"
+#include "llinventorypanel.h"
+#include "llfloaterinventory.h"
+#include "llmenugl.h"
+#include "llmoveview.h"
+#include "llmutelist.h"
+#include "llnearbychat.h"
+#include "llnotifications.h"
+#include "llnotify.h"
+#include "llpanelgrouplandmoney.h"
+#include "llpanelplaces.h"
+#include "llrecentpeople.h"
+#include "llselectmgr.h"
+#include "llsidetray.h"
+#include "llstartup.h"
+#include "llsky.h"
+#include "llslurl.h"
+#include "llstatenums.h"
+#include "llstatusbar.h"
+#include "llimview.h"
+#include "lltool.h"
+#include "lltoolbar.h"
+#include "lltoolmgr.h"
+#include "lltrans.h"
+#include "llui.h"			// for make_ui_sound
+#include "lluploaddialog.h"
+#include "llviewercamera.h"
+#include "llviewergenericmessage.h"
+#include "llviewerinventory.h"
+#include "llviewermenu.h"
+#include "llviewerobject.h"
+#include "llviewerobjectlist.h"
+#include "llviewerparcelmgr.h"
+#include "llviewerpartsource.h"
+#include "llviewerregion.h"
+#include "llviewerstats.h"
+#include "llviewertexteditor.h"
+#include "llviewerthrottle.h"
+#include "llviewerwindow.h"
+#include "llvlmanager.h"
+#include "llvoavatarself.h"
+#include "llvotextbubble.h"
+#include "llweb.h"
+#include "llworld.h"
+#include "pipeline.h"
+#include "llappviewer.h"
+#include "llfloaterworldmap.h"
+#include "llviewerdisplay.h"
+#include "llkeythrottle.h"
+#include "llgroupactions.h"
+#include "llagentui.h"
+#include "llpanelblockedlist.h"
+#include "llpanelplaceinfo.h"
+
+#include <boost/tokenizer.hpp>
+#include <boost/algorithm/string/split.hpp>
+
+#if LL_WINDOWS // For Windows specific error handler
+#include "llwindebug.h"	// For the invalid message handler
+#endif
+
+//#include "llnearbychathistory.h"
+#include "llnotificationmanager.h"
+
+//
+// Constants
+//
+const F32 BIRD_AUDIBLE_RADIUS = 32.0f;
+const F32 SIT_DISTANCE_FROM_TARGET = 0.25f;
+static const F32 LOGOUT_REPLY_TIME = 3.f;	// Wait this long after LogoutReply before quitting.
+
+// Determine how quickly residents' scripts can issue question dialogs
+// Allow bursts of up to 5 dialogs in 10 seconds. 10*2=20 seconds recovery if throttle kicks in
+static const U32 LLREQUEST_PERMISSION_THROTTLE_LIMIT	= 5;     // requests
+static const F32 LLREQUEST_PERMISSION_THROTTLE_INTERVAL	= 10.0f; // seconds
+
+extern BOOL gDebugClicks;
+
+// function prototypes
+void open_offer(const std::vector<LLUUID>& items, const std::string& from_name);
+bool check_offer_throttle(const std::string& from_name, bool check_only);
+
+//inventory offer throttle globals
+LLFrameTimer gThrottleTimer;
+const U32 OFFER_THROTTLE_MAX_COUNT=5; //number of items per time period
+const F32 OFFER_THROTTLE_TIME=10.f; //time period in seconds
+
+//script permissions
+const std::string SCRIPT_QUESTIONS[SCRIPT_PERMISSION_EOF] = 
+	{ 
+		"ScriptTakeMoney",
+		"ActOnControlInputs",
+		"RemapControlInputs",
+		"AnimateYourAvatar",
+		"AttachToYourAvatar",
+		"ReleaseOwnership",
+		"LinkAndDelink",
+		"AddAndRemoveJoints",
+		"ChangePermissions",
+		"TrackYourCamera",
+		"ControlYourCamera"
+	};
+
+const BOOL SCRIPT_QUESTION_IS_CAUTION[SCRIPT_PERMISSION_EOF] = 
+{
+	TRUE,	// ScriptTakeMoney,
+	FALSE,	// ActOnControlInputs
+	FALSE,	// RemapControlInputs
+	FALSE,	// AnimateYourAvatar
+	FALSE,	// AttachToYourAvatar
+	FALSE,	// ReleaseOwnership,
+	FALSE,	// LinkAndDelink,
+	FALSE,	// AddAndRemoveJoints
+	FALSE,	// ChangePermissions
+	FALSE,	// TrackYourCamera,
+	FALSE	// ControlYourCamera
+};
+
+bool friendship_offer_callback(const LLSD& notification, const LLSD& response)
+{
+	S32 option = LLNotification::getSelectedOption(notification, response);
+	LLUUID fid;
+	LLMessageSystem* msg = gMessageSystem;
+	const LLSD& payload = notification["payload"];
+
+	// add friend to recent people list
+	LLRecentPeople::instance().add(payload["from_id"]);
+
+	switch(option)
+	{
+	case 0:
+		// accept
+		LLAvatarTracker::formFriendship(payload["from_id"]);
+
+		fid = gInventory.findCategoryUUIDForType(LLAssetType::AT_CALLINGCARD);
+
+		// This will also trigger an onlinenotification if the user is online
+		msg->newMessageFast(_PREHASH_AcceptFriendship);
+		msg->nextBlockFast(_PREHASH_AgentData);
+		msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+		msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+		msg->nextBlockFast(_PREHASH_TransactionBlock);
+		msg->addUUIDFast(_PREHASH_TransactionID, payload["session_id"]);
+		msg->nextBlockFast(_PREHASH_FolderData);
+		msg->addUUIDFast(_PREHASH_FolderID, fid);
+		msg->sendReliable(LLHost(payload["sender"].asString()));
+		break;
+	case 1:
+		// decline
+		// We no longer notify other viewers, but we DO still send
+		// the rejection to the simulator to delete the pending userop.
+		msg->newMessageFast(_PREHASH_DeclineFriendship);
+		msg->nextBlockFast(_PREHASH_AgentData);
+		msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+		msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+		msg->nextBlockFast(_PREHASH_TransactionBlock);
+		msg->addUUIDFast(_PREHASH_TransactionID, payload["session_id"]);
+		msg->sendReliable(LLHost(payload["sender"].asString()));
+		break;
+	default:
+		// close button probably, possibly timed out
+		break;
+	}
+
+	return false;
+}
+static LLNotificationFunctorRegistration friendship_offer_callback_reg("OfferFriendship", friendship_offer_callback);
+static LLNotificationFunctorRegistration friendship_offer_callback_reg_nm("OfferFriendshipNoMessage", friendship_offer_callback);
+
+//const char BUSY_AUTO_RESPONSE[] =	"The Resident you messaged is in 'busy mode' which means they have "
+//									"requested not to be disturbed. Your message will still be shown in their IM "
+//									"panel for later viewing.";
+
+//
+// Functions
+//
+
+void give_money(const LLUUID& uuid, LLViewerRegion* region, S32 amount, BOOL is_group,
+				S32 trx_type, const std::string& desc)
+{
+	if(0 == amount || !region) return;
+	amount = abs(amount);
+	LL_INFOS("Messaging") << "give_money(" << uuid << "," << amount << ")"<< LL_ENDL;
+	if(can_afford_transaction(amount))
+	{
+//		gStatusBar->debitBalance(amount);
+		LLMessageSystem* msg = gMessageSystem;
+		msg->newMessageFast(_PREHASH_MoneyTransferRequest);
+		msg->nextBlockFast(_PREHASH_AgentData);
+		msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+        msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+		msg->nextBlockFast(_PREHASH_MoneyData);
+		msg->addUUIDFast(_PREHASH_SourceID, gAgent.getID() );
+		msg->addUUIDFast(_PREHASH_DestID, uuid);
+		msg->addU8Fast(_PREHASH_Flags, pack_transaction_flags(FALSE, is_group));
+		msg->addS32Fast(_PREHASH_Amount, amount);
+		msg->addU8Fast(_PREHASH_AggregatePermNextOwner, (U8)LLAggregatePermissions::AP_EMPTY);
+		msg->addU8Fast(_PREHASH_AggregatePermInventory, (U8)LLAggregatePermissions::AP_EMPTY);
+		msg->addS32Fast(_PREHASH_TransactionType, trx_type );
+		msg->addStringFast(_PREHASH_Description, desc);
+		msg->sendReliable(region->getHost());
+	}
+	else
+	{
+		LLFloaterBuyCurrency::buyCurrency("Giving", amount);
+	}
+}
+
+void send_complete_agent_movement(const LLHost& sim_host)
+{
+	LLMessageSystem* msg = gMessageSystem;
+	msg->newMessageFast(_PREHASH_CompleteAgentMovement);
+	msg->nextBlockFast(_PREHASH_AgentData);
+	msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+	msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+	msg->addU32Fast(_PREHASH_CircuitCode, msg->mOurCircuitCode);
+	msg->sendReliable(sim_host);
+}
+
+void process_logout_reply(LLMessageSystem* msg, void**)
+{
+	// The server has told us it's ok to quit.
+	LL_DEBUGS("Messaging") << "process_logout_reply" << LL_ENDL;
+
+	LLUUID agent_id;
+	msg->getUUID("AgentData", "AgentID", agent_id);
+	LLUUID session_id;
+	msg->getUUID("AgentData", "SessionID", session_id);
+	if((agent_id != gAgent.getID()) || (session_id != gAgent.getSessionID()))
+	{
+		LL_WARNS("Messaging") << "Bogus Logout Reply" << LL_ENDL;
+	}
+
+	LLInventoryModel::update_map_t parents;
+	S32 count = msg->getNumberOfBlocksFast( _PREHASH_InventoryData );
+	for(S32 i = 0; i < count; ++i)
+	{
+		LLUUID item_id;
+		msg->getUUIDFast(_PREHASH_InventoryData, _PREHASH_ItemID, item_id, i);
+
+		if( (1 == count) && item_id.isNull() )
+		{
+			// Detect dummy item.  Indicates an empty list.
+			break;
+		}
+
+		// We do not need to track the asset ids, just account for an
+		// updated inventory version.
+		LL_INFOS("Messaging") << "process_logout_reply itemID=" << item_id << LL_ENDL;
+		LLInventoryItem* item = gInventory.getItem( item_id );
+		if( item )
+		{
+			parents[item->getParentUUID()] = 0;
+			gInventory.addChangedMask(LLInventoryObserver::INTERNAL, item_id);
+		}
+		else
+		{
+			LL_INFOS("Messaging") << "process_logout_reply item not found: " << item_id << LL_ENDL;
+		}
+	}
+    LLAppViewer::instance()->forceQuit();
+}
+
+void process_layer_data(LLMessageSystem *mesgsys, void **user_data)
+{
+	LLViewerRegion *regionp = LLWorld::getInstance()->getRegion(mesgsys->getSender());
+
+	if (!regionp || gNoRender)
+	{
+		return;
+	}
+
+
+	S32 size;
+	S8 type;
+
+	mesgsys->getS8Fast(_PREHASH_LayerID, _PREHASH_Type, type);
+	size = mesgsys->getSizeFast(_PREHASH_LayerData, _PREHASH_Data);
+	if (0 == size)
+	{
+		LL_WARNS("Messaging") << "Layer data has zero size." << LL_ENDL;
+		return;
+	}
+	if (size < 0)
+	{
+		// getSizeFast() is probably trying to tell us about an error
+		LL_WARNS("Messaging") << "getSizeFast() returned negative result: "
+			<< size
+			<< LL_ENDL;
+		return;
+	}
+	U8 *datap = new U8[size];
+	mesgsys->getBinaryDataFast(_PREHASH_LayerData, _PREHASH_Data, datap, size);
+	LLVLData *vl_datap = new LLVLData(regionp, type, datap, size);
+	if (mesgsys->getReceiveCompressedSize())
+	{
+		gVLManager.addLayerData(vl_datap, mesgsys->getReceiveCompressedSize());
+	}
+	else
+	{
+		gVLManager.addLayerData(vl_datap, mesgsys->getReceiveSize());
+	}
+}
+
+// S32 exported_object_count = 0;
+// S32 exported_image_count = 0;
+// S32 current_object_count = 0;
+// S32 current_image_count = 0;
+
+// extern LLNotifyBox *gExporterNotify;
+// extern LLUUID gExporterRequestID;
+// extern std::string gExportDirectory;
+
+// extern LLUploadDialog *gExportDialog;
+
+// std::string gExportedFile;
+
+// std::map<LLUUID, std::string> gImageChecksums;
+
+// void export_complete()
+// {
+// 		LLUploadDialog::modalUploadFinished();
+// 		gExporterRequestID.setNull();
+// 		gExportDirectory = "";
+
+// 		LLFILE* fXML = LLFile::fopen(gExportedFile, "rb");		/* Flawfinder: ignore */
+// 		fseek(fXML, 0, SEEK_END);
+// 		long length = ftell(fXML);
+// 		fseek(fXML, 0, SEEK_SET);
+// 		U8 *buffer = new U8[length + 1];
+// 		size_t nread = fread(buffer, 1, length, fXML);
+// 		if (nread < (size_t) length)
+// 		{
+// 			LL_WARNS("Messaging") << "Short read" << LL_ENDL;
+// 		}
+// 		buffer[nread] = '\0';
+// 		fclose(fXML);
+
+// 		char *pos = (char *)buffer;
+// 		while ((pos = strstr(pos+1, "<sl:image ")) != 0)
+// 		{
+// 			char *pos_check = strstr(pos, "checksum=\"");
+
+// 			if (pos_check)
+// 			{
+// 				char *pos_uuid = strstr(pos_check, "\">");
+
+// 				if (pos_uuid)
+// 				{
+// 					char image_uuid_str[UUID_STR_SIZE];		/* Flawfinder: ignore */
+// 					memcpy(image_uuid_str, pos_uuid+2, UUID_STR_SIZE-1);		/* Flawfinder: ignore */
+// 					image_uuid_str[UUID_STR_SIZE-1] = 0;
+					
+// 					LLUUID image_uuid(image_uuid_str);
+
+// 					LL_INFOS("Messaging") << "Found UUID: " << image_uuid << LL_ENDL;
+
+// 					std::map<LLUUID, std::string>::iterator itor = gImageChecksums.find(image_uuid);
+// 					if (itor != gImageChecksums.end())
+// 					{
+// 						LL_INFOS("Messaging") << "Replacing with checksum: " << itor->second << LL_ENDL;
+// 						if (!itor->second.empty())
+// 						{
+// 							memcpy(&pos_check[10], itor->second.c_str(), 32);		/* Flawfinder: ignore */
+// 						}
+// 					}
+// 				}
+// 			}
+// 		}
+
+// 		LLFILE* fXMLOut = LLFile::fopen(gExportedFile, "wb");		/* Flawfinder: ignore */
+// 		if (fwrite(buffer, 1, length, fXMLOut) != length)
+// 		{
+// 			LL_WARNS("Messaging") << "Short write" << LL_ENDL;
+// 		}
+// 		fclose(fXMLOut);
+
+// 		delete [] buffer;
+// }
+
+
+// void exported_item_complete(const LLTSCode status, void *user_data)
+// {
+// 	//std::string *filename = (std::string *)user_data;
+
+// 	if (status < LLTS_OK)
+// 	{
+// 		LL_WARNS("Messaging") << "Export failed!" << LL_ENDL;
+// 	}
+// 	else
+// 	{
+// 		++current_object_count;
+// 		if (current_image_count == exported_image_count && current_object_count == exported_object_count)
+// 		{
+// 			LL_INFOS("Messaging") << "*** Export complete ***" << LL_ENDL;
+
+// 			export_complete();
+// 		}
+// 		else
+// 		{
+// 			gExportDialog->setMessage(llformat("Exported %d/%d object files, %d/%d textures.", current_object_count, exported_object_count, current_image_count, exported_image_count));
+// 		}
+// 	}
+// }
+
+// struct exported_image_info
+// {
+// 	LLUUID image_id;
+// 	std::string filename;
+// 	U32 image_num;
+// };
+
+// void exported_j2c_complete(const LLTSCode status, void *user_data)
+// {
+// 	exported_image_info *info = (exported_image_info *)user_data;
+// 	LLUUID image_id = info->image_id;
+// 	U32 image_num = info->image_num;
+// 	std::string filename = info->filename;
+// 	delete info;
+
+// 	if (status < LLTS_OK)
+// 	{
+// 		LL_WARNS("Messaging") << "Image download failed!" << LL_ENDL;
+// 	}
+// 	else
+// 	{
+// 		LLFILE* fIn = LLFile::fopen(filename, "rb");		/* Flawfinder: ignore */
+// 		if (fIn) 
+// 		{
+// 			LLPointer<LLImageJ2C> ImageUtility = new LLImageJ2C;
+// 			LLPointer<LLImageTGA> TargaUtility = new LLImageTGA;
+
+// 			fseek(fIn, 0, SEEK_END);
+// 			S32 length = ftell(fIn);
+// 			fseek(fIn, 0, SEEK_SET);
+// 			U8 *buffer = ImageUtility->allocateData(length);
+// 			if (fread(buffer, 1, length, fIn) != length)
+// 			{
+// 				LL_WARNS("Messaging") << "Short read" << LL_ENDL;
+// 			}
+// 			fclose(fIn);
+// 			LLFile::remove(filename);
+
+// 			// Convert to TGA
+// 			LLPointer<LLImageRaw> image = new LLImageRaw();
+
+// 			ImageUtility->updateData();
+// 			ImageUtility->decode(image, 100000.0f);
+			
+// 			TargaUtility->encode(image);
+// 			U8 *data = TargaUtility->getData();
+// 			S32 data_size = TargaUtility->getDataSize();
+
+// 			std::string file_path = gDirUtilp->getDirName(filename);
+			
+// 			std::string output_file = llformat("%s/image-%03d.tga", file_path.c_str(), image_num);//filename;
+// 			//S32 name_len = output_file.length();
+// 			//strcpy(&output_file[name_len-3], "tga");
+// 			LLFILE* fOut = LLFile::fopen(output_file, "wb");		/* Flawfinder: ignore */
+// 			char md5_hash_string[33];		/* Flawfinder: ignore */
+// 			strcpy(md5_hash_string, "00000000000000000000000000000000");		/* Flawfinder: ignore */
+// 			if (fOut)
+// 			{
+// 				if (fwrite(data, 1, data_size, fOut) != data_size)
+// 				{
+// 					LL_WARNS("Messaging") << "Short write" << LL_ENDL;
+// 				}
+// 				fseek(fOut, 0, SEEK_SET);
+// 				fclose(fOut);
+// 				fOut = LLFile::fopen(output_file, "rb");		/* Flawfinder: ignore */
+// 				LLMD5 my_md5_hash(fOut);
+// 				my_md5_hash.hex_digest(md5_hash_string);
+// 			}
+
+// 			gImageChecksums.insert(std::pair<LLUUID, std::string>(image_id, md5_hash_string));
+// 		}
+// 	}
+
+// 	++current_image_count;
+// 	if (current_image_count == exported_image_count && current_object_count == exported_object_count)
+// 	{
+// 		LL_INFOS("Messaging") << "*** Export textures complete ***" << LL_ENDL;
+// 			export_complete();
+// 	}
+// 	else
+// 	{
+// 		gExportDialog->setMessage(llformat("Exported %d/%d object files, %d/%d textures.", current_object_count, exported_object_count, current_image_count, exported_image_count));
+// 	}
+//}
+
+void process_derez_ack(LLMessageSystem*, void**)
+{
+	if(gViewerWindow) gViewerWindow->getWindow()->decBusyCount();
+}
+
+void process_places_reply(LLMessageSystem* msg, void** data)
+{
+	LLUUID query_id;
+
+	msg->getUUID("AgentData", "QueryID", query_id);
+	if (query_id.isNull())
+	{
+		LLFloaterLandHoldings::processPlacesReply(msg, data);
+	}
+	else if(gAgent.isInGroup(query_id))
+	{
+		LLPanelGroupLandMoney::processPlacesReply(msg, data);
+	}
+	else
+	{
+		LL_WARNS("Messaging") << "Got invalid PlacesReply message" << LL_ENDL;
+	}
+}
+
+void send_sound_trigger(const LLUUID& sound_id, F32 gain)
+{
+	if (sound_id.isNull() || gAgent.getRegion() == NULL)
+	{
+		// disconnected agent or zero guids don't get sent (no sound)
+		return;
+	}
+
+	LLMessageSystem* msg = gMessageSystem;
+	msg->newMessageFast(_PREHASH_SoundTrigger);
+	msg->nextBlockFast(_PREHASH_SoundData);
+	msg->addUUIDFast(_PREHASH_SoundID, sound_id);
+	// Client untrusted, ids set on sim
+	msg->addUUIDFast(_PREHASH_OwnerID, LLUUID::null );
+	msg->addUUIDFast(_PREHASH_ObjectID, LLUUID::null );
+	msg->addUUIDFast(_PREHASH_ParentID, LLUUID::null );
+
+	msg->addU64Fast(_PREHASH_Handle, gAgent.getRegion()->getHandle());
+
+	LLVector3 position = gAgent.getPositionAgent();
+	msg->addVector3Fast(_PREHASH_Position, position);
+	msg->addF32Fast(_PREHASH_Gain, gain);
+
+	gAgent.sendMessage();
+}
+
+bool join_group_response(const LLSD& notification, const LLSD& response)
+{
+	S32 option = LLNotification::getSelectedOption(notification, response);
+	BOOL delete_context_data = TRUE;
+	bool accept_invite = false;
+
+	LLUUID group_id = notification["payload"]["group_id"].asUUID();
+	LLUUID transaction_id = notification["payload"]["transaction_id"].asUUID();
+	std::string name = notification["payload"]["name"].asString();
+	std::string message = notification["payload"]["message"].asString();
+	S32 fee = notification["payload"]["fee"].asInteger();
+
+	if (option == 2 && !group_id.isNull())
+	{
+		LLGroupActions::show(group_id);
+		LLSD args;
+		args["MESSAGE"] = message;
+		LLNotifications::instance().add("JoinGroup", args, notification["payload"]);
+		return false;
+	}
+	if(option == 0 && !group_id.isNull())
+	{
+		// check for promotion or demotion.
+		S32 max_groups = MAX_AGENT_GROUPS;
+		if(gAgent.isInGroup(group_id)) ++max_groups;
+
+		if(gAgent.mGroups.count() < max_groups)
+		{
+			accept_invite = true;
+		}
+		else
+		{
+			delete_context_data = FALSE;
+			LLSD args;
+			args["NAME"] = name;
+			args["INVITE"] = message;
+			LLNotifications::instance().add("JoinedTooManyGroupsMember", args, notification["payload"]);
+		}
+	}
+
+	if (accept_invite)
+	{
+		// If there is a fee to join this group, make
+		// sure the user is sure they want to join.
+		if (fee > 0)
+		{
+			delete_context_data = FALSE;
+			LLSD args;
+			args["COST"] = llformat("%d", fee);
+			// Set the fee for next time to 0, so that we don't keep
+			// asking about a fee.
+			LLSD next_payload = notification["payload"];
+			next_payload["fee"] = 0;
+			LLNotifications::instance().add("JoinGroupCanAfford",
+									args,
+									next_payload);
+		}
+		else
+		{
+			send_improved_im(group_id,
+							 std::string("name"),
+							 std::string("message"),
+							IM_ONLINE,
+							IM_GROUP_INVITATION_ACCEPT,
+							transaction_id);
+		}
+	}
+	else
+	{
+		send_improved_im(group_id,
+						 std::string("name"),
+						 std::string("message"),
+						IM_ONLINE,
+						IM_GROUP_INVITATION_DECLINE,
+						transaction_id);
+	}
+
+	return false;
+}
+static LLNotificationFunctorRegistration jgr_1("JoinGroup", join_group_response);
+static LLNotificationFunctorRegistration jgr_2("JoinedTooManyGroupsMember", join_group_response);
+static LLNotificationFunctorRegistration jgr_3("JoinGroupCanAfford", join_group_response);
+
+
+//-----------------------------------------------------------------------------
+// Instant Message
+//-----------------------------------------------------------------------------
+class LLOpenAgentOffer : public LLInventoryFetchObserver
+{
+public:
+	LLOpenAgentOffer(const std::string& from_name) : mFromName(from_name) {}
+	/*virtual*/ void done()
+	{
+		open_offer(mComplete, mFromName);
+		gInventory.removeObserver(this);
+		delete this;
+	}
+private:
+	std::string mFromName;
+};
+
+//unlike the FetchObserver for AgentOffer, we only make one 
+//instance of the AddedObserver for TaskOffers
+//and it never dies.  We do this because we don't know the UUID of 
+//task offers until they are accepted, so we don't wouldn't 
+//know what to watch for, so instead we just watch for all additions.
+class LLOpenTaskOffer : public LLInventoryAddedObserver
+{
+protected:
+	/*virtual*/ void done()
+	{
+		open_offer(mAdded, "");
+		mAdded.clear();
+	}
+ };
+
+//one global instance to bind them
+LLOpenTaskOffer* gNewInventoryObserver=NULL;
+
+void start_new_inventory_observer()
+{
+	if (!gNewInventoryObserver) //task offer observer 
+	{
+		// Observer is deleted by gInventory
+		gNewInventoryObserver = new LLOpenTaskOffer;
+		gInventory.addObserver(gNewInventoryObserver);
+	}
+}
+
+class LLDiscardAgentOffer : public LLInventoryFetchComboObserver
+{
+public:
+	LLDiscardAgentOffer(const LLUUID& folder_id, const LLUUID& object_id) :
+		mFolderID(folder_id),
+		mObjectID(object_id) {}
+	virtual ~LLDiscardAgentOffer() {}
+	virtual void done()
+	{
+		LL_DEBUGS("Messaging") << "LLDiscardAgentOffer::done()" << LL_ENDL;
+		LLUUID trash_id;
+		trash_id = gInventory.findCategoryUUIDForType(LLAssetType::AT_TRASH);
+		bool notify = false;
+		if(trash_id.notNull() && mObjectID.notNull())
+		{
+			LLInventoryModel::update_list_t update;
+			LLInventoryModel::LLCategoryUpdate old_folder(mFolderID, -1);
+			update.push_back(old_folder);
+			LLInventoryModel::LLCategoryUpdate new_folder(trash_id, 1);
+			update.push_back(new_folder);
+			gInventory.accountForUpdate(update);
+			gInventory.moveObject(mObjectID, trash_id);
+			LLInventoryObject* obj = gInventory.getObject(mObjectID);
+			if(obj)
+			{
+				// no need to restamp since this is already a freshly
+				// stamped item.
+				obj->updateParentOnServer(FALSE);
+				notify = true;
+			}
+		}
+		else
+		{
+			LL_WARNS("Messaging") << "DiscardAgentOffer unable to find: "
+					<< (trash_id.isNull() ? "trash " : "")
+					<< (mObjectID.isNull() ? "object" : "") << LL_ENDL;
+		}
+		gInventory.removeObserver(this);
+		if(notify)
+		{
+			gInventory.notifyObservers();
+		}
+		delete this;
+	}
+protected:
+	LLUUID mFolderID;
+	LLUUID mObjectID;
+};
+
+
+//Returns TRUE if we are OK, FALSE if we are throttled
+//Set check_only true if you want to know the throttle status 
+//without registering a hit
+bool check_offer_throttle(const std::string& from_name, bool check_only)
+{
+	static U32 throttle_count;
+	static bool throttle_logged;
+	LLChat chat;
+	std::string log_message;
+
+	if (!gSavedSettings.getBOOL("ShowNewInventory"))
+		return false;
+
+	if (check_only)
+	{
+		return gThrottleTimer.hasExpired();
+	}
+	
+	if(gThrottleTimer.checkExpirationAndReset(OFFER_THROTTLE_TIME))
+	{
+		LL_DEBUGS("Messaging") << "Throttle Expired" << LL_ENDL;
+		throttle_count=1;
+		throttle_logged=false;
+		return true;
+	}
+	else //has not expired
+	{
+		LL_DEBUGS("Messaging") << "Throttle Not Expired, Count: " << throttle_count << LL_ENDL;
+		// When downloading the initial inventory we get a lot of new items
+		// coming in and can't tell that from spam.
+		if (LLStartUp::getStartupState() >= STATE_STARTED
+			&& throttle_count >= OFFER_THROTTLE_MAX_COUNT)
+		{
+			if (!throttle_logged)
+			{
+				// Use the name of the last item giver, who is probably the person
+				// spamming you.
+				std::ostringstream message;
+				message << LLAppViewer::instance()->getSecondLifeTitle();
+				if (!from_name.empty())
+				{
+					message << ": Items coming in too fast from " << from_name;
+				}
+				else
+				{
+					message << ": Items coming in too fast";
+				}
+				message << ", automatic preview disabled for "
+					<< OFFER_THROTTLE_TIME << " seconds.";
+				chat.mText = message.str();
+				//this is kinda important, so actually put it on screen
+				LLFloaterChat::addChat(chat, FALSE, FALSE);
+				throttle_logged=true;
+			}
+			return false;
+		}
+		else
+		{
+			throttle_count++;
+			return true;
+		}
+	}
+}
+ 
+void open_offer(const std::vector<LLUUID>& items, const std::string& from_name)
+{
+	std::vector<LLUUID>::const_iterator it = items.begin();
+	std::vector<LLUUID>::const_iterator end = items.end();
+	LLUUID trash_id(gInventory.findCategoryUUIDForType(LLAssetType::AT_TRASH));
+	LLInventoryItem* item;
+	for(; it != end; ++it)
+	{
+		const LLUUID& id = *it;
+		item = gInventory.getItem(id);
+		if(!item)
+		{
+			LL_WARNS("Messaging") << "Unable to show inventory item: " << id << LL_ENDL;
+			continue;
+		}
+		if(gInventory.isObjectDescendentOf(id, trash_id))
+		{
+			continue;
+		}
+		LLAssetType::EType asset_type = item->getType();
+
+		//if we are throttled, don't display them
+		if (check_offer_throttle(from_name, false))
+		{
+			// If we opened this ourselves, focus it
+			BOOL take_focus = from_name.empty() ? TAKE_FOCUS_YES : TAKE_FOCUS_NO;
+			switch(asset_type)
+			{
+			  case LLAssetType::AT_NOTECARD:
+				LLFloaterReg::showInstance("preview_notecard", LLSD(id), take_focus);
+				break;
+			  case LLAssetType::AT_LANDMARK:
+			  	{
+					LLInventoryCategory* parent_folder = gInventory.getCategory(item->getParentUUID());
+					LLSD args;
+					args["LANDMARK_NAME"] = item->getName();
+					args["FOLDER_NAME"] = std::string(parent_folder ? parent_folder->getName() : "unknown");
+					LLNotifications::instance().add("LandmarkCreated", args);
+
+					// Created landmark is passed to Places panel to allow its editing.
+					LLPanelPlaces *panel = dynamic_cast<LLPanelPlaces*>(LLSideTray::getInstance()->showPanel("panel_places", LLSD()));
+					if (panel)
+					{
+						panel->setItem(item);
+					}
+			  	}
+				break;
+			  case LLAssetType::AT_TEXTURE:
+				LLFloaterReg::showInstance("preview_texture", LLSD(id), take_focus);
+				break;
+			  default:
+				break;
+			}
+		}
+		//highlight item, if it's not in the trash or lost+found
+		
+		// Don't auto-open the inventory floater
+		LLFloaterInventory* view = NULL;
+		if(gSavedSettings.getBOOL("ShowInInventory") &&
+		   asset_type != LLAssetType::AT_CALLINGCARD &&
+		   item->getInventoryType() != LLInventoryType::IT_ATTACHMENT &&
+		   !from_name.empty())
+		{
+			view = LLFloaterInventory::showAgentInventory();
+		}
+		else
+		{
+			view = LLFloaterInventory::getActiveInventory();
+		}
+		if(!view)
+		{
+			return;
+		}
+
+		//Trash Check
+		LLUUID trash_id;
+		trash_id = gInventory.findCategoryUUIDForType(LLAssetType::AT_TRASH);
+		if(gInventory.isObjectDescendentOf(item->getUUID(), trash_id))
+		{
+			return;
+		}
+		LLUUID lost_and_found_id = gInventory.findCategoryUUIDForType(LLAssetType::AT_LOST_AND_FOUND);
+		//BOOL inventory_has_focus = gFocusMgr.childHasKeyboardFocus(view);
+		BOOL user_is_away = gAwayTimer.getStarted();
+
+		// don't select lost and found items if the user is active
+		if (gInventory.isObjectDescendentOf(item->getUUID(), lost_and_found_id)
+			&& !user_is_away)
+		{
+			return;
+		}
+
+		//Not sure about this check.  Could make it easy to miss incoming items.
+		//don't dick with highlight while the user is working
+		//if(inventory_has_focus && !user_is_away)
+		//	break;
+		LL_DEBUGS("Messaging") << "Highlighting" << item->getUUID()  << LL_ENDL;
+		//highlight item
+
+		if (view->getPanel())
+		{
+			LLFocusableElement* focus_ctrl = gFocusMgr.getKeyboardFocus();
+			view->getPanel()->setSelection(item->getUUID(), TAKE_FOCUS_NO);
+			gFocusMgr.setKeyboardFocus(focus_ctrl);
+		}
+	}
+}
+
+void inventory_offer_mute_callback(const LLUUID& blocked_id,
+								   const std::string& first_name,
+								   const std::string& last_name,
+								   BOOL is_group)
+{
+	std::string from_name;
+	LLMute::EType type;
+
+	if (is_group)
+	{
+		type = LLMute::GROUP;
+		from_name = first_name;
+	}
+	else
+	{
+		type = LLMute::AGENT;
+		from_name = first_name + " " + last_name;
+	}
+
+	LLMute mute(blocked_id, from_name, type);
+	if (LLMuteList::getInstance()->add(mute))
+	{
+		LLPanelBlockedList::showPanelAndSelect(blocked_id);
+	}
+
+	// purge the message queue of any previously queued inventory offers from the same source.
+	class OfferMatcher : public LLNotifyBoxView::Matcher
+	{
+	public:
+		OfferMatcher(const LLUUID& to_block) : blocked_id(to_block) {}
+		BOOL matches(const LLNotificationPtr notification) const
+		{
+			if(notification->getName() == "ObjectGiveItem" 
+				|| notification->getName() == "ObjectGiveItemUnknownUser"
+				|| notification->getName() == "UserGiveItem")
+			{
+				return (notification->getPayload()["from_id"].asUUID() == blocked_id);
+			}
+			return FALSE;
+		}
+	private:
+		const LLUUID& blocked_id;
+	};
+	gNotifyBoxView->purgeMessagesMatching(OfferMatcher(blocked_id));
+}
+
+LLOfferInfo::LLOfferInfo(const LLSD& sd)
+{
+	mIM = (EInstantMessage)sd["im_type"].asInteger();
+	mFromID = sd["from_id"].asUUID();
+	mFromGroup = sd["from_group"].asBoolean();
+	mFromObject = sd["from_object"].asBoolean();
+	mTransactionID = sd["transaction_id"].asUUID();
+	mFolderID = sd["folder_id"].asUUID();
+	mObjectID = sd["object_id"].asUUID();
+	mType = LLAssetType::lookup(sd["type"].asString().c_str());
+	mFromName = sd["from_name"].asString();
+	mDesc = sd["description"].asString();
+	mHost = LLHost(sd["sender"].asString());
+}
+
+LLSD LLOfferInfo::asLLSD()
+{
+	LLSD sd;
+	sd["im_type"] = mIM;
+	sd["from_id"] = mFromID;
+	sd["from_group"] = mFromGroup;
+	sd["from_object"] = mFromObject;
+	sd["transaction_id"] = mTransactionID;
+	sd["folder_id"] = mFolderID;
+	sd["object_id"] = mObjectID;
+	sd["type"] = LLAssetType::lookup(mType);
+	sd["from_name"] = mFromName;
+	sd["description"] = mDesc;
+	sd["sender"] = mHost.getIPandPort();
+	return sd;
+}
+
+bool LLOfferInfo::inventory_offer_callback(const LLSD& notification, const LLSD& response)
+ {
+	LLChat chat;
+	std::string log_message;
+	S32 button = LLNotification::getSelectedOption(notification, response);
+
+	// For muting, we need to add the mute, then decline the offer.
+	// This must be done here because:
+	// * callback may be called immediately,
+	// * adding the mute sends a message,
+	// * we can't build two messages at once.
+	if (2 == button)
+	{
+		gCacheName->get(mFromID, mFromGroup, &inventory_offer_mute_callback);
+	}
+
+	LLMessageSystem* msg = gMessageSystem;
+	msg->newMessageFast(_PREHASH_ImprovedInstantMessage);
+	msg->nextBlockFast(_PREHASH_AgentData);
+	msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+	msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+	msg->nextBlockFast(_PREHASH_MessageBlock);
+	msg->addBOOLFast(_PREHASH_FromGroup, FALSE);
+	msg->addUUIDFast(_PREHASH_ToAgentID, mFromID);
+	msg->addU8Fast(_PREHASH_Offline, IM_ONLINE);
+	msg->addUUIDFast(_PREHASH_ID, mTransactionID);
+	msg->addU32Fast(_PREHASH_Timestamp, NO_TIMESTAMP); // no timestamp necessary
+	std::string name;
+	LLAgentUI::buildFullname(name);
+	msg->addStringFast(_PREHASH_FromAgentName, name);
+	msg->addStringFast(_PREHASH_Message, ""); 
+	msg->addU32Fast(_PREHASH_ParentEstateID, 0);
+	msg->addUUIDFast(_PREHASH_RegionID, LLUUID::null);
+	msg->addVector3Fast(_PREHASH_Position, gAgent.getPositionAgent());
+	LLInventoryObserver* opener = NULL;
+	LLViewerInventoryCategory* catp = NULL;
+	catp = (LLViewerInventoryCategory*)gInventory.getCategory(mObjectID);
+	LLViewerInventoryItem* itemp = NULL;
+	if(!catp)
+	{
+		itemp = (LLViewerInventoryItem*)gInventory.getItem(mObjectID);
+	}
+
+	std::string from_string; // Used in the pop-up.
+	std::string chatHistory_string;  // Used in chat history.
+	if (mFromObject == TRUE)
+	{
+		if (mFromGroup)
+		{
+			std::string group_name;
+			if (gCacheName->getGroupName(mFromID, group_name))
+			{
+				from_string = LLTrans::getString("InvOfferAnObjectNamed") + " "+"'" 
+							+ mFromName + LLTrans::getString("'") +" " + LLTrans::getString("InvOfferOwnedByGroup") 
+				            + " "+ "'" + group_name + "'";
+				
+				chatHistory_string = mFromName + " " + LLTrans::getString("InvOfferOwnedByGroup") 
+								   + " " + group_name + "'";
+			}
+			else
+			{
+				from_string = LLTrans::getString("InvOfferAnObjectNamed") + " "+"'"
+				            + mFromName +"'"+ " " + LLTrans::getString("InvOfferOwnedByUnknownGroup");
+				chatHistory_string = mFromName + " " + LLTrans::getString("InvOfferOwnedByUnknownGroup");
+			}
+		}
+		else
+		{
+			std::string first_name, last_name;
+			if (gCacheName->getName(mFromID, first_name, last_name))
+			{
+				from_string = LLTrans::getString("InvOfferAnObjectNamed") + " "+ LLTrans::getString("'") + mFromName 
+							+ LLTrans::getString("'")+" " + LLTrans::getString("InvOfferOwnedBy") + first_name + " " + last_name;
+				chatHistory_string = mFromName + " " + LLTrans::getString("InvOfferOwnedBy") + " " + first_name + " " + last_name;
+			}
+			else
+			{
+				from_string = LLTrans::getString("InvOfferAnObjectNamed") + " "+LLTrans::getString("'") 
+				            + mFromName + LLTrans::getString("'")+" " + LLTrans::getString("InvOfferOwnedByUnknownUser");
+				chatHistory_string = mFromName + " " + LLTrans::getString("InvOfferOwnedByUnknownUser");
+			}
+		}
+	}
+	else
+	{
+		from_string = chatHistory_string = mFromName;
+	}
+	
+	bool busy=FALSE;
+	
+	switch(button)
+	{
+	case IOR_ACCEPT:
+		// ACCEPT. The math for the dialog works, because the accept
+		// for inventory_offered, task_inventory_offer or
+		// group_notice_inventory is 1 greater than the offer integer value.
+		// Generates IM_INVENTORY_ACCEPTED, IM_TASK_INVENTORY_ACCEPTED, 
+		// or IM_GROUP_NOTICE_INVENTORY_ACCEPTED
+		msg->addU8Fast(_PREHASH_Dialog, (U8)(mIM + 1));
+		msg->addBinaryDataFast(_PREHASH_BinaryBucket, &(mFolderID.mData),
+					 sizeof(mFolderID.mData));
+		// send the message
+		msg->sendReliable(mHost);
+
+		//don't spam them if they are getting flooded
+		if (check_offer_throttle(mFromName, true))
+		{
+			log_message = chatHistory_string + " " + LLTrans::getString("InvOfferGaveYou") + " " + mDesc + LLTrans::getString(".");
+ 			chat.mText = log_message;
+ 			LLFloaterChat::addChatHistory(chat);
+		}
+
+		// we will want to open this item when it comes back.
+		LL_DEBUGS("Messaging") << "Initializing an opener for tid: " << mTransactionID
+				 << LL_ENDL;
+		switch (mIM)
+		{
+		case IM_INVENTORY_OFFERED:
+		{
+			// This is an offer from an agent. In this case, the back
+			// end has already copied the items into your inventory,
+			// so we can fetch it out of our inventory.
+			LLInventoryFetchObserver::item_ref_t items;
+			items.push_back(mObjectID);
+			LLOpenAgentOffer* open_agent_offer = new LLOpenAgentOffer(from_string);
+			open_agent_offer->fetchItems(items);
+			if(catp || (itemp && itemp->isComplete()))
+			{
+				open_agent_offer->done();
+			}
+			else
+			{
+				opener = open_agent_offer;
+			}
+		}
+			break;
+		case IM_TASK_INVENTORY_OFFERED:
+		case IM_GROUP_NOTICE:
+		case IM_GROUP_NOTICE_REQUESTED:
+		{
+			// This is an offer from a task or group.
+			// We don't use a new instance of an opener
+			// We instead use the singular observer gOpenTaskOffer
+			// Since it already exists, we don't need to actually do anything
+		}
+		break;
+		default:
+			LL_WARNS("Messaging") << "inventory_offer_callback: unknown offer type" << LL_ENDL;
+			break;
+		}	// end switch (mIM)
+		break;
+
+	case IOR_BUSY:
+		//Busy falls through to decline.  Says to make busy message.
+		busy=TRUE;
+	case IOR_MUTE:
+		// MUTE falls through to decline
+	case IOR_DECLINE:
+		// DECLINE. The math for the dialog works, because the decline
+		// for inventory_offered, task_inventory_offer or
+		// group_notice_inventory is 2 greater than the offer integer value.
+		// Generates IM_INVENTORY_DECLINED, IM_TASK_INVENTORY_DECLINED,
+		// or IM_GROUP_NOTICE_INVENTORY_DECLINED
+	default:
+		// close button probably (or any of the fall-throughs from above)
+		msg->addU8Fast(_PREHASH_Dialog, (U8)(mIM + 2));
+		msg->addBinaryDataFast(_PREHASH_BinaryBucket, EMPTY_BINARY_BUCKET, EMPTY_BINARY_BUCKET_SIZE);
+		// send the message
+		msg->sendReliable(mHost);
+
+		log_message = LLTrans::getString("InvOfferYouDecline") + " " + mDesc + " " + LLTrans::getString("InvOfferFrom") + " " + mFromName +".";
+		chat.mText = log_message;
+		if( LLMuteList::getInstance()->isMuted(mFromID ) && ! LLMuteList::getInstance()->isLinden(mFromName) )  // muting for SL-42269
+		{
+			chat.mMuted = TRUE;
+		}
+		LLFloaterChat::addChatHistory(chat);
+
+		// If it's from an agent, we have to fetch the item to throw
+		// it away. If it's from a task or group, just denying the 
+		// request will suffice to discard the item.
+		if(IM_INVENTORY_OFFERED == mIM)
+		{
+			LLInventoryFetchComboObserver::folder_ref_t folders;
+			LLInventoryFetchComboObserver::item_ref_t items;
+			items.push_back(mObjectID);
+			LLDiscardAgentOffer* discard_agent_offer;
+			discard_agent_offer = new LLDiscardAgentOffer(mFolderID, mObjectID);
+			discard_agent_offer->fetch(folders, items);
+			if(catp || (itemp && itemp->isComplete()))
+			{
+				discard_agent_offer->done();
+			}
+			else
+			{
+				opener = discard_agent_offer;
+			}
+			
+		}
+		if (busy &&	(!mFromGroup && !mFromObject))
+		{
+			busy_message(msg,mFromID);
+		}
+		break;
+	}
+
+	if(IM_INVENTORY_OFFERED == mIM)
+	{
+		// add buddy to recent people list
+		LLRecentPeople::instance().add(mFromID);
+	}
+
+	if(opener)
+	{
+		gInventory.addObserver(opener);
+	}
+
+	delete this;
+	return false;
+}
+
+
+void inventory_offer_handler(LLOfferInfo* info, BOOL from_task)
+{
+	//Until throttling is implmented, busy mode should reject inventory instead of silently
+	//accepting it.  SEE SL-39554
+	if (gAgent.getBusy())
+	{
+		info->forceResponse(IOR_BUSY);
+		return;
+	}
+	
+	//If muted, don't even go through the messaging stuff.  Just curtail the offer here.
+	if (LLMuteList::getInstance()->isMuted(info->mFromID, info->mFromName))
+	{
+		info->forceResponse(IOR_MUTE);
+		return;
+	}
+
+	// Avoid the Accept/Discard dialog if the user so desires. JC
+	if (gSavedSettings.getBOOL("AutoAcceptNewInventory")
+		&& (info->mType == LLAssetType::AT_NOTECARD
+			|| info->mType == LLAssetType::AT_LANDMARK
+			|| info->mType == LLAssetType::AT_TEXTURE))
+	{
+		// For certain types, just accept the items into the inventory,
+		// and possibly open them on receipt depending upon "ShowNewInventory".
+		info->forceResponse(IOR_ACCEPT);
+		return;
+	}
+
+	// Strip any SLURL from the message display. (DEV-2754)
+	std::string msg = info->mDesc;
+	int indx = msg.find(" ( http://slurl.com/secondlife/");
+	if(indx >= 0)
+	{
+		LLStringUtil::truncate(msg, indx);
+	}
+	
+	LLSD args;
+	args["[OBJECTNAME]"] = msg;
+
+	LLSD payload;
+
+	// must protect against a NULL return from lookupHumanReadable()
+	std::string typestr = ll_safe_string(LLAssetType::lookupHumanReadable(info->mType));
+	if (!typestr.empty())
+	{
+		args["OBJECTTYPE"] = typestr;
+	}
+	else
+	{
+		LL_WARNS("Messaging") << "LLAssetType::lookupHumanReadable() returned NULL - probably bad asset type: " << info->mType << LL_ENDL;
+		args["OBJECTTYPE"] = "";
+
+		// This seems safest, rather than propagating bogosity
+		LL_WARNS("Messaging") << "Forcing an inventory-decline for probably-bad asset type." << LL_ENDL;
+		info->forceResponse(IOR_DECLINE);
+		return;
+	}
+
+	// Name cache callbacks don't store userdata, so can't save
+	// off the LLOfferInfo.  Argh.
+	BOOL name_found = FALSE;
+	if (info->mFromGroup)
+	{
+		std::string group_name;
+		if (gCacheName->getGroupName(info->mFromID, group_name))
+		{
+			args["FIRST"] = group_name;
+			args["LAST"] = "";
+			name_found = TRUE;
+		}
+	}
+	else
+	{
+		std::string first_name, last_name;
+		if (gCacheName->getName(info->mFromID, first_name, last_name))
+		{
+			args["FIRST"] = first_name;
+			args["LAST"] = last_name;
+			name_found = TRUE;
+		}
+	}
+
+	payload["from_id"] = info->mFromID;
+	args["OBJECTFROMNAME"] = info->mFromName;
+	args["NAME"] = info->mFromName;
+
+	LLNotification::Params p("ObjectGiveItem");
+	p.substitutions(args).payload(payload).functor.function(boost::bind(&LLOfferInfo::inventory_offer_callback, info, _1, _2));
+
+	if (from_task)
+	{
+		p.name = name_found ? "ObjectGiveItem" : "ObjectGiveItemUnknownUser";
+	}
+	else
+	{
+		p.name = "UserGiveItem";
+	}
+
+	LLNotifications::instance().add(p);
+}
+
+bool lure_callback(const LLSD& notification, const LLSD& response)
+{
+	S32 option = 0;
+	if (response.isInteger()) 
+	{
+		option = response.asInteger();
+	}
+	else
+	{
+		option = LLNotification::getSelectedOption(notification, response);
+	}
+	
+	LLUUID from_id = notification["payload"]["from_id"].asUUID();
+	LLUUID lure_id = notification["payload"]["lure_id"].asUUID();
+	BOOL godlike = notification["payload"]["godlike"].asBoolean();
+
+	switch(option)
+	{
+	case 0:
+		{
+			// accept
+			gAgent.teleportViaLure(lure_id, godlike);
+		}
+		break;
+	case 1:
+	default:
+		// decline
+		send_simple_im(from_id,
+					   LLStringUtil::null,
+					   IM_LURE_DECLINED,
+					   lure_id);
+		break;
+	}
+	return false;
+}
+static LLNotificationFunctorRegistration lure_callback_reg("TeleportOffered", lure_callback);
+
+bool goto_url_callback(const LLSD& notification, const LLSD& response)
+{
+	std::string url = notification["payload"]["url"].asString();
+	S32 option = LLNotification::getSelectedOption(notification, response);
+	if(1 == option)
+	{
+		LLWeb::loadURL(url);
+	}
+	return false;
+}
+static LLNotificationFunctorRegistration goto_url_callback_reg("GotoURL", goto_url_callback);
+
+void process_improved_im(LLMessageSystem *msg, void **user_data)
+{
+	if (gNoRender)
+	{
+		return;
+	}
+	LLUUID from_id;
+	BOOL from_group;
+	LLUUID to_id;
+	U8 offline;
+	U8 d = 0;
+	LLUUID session_id;
+	U32 timestamp;
+	std::string name;
+	std::string message;
+	U32 parent_estate_id = 0;
+	LLUUID region_id;
+	LLVector3 position;
+	U8 binary_bucket[MTUBYTES];
+	S32 binary_bucket_size;
+	LLChat chat;
+	std::string buffer;
+	
+	// *TODO: Translate - need to fix the full name to first/last (maybe)
+	msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, from_id);
+	msg->getBOOLFast(_PREHASH_MessageBlock, _PREHASH_FromGroup, from_group);
+	msg->getUUIDFast(_PREHASH_MessageBlock, _PREHASH_ToAgentID, to_id);
+	msg->getU8Fast(  _PREHASH_MessageBlock, _PREHASH_Offline, offline);
+	msg->getU8Fast(  _PREHASH_MessageBlock, _PREHASH_Dialog, d);
+	msg->getUUIDFast(_PREHASH_MessageBlock, _PREHASH_ID, session_id);
+	msg->getU32Fast( _PREHASH_MessageBlock, _PREHASH_Timestamp, timestamp);
+	//msg->getData("MessageBlock", "Count",		&count);
+	msg->getStringFast(_PREHASH_MessageBlock, _PREHASH_FromAgentName, name);
+	msg->getStringFast(_PREHASH_MessageBlock, _PREHASH_Message,		message);
+	msg->getU32Fast(_PREHASH_MessageBlock, _PREHASH_ParentEstateID, parent_estate_id);
+	msg->getUUIDFast(_PREHASH_MessageBlock, _PREHASH_RegionID, region_id);
+	msg->getVector3Fast(_PREHASH_MessageBlock, _PREHASH_Position, position);
+	msg->getBinaryDataFast(  _PREHASH_MessageBlock, _PREHASH_BinaryBucket, binary_bucket, 0, 0, MTUBYTES);
+	binary_bucket_size = msg->getSizeFast(_PREHASH_MessageBlock, _PREHASH_BinaryBucket);
+	EInstantMessage dialog = (EInstantMessage)d;
+
+    // make sure that we don't have an empty or all-whitespace name
+	LLStringUtil::trim(name);
+	if (name.empty())
+	{
+        name = LLTrans::getString("Unnamed");
+	}
+
+	BOOL is_busy = gAgent.getBusy();
+	BOOL is_muted = LLMuteList::getInstance()->isMuted(from_id, name, LLMute::flagTextChat);
+	BOOL is_linden = LLMuteList::getInstance()->isLinden(name);
+	BOOL is_owned_by_me = FALSE;
+	BOOL is_friend = (LLAvatarTracker::instance().getBuddyInfo(from_id) == NULL) ? false : true;
+	BOOL accept_im_from_only_friend = gSavedSettings.getBOOL("VoiceCallsFriendsOnly");
+	
+	chat.mMuted = is_muted && !is_linden;
+	chat.mFromID = from_id;
+	chat.mFromName = name;
+	chat.mSourceType = (from_id.isNull() || (name == std::string(SYSTEM_FROM))) ? CHAT_SOURCE_SYSTEM : CHAT_SOURCE_AGENT;
+
+	LLViewerObject *source = gObjectList.findObject(session_id); //Session ID is probably the wrong thing.
+	if (source)
+	{
+		is_owned_by_me = source->permYouOwner();
+	}
+
+	std::string separator_string(": ");
+	int message_offset = 0;
+
+		//Handle IRC styled /me messages.
+	std::string prefix = message.substr(0, 4);
+	if (prefix == "/me " || prefix == "/me'")
+	{
+		separator_string = "";
+		message_offset = 3;
+	}
+
+	LLSD args;
+	switch(dialog)
+	{
+	case IM_CONSOLE_AND_CHAT_HISTORY:
+		// These are used for system messages, hence don't need the name,
+		// as it is always "Second Life".
+	  	// *TODO: Translate
+		args["MESSAGE"] = message;
+
+		// Note: don't put the message in the IM history, even though was sent
+		// via the IM mechanism.
+		LLNotifications::instance().add("SystemMessageTip",args);
+		break;
+
+	case IM_NOTHING_SPECIAL: 
+		// Don't show dialog, just do IM
+		if (!gAgent.isGodlike()
+				&& gAgent.getRegion()->isPrelude() 
+				&& to_id.isNull() )
+		{
+			// do nothing -- don't distract newbies in
+			// Prelude with global IMs
+		}
+		else if (offline == IM_ONLINE && !is_linden && is_busy && name != SYSTEM_FROM)
+		{
+			// return a standard "busy" message, but only do it to online IM 
+			// (i.e. not other auto responses and not store-and-forward IM)
+			if (!gIMMgr->hasSession(session_id))
+			{
+				// if there is not a panel for this conversation (i.e. it is a new IM conversation
+				// initiated by the other party) then...
+				std::string my_name;
+				LLAgentUI::buildFullname(my_name);
+				std::string response = gSavedPerAccountSettings.getString("BusyModeResponse2");
+				pack_instant_message(
+					gMessageSystem,
+					gAgent.getID(),
+					FALSE,
+					gAgent.getSessionID(),
+					from_id,
+					my_name,
+					response,
+					IM_ONLINE,
+					IM_BUSY_AUTO_RESPONSE,
+					session_id);
+				gAgent.sendReliableMessage();
+			}
+
+			// now store incoming IM in chat history
+
+			buffer = message.substr(message_offset);
+	
+			LL_INFOS("Messaging") << "process_improved_im: session_id( " << session_id << " ), from_id( " << from_id << " )" << LL_ENDL;
+
+			// add to IM panel, but do not bother the user
+			gIMMgr->addMessage(
+				session_id,
+				from_id,
+				name,
+				buffer,
+				LLStringUtil::null,
+				dialog,
+				parent_estate_id,
+				region_id,
+				position,
+				true);
+
+			// pretend this is chat generated by self, so it does not show up on screen
+			chat.mText = std::string("IM: ") + name + separator_string + message.substr(message_offset);
+			LLFloaterChat::addChat( chat, TRUE, TRUE );
+		}
+		else if (from_id.isNull())
+		{
+			// Messages from "Second Life" ID don't go to IM history
+			// messages which should be routed to IM window come from a user ID with name=SYSTEM_NAME
+			chat.mText = name + ": " + message;
+			LLFloaterChat::addChat(chat, FALSE, FALSE);
+		}
+		else if (to_id.isNull())
+		{
+			// Message to everyone from GOD
+			args["NAME"] = name;
+			args["MESSAGE"] = message;
+			LLNotifications::instance().add("GodMessage", args);
+
+			// Treat like a system message and put in chat history.
+			// Claim to be from a local agent so it doesn't go into
+			// console.
+			chat.mText = name + separator_string + message.substr(message_offset);
+			BOOL local_agent = TRUE;
+			LLFloaterChat::addChat(chat, FALSE, local_agent);
+		}
+		else
+		{
+			// standard message, not from system
+			std::string saved;
+			if(offline == IM_OFFLINE)
+			{
+				saved = llformat("(Saved %s) ", formatted_time(timestamp).c_str());
+			}
+			buffer = saved + message.substr(message_offset);
+
+			LL_INFOS("Messaging") << "process_improved_im: session_id( " << session_id << " ), from_id( " << from_id << " )" << LL_ENDL;
+
+			bool mute_im = is_muted;
+			if(accept_im_from_only_friend&&!is_friend)
+			{
+				mute_im = true;
+			}
+			if (!mute_im || is_linden) 
+			{
+				gIMMgr->addMessage(
+					session_id,
+					from_id,
+					name,
+					buffer,
+					LLStringUtil::null,
+					dialog,
+					parent_estate_id,
+					region_id,
+					position,
+					true);
+				chat.mText = std::string("IM: ") + name + separator_string + saved + message.substr(message_offset);
+
+				BOOL local_agent = FALSE;
+				LLFloaterChat::addChat( chat, TRUE, local_agent );
+			}
+			else
+			{
+				// muted user, so don't start an IM session, just record line in chat
+				// history.  Pretend the chat is from a local agent,
+				// so it will go into the history but not be shown on screen.
+				chat.mText = buffer;
+				BOOL local_agent = TRUE;
+				LLFloaterChat::addChat( chat, TRUE, local_agent );
+			}
+		}
+		break;
+
+	case IM_TYPING_START:
+		{
+			LLPointer<LLIMInfo> im_info = new LLIMInfo(gMessageSystem);
+			gIMMgr->processIMTypingStart(im_info);
+		}
+		break;
+
+	case IM_TYPING_STOP:
+		{
+			LLPointer<LLIMInfo> im_info = new LLIMInfo(gMessageSystem);
+			gIMMgr->processIMTypingStop(im_info);
+		}
+		break;
+
+	case IM_MESSAGEBOX:
+		{
+			// This is a block, modeless dialog.
+			//*TODO: Translate
+			args["MESSAGE"] = message;
+			LLNotifications::instance().add("SystemMessage", args);
+		}
+		break;
+	case IM_GROUP_NOTICE:
+	case IM_GROUP_NOTICE_REQUESTED:
+		{
+			LL_INFOS("Messaging") << "Received IM_GROUP_NOTICE message." << LL_ENDL;
+			// Read the binary bucket for more information.
+			struct notice_bucket_header_t
+			{
+				U8 has_inventory;
+				U8 asset_type;
+				LLUUID group_id;
+			};
+			struct notice_bucket_full_t
+			{
+				struct notice_bucket_header_t header;
+				U8 item_name[DB_INV_ITEM_NAME_BUF_SIZE];
+			}* notice_bin_bucket;
+
+			// Make sure the binary bucket is big enough to hold the header 
+			// and a null terminated item name.
+			if ( (binary_bucket_size < (S32)((sizeof(notice_bucket_header_t) + sizeof(U8))))
+				|| (binary_bucket[binary_bucket_size - 1] != '\0') )
+			{
+				LL_WARNS("Messaging") << "Malformed group notice binary bucket" << LL_ENDL;
+				break;
+			}
+
+			notice_bin_bucket = (struct notice_bucket_full_t*) &binary_bucket[0];
+			U8 has_inventory = notice_bin_bucket->header.has_inventory;
+			U8 asset_type = notice_bin_bucket->header.asset_type;
+			LLUUID group_id = notice_bin_bucket->header.group_id;
+			std::string item_name = ll_safe_string((const char*) notice_bin_bucket->item_name);
+
+			// If there is inventory, give the user the inventory offer.
+			LLOfferInfo* info = NULL;
+
+			if (has_inventory)
+			{
+				info = new LLOfferInfo;
+				
+				info->mIM = IM_GROUP_NOTICE;
+				info->mFromID = from_id;
+				info->mFromGroup = from_group;
+				info->mTransactionID = session_id;
+				info->mType = (LLAssetType::EType) asset_type;
+				info->mFolderID = gInventory.findCategoryUUIDForType(info->mType);
+				std::string from_name;
+
+				from_name += "A group member named ";
+				from_name += name;
+
+				info->mFromName = from_name;
+				info->mDesc = item_name;
+				info->mHost = msg->getSender();
+			}
+			
+			std::string str(message);
+
+			// Tokenize the string.
+			// TODO: Support escaped tokens ("||" -> "|")
+			typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
+			boost::char_separator<char> sep("|","",boost::keep_empty_tokens);
+			tokenizer tokens(str, sep);
+			tokenizer::iterator iter = tokens.begin();
+
+			std::string subj(*iter++);
+			std::string mes(*iter++);
+
+			// Send the notification down the new path.
+			// For requested notices, we don't want to send the popups.
+			if (dialog != IM_GROUP_NOTICE_REQUESTED)
+			{
+				LLSD payload;
+				payload["subject"] = subj;
+				payload["message"] = mes;
+				payload["sender_name"] = name;
+				payload["group_id"] = group_id;
+				payload["inventory_name"] = item_name;
+				payload["inventory_offer"] = info ? info->asLLSD() : LLSD();
+
+				LLSD args;
+				args["SUBJECT"] = subj;
+				args["MESSAGE"] = mes;
+				LLNotifications::instance().add(LLNotification::Params("GroupNotice").substitutions(args).payload(payload).time_stamp(timestamp));
+			}
+
+			// Also send down the old path for now.
+			if (IM_GROUP_NOTICE_REQUESTED == dialog)
+			{
+				
+				LLPanelGroup::showNotice(subj,mes,group_id,has_inventory,item_name,info);
+			}
+		}
+		break;
+	case IM_GROUP_INVITATION:
+		{
+			//if (!is_linden && (is_busy || is_muted))
+			if ((is_busy || is_muted))
+			{
+				LLMessageSystem *msg = gMessageSystem;
+				busy_message(msg,from_id);
+			}
+			else
+			{
+				LL_INFOS("Messaging") << "Received IM_GROUP_INVITATION message." << LL_ENDL;
+				// Read the binary bucket for more information.
+				struct invite_bucket_t
+				{
+					S32 membership_fee;
+					LLUUID role_id;
+				}* invite_bucket;
+
+				// Make sure the binary bucket is the correct size.
+				if (binary_bucket_size != sizeof(invite_bucket_t))
+				{
+					LL_WARNS("Messaging") << "Malformed group invite binary bucket" << LL_ENDL;
+					break;
+				}
+
+				invite_bucket = (struct invite_bucket_t*) &binary_bucket[0];
+				S32 membership_fee = ntohl(invite_bucket->membership_fee);
+
+				LLSD payload;
+				payload["transaction_id"] = session_id;
+				payload["group_id"] = from_id;
+				payload["name"] = name;
+				payload["message"] = message;
+				payload["fee"] = membership_fee;
+
+				LLSD args;
+				args["MESSAGE"] = message;
+				LLNotifications::instance().add("JoinGroup", args, payload, join_group_response);
+			}
+		}
+		break;
+
+	case IM_INVENTORY_OFFERED:
+	case IM_TASK_INVENTORY_OFFERED:
+		// Someone has offered us some inventory.
+		{
+			LLOfferInfo* info = new LLOfferInfo;
+			bool mute_im = false;
+			if (IM_INVENTORY_OFFERED == dialog)
+			{
+				struct offer_agent_bucket_t
+				{
+					S8		asset_type;
+					LLUUID	object_id;
+				}* bucketp;
+
+				if (sizeof(offer_agent_bucket_t) != binary_bucket_size)
+				{
+					LL_WARNS("Messaging") << "Malformed inventory offer from agent" << LL_ENDL;
+					break;
+				}
+				bucketp = (struct offer_agent_bucket_t*) &binary_bucket[0];
+				info->mType = (LLAssetType::EType) bucketp->asset_type;
+				info->mObjectID = bucketp->object_id;
+				
+				if(accept_im_from_only_friend&&!is_friend)
+				{
+					mute_im = true;
+				}
+			}
+			else
+			{
+				if (sizeof(S8) != binary_bucket_size)
+				{
+					LL_WARNS("Messaging") << "Malformed inventory offer from object" << LL_ENDL;
+					break;
+				}
+				info->mType = (LLAssetType::EType) binary_bucket[0];
+				info->mObjectID = LLUUID::null;
+			}
+
+			info->mIM = dialog;
+			info->mFromID = from_id;
+			info->mFromGroup = from_group;
+			info->mTransactionID = session_id;
+			info->mFolderID = gInventory.findCategoryUUIDForType(info->mType);
+
+			if (dialog == IM_TASK_INVENTORY_OFFERED)
+			{
+				info->mFromObject = TRUE;
+			}
+			else
+			{
+				info->mFromObject = FALSE;
+			}
+			info->mFromName = name;
+			info->mDesc = message;
+			info->mHost = msg->getSender();
+			//if (((is_busy && !is_owned_by_me) || is_muted))
+			if ( is_muted || mute_im)
+			{
+				// Same as closing window
+				info->forceResponse(IOR_DECLINE);
+			}
+			else
+			{
+				inventory_offer_handler(info, dialog == IM_TASK_INVENTORY_OFFERED);
+			}
+		}
+		break;
+
+	case IM_INVENTORY_ACCEPTED:
+	{
+		args["NAME"] = name;
+		LLNotifications::instance().add("InventoryAccepted", args);
+		break;
+	}
+	case IM_INVENTORY_DECLINED:
+	{
+		args["NAME"] = name;
+		LLNotifications::instance().add("InventoryDeclined", args);
+		break;
+	}
+	// TODO: _DEPRECATED suffix as part of vote removal - DEV-24856
+	case IM_GROUP_VOTE:
+		{
+			LL_WARNS("Messaging") << "Received IM: IM_GROUP_VOTE_DEPRECATED" << LL_ENDL;
+		}
+		break;
+
+	case IM_GROUP_ELECTION_DEPRECATED:
+	{
+		LL_WARNS("Messaging") << "Received IM: IM_GROUP_ELECTION_DEPRECATED" << LL_ENDL;
+	}
+	break;
+	
+	case IM_SESSION_SEND:
+	{
+		if (!is_linden && is_busy)
+		{
+			return;
+		}
+
+		// Only show messages if we have a session open (which
+		// should happen after you get an "invitation"
+		if ( !gIMMgr->hasSession(session_id) )
+		{
+			return;
+		}
+
+		// standard message, not from system
+		std::string saved;
+		if(offline == IM_OFFLINE)
+		{
+			saved = llformat("(Saved %s) ", formatted_time(timestamp).c_str());
+		}
+		buffer = saved + message.substr(message_offset);
+		BOOL is_this_agent = FALSE;
+		if(from_id == gAgentID)
+		{
+			is_this_agent = TRUE;
+		}
+		gIMMgr->addMessage(
+			session_id,
+			from_id,
+			name,
+			buffer,
+			ll_safe_string((char*)binary_bucket),
+			IM_SESSION_INVITE,
+			parent_estate_id,
+			region_id,
+			position,
+			true);
+
+		chat.mText = std::string("IM: ") + name + separator_string +  saved + message.substr(message_offset);
+		LLFloaterChat::addChat(chat, TRUE, is_this_agent);
+	}
+	break;
+
+	case IM_FROM_TASK:
+		{
+			if (is_busy && !is_owned_by_me)
+			{
+				return;
+			}
+
+			LLSD substitutions;
+			substitutions["MSG"] = message.substr(message_offset);
+			LLNotifications::instance().add("ServerObjectMessage", substitutions);
+		}
+		break;
+	case IM_FROM_TASK_AS_ALERT:
+		if (is_busy && !is_owned_by_me)
+		{
+			return;
+		}
+		{
+			// Construct a viewer alert for this message.
+			args["NAME"] = name;
+			args["MESSAGE"] = message;
+			LLNotifications::instance().add("ObjectMessage", args);
+		}
+		break;
+	case IM_BUSY_AUTO_RESPONSE:
+		if (is_muted)
+		{
+			LL_DEBUGS("Messaging") << "Ignoring busy response from " << from_id << LL_ENDL;
+			return;
+		}
+		else
+		{
+			// TODO: after LLTrans hits release, get "busy response" into translatable file
+			buffer = llformat("%s (%s): %s", name.c_str(), "busy response", message.substr(message_offset).c_str());
+			gIMMgr->addMessage(session_id, from_id, name, buffer);
+		}
+		break;
+		
+	case IM_LURE_USER:
+		{
+			if (is_muted)
+			{ 
+				return;
+			}
+			else if (is_busy) 
+			{
+				busy_message(msg,from_id);
+			}
+			else
+			{
+				LLSD args;
+				// *TODO: Translate -> [FIRST] [LAST] (maybe)
+				args["NAME"] = name;
+				args["MESSAGE"] = message;
+				LLSD payload;
+				payload["from_id"] = from_id;
+				payload["lure_id"] = session_id;
+				payload["godlike"] = FALSE;
+				LLNotifications::instance().add("TeleportOffered", args, payload);
+			}
+		}
+		break;
+
+	case IM_GODLIKE_LURE_USER:
+		{
+			LLSD payload;
+			payload["from_id"] = from_id;
+			payload["lure_id"] = session_id;
+			payload["godlike"] = TRUE;
+			// do not show a message box, because you're about to be
+			// teleported.
+			LLNotifications::instance().forceResponse(LLNotification::Params("TeleportOffered").payload(payload), 0);
+		}
+		break;
+
+	case IM_GOTO_URL:
+		{
+			LLSD args;
+			// n.b. this is for URLs sent by the system, not for
+			// URLs sent by scripts (i.e. llLoadURL)
+			if (binary_bucket_size <= 0)
+			{
+				LL_WARNS("Messaging") << "bad binary_bucket_size: "
+					<< binary_bucket_size
+					<< " - aborting function." << LL_ENDL;
+				return;
+			}
+
+			std::string url;
+			
+			url.assign((char*)binary_bucket, binary_bucket_size-1);
+			args["MESSAGE"] = message;
+			args["URL"] = url;
+			LLSD payload;
+			payload["url"] = url;
+			LLNotifications::instance().add("GotoURL", args, payload );
+		}
+		break;
+
+	case IM_FRIENDSHIP_OFFERED:
+		{
+			LLSD payload;
+			payload["from_id"] = from_id;
+			payload["session_id"] = session_id;;
+			payload["online"] = (offline == IM_ONLINE);
+			payload["sender"] = msg->getSender().getIPandPort();
+
+			if (is_busy)
+			{
+				busy_message(msg, from_id);
+				LLNotifications::instance().forceResponse(LLNotification::Params("OfferFriendship").payload(payload), 1);
+			}
+			else if (is_muted)
+			{
+				LLNotifications::instance().forceResponse(LLNotification::Params("OfferFriendship").payload(payload), 1);
+			}
+			else
+			{
+				args["[NAME]"] = name;
+				if(message.empty())
+				{
+					//support for frienship offers from clients before July 2008
+				        LLNotifications::instance().add("OfferFriendshipNoMessage", args, payload);
+				}
+				else
+				{
+					args["[MESSAGE]"] = message;
+				        LLNotifications::instance().add("OfferFriendship", args, payload);
+				}
+			}
+		}
+		break;
+
+	case IM_FRIENDSHIP_ACCEPTED:
+		{
+			// In the case of an offline IM, the formFriendship() may be extraneous
+			// as the database should already include the relationship.  But it
+			// doesn't hurt for dupes.
+			LLAvatarTracker::formFriendship(from_id);
+			
+			std::vector<std::string> strings;
+			strings.push_back(from_id.asString());
+			send_generic_message("requestonlinenotification", strings);
+			
+			args["NAME"] = name;
+			LLNotifications::instance().add("FriendshipAccepted", args);
+		}
+		break;
+
+	case IM_FRIENDSHIP_DECLINED_DEPRECATED:
+	default:
+		LL_WARNS("Messaging") << "Instant message calling for unknown dialog "
+				<< (S32)dialog << LL_ENDL;
+		break;
+	}
+
+	LLWindow* viewer_window = gViewerWindow->getWindow();
+	if (viewer_window && viewer_window->getMinimized())
+	{
+		viewer_window->flashIcon(5.f);
+	}
+}
+
+void busy_message (LLMessageSystem* msg, LLUUID from_id) 
+{
+	if (gAgent.getBusy())
+	{
+		std::string my_name;
+		LLAgentUI::buildFullname(my_name);
+		std::string response = gSavedPerAccountSettings.getString("BusyModeResponse2");
+		pack_instant_message(
+			gMessageSystem,
+			gAgent.getID(),
+			FALSE,
+			gAgent.getSessionID(),
+			from_id,
+			my_name,
+			response,
+			IM_ONLINE,
+			IM_BUSY_AUTO_RESPONSE);
+		gAgent.sendReliableMessage();
+	}
+}
+
+bool callingcard_offer_callback(const LLSD& notification, const LLSD& response)
+{
+	S32 option = LLNotification::getSelectedOption(notification, response);
+	LLUUID fid;
+	LLUUID from_id;
+	LLMessageSystem* msg = gMessageSystem;
+	switch(option)
+	{
+	case 0:
+		// accept
+		msg->newMessageFast(_PREHASH_AcceptCallingCard);
+		msg->nextBlockFast(_PREHASH_AgentData);
+		msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+		msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+		msg->nextBlockFast(_PREHASH_TransactionBlock);
+		msg->addUUIDFast(_PREHASH_TransactionID, notification["payload"]["transaction_id"].asUUID());
+		fid = gInventory.findCategoryUUIDForType(LLAssetType::AT_CALLINGCARD);
+		msg->nextBlockFast(_PREHASH_FolderData);
+		msg->addUUIDFast(_PREHASH_FolderID, fid);
+		msg->sendReliable(LLHost(notification["payload"]["sender"].asString()));
+		break;
+	case 1:
+		// decline		
+		msg->newMessageFast(_PREHASH_DeclineCallingCard);
+		msg->nextBlockFast(_PREHASH_AgentData);
+		msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+		msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+		msg->nextBlockFast(_PREHASH_TransactionBlock);
+		msg->addUUIDFast(_PREHASH_TransactionID, notification["payload"]["transaction_id"].asUUID());
+		msg->sendReliable(LLHost(notification["payload"]["sender"].asString()));
+		busy_message(msg, notification["payload"]["source_id"].asUUID());
+		break;
+	default:
+		// close button probably, possibly timed out
+		break;
+	}
+
+	return false;
+}
+static LLNotificationFunctorRegistration callingcard_offer_cb_reg("OfferCallingCard", callingcard_offer_callback);
+
+void process_offer_callingcard(LLMessageSystem* msg, void**)
+{
+	// someone has offered to form a friendship
+	LL_DEBUGS("Messaging") << "callingcard offer" << LL_ENDL;
+
+	LLUUID source_id;
+	msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, source_id);
+	LLUUID tid;
+	msg->getUUIDFast(_PREHASH_AgentBlock, _PREHASH_TransactionID, tid);
+
+	LLSD payload;
+	payload["transaction_id"] = tid;
+	payload["source_id"] = source_id;
+	payload["sender"] = msg->getSender().getIPandPort();
+
+	LLViewerObject* source = gObjectList.findObject(source_id);
+	LLSD args;
+	std::string source_name;
+	if(source && source->isAvatar())
+	{
+		LLNameValue* nvfirst = source->getNVPair("FirstName");
+		LLNameValue* nvlast  = source->getNVPair("LastName");
+		if (nvfirst && nvlast)
+		{
+			args["FIRST"] = nvfirst->getString();
+			args["LAST"] = nvlast->getString();
+			source_name = std::string(nvfirst->getString()) + " " + nvlast->getString();
+		}
+	}
+
+	if(!source_name.empty())
+	{
+		if (gAgent.getBusy() 
+			|| LLMuteList::getInstance()->isMuted(source_id, source_name, LLMute::flagTextChat))
+		{
+			// automatically decline offer
+			LLNotifications::instance().forceResponse(LLNotification::Params("OfferCallingCard").payload(payload), 1);
+		}
+		else
+		{
+			LLNotifications::instance().add("OfferCallingCard", args, payload);
+		}
+	}
+	else
+	{
+		LL_WARNS("Messaging") << "Calling card offer from an unknown source." << LL_ENDL;
+	}
+}
+
+void process_accept_callingcard(LLMessageSystem* msg, void**)
+{
+	LLNotifications::instance().add("CallingCardAccepted");
+}
+
+void process_decline_callingcard(LLMessageSystem* msg, void**)
+{
+	LLNotifications::instance().add("CallingCardDeclined");
+}
+
+
+void process_chat_from_simulator(LLMessageSystem *msg, void **user_data)
+{
+	LLChat		chat;
+	std::string		mesg;
+	std::string		from_name;
+	U8			source_temp;
+	U8			type_temp;
+	U8			audible_temp;
+	LLColor4	color(1.0f, 1.0f, 1.0f, 1.0f);
+	LLUUID		from_id;
+	LLUUID		owner_id;
+	BOOL		is_owned_by_me = FALSE;
+	LLViewerObject*	chatter;
+
+	msg->getString("ChatData", "FromName", from_name);
+	chat.mFromName = from_name;
+	
+	msg->getUUID("ChatData", "SourceID", from_id);
+	chat.mFromID = from_id;
+	
+	// Object owner for objects
+	msg->getUUID("ChatData", "OwnerID", owner_id);
+	
+	msg->getU8Fast(_PREHASH_ChatData, _PREHASH_SourceType, source_temp);
+	chat.mSourceType = (EChatSourceType)source_temp;
+
+	msg->getU8("ChatData", "ChatType", type_temp);
+	chat.mChatType = (EChatType)type_temp;
+
+	msg->getU8Fast(_PREHASH_ChatData, _PREHASH_Audible, audible_temp);
+	chat.mAudible = (EChatAudible)audible_temp;
+	
+	chat.mTime = LLFrameTimer::getElapsedSeconds();
+	
+	BOOL is_busy = gAgent.getBusy();
+
+	BOOL is_muted = FALSE;
+	BOOL is_linden = FALSE;
+	is_muted = LLMuteList::getInstance()->isMuted(
+		from_id,
+		from_name,
+		LLMute::flagTextChat) 
+		|| LLMuteList::getInstance()->isMuted(owner_id, LLMute::flagTextChat);
+	is_linden = chat.mSourceType != CHAT_SOURCE_OBJECT &&
+		LLMuteList::getInstance()->isLinden(from_name);
+
+	BOOL is_audible = (CHAT_AUDIBLE_FULLY == chat.mAudible);
+	chatter = gObjectList.findObject(from_id);
+	if (chatter)
+	{
+		chat.mPosAgent = chatter->getPositionAgent();
+		
+		// Make swirly things only for talking objects. (not script debug messages, though)
+		if (chat.mSourceType == CHAT_SOURCE_OBJECT 
+			&& chat.mChatType != CHAT_TYPE_DEBUG_MSG)
+		{
+			LLPointer<LLViewerPartSourceChat> psc = new LLViewerPartSourceChat(chatter->getPositionAgent());
+			psc->setSourceObject(chatter);
+			psc->setColor(color);
+			//We set the particles to be owned by the object's owner, 
+			//just in case they should be muted by the mute list
+			psc->setOwnerUUID(owner_id);
+			LLViewerPartSim::getInstance()->addPartSource(psc);
+		}
+
+		// record last audible utterance
+		if (is_audible
+			&& (is_linden || (!is_muted && !is_busy)))
+		{
+			if (chat.mChatType != CHAT_TYPE_START 
+				&& chat.mChatType != CHAT_TYPE_STOP)
+			{
+				gAgent.heardChat(chat.mFromID);
+			}
+		}
+
+		is_owned_by_me = chatter->permYouOwner();
+	}
+
+	if (is_audible)
+	{
+		BOOL visible_in_chat_bubble = FALSE;
+		std::string verb;
+
+		color.setVec(1.f,1.f,1.f,1.f);
+		msg->getStringFast(_PREHASH_ChatData, _PREHASH_Message, mesg);
+
+		BOOL ircstyle = FALSE;
+
+		// Look for IRC-style emotes here so chatbubbles work
+		std::string prefix = mesg.substr(0, 4);
+		if (prefix == "/me " || prefix == "/me'")
+		{
+			chat.mText = from_name;
+			chat.mText += mesg.substr(3);
+			ircstyle = TRUE;
+		}
+		else
+		{
+			chat.mText = mesg;
+		}
+
+		// Look for the start of typing so we can put "..." in the bubbles.
+		if (CHAT_TYPE_START == chat.mChatType)
+		{
+			LLLocalSpeakerMgr::getInstance()->setSpeakerTyping(from_id, TRUE);
+
+			// Might not have the avatar constructed yet, eg on login.
+			if (chatter && chatter->isAvatar())
+			{
+				((LLVOAvatar*)chatter)->startTyping();
+			}
+			return;
+		}
+		else if (CHAT_TYPE_STOP == chat.mChatType)
+		{
+			LLLocalSpeakerMgr::getInstance()->setSpeakerTyping(from_id, FALSE);
+
+			// Might not have the avatar constructed yet, eg on login.
+			if (chatter && chatter->isAvatar())
+			{
+				((LLVOAvatar*)chatter)->stopTyping();
+			}
+			return;
+		}
+
+		// We have a real utterance now, so can stop showing "..." and proceed.
+		if (chatter && chatter->isAvatar())
+		{
+			LLLocalSpeakerMgr::getInstance()->setSpeakerTyping(from_id, FALSE);
+			((LLVOAvatar*)chatter)->stopTyping();
+
+			if (!is_muted && !is_busy)
+			{
+				visible_in_chat_bubble = gSavedSettings.getBOOL("UseChatBubbles");
+				((LLVOAvatar*)chatter)->addChat(chat);
+			}
+		}
+
+		// Look for IRC-style emotes
+		if (ircstyle)
+		{
+			// set CHAT_STYLE_IRC to avoid adding Avatar Name as author of message. See EXT-656
+			chat.mChatStyle = CHAT_STYLE_IRC;
+
+			// Do nothing, ircstyle is fixed above for chat bubbles
+		}
+		else
+		{
+			switch(chat.mChatType)
+			{
+			case CHAT_TYPE_WHISPER:
+				verb = "(" + LLTrans::getString("whisper") + ")";
+				break;
+			case CHAT_TYPE_DEBUG_MSG:
+			case CHAT_TYPE_OWNER:
+			case CHAT_TYPE_NORMAL:
+				verb = "";
+				break;
+			case CHAT_TYPE_SHOUT:
+				verb = "(" + LLTrans::getString("shout") + ")";
+				break;
+			case CHAT_TYPE_START:
+			case CHAT_TYPE_STOP:
+				LL_WARNS("Messaging") << "Got chat type start/stop in main chat processing." << LL_ENDL;
+				break;
+			default:
+				LL_WARNS("Messaging") << "Unknown type " << chat.mChatType << " in chat!" << LL_ENDL;
+				verb = "";
+				break;
+			}
+
+
+			chat.mText = "";
+			chat.mText += verb;
+			chat.mText += mesg;
+		}
+		
+		if (chatter)
+		{
+			chat.mPosAgent = chatter->getPositionAgent();
+		}
+
+		// truth table:
+		// LINDEN	BUSY	MUTED	OWNED_BY_YOU	TASK		DISPLAY		STORE IN HISTORY
+		// F		F		F		F				*			Yes			Yes
+		// F		F		F		T				*			Yes			Yes
+		// F		F		T		F				*			No			No
+		// F		F		T		T				*			No			No
+		// F		T		F		F				*			No			Yes
+		// F		T		F		T				*			Yes			Yes
+		// F		T		T		F				*			No			No
+		// F		T		T		T				*			No			No
+		// T		*		*		*				F			Yes			Yes
+
+		chat.mMuted = is_muted && !is_linden;
+
+		if (!visible_in_chat_bubble 
+			&& (is_linden || !is_busy || is_owned_by_me))
+		{
+			// show on screen and add to history
+			LLNotificationsUI::LLNotificationManager::instance().onChat(
+					chat, LLNotificationsUI::NT_NEARBYCHAT);
+
+            // adding temporarily so that communications window chat bar 
+            // works until the new chat window is ready
+			chat.mText = from_name + ": " + chat.mText;
+			LLFloaterChat::addChat(chat, FALSE, FALSE);
+		}
+		else
+		{
+			LLNotificationsUI::LLNotificationManager::instance().onChat(
+					chat, LLNotificationsUI::NT_NEARBYCHAT);
+			// adding temporarily
+			LLFloaterChat::addChatHistory(chat);
+		}
+	}
+}
+
+
+// Simulator we're on is informing the viewer that the agent
+// is starting to teleport (perhaps to another sim, perhaps to the 
+// same sim). If we initiated the teleport process by sending some kind 
+// of TeleportRequest, then this info is redundant, but if the sim 
+// initiated the teleport (via a script call, being killed, etc.) 
+// then this info is news to us.
+void process_teleport_start(LLMessageSystem *msg, void**)
+{
+	U32 teleport_flags = 0x0;
+	msg->getU32("Info", "TeleportFlags", teleport_flags);
+
+	if (teleport_flags & TELEPORT_FLAGS_DISABLE_CANCEL)
+	{
+		gViewerWindow->setProgressCancelButtonVisible(FALSE);
+	}
+	else
+	{
+		gViewerWindow->setProgressCancelButtonVisible(TRUE, LLTrans::getString("Cancel"));
+	}
+
+	// Freeze the UI and show progress bar
+	// Note: could add data here to differentiate between normal teleport and death.
+
+	if( gAgent.getTeleportState() == LLAgent::TELEPORT_NONE )
+	{
+		gTeleportDisplay = TRUE;
+		gAgent.setTeleportState( LLAgent::TELEPORT_START );
+		make_ui_sound("UISndTeleportOut");
+		
+		// Don't call LLFirstUse::useTeleport here because this could be
+		// due to being killed, which would send you home, not to a Telehub
+	}
+}
+
+void process_teleport_progress(LLMessageSystem* msg, void**)
+{
+	LLUUID agent_id;
+	msg->getUUID("AgentData", "AgentID", agent_id);
+	if((gAgent.getID() != agent_id)
+	   || (gAgent.getTeleportState() == LLAgent::TELEPORT_NONE))
+	{
+		LL_WARNS("Messaging") << "Unexpected teleport progress message." << LL_ENDL;
+		return;
+	}
+	U32 teleport_flags = 0x0;
+	msg->getU32("Info", "TeleportFlags", teleport_flags);
+	if (teleport_flags & TELEPORT_FLAGS_DISABLE_CANCEL)
+	{
+		gViewerWindow->setProgressCancelButtonVisible(FALSE);
+	}
+	else
+	{
+		gViewerWindow->setProgressCancelButtonVisible(TRUE, LLTrans::getString("Cancel"));
+	}
+	std::string buffer;
+	msg->getString("Info", "Message", buffer);
+	LL_DEBUGS("Messaging") << "teleport progress: " << buffer << LL_ENDL;
+
+	//Sorta hacky...default to using simulator raw messages
+	//if we don't find the coresponding mapping in our progress mappings
+	std::string message = buffer;
+
+	if (LLAgent::sTeleportProgressMessages.find(buffer) != 
+		LLAgent::sTeleportProgressMessages.end() )
+	{
+		message = LLAgent::sTeleportProgressMessages[buffer];
+	}
+
+	gAgent.setTeleportMessage(LLAgent::sTeleportProgressMessages[message]);
+}
+
+class LLFetchInWelcomeArea : public LLInventoryFetchDescendentsObserver
+{
+public:
+	LLFetchInWelcomeArea() {}
+	virtual void done()
+	{
+		LLIsType is_landmark(LLAssetType::AT_LANDMARK);
+		LLIsType is_card(LLAssetType::AT_CALLINGCARD);
+
+		LLInventoryModel::cat_array_t	card_cats;
+		LLInventoryModel::item_array_t	card_items;
+		LLInventoryModel::cat_array_t	land_cats;
+		LLInventoryModel::item_array_t	land_items;
+
+		folder_ref_t::iterator it = mCompleteFolders.begin();
+		folder_ref_t::iterator end = mCompleteFolders.end();
+		for(; it != end; ++it)
+		{
+			gInventory.collectDescendentsIf(
+				(*it),
+				land_cats,
+				land_items,
+				LLInventoryModel::EXCLUDE_TRASH,
+				is_landmark);
+			gInventory.collectDescendentsIf(
+				(*it),
+				card_cats,
+				card_items,
+				LLInventoryModel::EXCLUDE_TRASH,
+				is_card);
+		}
+		LLSD args;
+		if ( land_items.count() > 0 )
+		{	// Show notification that they can now teleport to landmarks.  Use a random landmark from the inventory
+			S32 random_land = ll_rand( land_items.count() - 1 );
+			args["NAME"] = land_items[random_land]->getName();
+			LLNotifications::instance().add("TeleportToLandmark",args);
+		}
+		if ( card_items.count() > 0 )
+		{	// Show notification that they can now contact people.  Use a random calling card from the inventory
+			S32 random_card = ll_rand( card_items.count() - 1 );
+			args["NAME"] = card_items[random_card]->getName();
+			LLNotifications::instance().add("TeleportToPerson",args);
+		}
+
+		gInventory.removeObserver(this);
+		delete this;
+	}
+};
+
+
+
+class LLPostTeleportNotifiers : public LLEventTimer 
+{
+public:
+	LLPostTeleportNotifiers();
+	virtual ~LLPostTeleportNotifiers();
+
+	//function to be called at the supplied frequency
+	virtual BOOL tick();
+};
+
+LLPostTeleportNotifiers::LLPostTeleportNotifiers() : LLEventTimer( 2.0 )
+{
+};
+
+LLPostTeleportNotifiers::~LLPostTeleportNotifiers()
+{
+}
+
+BOOL LLPostTeleportNotifiers::tick()
+{
+	BOOL all_done = FALSE;
+	if ( gAgent.getTeleportState() == LLAgent::TELEPORT_NONE )
+	{
+		// get callingcards and landmarks available to the user arriving.
+		LLInventoryFetchDescendentsObserver::folder_ref_t folders;
+		LLUUID folder_id;
+		folder_id = gInventory.findCategoryUUIDForType(LLAssetType::AT_CALLINGCARD);
+		if(folder_id.notNull()) 
+			folders.push_back(folder_id);
+		folder_id = gInventory.findCategoryUUIDForType(LLAssetType::AT_LANDMARK);
+		if(folder_id.notNull()) 
+			folders.push_back(folder_id);
+		if(!folders.empty())
+		{
+			LLFetchInWelcomeArea* fetcher = new LLFetchInWelcomeArea;
+			fetcher->fetchDescendents(folders);
+			if(fetcher->isEverythingComplete())
+			{
+				fetcher->done();
+			}
+			else
+			{
+				gInventory.addObserver(fetcher);
+			}
+		}
+		all_done = TRUE;
+	}
+
+	return all_done;
+}
+
+
+
+// Teleport notification from the simulator
+// We're going to pretend to be a new agent
+void process_teleport_finish(LLMessageSystem* msg, void**)
+{
+	LL_DEBUGS("Messaging") << "Got teleport location message" << LL_ENDL;
+	LLUUID agent_id;
+	msg->getUUIDFast(_PREHASH_Info, _PREHASH_AgentID, agent_id);
+	if (agent_id != gAgent.getID())
+	{
+		LL_WARNS("Messaging") << "Got teleport notification for wrong agent!" << LL_ENDL;
+		return;
+	}
+
+	// Do teleport effect for where you're leaving
+	// VEFFECT: TeleportStart
+	LLHUDEffectSpiral *effectp = (LLHUDEffectSpiral *)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_POINT, TRUE);
+	effectp->setPositionGlobal(gAgent.getPositionGlobal());
+	effectp->setColor(LLColor4U(gAgent.getEffectColor()));
+	LLHUDManager::getInstance()->sendEffects();
+
+	U32 location_id;
+	U32 sim_ip;
+	U16 sim_port;
+	LLVector3 pos, look_at;
+	U64 region_handle;
+	msg->getU32Fast(_PREHASH_Info, _PREHASH_LocationID, location_id);
+	msg->getIPAddrFast(_PREHASH_Info, _PREHASH_SimIP, sim_ip);
+	msg->getIPPortFast(_PREHASH_Info, _PREHASH_SimPort, sim_port);
+	//msg->getVector3Fast(_PREHASH_Info, _PREHASH_Position, pos);
+	//msg->getVector3Fast(_PREHASH_Info, _PREHASH_LookAt, look_at);
+	msg->getU64Fast(_PREHASH_Info, _PREHASH_RegionHandle, region_handle);
+	U32 teleport_flags;
+	msg->getU32Fast(_PREHASH_Info, _PREHASH_TeleportFlags, teleport_flags);
+	
+	
+	std::string seedCap;
+	msg->getStringFast(_PREHASH_Info, _PREHASH_SeedCapability, seedCap);
+
+	// update home location if we are teleporting out of prelude - specific to teleporting to welcome area 
+	if((teleport_flags & TELEPORT_FLAGS_SET_HOME_TO_TARGET)
+	   && (!gAgent.isGodlike()))
+	{
+		gAgent.setHomePosRegion(region_handle, pos);
+
+		// Create a timer that will send notices when teleporting is all finished.  Since this is 
+		// based on the LLEventTimer class, it will be managed by that class and not orphaned or leaked.
+		new LLPostTeleportNotifiers();
+	}
+
+	LLHost sim_host(sim_ip, sim_port);
+
+	// Viewer trusts the simulator.
+	gMessageSystem->enableCircuit(sim_host, TRUE);
+	LLViewerRegion* regionp =  LLWorld::getInstance()->addRegion(region_handle, sim_host);
+
+/*
+	// send camera update to new region
+	gAgent.updateCamera();
+
+	// likewise make sure the camera is behind the avatar
+	gAgent.resetView(TRUE);
+	LLVector3 shift_vector = regionp->getPosRegionFromGlobal(gAgent.getRegion()->getOriginGlobal());
+	gAgent.setRegion(regionp);
+	gObjectList.shiftObjects(shift_vector);
+
+	if (gAgent.getAvatarObject())
+	{
+		gAgent.getAvatarObject()->clearChatText();
+		gAgent.slamLookAt(look_at);
+	}
+	gAgent.setPositionAgent(pos);
+	gAssetStorage->setUpstream(sim);
+	gCacheName->setUpstream(sim);
+*/
+
+	// now, use the circuit info to tell simulator about us!
+	LL_INFOS("Messaging") << "process_teleport_finish() Enabling "
+			<< sim_host << " with code " << msg->mOurCircuitCode << LL_ENDL;
+	msg->newMessageFast(_PREHASH_UseCircuitCode);
+	msg->nextBlockFast(_PREHASH_CircuitCode);
+	msg->addU32Fast(_PREHASH_Code, msg->getOurCircuitCode());
+	msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+	msg->addUUIDFast(_PREHASH_ID, gAgent.getID());
+	msg->sendReliable(sim_host);
+
+	send_complete_agent_movement(sim_host);
+	gAgent.setTeleportState( LLAgent::TELEPORT_MOVING );
+	gAgent.setTeleportMessage(LLAgent::sTeleportProgressMessages["contacting"]);
+
+	regionp->setSeedCapability(seedCap);
+
+	// Don't send camera updates to the new region until we're
+	// actually there...
+
+
+	// Now do teleport effect for where you're going.
+	// VEFFECT: TeleportEnd
+	effectp = (LLHUDEffectSpiral *)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_POINT, TRUE);
+	effectp->setPositionGlobal(gAgent.getPositionGlobal());
+
+	effectp->setColor(LLColor4U(gAgent.getEffectColor()));
+	LLHUDManager::getInstance()->sendEffects();
+
+//	gTeleportDisplay = TRUE;
+//	gTeleportDisplayTimer.reset();
+//	gViewerWindow->setShowProgress(TRUE);
+}
+
+// stuff we have to do every time we get an AvatarInitComplete from a sim
+/*
+void process_avatar_init_complete(LLMessageSystem* msg, void**)
+{
+	LLVector3 agent_pos;
+	msg->getVector3Fast(_PREHASH_AvatarData, _PREHASH_Position, agent_pos);
+	agent_movement_complete(msg->getSender(), agent_pos);
+}
+*/
+
+void process_agent_movement_complete(LLMessageSystem* msg, void**)
+{
+	gAgentMovementCompleted = true;
+
+	LLUUID agent_id;
+	msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, agent_id);
+	LLUUID session_id;
+	msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_SessionID, session_id);
+	if((gAgent.getID() != agent_id) || (gAgent.getSessionID() != session_id))
+	{
+		LL_WARNS("Messaging") << "Incorrect id in process_agent_movement_complete()"
+				<< LL_ENDL;
+		return;
+	}
+
+	LL_DEBUGS("Messaging") << "process_agent_movement_complete()" << LL_ENDL;
+
+	// *TODO: check timestamp to make sure the movement compleation
+	// makes sense.
+	LLVector3 agent_pos;
+	msg->getVector3Fast(_PREHASH_Data, _PREHASH_Position, agent_pos);
+	LLVector3 look_at;
+	msg->getVector3Fast(_PREHASH_Data, _PREHASH_LookAt, look_at);
+	U64 region_handle;
+	msg->getU64Fast(_PREHASH_Data, _PREHASH_RegionHandle, region_handle);
+	
+	std::string version_channel;
+	msg->getString("SimData", "ChannelVersion", version_channel);
+
+	LLVOAvatar* avatarp = gAgent.getAvatarObject();
+	if (!avatarp)
+	{
+		// Could happen if you were immediately god-teleported away on login,
+		// maybe other cases.  Continue, but warn.
+		LL_WARNS("Messaging") << "agent_movement_complete() with NULL avatarp." << LL_ENDL;
+	}
+
+	F32 x, y;
+	from_region_handle(region_handle, &x, &y);
+	LLViewerRegion* regionp = LLWorld::getInstance()->getRegionFromHandle(region_handle);
+	if (!regionp)
+	{
+		if (gAgent.getRegion())
+		{
+			LL_WARNS("Messaging") << "current region " << gAgent.getRegion()->getOriginGlobal() << LL_ENDL;
+		}
+
+		LL_WARNS("Messaging") << "Agent being sent to invalid home region: " 
+			<< x << ":" << y 
+			<< " current pos " << gAgent.getPositionGlobal()
+			<< LL_ENDL;
+		LLAppViewer::instance()->forceDisconnect("You were sent to an invalid region.");
+		return;
+
+	}
+
+	LL_INFOS("Messaging") << "Changing home region to " << x << ":" << y << LL_ENDL;
+
+	// set our upstream host the new simulator and shuffle things as
+	// appropriate.
+	LLVector3 shift_vector = regionp->getPosRegionFromGlobal(
+		gAgent.getRegion()->getOriginGlobal());
+	gAgent.setRegion(regionp);
+	gObjectList.shiftObjects(shift_vector);
+	gAssetStorage->setUpstream(msg->getSender());
+	gCacheName->setUpstream(msg->getSender());
+	gViewerThrottle.sendToSim();
+	gViewerWindow->sendShapeToSim();
+
+	bool is_teleport = gAgent.getTeleportState() == LLAgent::TELEPORT_MOVING;
+
+	if( is_teleport )
+	{
+		// Force the camera back onto the agent, don't animate.
+		gAgent.setFocusOnAvatar(TRUE, FALSE);
+		gAgent.slamLookAt(look_at);
+		gAgent.updateCamera();
+
+		gAgent.setTeleportState( LLAgent::TELEPORT_START_ARRIVAL );
+
+		// set the appearance on teleport since the new sim does not
+		// know what you look like.
+		gAgent.sendAgentSetAppearance();
+
+		if (avatarp)
+		{
+			// Chat the "back" SLURL. (DEV-4907)
+			LLChat chat("Teleport completed from " + gAgent.getTeleportSourceSLURL());
+			chat.mSourceType = CHAT_SOURCE_SYSTEM;
+ 			LLFloaterChat::addChatHistory(chat);
+
+			// Set the new position
+			avatarp->setPositionAgent(agent_pos);
+			avatarp->clearChat();
+			avatarp->slamPosition();
+		}
+	}
+	else
+	{
+		// This is likely just the initial logging in phase.
+		gAgent.setTeleportState( LLAgent::TELEPORT_NONE );
+	}
+
+	if ( LLTracker::isTracking(NULL) )
+	{
+		// Check distance to beacon, if < 5m, remove beacon
+		LLVector3d beacon_pos = LLTracker::getTrackedPositionGlobal();
+		LLVector3 beacon_dir(agent_pos.mV[VX] - (F32)fmod(beacon_pos.mdV[VX], 256.0), agent_pos.mV[VY] - (F32)fmod(beacon_pos.mdV[VY], 256.0), 0);
+		if (beacon_dir.magVecSquared() < 25.f)
+		{
+			LLTracker::stopTracking(NULL);
+		}
+		else if ( is_teleport )
+		{
+			//look at the beacon
+			LLVector3 global_agent_pos = agent_pos;
+			global_agent_pos[0] += x;
+			global_agent_pos[1] += y;
+			look_at = (LLVector3)beacon_pos - global_agent_pos;
+			look_at.normVec();
+			gAgent.slamLookAt(look_at);
+		}
+	}
+
+	// TODO: Put back a check for flying status! DK 12/19/05
+	// Sim tells us whether the new position is off the ground
+	/*
+	if (teleport_flags & TELEPORT_FLAGS_IS_FLYING)
+	{
+		gAgent.setFlying(TRUE);
+	}
+	else
+	{
+		gAgent.setFlying(FALSE);
+	}
+	*/
+
+	send_agent_update(TRUE, TRUE);
+
+	if (gAgent.getRegion()->getBlockFly())
+	{
+		gAgent.setFlying(gAgent.canFly());
+	}
+
+	// force simulator to recognize busy state
+	if (gAgent.getBusy())
+	{
+		gAgent.setBusy();
+	}
+	else
+	{
+		gAgent.clearBusy();
+	}
+
+	if (avatarp)
+	{
+		avatarp->mFootPlane.clearVec();
+	}
+	
+	// send walk-vs-run status
+	gAgent.sendWalkRun(gAgent.getRunning() || gAgent.getAlwaysRun());
+
+	// If the server version has changed, display an info box and offer
+	// to display the release notes, unless this is the initial log in.
+	if (gLastVersionChannel == version_channel)
+	{
+		return;
+	}
+
+	if (!gLastVersionChannel.empty())
+	{
+		LLSD payload;
+		payload["message"] = version_channel;
+		LLNotifications::instance().add("ServerVersionChanged", LLSD(), payload, server_version_changed_callback);
+	}
+
+	gLastVersionChannel = version_channel;
+}
+
+bool server_version_changed_callback(const LLSD& notification, const LLSD& response)
+{
+	if(notification["payload"]["message"].asString() =="")
+		return false;
+	std::string url ="http://wiki.secondlife.com/wiki/Release_Notes/";
+	//parse the msg string
+	std::string server_version = notification["payload"]["message"].asString();
+	std::vector<std::string> s_vect;
+	boost::algorithm::split(s_vect, server_version, isspace);
+	for(U32 i = 0; i < s_vect.size(); i++)
+	{
+    	if (i != (s_vect.size() - 1))
+		{
+			if(i != (s_vect.size() - 2))
+			{
+			   url += s_vect[i] + "_";
+			}
+			else
+			{
+				url += s_vect[i] + "/";
+			}
+		}
+		else
+		{
+			url += s_vect[i].substr(0,4);
+		}
+	}
+	
+	LLWeb::loadURL(url);
+	return false;
+}
+
+
+void process_crossed_region(LLMessageSystem* msg, void**)
+{
+	LLUUID agent_id;
+	msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, agent_id);
+	LLUUID session_id;
+	msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_SessionID, session_id);
+	if((gAgent.getID() != agent_id) || (gAgent.getSessionID() != session_id))
+	{
+		LL_WARNS("Messaging") << "Incorrect id in process_crossed_region()"
+				<< LL_ENDL;
+		return;
+	}
+	LL_INFOS("Messaging") << "process_crossed_region()" << LL_ENDL;
+
+	U32 sim_ip;
+	msg->getIPAddrFast(_PREHASH_RegionData, _PREHASH_SimIP, sim_ip);
+	U16 sim_port;
+	msg->getIPPortFast(_PREHASH_RegionData, _PREHASH_SimPort, sim_port);
+	LLHost sim_host(sim_ip, sim_port);
+	U64 region_handle;
+	msg->getU64Fast(_PREHASH_RegionData, _PREHASH_RegionHandle, region_handle);
+	
+	std::string seedCap;
+	msg->getStringFast(_PREHASH_RegionData, _PREHASH_SeedCapability, seedCap);
+
+	send_complete_agent_movement(sim_host);
+
+	LLViewerRegion* regionp = LLWorld::getInstance()->addRegion(region_handle, sim_host);
+	regionp->setSeedCapability(seedCap);
+}
+
+
+
+// Sends avatar and camera information to simulator.
+// Sent roughly once per frame, or 20 times per second, whichever is less often
+
+const F32 THRESHOLD_HEAD_ROT_QDOT = 0.9997f;	// ~= 2.5 degrees -- if its less than this we need to update head_rot
+const F32 MAX_HEAD_ROT_QDOT = 0.99999f;			// ~= 0.5 degrees -- if its greater than this then no need to update head_rot
+												// between these values we delay the updates (but no more than one second)
+
+
+void send_agent_update(BOOL force_send, BOOL send_reliable)
+{
+	if (gAgent.getTeleportState() != LLAgent::TELEPORT_NONE)
+	{
+		// We don't care if they want to send an agent update, they're not allowed to until the simulator
+		// that's the target is ready to receive them (after avatar_init_complete is received)
+		return;
+	}
+
+	// We have already requested to log out.  Don't send agent updates.
+	if(LLAppViewer::instance()->logoutRequestSent())
+	{
+		return;
+	}
+
+	// no region to send update to
+	if(gAgent.getRegion() == NULL)
+	{
+		return;
+	}
+
+	const F32 TRANSLATE_THRESHOLD = 0.01f;
+
+	// NOTA BENE: This is (intentionally?) using the small angle sine approximation to test for rotation
+	//			  Plus, there is an extra 0.5 in the mix since the perpendicular between last_camera_at and getAtAxis() bisects cam_rot_change
+	//			  Thus, we're actually testing against 0.2 degrees
+	const F32 ROTATION_THRESHOLD = 0.1f * 2.f*F_PI/360.f;			//  Rotation thresh 0.2 deg, see note above
+
+	const U8 DUP_MSGS = 1;				//  HACK!  number of times to repeat data on motionless agent
+
+	//  Store data on last sent update so that if no changes, no send
+	static LLVector3 last_camera_pos_agent, 
+					 last_camera_at, 
+					 last_camera_left,
+					 last_camera_up;
+	
+	static LLVector3 cam_center_chg,
+					 cam_rot_chg;
+
+	static LLQuaternion last_head_rot;
+	static U32 last_control_flags = 0;
+	static U8 last_render_state;
+	static U8 duplicate_count = 0;
+	static F32 head_rot_chg = 1.0;
+	static U8 last_flags;
+
+	LLMessageSystem	*msg = gMessageSystem;
+	LLVector3		camera_pos_agent;				// local to avatar's region
+	U8				render_state;
+
+	LLQuaternion body_rotation = gAgent.getFrameAgent().getQuaternion();
+	LLQuaternion head_rotation = gAgent.getHeadRotation();
+
+	camera_pos_agent = gAgent.getCameraPositionAgent();
+
+	render_state = gAgent.getRenderState();
+
+	U32		control_flag_change = 0;
+	U8		flag_change = 0;
+
+	cam_center_chg = last_camera_pos_agent - camera_pos_agent;
+	cam_rot_chg = last_camera_at - LLViewerCamera::getInstance()->getAtAxis();
+
+	// If a modifier key is held down, turn off
+	// LBUTTON and ML_LBUTTON so that using the camera (alt-key) doesn't
+	// trigger a control event.
+	U32 control_flags = gAgent.getControlFlags();
+	MASK	key_mask = gKeyboard->currentMask(TRUE);
+	if (key_mask & MASK_ALT || key_mask & MASK_CONTROL)
+	{
+		control_flags &= ~(	AGENT_CONTROL_LBUTTON_DOWN |
+							AGENT_CONTROL_ML_LBUTTON_DOWN );
+		control_flags |= 	AGENT_CONTROL_LBUTTON_UP |
+							AGENT_CONTROL_ML_LBUTTON_UP ;
+	}
+
+	control_flag_change = last_control_flags ^ control_flags;
+
+	U8 flags = AU_FLAGS_NONE;
+	if (gAgent.isGroupTitleHidden())
+	{
+		flags |= AU_FLAGS_HIDETITLE;
+	}
+	if (gAgent.getAutoPilot())
+	{
+		flags |= AU_FLAGS_CLIENT_AUTOPILOT;
+	}
+
+	flag_change = last_flags ^ flags;
+
+	head_rot_chg = dot(last_head_rot, head_rotation);
+
+	if (force_send || 
+		(cam_center_chg.magVec() > TRANSLATE_THRESHOLD) || 
+		(head_rot_chg < THRESHOLD_HEAD_ROT_QDOT) ||	
+		(last_render_state != render_state) ||
+		(cam_rot_chg.magVec() > ROTATION_THRESHOLD) ||
+		control_flag_change != 0 ||
+		flag_change != 0)  
+	{
+/*
+		if (head_rot_chg < THRESHOLD_HEAD_ROT_QDOT)
+		{
+			//LL_INFOS("Messaging") << "head rot " << head_rotation << LL_ENDL;
+			LL_INFOS("Messaging") << "head_rot_chg = " << head_rot_chg << LL_ENDL;
+		}
+		if (cam_rot_chg.magVec() > ROTATION_THRESHOLD) 
+		{
+			LL_INFOS("Messaging") << "cam rot " <<  cam_rot_chg.magVec() << LL_ENDL;
+		}
+		if (cam_center_chg.magVec() > TRANSLATE_THRESHOLD)
+		{
+			LL_INFOS("Messaging") << "cam center " << cam_center_chg.magVec() << LL_ENDL;
+		}
+//		if (drag_delta_chg.magVec() > TRANSLATE_THRESHOLD)
+//		{
+//			LL_INFOS("Messaging") << "drag delta " << drag_delta_chg.magVec() << LL_ENDL;
+//		}
+		if (control_flag_change)
+		{
+			LL_INFOS("Messaging") << "dcf = " << control_flag_change << LL_ENDL;
+		}
+*/
+
+		duplicate_count = 0;
+	}
+	else
+	{
+		duplicate_count++;
+
+		if (head_rot_chg < MAX_HEAD_ROT_QDOT  &&  duplicate_count < AGENT_UPDATES_PER_SECOND)
+		{
+			// The head_rotation is sent for updating things like attached guns.
+			// We only trigger a new update when head_rotation deviates beyond
+			// some threshold from the last update, however this can break fine
+			// adjustments when trying to aim an attached gun, so what we do here
+			// (where we would normally skip sending an update when nothing has changed)
+			// is gradually reduce the threshold to allow a better update to 
+			// eventually get sent... should update to within 0.5 degrees in less 
+			// than a second.
+			if (head_rot_chg < THRESHOLD_HEAD_ROT_QDOT + (MAX_HEAD_ROT_QDOT - THRESHOLD_HEAD_ROT_QDOT) * duplicate_count / AGENT_UPDATES_PER_SECOND)
+			{
+				duplicate_count = 0;
+			}
+			else
+			{
+				return;
+			}
+		}
+		else
+		{
+			return;
+		}
+	}
+
+	if (duplicate_count < DUP_MSGS && !gDisconnected)
+	{
+		// Build the message
+		msg->newMessageFast(_PREHASH_AgentUpdate);
+		msg->nextBlockFast(_PREHASH_AgentData);
+		msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+		msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+		msg->addQuatFast(_PREHASH_BodyRotation, body_rotation);
+		msg->addQuatFast(_PREHASH_HeadRotation, head_rotation);
+		msg->addU8Fast(_PREHASH_State, render_state);
+		msg->addU8Fast(_PREHASH_Flags, flags);
+
+//		if (camera_pos_agent.mV[VY] > 255.f)
+//		{
+//			LL_INFOS("Messaging") << "Sending camera center " << camera_pos_agent << LL_ENDL;
+//		}
+		
+		msg->addVector3Fast(_PREHASH_CameraCenter, camera_pos_agent);
+		msg->addVector3Fast(_PREHASH_CameraAtAxis, LLViewerCamera::getInstance()->getAtAxis());
+		msg->addVector3Fast(_PREHASH_CameraLeftAxis, LLViewerCamera::getInstance()->getLeftAxis());
+		msg->addVector3Fast(_PREHASH_CameraUpAxis, LLViewerCamera::getInstance()->getUpAxis());
+		msg->addF32Fast(_PREHASH_Far, gAgent.mDrawDistance);
+		
+		msg->addU32Fast(_PREHASH_ControlFlags, control_flags);
+
+		if (gDebugClicks)
+		{
+			if (control_flags & AGENT_CONTROL_LBUTTON_DOWN)
+			{
+				LL_INFOS("Messaging") << "AgentUpdate left button down" << LL_ENDL;
+			}
+
+			if (control_flags & AGENT_CONTROL_LBUTTON_UP)
+			{
+				LL_INFOS("Messaging") << "AgentUpdate left button up" << LL_ENDL;
+			}
+		}
+
+		gAgent.enableControlFlagReset();
+
+		if (!send_reliable)
+		{
+			gAgent.sendMessage();
+		}
+		else
+		{
+			gAgent.sendReliableMessage();
+		}
+
+//		LL_DEBUGS("Messaging") << "agent " << avatar_pos_agent << " cam " << camera_pos_agent << LL_ENDL;
+
+		// Copy the old data 
+		last_head_rot = head_rotation;
+		last_render_state = render_state;
+		last_camera_pos_agent = camera_pos_agent;
+		last_camera_at = LLViewerCamera::getInstance()->getAtAxis();
+		last_camera_left = LLViewerCamera::getInstance()->getLeftAxis();
+		last_camera_up = LLViewerCamera::getInstance()->getUpAxis();
+		last_control_flags = control_flags;
+		last_flags = flags;
+	}
+}
+
+
+
+// *TODO: Remove this dependency, or figure out a better way to handle
+// this hack.
+extern U32 gObjectBits;
+
+void process_object_update(LLMessageSystem *mesgsys, void **user_data)
+{	
+	LLMemType mt(LLMemType::MTYPE_OBJECT);
+	// Update the data counters
+	if (mesgsys->getReceiveCompressedSize())
+	{
+		gObjectBits += mesgsys->getReceiveCompressedSize() * 8;
+	}
+	else
+	{
+		gObjectBits += mesgsys->getReceiveSize() * 8;
+	}
+
+	// Update the object...
+	gObjectList.processObjectUpdate(mesgsys, user_data, OUT_FULL);
+}
+
+void process_compressed_object_update(LLMessageSystem *mesgsys, void **user_data)
+{
+	LLMemType mt(LLMemType::MTYPE_OBJECT);
+	// Update the data counters
+	if (mesgsys->getReceiveCompressedSize())
+	{
+		gObjectBits += mesgsys->getReceiveCompressedSize() * 8;
+	}
+	else
+	{
+		gObjectBits += mesgsys->getReceiveSize() * 8;
+	}
+
+	// Update the object...
+	gObjectList.processCompressedObjectUpdate(mesgsys, user_data, OUT_FULL_COMPRESSED);
+}
+
+void process_cached_object_update(LLMessageSystem *mesgsys, void **user_data)
+{
+	LLMemType mt(LLMemType::MTYPE_OBJECT);
+	// Update the data counters
+	if (mesgsys->getReceiveCompressedSize())
+	{
+		gObjectBits += mesgsys->getReceiveCompressedSize() * 8;
+	}
+	else
+	{
+		gObjectBits += mesgsys->getReceiveSize() * 8;
+	}
+
+	// Update the object...
+	gObjectList.processCachedObjectUpdate(mesgsys, user_data, OUT_FULL_CACHED);
+}
+
+
+void process_terse_object_update_improved(LLMessageSystem *mesgsys, void **user_data)
+{
+	LLMemType mt(LLMemType::MTYPE_OBJECT);
+	if (mesgsys->getReceiveCompressedSize())
+	{
+		gObjectBits += mesgsys->getReceiveCompressedSize() * 8;
+	}
+	else
+	{
+		gObjectBits += mesgsys->getReceiveSize() * 8;
+	}
+
+	gObjectList.processCompressedObjectUpdate(mesgsys, user_data, OUT_TERSE_IMPROVED);
+}
+
+static LLFastTimer::DeclareTimer FTM_PROCESS_OBJECTS("Process Objects");
+
+
+void process_kill_object(LLMessageSystem *mesgsys, void **user_data)
+{
+	LLFastTimer t(FTM_PROCESS_OBJECTS);
+
+	LLUUID		id;
+	U32			local_id;
+	S32			i;
+	S32			num_objects;
+
+	num_objects = mesgsys->getNumberOfBlocksFast(_PREHASH_ObjectData);
+
+	for (i = 0; i < num_objects; i++)
+	{
+		mesgsys->getU32Fast(_PREHASH_ObjectData, _PREHASH_ID, local_id, i);
+
+		LLViewerObjectList::getUUIDFromLocal(id,
+											local_id,
+											gMessageSystem->getSenderIP(),
+											gMessageSystem->getSenderPort());
+		if (id == LLUUID::null)
+		{
+			LL_DEBUGS("Messaging") << "Unknown kill for local " << local_id << LL_ENDL;
+			gObjectList.mNumUnknownKills++;
+			continue;
+		}
+		else
+		{
+			LL_DEBUGS("Messaging") << "Kill message for local " << local_id << LL_ENDL;
+		}
+
+		LLSelectMgr::getInstance()->removeObjectFromSelections(id);
+
+		// ...don't kill the avatar
+		if (!(id == gAgentID))
+		{
+			LLViewerObject *objectp = gObjectList.findObject(id);
+			if (objectp)
+			{
+				// Display green bubble on kill
+				if ( gShowObjectUpdates )
+				{
+					LLViewerObject* newobject;
+					newobject = gObjectList.createObjectViewer(LL_PCODE_LEGACY_TEXT_BUBBLE, objectp->getRegion());
+
+					LLVOTextBubble* bubble = (LLVOTextBubble*) newobject;
+
+					bubble->mColor.setVec(0.f, 1.f, 0.f, 1.f);
+					bubble->setScale( 2.0f * bubble->getScale() );
+					bubble->setPositionGlobal(objectp->getPositionGlobal());
+					gPipeline.addObject(bubble);
+				}
+
+				// Do the kill
+				gObjectList.killObject(objectp);
+			}
+			else
+			{
+				LL_WARNS("Messaging") << "Object in UUID lookup, but not on object list in kill!" << LL_ENDL;
+				gObjectList.mNumUnknownKills++;
+			}
+		}
+	}
+}
+
+void process_time_synch(LLMessageSystem *mesgsys, void **user_data)
+{
+	LLVector3 sun_direction;
+	LLVector3 sun_ang_velocity;
+	F32 phase;
+	U64	space_time_usec;
+
+    U32 seconds_per_day;
+    U32 seconds_per_year;
+
+	// "SimulatorViewerTimeMessage"
+	mesgsys->getU64Fast(_PREHASH_TimeInfo, _PREHASH_UsecSinceStart, space_time_usec);
+	mesgsys->getU32Fast(_PREHASH_TimeInfo, _PREHASH_SecPerDay, seconds_per_day);
+	mesgsys->getU32Fast(_PREHASH_TimeInfo, _PREHASH_SecPerYear, seconds_per_year);
+
+	// This should eventually be moved to an "UpdateHeavenlyBodies" message
+	mesgsys->getF32Fast(_PREHASH_TimeInfo, _PREHASH_SunPhase, phase);
+	mesgsys->getVector3Fast(_PREHASH_TimeInfo, _PREHASH_SunDirection, sun_direction);
+	mesgsys->getVector3Fast(_PREHASH_TimeInfo, _PREHASH_SunAngVelocity, sun_ang_velocity);
+
+	LLWorld::getInstance()->setSpaceTimeUSec(space_time_usec);
+
+	//LL_DEBUGS("Messaging") << "time_synch() - " << sun_direction << ", " << sun_ang_velocity
+	//		 << ", " << phase << LL_ENDL;
+
+	gSky.setSunPhase(phase);
+	gSky.setSunTargetDirection(sun_direction, sun_ang_velocity);
+	if (!gNoRender && !(gSavedSettings.getBOOL("SkyOverrideSimSunPosition") || gSky.getOverrideSun()))
+	{
+		gSky.setSunDirection(sun_direction, sun_ang_velocity);
+	}
+}
+
+void process_sound_trigger(LLMessageSystem *msg, void **)
+{
+	if (!gAudiop) return;
+
+	U64		region_handle = 0;
+	F32		gain = 0;
+	LLUUID	sound_id;
+	LLUUID	owner_id;
+	LLUUID	object_id;
+	LLUUID	parent_id;
+	LLVector3	pos_local;
+
+	msg->getUUIDFast(_PREHASH_SoundData, _PREHASH_SoundID, sound_id);
+	msg->getUUIDFast(_PREHASH_SoundData, _PREHASH_OwnerID, owner_id);
+	msg->getUUIDFast(_PREHASH_SoundData, _PREHASH_ObjectID, object_id);
+	msg->getUUIDFast(_PREHASH_SoundData, _PREHASH_ParentID, parent_id);
+	msg->getU64Fast(_PREHASH_SoundData, _PREHASH_Handle, region_handle);
+	msg->getVector3Fast(_PREHASH_SoundData, _PREHASH_Position, pos_local);
+	msg->getF32Fast(_PREHASH_SoundData, _PREHASH_Gain, gain);
+
+	// adjust sound location to true global coords
+	LLVector3d	pos_global = from_region_handle(region_handle);
+	pos_global.mdV[VX] += pos_local.mV[VX];
+	pos_global.mdV[VY] += pos_local.mV[VY];
+	pos_global.mdV[VZ] += pos_local.mV[VZ];
+
+	// Don't play a trigger sound if you can't hear it due
+	// to parcel "local audio only" settings.
+	if (!LLViewerParcelMgr::getInstance()->canHearSound(pos_global)) return;
+
+	// Don't play sounds triggered by someone you muted.
+	if (LLMuteList::getInstance()->isMuted(owner_id, LLMute::flagObjectSounds)) return;
+	
+	// Don't play sounds from an object you muted
+	if (LLMuteList::getInstance()->isMuted(object_id)) return;
+
+	// Don't play sounds from an object whose parent you muted
+	if (parent_id.notNull()
+		&& LLMuteList::getInstance()->isMuted(parent_id))
+	{
+		return;
+	}
+
+	// Don't play sounds from a region with maturity above current agent maturity
+	if( !gAgent.canAccessMaturityInRegion( region_handle ) )
+	{
+		return;
+	}
+		
+	gAudiop->triggerSound(sound_id, owner_id, gain, LLAudioEngine::AUDIO_TYPE_SFX, pos_global);
+}
+
+void process_preload_sound(LLMessageSystem *msg, void **user_data)
+{
+	if (!gAudiop)
+	{
+		return;
+	}
+
+	LLUUID sound_id;
+	LLUUID object_id;
+	LLUUID owner_id;
+
+	msg->getUUIDFast(_PREHASH_DataBlock, _PREHASH_SoundID, sound_id);
+	msg->getUUIDFast(_PREHASH_DataBlock, _PREHASH_ObjectID, object_id);
+	msg->getUUIDFast(_PREHASH_DataBlock, _PREHASH_OwnerID, owner_id);
+
+	LLViewerObject *objectp = gObjectList.findObject(object_id);
+	if (!objectp) return;
+
+	if (LLMuteList::getInstance()->isMuted(object_id)) return;
+	if (LLMuteList::getInstance()->isMuted(owner_id, LLMute::flagObjectSounds)) return;
+	
+	LLAudioSource *sourcep = objectp->getAudioSource(owner_id);
+	if (!sourcep) return;
+	
+	LLAudioData *datap = gAudiop->getAudioData(sound_id);
+
+	// Note that I don't actually do any loading of the
+	// audio data into a buffer at this point, as it won't actually
+	// help us out.
+
+	// Don't play sounds from a region with maturity above current agent maturity
+	LLVector3d pos_global = objectp->getPositionGlobal();
+	if( !gAgent.canAccessMaturityAtGlobal( pos_global ) )
+	{
+		return;
+	}
+	
+	// Add audioData starts a transfer internally.
+	sourcep->addAudioData(datap, FALSE);
+}
+
+void process_attached_sound(LLMessageSystem *msg, void **user_data)
+{
+	F32 gain = 0;
+	LLUUID sound_id;
+	LLUUID object_id;
+	LLUUID owner_id;
+	U8 flags;
+
+	msg->getUUIDFast(_PREHASH_DataBlock, _PREHASH_SoundID, sound_id);
+	msg->getUUIDFast(_PREHASH_DataBlock, _PREHASH_ObjectID, object_id);
+	msg->getUUIDFast(_PREHASH_DataBlock, _PREHASH_OwnerID, owner_id);
+	msg->getF32Fast(_PREHASH_DataBlock, _PREHASH_Gain, gain);
+	msg->getU8Fast(_PREHASH_DataBlock, _PREHASH_Flags, flags);
+
+	LLViewerObject *objectp = gObjectList.findObject(object_id);
+	if (!objectp)
+	{
+		// we don't know about this object, just bail
+		return;
+	}
+	
+	if (LLMuteList::getInstance()->isMuted(object_id)) return;
+	
+	if (LLMuteList::getInstance()->isMuted(owner_id, LLMute::flagObjectSounds)) return;
+
+	
+	// Don't play sounds from a region with maturity above current agent maturity
+	LLVector3d pos = objectp->getPositionGlobal();
+	if( !gAgent.canAccessMaturityAtGlobal(pos) )
+	{
+		return;
+	}
+	
+	objectp->setAttachedSound(sound_id, owner_id, gain, flags);
+}
+
+
+void process_attached_sound_gain_change(LLMessageSystem *mesgsys, void **user_data)
+{
+	F32 gain = 0;
+	LLUUID object_guid;
+	LLViewerObject *objectp = NULL;
+
+	mesgsys->getUUIDFast(_PREHASH_DataBlock, _PREHASH_ObjectID, object_guid);
+
+	if (!((objectp = gObjectList.findObject(object_guid))))
+	{
+		// we don't know about this object, just bail
+		return;
+	}
+
+ 	mesgsys->getF32Fast(_PREHASH_DataBlock, _PREHASH_Gain, gain);
+
+	objectp->adjustAudioGain(gain);
+}
+
+
+void process_health_message(LLMessageSystem *mesgsys, void **user_data)
+{
+	F32 health;
+
+	mesgsys->getF32Fast(_PREHASH_HealthData, _PREHASH_Health, health);
+
+	if (gStatusBar)
+	{
+		gStatusBar->setHealth((S32)health);
+	}
+}
+
+
+void process_sim_stats(LLMessageSystem *msg, void **user_data)
+{	
+	S32 count = msg->getNumberOfBlocks("Stat");
+	for (S32 i = 0; i < count; ++i)
+	{
+		U32 stat_id;
+		F32 stat_value;
+		msg->getU32("Stat", "StatID", stat_id, i);
+		msg->getF32("Stat", "StatValue", stat_value, i);
+		switch (stat_id)
+		{
+		case LL_SIM_STAT_TIME_DILATION:
+			LLViewerStats::getInstance()->mSimTimeDilation.addValue(stat_value);
+			break;
+		case LL_SIM_STAT_FPS:
+			LLViewerStats::getInstance()->mSimFPS.addValue(stat_value);
+			break;
+		case LL_SIM_STAT_PHYSFPS:
+			LLViewerStats::getInstance()->mSimPhysicsFPS.addValue(stat_value);
+			break;
+		case LL_SIM_STAT_AGENTUPS:
+			LLViewerStats::getInstance()->mSimAgentUPS.addValue(stat_value);
+			break;
+		case LL_SIM_STAT_FRAMEMS:
+			LLViewerStats::getInstance()->mSimFrameMsec.addValue(stat_value);
+			break;
+		case LL_SIM_STAT_NETMS:
+			LLViewerStats::getInstance()->mSimNetMsec.addValue(stat_value);
+			break;
+		case LL_SIM_STAT_SIMOTHERMS:
+			LLViewerStats::getInstance()->mSimSimOtherMsec.addValue(stat_value);
+			break;
+		case LL_SIM_STAT_SIMPHYSICSMS:
+			LLViewerStats::getInstance()->mSimSimPhysicsMsec.addValue(stat_value);
+			break;
+		case LL_SIM_STAT_AGENTMS:
+			LLViewerStats::getInstance()->mSimAgentMsec.addValue(stat_value);
+			break;
+		case LL_SIM_STAT_IMAGESMS:
+			LLViewerStats::getInstance()->mSimImagesMsec.addValue(stat_value);
+			break;
+		case LL_SIM_STAT_SCRIPTMS:
+			LLViewerStats::getInstance()->mSimScriptMsec.addValue(stat_value);
+			break;
+		case LL_SIM_STAT_NUMTASKS:
+			LLViewerStats::getInstance()->mSimObjects.addValue(stat_value);
+			break;
+		case LL_SIM_STAT_NUMTASKSACTIVE:
+			LLViewerStats::getInstance()->mSimActiveObjects.addValue(stat_value);
+			break;
+		case LL_SIM_STAT_NUMAGENTMAIN:
+			LLViewerStats::getInstance()->mSimMainAgents.addValue(stat_value);
+			break;
+		case LL_SIM_STAT_NUMAGENTCHILD:
+			LLViewerStats::getInstance()->mSimChildAgents.addValue(stat_value);
+			break;
+		case LL_SIM_STAT_NUMSCRIPTSACTIVE:
+			LLViewerStats::getInstance()->mSimActiveScripts.addValue(stat_value);
+			break;
+		case LL_SIM_STAT_SCRIPT_EPS:
+			LLViewerStats::getInstance()->mSimScriptEPS.addValue(stat_value);
+			break;
+		case LL_SIM_STAT_INPPS:
+			LLViewerStats::getInstance()->mSimInPPS.addValue(stat_value);
+			break;
+		case LL_SIM_STAT_OUTPPS:
+			LLViewerStats::getInstance()->mSimOutPPS.addValue(stat_value);
+			break;
+		case LL_SIM_STAT_PENDING_DOWNLOADS:
+			LLViewerStats::getInstance()->mSimPendingDownloads.addValue(stat_value);
+			break;
+		case LL_SIM_STAT_PENDING_UPLOADS:
+			LLViewerStats::getInstance()->mSimPendingUploads.addValue(stat_value);
+			break;
+		case LL_SIM_STAT_PENDING_LOCAL_UPLOADS:
+			LLViewerStats::getInstance()->mSimPendingLocalUploads.addValue(stat_value);
+			break;
+		case LL_SIM_STAT_TOTAL_UNACKED_BYTES:
+			LLViewerStats::getInstance()->mSimTotalUnackedBytes.addValue(stat_value / 1024.f);
+			break;
+		case LL_SIM_STAT_PHYSICS_PINNED_TASKS:
+			LLViewerStats::getInstance()->mPhysicsPinnedTasks.addValue(stat_value);
+			break;
+		case LL_SIM_STAT_PHYSICS_LOD_TASKS:
+			LLViewerStats::getInstance()->mPhysicsLODTasks.addValue(stat_value);
+			break;
+		case LL_SIM_STAT_SIMPHYSICSSTEPMS:
+			LLViewerStats::getInstance()->mSimSimPhysicsStepMsec.addValue(stat_value);
+			break;
+		case LL_SIM_STAT_SIMPHYSICSSHAPEMS:
+			LLViewerStats::getInstance()->mSimSimPhysicsShapeUpdateMsec.addValue(stat_value);
+			break;
+		case LL_SIM_STAT_SIMPHYSICSOTHERMS:
+			LLViewerStats::getInstance()->mSimSimPhysicsOtherMsec.addValue(stat_value);
+			break;
+		case LL_SIM_STAT_SIMPHYSICSMEMORY:
+			LLViewerStats::getInstance()->mPhysicsMemoryAllocated.addValue(stat_value);
+			break;
+		case LL_SIM_STAT_SIMSPARETIME:
+			LLViewerStats::getInstance()->mSimSpareMsec.addValue(stat_value);
+			break;
+		case LL_SIM_STAT_SIMSLEEPTIME:
+			LLViewerStats::getInstance()->mSimSleepMsec.addValue(stat_value);
+			break;
+		case LL_SIM_STAT_IOPUMPTIME:
+			LLViewerStats::getInstance()->mSimPumpIOMsec.addValue(stat_value);
+			break;
+		default:
+			// Used to be a commented out warning.
+ 			LL_DEBUGS("Messaging") << "Unknown stat id" << stat_id << LL_ENDL;
+		  break;
+		}
+	}
+
+	/*
+	msg->getF32Fast(_PREHASH_Statistics, _PREHASH_PhysicsTimeDilation, time_dilation);
+	LLViewerStats::getInstance()->mSimTDStat.addValue(time_dilation);
+
+	// Process information
+	//	{	CpuUsage			F32				}
+	//	{	SimMemTotal			F32				}
+	//	{	SimMemRSS			F32				}
+	//	{	ProcessUptime		F32				}
+	F32 cpu_usage;
+	F32 sim_mem_total;
+	F32 sim_mem_rss;
+	F32 process_uptime;
+	msg->getF32Fast(_PREHASH_Statistics, _PREHASH_CpuUsage, cpu_usage);
+	msg->getF32Fast(_PREHASH_Statistics, _PREHASH_SimMemTotal, sim_mem_total);
+	msg->getF32Fast(_PREHASH_Statistics, _PREHASH_SimMemRSS, sim_mem_rss);
+	msg->getF32Fast(_PREHASH_Statistics, _PREHASH_ProcessUptime, process_uptime);
+	LLViewerStats::getInstance()->mSimCPUUsageStat.addValue(cpu_usage);
+	LLViewerStats::getInstance()->mSimMemTotalStat.addValue(sim_mem_total);
+	LLViewerStats::getInstance()->mSimMemRSSStat.addValue(sim_mem_rss);
+	*/
+
+	//
+	// Various hacks that aren't statistics, but are being handled here.
+	//
+	U32 max_tasks_per_region;
+	U32 region_flags;
+	msg->getU32("Region", "ObjectCapacity", max_tasks_per_region);
+	msg->getU32("Region", "RegionFlags", region_flags);
+
+	LLViewerRegion* regionp = gAgent.getRegion();
+	if (regionp)
+	{
+		BOOL was_flying = gAgent.getFlying();
+		regionp->setRegionFlags(region_flags);
+		regionp->setMaxTasks(max_tasks_per_region);
+		// HACK: This makes agents drop from the sky if the region is 
+		// set to no fly while people are still in the sim.
+		if (was_flying && regionp->getBlockFly())
+		{
+			gAgent.setFlying(gAgent.canFly());
+		}
+	}
+}
+
+
+
+void process_avatar_animation(LLMessageSystem *mesgsys, void **user_data)
+{
+	LLUUID	animation_id;
+	LLUUID	uuid;
+	S32		anim_sequence_id;
+	LLVOAvatar *avatarp;
+	
+	mesgsys->getUUIDFast(_PREHASH_Sender, _PREHASH_ID, uuid);
+
+	//clear animation flags
+	avatarp = (LLVOAvatar *)gObjectList.findObject(uuid);
+
+	if (!avatarp)
+	{
+		// no agent by this ID...error?
+		LL_WARNS("Messaging") << "Received animation state for unknown avatar" << uuid << LL_ENDL;
+		return;
+	}
+
+	S32 num_blocks = mesgsys->getNumberOfBlocksFast(_PREHASH_AnimationList);
+	S32 num_source_blocks = mesgsys->getNumberOfBlocksFast(_PREHASH_AnimationSourceList);
+
+	avatarp->mSignaledAnimations.clear();
+	
+	if (avatarp->isSelf())
+	{
+		LLUUID object_id;
+
+		for( S32 i = 0; i < num_blocks; i++ )
+		{
+			mesgsys->getUUIDFast(_PREHASH_AnimationList, _PREHASH_AnimID, animation_id, i);
+			mesgsys->getS32Fast(_PREHASH_AnimationList, _PREHASH_AnimSequenceID, anim_sequence_id, i);
+
+			LL_DEBUGS("Messaging") << "Anim sequence ID: " << anim_sequence_id << LL_ENDL;
+
+			avatarp->mSignaledAnimations[animation_id] = anim_sequence_id;
+
+			if (i < num_source_blocks)
+			{
+				mesgsys->getUUIDFast(_PREHASH_AnimationSourceList, _PREHASH_ObjectID, object_id, i);
+			
+				LLViewerObject* object = gObjectList.findObject(object_id);
+				if (object)
+				{
+					object->mFlags |= FLAGS_ANIM_SOURCE;
+
+					BOOL anim_found = FALSE;
+					LLVOAvatar::AnimSourceIterator anim_it = avatarp->mAnimationSources.find(object_id);
+					for (;anim_it != avatarp->mAnimationSources.end(); ++anim_it)
+					{
+						if (anim_it->second == animation_id)
+						{
+							anim_found = TRUE;
+							break;
+						}
+					}
+
+					if (!anim_found)
+					{
+						avatarp->mAnimationSources.insert(LLVOAvatar::AnimationSourceMap::value_type(object_id, animation_id));
+					}
+				}
+			}
+		}
+	}
+	else
+	{
+		for( S32 i = 0; i < num_blocks; i++ )
+		{
+			mesgsys->getUUIDFast(_PREHASH_AnimationList, _PREHASH_AnimID, animation_id, i);
+			mesgsys->getS32Fast(_PREHASH_AnimationList, _PREHASH_AnimSequenceID, anim_sequence_id, i);
+			avatarp->mSignaledAnimations[animation_id] = anim_sequence_id;
+		}
+	}
+
+	if (num_blocks)
+	{
+		avatarp->processAnimationStateChanges();
+	}
+}
+
+void process_avatar_appearance(LLMessageSystem *mesgsys, void **user_data)
+{
+	LLUUID uuid;
+	mesgsys->getUUIDFast(_PREHASH_Sender, _PREHASH_ID, uuid);
+
+	LLVOAvatar* avatarp = (LLVOAvatar *)gObjectList.findObject(uuid);
+	if( avatarp )
+	{
+		avatarp->processAvatarAppearance( mesgsys );
+	}
+	else
+	{
+		LL_WARNS("Messaging") << "avatar_appearance sent for unknown avatar " << uuid << LL_ENDL;
+	}
+}
+
+void process_camera_constraint(LLMessageSystem *mesgsys, void **user_data)
+{
+	LLVector4 cameraCollidePlane;
+	mesgsys->getVector4Fast(_PREHASH_CameraCollidePlane, _PREHASH_Plane, cameraCollidePlane);
+
+	gAgent.setCameraCollidePlane(cameraCollidePlane);
+}
+
+void near_sit_object(BOOL success, void *data)
+{
+	if (success)
+	{
+		// Send message to sit on object
+		gMessageSystem->newMessageFast(_PREHASH_AgentSit);
+		gMessageSystem->nextBlockFast(_PREHASH_AgentData);
+		gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+		gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+		gAgent.sendReliableMessage();
+	}
+}
+
+void process_avatar_sit_response(LLMessageSystem *mesgsys, void **user_data)
+{
+	LLVector3 sitPosition;
+	LLQuaternion sitRotation;
+	LLUUID sitObjectID;
+	BOOL use_autopilot;
+	mesgsys->getUUIDFast(_PREHASH_SitObject, _PREHASH_ID, sitObjectID);
+	mesgsys->getBOOLFast(_PREHASH_SitTransform, _PREHASH_AutoPilot, use_autopilot);
+	mesgsys->getVector3Fast(_PREHASH_SitTransform, _PREHASH_SitPosition, sitPosition);
+	mesgsys->getQuatFast(_PREHASH_SitTransform, _PREHASH_SitRotation, sitRotation);
+	LLVector3 camera_eye;
+	mesgsys->getVector3Fast(_PREHASH_SitTransform, _PREHASH_CameraEyeOffset, camera_eye);
+	LLVector3 camera_at;
+	mesgsys->getVector3Fast(_PREHASH_SitTransform, _PREHASH_CameraAtOffset, camera_at);
+	BOOL force_mouselook;
+	mesgsys->getBOOLFast(_PREHASH_SitTransform, _PREHASH_ForceMouselook, force_mouselook);
+
+	LLVOAvatar* avatar = gAgent.getAvatarObject();
+
+	if (avatar && dist_vec_squared(camera_eye, camera_at) > 0.0001f)
+	{
+		gAgent.setSitCamera(sitObjectID, camera_eye, camera_at);
+	}
+	
+	gAgent.setForceMouselook(force_mouselook);
+
+	LLViewerObject* object = gObjectList.findObject(sitObjectID);
+	if (object)
+	{
+		LLVector3 sit_spot = object->getPositionAgent() + (sitPosition * object->getRotation());
+		if (!use_autopilot || (avatar && avatar->isSitting() && avatar->getRoot() == object->getRoot()))
+		{
+			//we're already sitting on this object, so don't autopilot
+		}
+		else
+		{
+			gAgent.startAutoPilotGlobal(gAgent.getPosGlobalFromAgent(sit_spot), "Sit", &sitRotation, near_sit_object, NULL, 0.5f);
+		}
+	}
+	else
+	{
+		LL_WARNS("Messaging") << "Received sit approval for unknown object " << sitObjectID << LL_ENDL;
+	}
+}
+
+void process_clear_follow_cam_properties(LLMessageSystem *mesgsys, void **user_data)
+{
+	LLUUID		source_id;
+
+	mesgsys->getUUIDFast(_PREHASH_ObjectData, _PREHASH_ObjectID, source_id);
+
+	LLFollowCamMgr::removeFollowCamParams(source_id);
+}
+
+void process_set_follow_cam_properties(LLMessageSystem *mesgsys, void **user_data)
+{
+	S32			type;
+	F32			value;
+	bool		settingPosition = false;
+	bool		settingFocus	= false;
+	bool		settingFocusOffset = false;
+	LLVector3	position;
+	LLVector3	focus;
+	LLVector3	focus_offset;
+
+	LLUUID		source_id;
+
+	mesgsys->getUUIDFast(_PREHASH_ObjectData, _PREHASH_ObjectID, source_id);
+
+	LLViewerObject* objectp = gObjectList.findObject(source_id);
+	if (objectp)
+	{
+		objectp->mFlags |= FLAGS_CAMERA_SOURCE;
+	}
+
+	S32 num_objects = mesgsys->getNumberOfBlocks("CameraProperty");
+	for (S32 block_index = 0; block_index < num_objects; block_index++)
+	{
+		mesgsys->getS32("CameraProperty", "Type", type, block_index);
+		mesgsys->getF32("CameraProperty", "Value", value, block_index);
+		switch(type)
+		{
+		case FOLLOWCAM_PITCH:
+			LLFollowCamMgr::setPitch(source_id, value);
+			break;
+		case FOLLOWCAM_FOCUS_OFFSET_X:
+			focus_offset.mV[VX] = value;
+			settingFocusOffset = true;
+			break;
+		case FOLLOWCAM_FOCUS_OFFSET_Y:
+			focus_offset.mV[VY] = value;
+			settingFocusOffset = true;
+			break;
+		case FOLLOWCAM_FOCUS_OFFSET_Z:
+			focus_offset.mV[VZ] = value;
+			settingFocusOffset = true;
+			break;
+		case FOLLOWCAM_POSITION_LAG:
+			LLFollowCamMgr::setPositionLag(source_id, value);
+			break;
+		case FOLLOWCAM_FOCUS_LAG:
+			LLFollowCamMgr::setFocusLag(source_id, value);
+			break;
+		case FOLLOWCAM_DISTANCE:
+			LLFollowCamMgr::setDistance(source_id, value);
+			break;
+		case FOLLOWCAM_BEHINDNESS_ANGLE:
+			LLFollowCamMgr::setBehindnessAngle(source_id, value);
+			break;
+		case FOLLOWCAM_BEHINDNESS_LAG:
+			LLFollowCamMgr::setBehindnessLag(source_id, value);
+			break;
+		case FOLLOWCAM_POSITION_THRESHOLD:
+			LLFollowCamMgr::setPositionThreshold(source_id, value);
+			break;
+		case FOLLOWCAM_FOCUS_THRESHOLD:
+			LLFollowCamMgr::setFocusThreshold(source_id, value);
+			break;
+		case FOLLOWCAM_ACTIVE:
+			//if 1, set using followcam,. 
+			LLFollowCamMgr::setCameraActive(source_id, value != 0.f);
+			break;
+		case FOLLOWCAM_POSITION_X:
+			settingPosition = true;
+			position.mV[ 0 ] = value;
+			break;
+		case FOLLOWCAM_POSITION_Y:
+			settingPosition = true;
+			position.mV[ 1 ] = value;
+			break;
+		case FOLLOWCAM_POSITION_Z:
+			settingPosition = true;
+			position.mV[ 2 ] = value;
+			break;
+		case FOLLOWCAM_FOCUS_X:
+			settingFocus = true;
+			focus.mV[ 0 ] = value;
+			break;
+		case FOLLOWCAM_FOCUS_Y:
+			settingFocus = true;
+			focus.mV[ 1 ] = value;
+			break;
+		case FOLLOWCAM_FOCUS_Z:
+			settingFocus = true;
+			focus.mV[ 2 ] = value;
+			break;
+		case FOLLOWCAM_POSITION_LOCKED:
+			LLFollowCamMgr::setPositionLocked(source_id, value != 0.f);
+			break;
+		case FOLLOWCAM_FOCUS_LOCKED:
+			LLFollowCamMgr::setFocusLocked(source_id, value != 0.f);
+			break;
+
+		default:
+			break;
+		}
+	}
+
+	if ( settingPosition )
+	{
+		LLFollowCamMgr::setPosition(source_id, position);
+	}
+	if ( settingFocus )
+	{
+		LLFollowCamMgr::setFocus(source_id, focus);
+	}
+	if ( settingFocusOffset )
+	{
+		LLFollowCamMgr::setFocusOffset(source_id, focus_offset);
+	}
+}
+//end Ventrella 
+
+
+// Culled from newsim lltask.cpp
+void process_name_value(LLMessageSystem *mesgsys, void **user_data)
+{
+	std::string	temp_str;
+	LLUUID	id;
+	S32		i, num_blocks;
+
+	mesgsys->getUUIDFast(_PREHASH_TaskData, _PREHASH_ID, id);
+
+	LLViewerObject* object = gObjectList.findObject(id);
+
+	if (object)
+	{
+		num_blocks = mesgsys->getNumberOfBlocksFast(_PREHASH_NameValueData);
+		for (i = 0; i < num_blocks; i++)
+		{
+			mesgsys->getStringFast(_PREHASH_NameValueData, _PREHASH_NVPair, temp_str, i);
+			LL_INFOS("Messaging") << "Added to object Name Value: " << temp_str << LL_ENDL;
+			object->addNVPair(temp_str);
+		}
+	}
+	else
+	{
+		LL_INFOS("Messaging") << "Can't find object " << id << " to add name value pair" << LL_ENDL;
+	}
+}
+
+void process_remove_name_value(LLMessageSystem *mesgsys, void **user_data)
+{
+	std::string	temp_str;
+	LLUUID	id;
+	S32		i, num_blocks;
+
+	mesgsys->getUUIDFast(_PREHASH_TaskData, _PREHASH_ID, id);
+
+	LLViewerObject* object = gObjectList.findObject(id);
+
+	if (object)
+	{
+		num_blocks = mesgsys->getNumberOfBlocksFast(_PREHASH_NameValueData);
+		for (i = 0; i < num_blocks; i++)
+		{
+			mesgsys->getStringFast(_PREHASH_NameValueData, _PREHASH_NVPair, temp_str, i);
+			LL_INFOS("Messaging") << "Removed from object Name Value: " << temp_str << LL_ENDL;
+			object->removeNVPair(temp_str);
+		}
+	}
+	else
+	{
+		LL_INFOS("Messaging") << "Can't find object " << id << " to remove name value pair" << LL_ENDL;
+	}
+}
+
+void process_kick_user(LLMessageSystem *msg, void** /*user_data*/)
+{
+	std::string message;
+
+	msg->getStringFast(_PREHASH_UserInfo, _PREHASH_Reason, message);
+
+	LLAppViewer::instance()->forceDisconnect(message);
+}
+
+
+/*
+void process_user_list_reply(LLMessageSystem *msg, void **user_data)
+{
+	LLUserList::processUserListReply(msg, user_data);
+	return;
+	char	firstname[MAX_STRING+1];
+	char	lastname[MAX_STRING+1];
+	U8		status;
+	S32		user_count;
+
+	user_count = msg->getNumberOfBlocks("UserBlock");
+
+	for (S32 i = 0; i < user_count; i++)
+	{
+		msg->getData("UserBlock", i, "FirstName", firstname);
+		msg->getData("UserBlock", i, "LastName", lastname);
+		msg->getData("UserBlock", i, "Status", &status);
+
+		if (status & 0x01)
+		{
+			dialog_friends_add_friend(buffer, TRUE);
+		}
+		else
+		{
+			dialog_friends_add_friend(buffer, FALSE);
+		}
+	}
+
+	dialog_friends_done_adding();
+}
+*/
+
+// this is not handled in processUpdateMessage
+/*
+void process_time_dilation(LLMessageSystem *msg, void **user_data)
+{
+	// get the time_dilation
+	U16 foo;
+	msg->getData("TimeDilation", "TimeDilation", &foo);
+	F32 time_dilation = ((F32) foo) / 65535.f;
+
+	// get the pointer to the right region
+	U32 ip = msg->getSenderIP();
+	U32 port = msg->getSenderPort();
+	LLViewerRegion *regionp = LLWorld::getInstance()->getRegion(ip, port);
+	if (regionp)
+	{
+		regionp->setTimeDilation(time_dilation);
+	}
+}
+*/
+
+
+
+void process_money_balance_reply( LLMessageSystem* msg, void** )
+{
+	S32 balance = 0;
+	S32 credit = 0;
+	S32 committed = 0;
+	std::string desc;
+
+	msg->getS32("MoneyData", "MoneyBalance", balance);
+	msg->getS32("MoneyData", "SquareMetersCredit", credit);
+	msg->getS32("MoneyData", "SquareMetersCommitted", committed);
+	msg->getStringFast(_PREHASH_MoneyData, _PREHASH_Description, desc);
+	LL_INFOS("Messaging") << "L$, credit, committed: " << balance << " " << credit << " "
+			<< committed << LL_ENDL;
+
+	if (gStatusBar)
+	{
+		S32 old_balance = gStatusBar->getBalance();
+
+		// This is an update, not the first transmission of balance
+		if (old_balance != 0)
+		{
+			// this is actually an update
+			if (balance > old_balance)
+			{
+				LLFirstUse::useBalanceIncrease(balance - old_balance);
+			}
+			else if (balance < old_balance)
+			{
+				LLFirstUse::useBalanceDecrease(balance - old_balance);
+			}
+		}
+
+		gStatusBar->setBalance(balance);
+		gStatusBar->setLandCredit(credit);
+		gStatusBar->setLandCommitted(committed);
+	}
+
+	LLUUID tid;
+	msg->getUUID("MoneyData", "TransactionID", tid);
+	static std::deque<LLUUID> recent;
+	if(!desc.empty() && gSavedSettings.getBOOL("NotifyMoneyChange")
+	   && (std::find(recent.rbegin(), recent.rend(), tid) == recent.rend()))
+	{
+		// Make the user confirm the transaction, since they might
+		// have missed something during an event.
+		// *TODO: Translate
+		LLSD args;
+		args["MESSAGE"] = desc;
+		LLNotifications::instance().add("SystemMessage", args);
+
+		// Once the 'recent' container gets large enough, chop some
+		// off the beginning.
+		const U32 MAX_LOOKBACK = 30;
+		const S32 POP_FRONT_SIZE = 12;
+		if(recent.size() > MAX_LOOKBACK)
+		{
+			LL_DEBUGS("Messaging") << "Removing oldest transaction records" << LL_ENDL;
+			recent.erase(recent.begin(), recent.begin() + POP_FRONT_SIZE);
+		}
+		//LL_DEBUGS("Messaging") << "Pushing back transaction " << tid << LL_ENDL;
+		recent.push_back(tid);
+	}
+}
+
+bool handle_special_notification_callback(const LLSD& notification, const LLSD& response)
+{
+	S32 option = LLNotification::getSelectedOption(notification, response);
+	
+	if (0 == option)
+	{
+		// set the preference to the maturity of the region we're calling
+		int preferredMaturity = notification["payload"]["_region_access"].asInteger();
+		gSavedSettings.setU32("PreferredMaturity", preferredMaturity);
+		gAgent.sendMaturityPreferenceToServer(preferredMaturity);
+
+	}
+	
+	return false;
+}
+
+// some of the server notifications need special handling. This is where we do that.
+bool handle_special_notification(std::string notificationID, LLSD& llsdBlock)
+{
+	int regionAccess = llsdBlock["_region_access"].asInteger();
+	llsdBlock["REGIONMATURITY"] = LLViewerRegion::accessToString(regionAccess);
+	
+	// we're going to throw the LLSD in there in case anyone ever wants to use it
+	LLNotifications::instance().add(notificationID+"_Notify", llsdBlock);
+	
+	if (regionAccess == SIM_ACCESS_MATURE)
+	{
+		if (gAgent.isTeen())
+		{
+			LLNotifications::instance().add(notificationID+"_KB", llsdBlock);
+			return true;
+		}
+		else if (gAgent.prefersPG())
+		{
+			LLNotifications::instance().add(notificationID+"_Change", llsdBlock, llsdBlock, handle_special_notification_callback);
+			return true;
+		}
+	}
+	else if (regionAccess == SIM_ACCESS_ADULT)
+	{
+		if (!gAgent.isAdult())
+		{
+			LLNotifications::instance().add(notificationID+"_KB", llsdBlock);
+			return true;
+		}
+		else if (gAgent.prefersPG() || gAgent.prefersMature())
+		{
+			LLNotifications::instance().add(notificationID+"_Change", llsdBlock, llsdBlock, handle_special_notification_callback);
+			return true;
+		}
+	}
+	return false;
+}
+
+bool attempt_standard_notification(LLMessageSystem* msgsystem)
+{
+	// if we have additional alert data
+	if (msgsystem->has(_PREHASH_AlertInfo) && msgsystem->getNumberOfBlocksFast(_PREHASH_AlertInfo) > 0)
+	{
+		// notification was specified using the new mechanism, so we can just handle it here
+		std::string notificationID;
+		std::string llsdRaw;
+		LLSD llsdBlock;
+		msgsystem->getStringFast(_PREHASH_AlertInfo, _PREHASH_Message, notificationID);
+		msgsystem->getStringFast(_PREHASH_AlertInfo, _PREHASH_ExtraParams, llsdRaw);
+		if (llsdRaw.length())
+		{
+			std::istringstream llsdData(llsdRaw);
+			if (!LLSDSerialize::deserialize(llsdBlock, llsdData, llsdRaw.length()))
+			{
+				llwarns << "attempt_standard_notification: Attempted to read notification parameter data into LLSD but failed:" << llsdRaw << llendl;
+			}
+		}
+		
+		if (
+			(notificationID == "RegionEntryAccessBlocked") ||
+			(notificationID == "LandClaimAccessBlocked") ||
+			(notificationID == "LandBuyAccessBlocked")
+		   )
+		{
+			/*---------------------------------------------------------------------
+			 (Commented so a grep will find the notification strings, since
+			 we construct them on the fly; if you add additional notifications,
+			 please update the comment.)
+			 
+			 Could throw any of the following notifications:
+			 
+				RegionEntryAccessBlocked
+				RegionEntryAccessBlocked_Notify
+				RegionEntryAccessBlocked_Change
+				RegionEntryAccessBlocked_KB
+				LandClaimAccessBlocked 
+				LandClaimAccessBlocked_Notify 
+				LandClaimAccessBlocked_Change 
+				LandClaimAccessBlocked_KB 
+				LandBuyAccessBlocked
+				LandBuyAccessBlocked_Notify
+				LandBuyAccessBlocked_Change
+				LandBuyAccessBlocked_KB
+			 
+			-----------------------------------------------------------------------*/ 
+			if (handle_special_notification(notificationID, llsdBlock))
+			{
+				return true;
+			}
+		}
+		
+		LLNotifications::instance().add(notificationID, llsdBlock);
+		return true;
+	}	
+	return false;
+}
+
+
+void process_agent_alert_message(LLMessageSystem* msgsystem, void** user_data)
+{
+	// make sure the cursor is back to the usual default since the
+	// alert is probably due to some kind of error.
+	gViewerWindow->getWindow()->resetBusyCount();
+	
+	if (!attempt_standard_notification(msgsystem))
+	{
+		BOOL modal = FALSE;
+		msgsystem->getBOOL("AlertData", "Modal", modal);
+		std::string buffer;
+		msgsystem->getStringFast(_PREHASH_AlertData, _PREHASH_Message, buffer);
+		process_alert_core(buffer, modal);
+	}
+}
+
+// The only difference between this routine and the previous is the fact that
+// for this routine, the modal parameter is always false. Sadly, for the message
+// handled by this routine, there is no "Modal" parameter on the message, and
+// there's no API to tell if a message has the given parameter or not.
+// So we can't handle the messages with the same handler.
+void process_alert_message(LLMessageSystem *msgsystem, void **user_data)
+{
+	// make sure the cursor is back to the usual default since the
+	// alert is probably due to some kind of error.
+	gViewerWindow->getWindow()->resetBusyCount();
+		
+	if (!attempt_standard_notification(msgsystem))
+	{
+		BOOL modal = FALSE;
+		std::string buffer;
+		msgsystem->getStringFast(_PREHASH_AlertData, _PREHASH_Message, buffer);
+		process_alert_core(buffer, modal);
+	}
+}
+
+void process_alert_core(const std::string& message, BOOL modal)
+{
+	// HACK -- handle callbacks for specific alerts
+	if ( message == "You died and have been teleported to your home location")
+	{
+		LLViewerStats::getInstance()->incStat(LLViewerStats::ST_KILLED_COUNT);
+	}
+	else if( message == "Home position set." )
+	{
+		// save the home location image to disk
+		std::string snap_filename = gDirUtilp->getLindenUserDir();
+		snap_filename += gDirUtilp->getDirDelimiter();
+		snap_filename += SCREEN_HOME_FILENAME;
+		gViewerWindow->saveSnapshot(snap_filename, gViewerWindow->getWindowDisplayWidth(), gViewerWindow->getWindowDisplayHeight(), FALSE, FALSE);
+	}
+
+	const std::string ALERT_PREFIX("ALERT: ");
+	const std::string NOTIFY_PREFIX("NOTIFY: ");
+	if (message.find(ALERT_PREFIX) == 0)
+	{
+		// Allow the server to spawn a named alert so that server alerts can be
+		// translated out of English.
+		std::string alert_name(message.substr(ALERT_PREFIX.length()));
+		LLNotifications::instance().add(alert_name);
+	}
+	else if (message.find(NOTIFY_PREFIX) == 0)
+	{
+		// Allow the server to spawn a named notification so that server notifications can be
+		// translated out of English.
+		std::string notify_name(message.substr(NOTIFY_PREFIX.length()));
+		LLNotifications::instance().add(notify_name);
+	}
+	else if (message[0] == '/')
+	{
+		// System message is important, show in upper-right box not tip
+		std::string text(message.substr(1));
+		LLSD args;
+		if (text.substr(0,17) == "RESTART_X_MINUTES")
+		{
+			S32 mins = 0;
+			LLStringUtil::convertToS32(text.substr(18), mins);
+			args["MINUTES"] = llformat("%d",mins);
+			LLNotifications::instance().add("RegionRestartMinutes", args);
+		}
+		else if (text.substr(0,17) == "RESTART_X_SECONDS")
+		{
+			S32 secs = 0;
+			LLStringUtil::convertToS32(text.substr(18), secs);
+			args["SECONDS"] = llformat("%d",secs);
+			LLNotifications::instance().add("RegionRestartSeconds", args);
+		}
+		else
+		{
+			std::string new_msg =LLNotifications::instance().getGlobalString(text);
+			args["MESSAGE"] = new_msg;
+			LLNotifications::instance().add("SystemMessage", args);
+		}
+	}
+	else if (modal)
+	{
+		LLSD args;
+		std::string new_msg =LLNotifications::instance().getGlobalString(message);
+		args["ERROR_MESSAGE"] = new_msg;
+		LLNotifications::instance().add("ErrorMessage", args);
+	}
+	else
+	{
+		LLSD args;
+		std::string new_msg =LLNotifications::instance().getGlobalString(message);
+		args["MESSAGE"] = new_msg;
+		LLNotifications::instance().add("SystemMessageTip", args);
+	}
+}
+
+mean_collision_list_t				gMeanCollisionList;
+time_t								gLastDisplayedTime = 0;
+
+void handle_show_mean_events(void *)
+{
+	if (gNoRender)
+	{
+		return;
+	}
+	LLFloaterReg::showInstance("bumps");
+	//LLFloaterBump::showInstance();
+}
+
+void mean_name_callback(const LLUUID &id, const std::string& first, const std::string& last, BOOL always_false)
+{
+	if (gNoRender)
+	{
+		return;
+	}
+
+	static const U32 max_collision_list_size = 20;
+	if (gMeanCollisionList.size() > max_collision_list_size)
+	{
+		mean_collision_list_t::iterator iter = gMeanCollisionList.begin();
+		for (U32 i=0; i<max_collision_list_size; i++) iter++;
+		for_each(iter, gMeanCollisionList.end(), DeletePointer());
+		gMeanCollisionList.erase(iter, gMeanCollisionList.end());
+	}
+
+	for (mean_collision_list_t::iterator iter = gMeanCollisionList.begin();
+		 iter != gMeanCollisionList.end(); ++iter)
+	{
+		LLMeanCollisionData *mcd = *iter;
+		if (mcd->mPerp == id)
+		{
+			mcd->mFirstName = first;
+			mcd->mLastName = last;
+		}
+	}
+}
+
+void process_mean_collision_alert_message(LLMessageSystem *msgsystem, void **user_data)
+{
+	if (gAgent.inPrelude())
+	{
+		// In prelude, bumping is OK.  This dialog is rather confusing to 
+		// newbies, so we don't show it.  Drop the packet on the floor.
+		return;
+	}
+
+	// make sure the cursor is back to the usual default since the
+	// alert is probably due to some kind of error.
+	gViewerWindow->getWindow()->resetBusyCount();
+
+	LLUUID perp;
+	U32	   time;
+	U8	   u8type;
+	EMeanCollisionType	   type;
+	F32    mag;
+
+	S32 i, num = msgsystem->getNumberOfBlocks(_PREHASH_MeanCollision);
+
+	for (i = 0; i < num; i++)
+	{
+		msgsystem->getUUIDFast(_PREHASH_MeanCollision, _PREHASH_Perp, perp);
+		msgsystem->getU32Fast(_PREHASH_MeanCollision, _PREHASH_Time, time);
+		msgsystem->getF32Fast(_PREHASH_MeanCollision, _PREHASH_Mag, mag);
+		msgsystem->getU8Fast(_PREHASH_MeanCollision, _PREHASH_Type, u8type);
+
+		type = (EMeanCollisionType)u8type;
+
+		BOOL b_found = FALSE;
+
+		for (mean_collision_list_t::iterator iter = gMeanCollisionList.begin();
+			 iter != gMeanCollisionList.end(); ++iter)
+		{
+			LLMeanCollisionData *mcd = *iter;
+			if ((mcd->mPerp == perp) && (mcd->mType == type))
+			{
+				mcd->mTime = time;
+				mcd->mMag = mag;
+				b_found = TRUE;
+				break;
+			}
+		}
+
+		if (!b_found)
+		{
+			LLMeanCollisionData *mcd = new LLMeanCollisionData(gAgentID, perp, time, type, mag);
+			gMeanCollisionList.push_front(mcd);
+			const BOOL is_group = FALSE;
+			gCacheName->get(perp, is_group, &mean_name_callback);
+		}
+	}
+}
+
+void process_frozen_message(LLMessageSystem *msgsystem, void **user_data)
+{
+	// make sure the cursor is back to the usual default since the
+	// alert is probably due to some kind of error.
+	gViewerWindow->getWindow()->resetBusyCount();
+	BOOL b_frozen;
+	
+	msgsystem->getBOOL("FrozenData", "Data", b_frozen);
+
+	// TODO: make being frozen change view
+	if (b_frozen)
+	{
+	}
+	else
+	{
+	}
+}
+
+// do some extra stuff once we get our economy data
+void process_economy_data(LLMessageSystem *msg, void** /*user_data*/)
+{
+	LLGlobalEconomy::processEconomyData(msg, LLGlobalEconomy::Singleton::getInstance());
+
+	S32 upload_cost = LLGlobalEconomy::Singleton::getInstance()->getPriceUpload();
+
+	LL_INFOS_ONCE("Messaging") << "EconomyData message arrived; upload cost is L$" << upload_cost << LL_ENDL;
+
+	gMenuHolder->childSetLabelArg("Upload Image", "[COST]", llformat("%d", upload_cost));
+	gMenuHolder->childSetLabelArg("Upload Sound", "[COST]", llformat("%d", upload_cost));
+	gMenuHolder->childSetLabelArg("Upload Animation", "[COST]", llformat("%d", upload_cost));
+	gMenuHolder->childSetLabelArg("Bulk Upload", "[COST]", llformat("%d", upload_cost));
+}
+
+void notify_cautioned_script_question(const LLSD& notification, const LLSD& response, S32 orig_questions, BOOL granted)
+{
+	// only continue if at least some permissions were requested
+	if (orig_questions)
+	{
+		// check to see if the person we are asking
+
+		// "'[OBJECTNAME]', an object owned by '[OWNERNAME]', 
+		// located in [REGIONNAME] at [REGIONPOS], 
+		// has been <granted|denied> permission to: [PERMISSIONS]."
+
+		LLUIString notice(LLTrans::getString(granted ? "ScriptQuestionCautionChatGranted" : "ScriptQuestionCautionChatDenied"));
+
+		// always include the object name and owner name 
+		notice.setArg("[OBJECTNAME]", notification["payload"]["object_name"].asString());
+		notice.setArg("[OWNERNAME]", notification["payload"]["owner_name"].asString());
+
+		// try to lookup viewerobject that corresponds to the object that
+		// requested permissions (here, taskid->requesting object id)
+		BOOL foundpos = FALSE;
+		LLViewerObject* viewobj = gObjectList.findObject(notification["payload"]["task_id"].asUUID());
+		if (viewobj)
+		{
+			// found the viewerobject, get it's position in its region
+			LLVector3 objpos(viewobj->getPosition());
+			
+			// try to lookup the name of the region the object is in
+			LLViewerRegion* viewregion = viewobj->getRegion();
+			if (viewregion)
+			{
+				// got the region, so include the region and 3d coordinates of the object
+				notice.setArg("[REGIONNAME]", viewregion->getName());				
+				std::string formatpos = llformat("%.1f, %.1f,%.1f", objpos[VX], objpos[VY], objpos[VZ]);
+				notice.setArg("[REGIONPOS]", formatpos);
+
+				foundpos = TRUE;
+			}
+		}
+
+		if (!foundpos)
+		{
+			// unable to determine location of the object
+			notice.setArg("[REGIONNAME]", "(unknown region)");
+			notice.setArg("[REGIONPOS]", "(unknown position)");
+		}
+
+		// check each permission that was requested, and list each 
+		// permission that has been flagged as a caution permission
+		BOOL caution = FALSE;
+		S32 count = 0;
+		std::string perms;
+		for (S32 i = 0; i < SCRIPT_PERMISSION_EOF; i++)
+		{
+			if ((orig_questions & LSCRIPTRunTimePermissionBits[i]) && SCRIPT_QUESTION_IS_CAUTION[i])
+			{
+				count++;
+				caution = TRUE;
+
+				// add a comma before the permission description if it is not the first permission
+				// added to the list or the last permission to check
+				if ((count > 1) && (i < SCRIPT_PERMISSION_EOF))
+				{
+					perms.append(", ");
+				}
+
+				perms.append(LLTrans::getString(SCRIPT_QUESTIONS[i]));
+			}
+		}
+
+		notice.setArg("[PERMISSIONS]", perms);
+
+		// log a chat message as long as at least one requested permission
+		// is a caution permission
+		if (caution)
+		{
+			LLChat chat(notice.getString());
+			LLFloaterChat::addChat(chat, FALSE, FALSE);
+		}
+	}
+}
+
+bool script_question_cb(const LLSD& notification, const LLSD& response)
+{
+	S32 option = LLNotification::getSelectedOption(notification, response);
+	LLMessageSystem *msg = gMessageSystem;
+	S32 orig = notification["payload"]["questions"].asInteger();
+	S32 new_questions = orig;
+
+	// check whether permissions were granted or denied
+	BOOL allowed = TRUE;
+	// the "yes/accept" button is the first button in the template, making it button 0
+	// if any other button was clicked, the permissions were denied
+	if (option != 0)
+	{
+		new_questions = 0;
+		allowed = FALSE;
+	}	
+
+	LLUUID task_id = notification["payload"]["task_id"].asUUID();
+	LLUUID item_id = notification["payload"]["item_id"].asUUID();
+
+	// reply with the permissions granted or denied
+	msg->newMessageFast(_PREHASH_ScriptAnswerYes);
+	msg->nextBlockFast(_PREHASH_AgentData);
+	msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+	msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+	msg->nextBlockFast(_PREHASH_Data);
+	msg->addUUIDFast(_PREHASH_TaskID, task_id);
+	msg->addUUIDFast(_PREHASH_ItemID, item_id);
+	msg->addS32Fast(_PREHASH_Questions, new_questions);
+	msg->sendReliable(LLHost(notification["payload"]["sender"].asString()));
+
+	// only log a chat message if caution prompts are enabled
+	if (gSavedSettings.getBOOL("PermissionsCautionEnabled"))
+	{
+		// log a chat message, if appropriate
+		notify_cautioned_script_question(notification, response, orig, allowed);
+	}
+
+	if ( response["Mute"] ) // mute
+	{
+		LLMuteList::getInstance()->add(LLMute(item_id, notification["payload"]["object_name"].asString(), LLMute::OBJECT));
+
+		// purge the message queue of any previously queued requests from the same source. DEV-4879
+		class OfferMatcher : public LLNotifyBoxView::Matcher
+		{
+		public:
+			OfferMatcher(const LLUUID& to_block) : blocked_id(to_block) {}
+			BOOL matches(const LLNotificationPtr notification) const
+			{
+				if (notification->getName() == "ScriptQuestionCaution"
+					|| notification->getName() == "ScriptQuestion")
+				{
+					return (notification->getPayload()["item_id"].asUUID() == blocked_id);
+				}
+				return FALSE;
+			}
+		private:
+			const LLUUID& blocked_id;
+		};
+		// should do this via the channel
+		gNotifyBoxView->purgeMessagesMatching(OfferMatcher(item_id));
+	}
+
+	if (response["Details"])
+	{
+		// respawn notification...
+		LLNotifications::instance().add(notification["name"], notification["substitutions"], notification["payload"]);
+
+		// ...with description on top
+		LLNotifications::instance().add("DebitPermissionDetails");
+	}
+	return false;
+}
+static LLNotificationFunctorRegistration script_question_cb_reg_1("ScriptQuestion", script_question_cb);
+static LLNotificationFunctorRegistration script_question_cb_reg_2("ScriptQuestionCaution", script_question_cb);
+
+void process_script_question(LLMessageSystem *msg, void **user_data)
+{
+	// *TODO: Translate owner name -> [FIRST] [LAST]
+
+	LLHost sender = msg->getSender();
+
+	LLUUID taskid;
+	LLUUID itemid;
+	S32		questions;
+	std::string object_name;
+	std::string owner_name;
+
+	// taskid -> object key of object requesting permissions
+	msg->getUUIDFast(_PREHASH_Data, _PREHASH_TaskID, taskid );
+	// itemid -> script asset key of script requesting permissions
+	msg->getUUIDFast(_PREHASH_Data, _PREHASH_ItemID, itemid );
+	msg->getStringFast(_PREHASH_Data, _PREHASH_ObjectName, object_name);
+	msg->getStringFast(_PREHASH_Data, _PREHASH_ObjectOwner, owner_name);
+	msg->getS32Fast(_PREHASH_Data, _PREHASH_Questions, questions );
+
+	// Special case. If the objects are owned by this agent, throttle per-object instead
+	// of per-owner. It's common for residents to reset a ton of scripts that re-request
+	// permissions, as with tier boxes. UUIDs can't be valid agent names and vice-versa,
+	// so we'll reuse the same namespace for both throttle types.
+	std::string throttle_name = owner_name;
+	std::string self_name;
+	LLAgentUI::buildName( self_name );
+	if( owner_name == self_name )
+	{
+		throttle_name = taskid.getString();
+	}
+	
+	// don't display permission requests if this object is muted
+	if (LLMuteList::getInstance()->isMuted(taskid)) return;
+	
+	// throttle excessive requests from any specific user's scripts
+	typedef LLKeyThrottle<std::string> LLStringThrottle;
+	static LLStringThrottle question_throttle( LLREQUEST_PERMISSION_THROTTLE_LIMIT, LLREQUEST_PERMISSION_THROTTLE_INTERVAL );
+
+	switch (question_throttle.noteAction(throttle_name))
+	{
+		case LLStringThrottle::THROTTLE_NEWLY_BLOCKED:
+			LL_INFOS("Messaging") << "process_script_question throttled"
+					<< " owner_name:" << owner_name
+					<< LL_ENDL;
+			// Fall through
+
+		case LLStringThrottle::THROTTLE_BLOCKED:
+			// Escape altogether until we recover
+			return;
+
+		case LLStringThrottle::THROTTLE_OK:
+			break;
+	}
+
+	std::string script_question;
+	if (questions)
+	{
+		BOOL caution = FALSE;
+		S32 count = 0;
+		LLSD args;
+		args["OBJECTNAME"] = object_name;
+		args["NAME"] = owner_name;
+
+		// check the received permission flags against each permission
+		for (S32 i = 0; i < SCRIPT_PERMISSION_EOF; i++)
+		{
+			if (questions & LSCRIPTRunTimePermissionBits[i])
+			{
+				count++;
+				script_question += "    " + LLTrans::getString(SCRIPT_QUESTIONS[i]) + "\n";
+
+				// check whether permission question should cause special caution dialog
+				caution |= (SCRIPT_QUESTION_IS_CAUTION[i]);
+			}
+		}
+		args["QUESTIONS"] = script_question;
+
+		LLSD payload;
+		payload["task_id"] = taskid;
+		payload["item_id"] = itemid;
+		payload["sender"] = sender.getIPandPort();
+		payload["questions"] = questions;
+		payload["object_name"] = object_name;
+		payload["owner_name"] = owner_name;
+
+		// check whether cautions are even enabled or not
+		if (gSavedSettings.getBOOL("PermissionsCautionEnabled"))
+		{
+			// display the caution permissions prompt
+			LLNotifications::instance().add(caution ? "ScriptQuestionCaution" : "ScriptQuestion", args, payload);
+		}
+		else
+		{
+			// fall back to default behavior if cautions are entirely disabled
+			LLNotifications::instance().add("ScriptQuestion", args, payload);
+		}
+
+	}
+}
+
+
+void process_derez_container(LLMessageSystem *msg, void**)
+{
+	LL_WARNS("Messaging") << "call to deprecated process_derez_container" << LL_ENDL;
+}
+
+void container_inventory_arrived(LLViewerObject* object,
+								 InventoryObjectList* inventory,
+								 S32 serial_num,
+								 void* data)
+{
+	LL_DEBUGS("Messaging") << "container_inventory_arrived()" << LL_ENDL;
+	if( gAgent.cameraMouselook() )
+	{
+		gAgent.changeCameraToDefault();
+	}
+
+	LLFloaterInventory* view = LLFloaterInventory::getActiveInventory();
+
+	if (inventory->size() > 2)
+	{
+		// create a new inventory category to put this in
+		LLUUID cat_id;
+		cat_id = gInventory.createNewCategory(gInventory.getRootFolderID(),
+											  LLAssetType::AT_NONE,
+											  LLTrans::getString("AcquiredItems"));
+
+		InventoryObjectList::const_iterator it = inventory->begin();
+		InventoryObjectList::const_iterator end = inventory->end();
+		for ( ; it != end; ++it)
+		{
+			if ((*it)->getType() != LLAssetType::AT_CATEGORY &&
+				(*it)->getType() != LLAssetType::AT_ROOT_CATEGORY)
+			{
+				LLInventoryObject* obj = (LLInventoryObject*)(*it);
+				LLInventoryItem* item = (LLInventoryItem*)(obj);
+				LLUUID item_id;
+				item_id.generate();
+				time_t creation_date_utc = time_corrected();
+				LLPointer<LLViewerInventoryItem> new_item
+					= new LLViewerInventoryItem(item_id,
+												cat_id,
+												item->getPermissions(),
+												item->getAssetUUID(),
+												item->getType(),
+												item->getInventoryType(),
+												item->getName(),
+												item->getDescription(),
+												LLSaleInfo::DEFAULT,
+												item->getFlags(),
+												creation_date_utc);
+				new_item->updateServer(TRUE);
+				gInventory.updateItem(new_item);
+			}
+		}
+		gInventory.notifyObservers();
+		if(view)
+		{
+			view->getPanel()->setSelection(cat_id, TAKE_FOCUS_NO);
+		}
+	}
+	else if (inventory->size() == 2)
+	{
+		// we're going to get one fake root category as well as the
+		// one actual object
+		InventoryObjectList::iterator it = inventory->begin();
+
+		if ((*it)->getType() == LLAssetType::AT_CATEGORY ||
+			(*it)->getType() == LLAssetType::AT_ROOT_CATEGORY)
+		{
+			++it;
+		}
+
+		LLInventoryItem* item = (LLInventoryItem*)((LLInventoryObject*)(*it));
+		LLUUID category = gInventory.findCategoryUUIDForType(item->getType());
+
+		LLUUID item_id;
+		item_id.generate();
+		time_t creation_date_utc = time_corrected();
+		LLPointer<LLViewerInventoryItem> new_item
+			= new LLViewerInventoryItem(item_id, category,
+										item->getPermissions(),
+										item->getAssetUUID(),
+										item->getType(),
+										item->getInventoryType(),
+										item->getName(),
+										item->getDescription(),
+										LLSaleInfo::DEFAULT,
+										item->getFlags(),
+										creation_date_utc);
+		new_item->updateServer(TRUE);
+		gInventory.updateItem(new_item);
+		gInventory.notifyObservers();
+		if(view)
+		{
+			view->getPanel()->setSelection(item_id, TAKE_FOCUS_NO);
+		}
+	}
+
+	// we've got the inventory, now delete this object if this was a take
+	BOOL delete_object = (BOOL)(intptr_t)data;
+	LLViewerRegion *region = gAgent.getRegion();
+	if (delete_object && region)
+	{
+		gMessageSystem->newMessageFast(_PREHASH_ObjectDelete);
+		gMessageSystem->nextBlockFast(_PREHASH_AgentData);
+		gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+		gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+		const U8 NO_FORCE = 0;
+		gMessageSystem->addU8Fast(_PREHASH_Force, NO_FORCE);
+		gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
+		gMessageSystem->addU32Fast(_PREHASH_ObjectLocalID, object->getLocalID());
+		gMessageSystem->sendReliable(region->getHost());
+	}
+}
+
+// method to format the time.
+std::string formatted_time(const time_t& the_time)
+{
+	std::string dateStr = "["+LLTrans::getString("LTimeWeek")+"] ["
+						+LLTrans::getString("LTimeMonth")+"] ["
+						+LLTrans::getString("LTimeDay")+"] ["
+						+LLTrans::getString("LTimeHour")+"]:["
+						+LLTrans::getString("LTimeMin")+"]:["
+						+LLTrans::getString("LTimeSec")+"] ["
+						+LLTrans::getString("LTimeYear")+"]";
+
+	LLSD substitution;
+	substitution["datetime"] = (S32) the_time;
+	LLStringUtil::format (dateStr, substitution);
+	return dateStr;
+}
+
+
+void process_teleport_failed(LLMessageSystem *msg, void**)
+{
+	std::string reason;
+	std::string big_reason;
+	LLSD args;
+
+	// if we have additional alert data
+	if (msg->has(_PREHASH_AlertInfo) && msg->getSizeFast(_PREHASH_AlertInfo, _PREHASH_Message) > 0)
+	{
+		// Get the message ID
+		msg->getStringFast(_PREHASH_AlertInfo, _PREHASH_Message, reason);
+		big_reason = LLAgent::sTeleportErrorMessages[reason];
+		if ( big_reason.size() > 0 )
+		{	// Substitute verbose reason from the local map
+			args["REASON"] = big_reason;
+		}
+		else
+		{	// Nothing found in the map - use what the server returned in the original message block
+			msg->getStringFast(_PREHASH_Info, _PREHASH_Reason, reason);
+			args["REASON"] = reason;
+		}
+
+		LLSD llsd_block;
+		std::string llsd_raw;
+		msg->getStringFast(_PREHASH_AlertInfo, _PREHASH_ExtraParams, llsd_raw);
+		if (llsd_raw.length())
+		{
+			std::istringstream llsd_data(llsd_raw);
+			if (!LLSDSerialize::deserialize(llsd_block, llsd_data, llsd_raw.length()))
+			{
+				llwarns << "process_teleport_failed: Attempted to read alert parameter data into LLSD but failed:" << llsd_raw << llendl;
+			}
+			else
+			{
+				// change notification name in this special case
+				if (handle_special_notification("RegionEntryAccessBlocked", llsd_block))
+				{
+					if( gAgent.getTeleportState() != LLAgent::TELEPORT_NONE )
+					{
+						gAgent.setTeleportState( LLAgent::TELEPORT_NONE );
+					}
+					return;
+				}
+			}
+		}
+
+	}
+	else
+	{
+		msg->getStringFast(_PREHASH_Info, _PREHASH_Reason, reason);
+
+		big_reason = LLAgent::sTeleportErrorMessages[reason];
+		if ( big_reason.size() > 0 )
+		{	// Substitute verbose reason from the local map
+			args["REASON"] = big_reason;
+		}
+		else
+		{	// Nothing found in the map - use what the server returned
+			args["REASON"] = reason;
+		}
+	}
+
+	LLNotifications::instance().add("CouldNotTeleportReason", args);
+
+	// Let the interested parties know that teleport failed.
+	LLViewerParcelMgr::getInstance()->onTeleportFailed();
+
+	if( gAgent.getTeleportState() != LLAgent::TELEPORT_NONE )
+	{
+		gAgent.setTeleportState( LLAgent::TELEPORT_NONE );
+	}
+}
+
+void process_teleport_local(LLMessageSystem *msg,void**)
+{
+	LLUUID agent_id;
+	msg->getUUIDFast(_PREHASH_Info, _PREHASH_AgentID, agent_id);
+	if (agent_id != gAgent.getID())
+	{
+		LL_WARNS("Messaging") << "Got teleport notification for wrong agent!" << LL_ENDL;
+		return;
+	}
+
+	U32 location_id;
+	LLVector3 pos, look_at;
+	U32 teleport_flags;
+	msg->getU32Fast(_PREHASH_Info, _PREHASH_LocationID, location_id);
+	msg->getVector3Fast(_PREHASH_Info, _PREHASH_Position, pos);
+	msg->getVector3Fast(_PREHASH_Info, _PREHASH_LookAt, look_at);
+	msg->getU32Fast(_PREHASH_Info, _PREHASH_TeleportFlags, teleport_flags);
+
+	if( gAgent.getTeleportState() != LLAgent::TELEPORT_NONE )
+	{
+		gAgent.setTeleportState( LLAgent::TELEPORT_NONE );
+	}
+
+	// Sim tells us whether the new position is off the ground
+	if (teleport_flags & TELEPORT_FLAGS_IS_FLYING)
+	{
+		gAgent.setFlying(TRUE);
+	}
+	else
+	{
+		gAgent.setFlying(FALSE);
+	}
+
+	gAgent.setPositionAgent(pos);
+	gAgent.slamLookAt(look_at);
+
+	// likewise make sure the camera is behind the avatar
+	gAgent.resetView(TRUE, TRUE);
+
+	// send camera update to new region
+	gAgent.updateCamera();
+
+	send_agent_update(TRUE, TRUE);
+
+	// Let the interested parties know we've teleported.
+	// Vadim *HACK: Agent position seems to get reset (to render position?)
+	//              on each frame, so we have to pass the new position manually.
+	LLViewerParcelMgr::getInstance()->onTeleportFinished(true, gAgent.getPosGlobalFromAgent(pos));
+}
+
+void send_simple_im(const LLUUID& to_id,
+					const std::string& message,
+					EInstantMessage dialog,
+					const LLUUID& id)
+{
+	std::string my_name;
+	LLAgentUI::buildFullname(my_name);
+	send_improved_im(to_id,
+					 my_name,
+					 message,
+					 IM_ONLINE,
+					 dialog,
+					 id,
+					 NO_TIMESTAMP,
+					 (U8*)EMPTY_BINARY_BUCKET,
+					 EMPTY_BINARY_BUCKET_SIZE);
+}
+
+void send_group_notice(const LLUUID& group_id,
+					   const std::string& subject,
+					   const std::string& message,
+					   const LLInventoryItem* item)
+{
+	// Put this notice into an instant message form.
+	// This will mean converting the item to a binary bucket,
+	// and the subject/message into a single field.
+	std::string my_name;
+	LLAgentUI::buildFullname(my_name);
+
+	// Combine subject + message into a single string.
+	std::ostringstream subject_and_message;
+	// TODO: turn all existing |'s into ||'s in subject and message.
+	subject_and_message << subject << "|" << message;
+
+	// Create an empty binary bucket.
+	U8 bin_bucket[MAX_INVENTORY_BUFFER_SIZE];
+	U8* bucket_to_send = bin_bucket;
+	bin_bucket[0] = '\0';
+	S32 bin_bucket_size = EMPTY_BINARY_BUCKET_SIZE;
+	// If there is an item being sent, pack it into the binary bucket.
+	if (item)
+	{
+		LLSD item_def;
+		item_def["item_id"] = item->getUUID();
+		item_def["owner_id"] = item->getPermissions().getOwner();
+		std::ostringstream ostr;
+		LLSDSerialize::serialize(item_def, ostr, LLSDSerialize::LLSD_XML);
+		bin_bucket_size = ostr.str().copy(
+			(char*)bin_bucket, ostr.str().size());
+		bin_bucket[bin_bucket_size] = '\0';
+	}
+	else
+	{
+		bucket_to_send = (U8*) EMPTY_BINARY_BUCKET;
+	}
+   
+
+	send_improved_im(
+			group_id,
+			my_name,
+			subject_and_message.str(),
+			IM_ONLINE,
+			IM_GROUP_NOTICE,
+			LLUUID::null,
+			NO_TIMESTAMP,
+			bucket_to_send,
+			bin_bucket_size);
+}
+
+bool handle_lure_callback(const LLSD& notification, const LLSD& response)
+{
+	std::string text = response["message"].asString();
+	S32 option = LLNotification::getSelectedOption(notification, response);
+
+	if(0 == option)
+	{
+		LLMessageSystem* msg = gMessageSystem;
+		msg->newMessageFast(_PREHASH_StartLure);
+		msg->nextBlockFast(_PREHASH_AgentData);
+		msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+		msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+		msg->nextBlockFast(_PREHASH_Info);
+		msg->addU8Fast(_PREHASH_LureType, (U8)0); // sim will fill this in.
+		msg->addStringFast(_PREHASH_Message, text);
+		for(LLSD::array_const_iterator it = notification["payload"]["ids"].beginArray();
+			it != notification["payload"]["ids"].endArray();
+			++it)
+		{
+			msg->nextBlockFast(_PREHASH_TargetData);
+			msg->addUUIDFast(_PREHASH_TargetID, it->asUUID());
+		}
+		gAgent.sendReliableMessage();
+	}
+
+	return false;
+}
+
+void handle_lure(const LLUUID& invitee)
+{
+	LLDynamicArray<LLUUID> ids;
+	ids.push_back(invitee);
+	handle_lure(ids);
+}
+
+// Prompt for a message to the invited user.
+void handle_lure(const std::vector<LLUUID>& ids)
+{
+	LLSD edit_args;
+	edit_args["REGION"] = gAgent.getRegion()->getName();
+
+	LLSD payload;
+	for (LLDynamicArray<LLUUID>::const_iterator it = ids.begin();
+		it != ids.end();
+		++it)
+	{
+		payload["ids"].append(*it);
+	}
+	if (gAgent.isGodlike())
+	{
+		LLNotifications::instance().add("OfferTeleportFromGod", edit_args, payload, handle_lure_callback);
+	}
+	else
+	{
+		LLNotifications::instance().add("OfferTeleport", edit_args, payload, handle_lure_callback);
+	}
+}
+
+
+void send_improved_im(const LLUUID& to_id,
+							const std::string& name,
+							const std::string& message,
+							U8 offline,
+							EInstantMessage dialog,
+							const LLUUID& id,
+							U32 timestamp, 
+							const U8* binary_bucket,
+							S32 binary_bucket_size)
+{
+	pack_instant_message(
+		gMessageSystem,
+		gAgent.getID(),
+		FALSE,
+		gAgent.getSessionID(),
+		to_id,
+		name,
+		message,
+		offline,
+		dialog,
+		id,
+		0,
+		LLUUID::null,
+		gAgent.getPositionAgent(),
+		timestamp,
+		binary_bucket,
+		binary_bucket_size);
+	gAgent.sendReliableMessage();
+}
+
+
+void send_places_query(const LLUUID& query_id,
+					   const LLUUID& trans_id,
+					   const std::string& query_text,
+					   U32 query_flags,
+					   S32 category,
+					   const std::string& sim_name)
+{
+	LLMessageSystem* msg = gMessageSystem;
+
+	msg->newMessage("PlacesQuery");
+	msg->nextBlock("AgentData");
+	msg->addUUID("AgentID", gAgent.getID());
+	msg->addUUID("SessionID", gAgent.getSessionID());
+	msg->addUUID("QueryID", query_id);
+	msg->nextBlock("TransactionData");
+	msg->addUUID("TransactionID", trans_id);
+	msg->nextBlock("QueryData");
+	msg->addString("QueryText", query_text);
+	msg->addU32("QueryFlags", query_flags);
+	msg->addS8("Category", (S8)category);
+	msg->addString("SimName", sim_name);
+	gAgent.sendReliableMessage();
+}
+
+
+void process_user_info_reply(LLMessageSystem* msg, void**)
+{
+	LLUUID agent_id;
+	msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, agent_id);
+	if(agent_id != gAgent.getID())
+	{
+		LL_WARNS("Messaging") << "process_user_info_reply - "
+				<< "wrong agent id." << LL_ENDL;
+	}
+	
+	BOOL im_via_email;
+	msg->getBOOLFast(_PREHASH_UserData, _PREHASH_IMViaEMail, im_via_email);
+	std::string email;
+	msg->getStringFast(_PREHASH_UserData, _PREHASH_EMail, email);
+	std::string dir_visibility;
+	msg->getString( "UserData", "DirectoryVisibility", dir_visibility);
+
+	LLFloaterPreference::updateUserInfo(dir_visibility, im_via_email, email);
+	LLFloaterPostcard::updateUserInfo(email);
+}
+
+
+//---------------------------------------------------------------------------
+// Script Dialog
+//---------------------------------------------------------------------------
+
+const S32 SCRIPT_DIALOG_MAX_BUTTONS = 12;
+const S32 SCRIPT_DIALOG_BUTTON_STR_SIZE = 24;
+const S32 SCRIPT_DIALOG_MAX_MESSAGE_SIZE = 512;
+const char* SCRIPT_DIALOG_HEADER = "Script Dialog:\n";
+
+bool callback_script_dialog(const LLSD& notification, const LLSD& response)
+{
+	LLNotificationForm form(notification["form"]);
+	std::string button = LLNotification::getSelectedOptionName(response);
+	S32 button_idx = LLNotification::getSelectedOption(notification, response);
+	// Didn't click "Ignore"
+	if (button_idx != -1)
+	{
+		LLMessageSystem* msg = gMessageSystem;
+		msg->newMessage("ScriptDialogReply");
+		msg->nextBlock("AgentData");
+		msg->addUUID("AgentID", gAgent.getID());
+		msg->addUUID("SessionID", gAgent.getSessionID());
+		msg->nextBlock("Data");
+		msg->addUUID("ObjectID", notification["payload"]["object_id"].asUUID());
+		msg->addS32("ChatChannel", notification["payload"]["chat_channel"].asInteger());
+		msg->addS32("ButtonIndex", button_idx);
+		msg->addString("ButtonLabel", button);
+		msg->sendReliable(LLHost(notification["payload"]["sender"].asString()));
+	}
+
+	return false;
+}
+static LLNotificationFunctorRegistration callback_script_dialog_reg_1("ScriptDialog", callback_script_dialog);
+static LLNotificationFunctorRegistration callback_script_dialog_reg_2("ScriptDialogGroup", callback_script_dialog);
+
+void process_script_dialog(LLMessageSystem* msg, void**)
+{
+	S32 i;
+	LLSD payload;
+
+	LLUUID object_id;
+	msg->getUUID("Data", "ObjectID", object_id);
+
+	if (LLMuteList::getInstance()->isMuted(object_id))
+	{
+		return;
+	}
+
+	std::string message; 
+	std::string first_name;
+	std::string last_name;
+	std::string title;
+
+	S32 chat_channel;
+	msg->getString("Data", "FirstName", first_name);
+	msg->getString("Data", "LastName", last_name);
+	msg->getString("Data", "ObjectName", title);
+	msg->getString("Data", "Message", message);
+	msg->getS32("Data", "ChatChannel", chat_channel);
+
+		// unused for now
+	LLUUID image_id;
+	msg->getUUID("Data", "ImageID", image_id);
+
+	payload["sender"] = msg->getSender().getIPandPort();
+	payload["object_id"] = object_id;
+	payload["chat_channel"] = chat_channel;
+
+	// build up custom form
+	S32 button_count = msg->getNumberOfBlocks("Buttons");
+	if (button_count > SCRIPT_DIALOG_MAX_BUTTONS)
+	{
+		llwarns << "Too many script dialog buttons - omitting some" << llendl;
+		button_count = SCRIPT_DIALOG_MAX_BUTTONS;
+	}
+
+	LLNotificationForm form;
+	for (i = 0; i < button_count; i++)
+	{
+		std::string tdesc;
+		msg->getString("Buttons", "ButtonLabel", tdesc, i);
+		form.addElement("button", std::string(tdesc));
+	}
+
+	LLSD args;
+	args["TITLE"] = title;
+	args["MESSAGE"] = message;
+	LLNotificationPtr notification;
+	if (!first_name.empty())
+	{
+		args["FIRST"] = first_name;
+		args["LAST"] = last_name;
+		notification = LLNotifications::instance().add(
+			LLNotification::Params("ScriptDialog").substitutions(args).payload(payload).form_elements(form.asLLSD()));
+	}
+	else
+	{
+		args["GROUPNAME"] = last_name;
+		notification = LLNotifications::instance().add(
+			LLNotification::Params("ScriptDialogGroup").substitutions(args).payload(payload).form_elements(form.asLLSD()));
+	}
+}
+
+//---------------------------------------------------------------------------
+
+
+std::vector<LLSD> gLoadUrlList;
+
+bool callback_load_url(const LLSD& notification, const LLSD& response)
+{
+	S32 option = LLNotification::getSelectedOption(notification, response);
+
+	if (0 == option)
+	{
+		LLWeb::loadURL(notification["payload"]["url"].asString());
+	}
+
+	return false;
+}
+static LLNotificationFunctorRegistration callback_load_url_reg("LoadWebPage", callback_load_url);
+
+
+// We've got the name of the person who owns the object hurling the url.
+// Display confirmation dialog.
+void callback_load_url_name(const LLUUID& id, const std::string& first, const std::string& last, BOOL is_group)
+{
+	std::vector<LLSD>::iterator it;
+	for (it = gLoadUrlList.begin(); it != gLoadUrlList.end(); )
+	{
+		LLSD load_url_info = *it;
+		if (load_url_info["owner_id"].asUUID() == id)
+		{
+			it = gLoadUrlList.erase(it);
+
+			std::string owner_name;
+			if (is_group)
+			{
+				owner_name = first + LLTrans::getString("Group");
+			}
+			else
+			{
+				owner_name = first + " " + last;
+			}
+
+			// For legacy name-only mutes.
+			if (LLMuteList::getInstance()->isMuted(LLUUID::null, owner_name))
+			{
+				continue;
+			}
+			LLSD args;
+			args["URL"] = load_url_info["url"].asString();
+			args["MESSAGE"] = load_url_info["message"].asString();;
+			args["OBJECTNAME"] = load_url_info["object_name"].asString();
+			args["NAME"] = owner_name;
+
+			LLNotifications::instance().add("LoadWebPage", args, load_url_info);
+		}
+		else
+		{
+			++it;
+		}
+	}
+}
+
+void process_load_url(LLMessageSystem* msg, void**)
+{
+	LLUUID object_id;
+	LLUUID owner_id;
+	BOOL owner_is_group;
+	char object_name[256];		/* Flawfinder: ignore */
+	char message[256];		/* Flawfinder: ignore */
+	char url[256];		/* Flawfinder: ignore */
+
+	msg->getString("Data", "ObjectName", 256, object_name);
+	msg->getUUID(  "Data", "ObjectID", object_id);
+	msg->getUUID(  "Data", "OwnerID", owner_id);
+	msg->getBOOL(  "Data", "OwnerIsGroup", owner_is_group);
+	msg->getString("Data", "Message", 256, message);
+	msg->getString("Data", "URL", 256, url);
+
+	LLSD payload;
+	payload["object_id"] = object_id;
+	payload["owner_id"] = owner_id;
+	payload["owner_is_group"] = owner_is_group;
+	payload["object_name"] = object_name;
+	payload["message"] = message;
+	payload["url"] = url;
+
+	// URL is safety checked in load_url above
+
+	// Check if object or owner is muted
+	if (LLMuteList::getInstance()->isMuted(object_id, object_name) ||
+	    LLMuteList::getInstance()->isMuted(owner_id))
+	{
+		LL_INFOS("Messaging")<<"Ignoring load_url from muted object/owner."<<LL_ENDL;
+		return;
+	}
+
+	// Add to list of pending name lookups
+	gLoadUrlList.push_back(payload);
+
+	gCacheName->get(owner_id, owner_is_group, &callback_load_url_name);
+}
+
+
+void callback_download_complete(void** data, S32 result, LLExtStat ext_status)
+{
+	std::string* filepath = (std::string*)data;
+	LLSD args;
+	args["DOWNLOAD_PATH"] = *filepath;
+	LLNotifications::instance().add("FinishedRawDownload", args);
+	delete filepath;
+}
+
+
+void process_initiate_download(LLMessageSystem* msg, void**)
+{
+	LLUUID agent_id;
+	msg->getUUID("AgentData", "AgentID", agent_id);
+	if (agent_id != gAgent.getID())
+	{
+		LL_WARNS("Messaging") << "Initiate download for wrong agent" << LL_ENDL;
+		return;
+	}
+
+	std::string sim_filename;
+	std::string viewer_filename;
+	msg->getString("FileData", "SimFilename", sim_filename);
+	msg->getString("FileData", "ViewerFilename", viewer_filename);
+
+	if (!gXferManager->validateFileForRequest(viewer_filename))
+	{
+		llwarns << "SECURITY: Unauthorized download to local file " << viewer_filename << llendl;
+		return;
+	}
+	gXferManager->requestFile(viewer_filename,
+		sim_filename,
+		LL_PATH_NONE,
+		msg->getSender(),
+		FALSE,	// don't delete remote
+		callback_download_complete,
+		(void**)new std::string(viewer_filename));
+}
+
+
+void process_script_teleport_request(LLMessageSystem* msg, void**)
+{
+	std::string object_name;
+	std::string sim_name;
+	LLVector3 pos;
+	LLVector3 look_at;
+
+	msg->getString("Data", "ObjectName", object_name);
+	msg->getString("Data", "SimName", sim_name);
+	msg->getVector3("Data", "SimPosition", pos);
+	msg->getVector3("Data", "LookAt", look_at);
+
+	LLFloaterWorldMap* instance = LLFloaterWorldMap::getInstance();
+	if(instance)
+	{
+		instance->trackURL(
+						   sim_name, (S32)pos.mV[VX], (S32)pos.mV[VY], (S32)pos.mV[VZ]);
+		LLFloaterReg::showInstance("world_map", "center");
+	}
+	
+	// remove above two lines and replace with below line
+	// to re-enable parcel browser for llMapDestination()
+	// LLURLDispatcher::dispatch(LLSLURL::buildSLURL(sim_name, (S32)pos.mV[VX], (S32)pos.mV[VY], (S32)pos.mV[VZ]), FALSE);
+	
+}
+
+void process_covenant_reply(LLMessageSystem* msg, void**)
+{
+	LLUUID covenant_id, estate_owner_id;
+	std::string estate_name;
+	U32 covenant_timestamp;
+	msg->getUUID("Data", "CovenantID", covenant_id);
+	msg->getU32("Data", "CovenantTimestamp", covenant_timestamp);
+	msg->getString("Data", "EstateName", estate_name);
+	msg->getUUID("Data", "EstateOwnerID", estate_owner_id);
+
+	LLPanelEstateCovenant::updateEstateName(estate_name);
+	LLPanelLandCovenant::updateEstateName(estate_name);
+	LLFloaterBuyLand::updateEstateName(estate_name);
+
+	std::string owner_name =
+		LLSLURL::buildCommand("agent", estate_owner_id, "inspect");
+	LLPanelEstateCovenant::updateEstateOwnerName(owner_name);
+	LLPanelLandCovenant::updateEstateOwnerName(owner_name);
+	LLFloaterBuyLand::updateEstateOwnerName(owner_name);
+
+	LLPanelPlaceInfo* panel = LLSideTray::getInstance()->findChild<LLPanelPlaceInfo>("panel_place_info");
+	if (panel)
+	{
+		panel->updateEstateName(estate_name);
+		panel->updateEstateOwnerName(owner_name);
+	}
+
+	// standard message, not from system
+	std::string last_modified;
+	if (covenant_timestamp == 0)
+	{
+		last_modified = LLTrans::getString("covenant_last_modified")+LLTrans::getString("never_text");
+	}
+	else
+	{
+		last_modified = LLTrans::getString("covenant_last_modified")+"["
+						+LLTrans::getString("LTimeWeek")+"] ["
+						+LLTrans::getString("LTimeMonth")+"] ["
+						+LLTrans::getString("LTimeDay")+"] ["
+						+LLTrans::getString("LTimeHour")+"]:["
+						+LLTrans::getString("LTimeMin")+"]:["
+						+LLTrans::getString("LTimeSec")+"] ["
+						+LLTrans::getString("LTimeYear")+"]";
+		LLSD substitution;
+		substitution["datetime"] = (S32) covenant_timestamp;
+		LLStringUtil::format (last_modified, substitution);
+	}
+
+	LLPanelEstateCovenant::updateLastModified(last_modified);
+	LLPanelLandCovenant::updateLastModified(last_modified);
+	LLFloaterBuyLand::updateLastModified(last_modified);
+
+	// load the actual covenant asset data
+	const BOOL high_priority = TRUE;
+	if (covenant_id.notNull())
+	{
+		gAssetStorage->getEstateAsset(gAgent.getRegionHost(),
+									gAgent.getID(),
+									gAgent.getSessionID(),
+									covenant_id,
+                                    LLAssetType::AT_NOTECARD,
+									ET_Covenant,
+                                    onCovenantLoadComplete,
+									NULL,
+									high_priority);
+	}
+	else
+	{
+		std::string covenant_text;
+		if (estate_owner_id.isNull())
+		{
+			// mainland
+			covenant_text = LLTrans::getString("RegionNoCovenant");
+		}
+		else
+		{
+			covenant_text = LLTrans::getString("RegionNoCovenantOtherOwner");
+		}
+		LLPanelEstateCovenant::updateCovenantText(covenant_text, covenant_id);
+		LLPanelLandCovenant::updateCovenantText(covenant_text);
+		LLFloaterBuyLand::updateCovenantText(covenant_text, covenant_id);
+		if (panel)
+		{
+			panel->updateCovenantText(covenant_text);
+		}
+	}
+}
+
+void onCovenantLoadComplete(LLVFS *vfs,
+					const LLUUID& asset_uuid,
+					LLAssetType::EType type,
+					void* user_data, S32 status, LLExtStat ext_status)
+{
+	LL_DEBUGS("Messaging") << "onCovenantLoadComplete()" << LL_ENDL;
+	std::string covenant_text;
+	if(0 == status)
+	{
+		LLVFile file(vfs, asset_uuid, type, LLVFile::READ);
+		
+		S32 file_length = file.getSize();
+		
+		std::vector<char> buffer(file_length+1);
+		file.read((U8*)&buffer[0], file_length);		
+		// put a EOS at the end
+		buffer[file_length] = '\0';
+		
+		if( (file_length > 19) && !strncmp( &buffer[0], "Linden text version", 19 ) )
+		{
+			LLViewerTextEditor::Params params;
+			params.name("temp");
+			params.max_text_length(file_length+1);
+			LLViewerTextEditor * editor = LLUICtrlFactory::create<LLViewerTextEditor> (params);
+			if( !editor->importBuffer( &buffer[0], file_length+1 ) )
+			{
+				LL_WARNS("Messaging") << "Problem importing estate covenant." << LL_ENDL;
+				covenant_text = "Problem importing estate covenant.";
+			}
+			else
+			{
+				// Version 0 (just text, doesn't include version number)
+				covenant_text = editor->getText();
+			}
+			delete editor;
+		}
+		else
+		{
+			LL_WARNS("Messaging") << "Problem importing estate covenant: Covenant file format error." << LL_ENDL;
+			covenant_text = "Problem importing estate covenant: Covenant file format error.";
+		}
+	}
+	else
+	{
+		LLViewerStats::getInstance()->incStat( LLViewerStats::ST_DOWNLOAD_FAILED );
+		
+		if( LL_ERR_ASSET_REQUEST_NOT_IN_DATABASE == status ||
+		    LL_ERR_FILE_EMPTY == status)
+		{
+			covenant_text = "Estate covenant notecard is missing from database.";
+		}
+		else if (LL_ERR_INSUFFICIENT_PERMISSIONS == status)
+		{
+			covenant_text = "Insufficient permissions to view estate covenant.";
+		}
+		else
+		{
+			covenant_text = "Unable to load estate covenant at this time.";
+		}
+		
+		LL_WARNS("Messaging") << "Problem loading notecard: " << status << LL_ENDL;
+	}
+	LLPanelEstateCovenant::updateCovenantText(covenant_text, asset_uuid);
+	LLPanelLandCovenant::updateCovenantText(covenant_text);
+	LLFloaterBuyLand::updateCovenantText(covenant_text, asset_uuid);
+
+	LLPanelPlaceInfo* panel = LLSideTray::getInstance()->findChild<LLPanelPlaceInfo>("panel_place_info");
+	if (panel)
+	{
+		panel->updateCovenantText(covenant_text);
+	}
+}
+
+
+void process_feature_disabled_message(LLMessageSystem* msg, void**)
+{
+	// Handle Blacklisted feature simulator response...
+	LLUUID	agentID;
+	LLUUID	transactionID;
+	std::string	messageText;
+	msg->getStringFast(_PREHASH_FailureInfo,_PREHASH_ErrorMessage, messageText,0);
+	msg->getUUIDFast(_PREHASH_FailureInfo,_PREHASH_AgentID,agentID);
+	msg->getUUIDFast(_PREHASH_FailureInfo,_PREHASH_TransactionID,transactionID);
+	
+	LL_WARNS("Messaging") << "Blacklisted Feature Response:" << messageText << LL_ENDL;
+}
+
+// ------------------------------------------------------------
+// Message system exception callbacks
+// ------------------------------------------------------------
+
+void invalid_message_callback(LLMessageSystem* msg,
+								   void*,
+								   EMessageException exception)
+{
+    LLAppViewer::instance()->badNetworkHandler();
+}
+
+// Please do not add more message handlers here. This file is huge.
+// Put them in a file related to the functionality you are implementing.
+
+void LLOfferInfo::forceResponse(InventoryOfferResponse response)
+{
+	LLNotification::Params params("UserGiveItem");
+	params.functor.function(boost::bind(&LLOfferInfo::inventory_offer_callback, this, _1, _2));
+	LLNotifications::instance().forceResponse(params, response);
+}
diff --git a/indra/newview/skins/default/textures/textures.xml b/indra/newview/skins/default/textures/textures.xml
index d3366cdcaa5..7f9d09a7d65 100644
--- a/indra/newview/skins/default/textures/textures.xml
+++ b/indra/newview/skins/default/textures/textures.xml
@@ -7,7 +7,7 @@
   <texture name="Accordion_Off" file_name="containers/Accordion_Off.png" preload="false" />
   <texture name="Accordion_Press" file_name="containers/Accordion_Press.png" preload="false" />
 
- <texture name="Activate_Checkmark" file_name="taskpanel/Activate_Checkmark.png" preload="false" />
+<texture name="Activate_Checkmark" file_name="taskpanel/Activate_Checkmark.png" preload="false" />
 
   <texture name="AddItem_Disabled" file_name="icons/AddItem_Disabled.png" preload="false" />
   <texture name="AddItem_Off" file_name="icons/AddItem_Off.png" preload="false" />
@@ -394,6 +394,10 @@
   <texture name="TabIcon_Home_Off" file_name="taskpanel/TabIcon_Home_Off.png" preload="false" />
   <texture name="TabIcon_Home_Over" file_name="taskpanel/TabIcon_Home_Over.png" preload="false" />
   <texture name="TabIcon_Home_Selected" file_name="taskpanel/TabIcon_Home_Selected.png" preload="false" />
+  <texture name="TabIcon_Inventory_Large" file_name="taskpanel/TabIcon_Inventory_Large.png" preload="false" />
+  <texture name="TabIcon_Inventory_Off" file_name="taskpanel/TabIcon_Inventory_Off.png" preload="false" />
+  <texture name="TabIcon_Inventory_Over" file_name="taskpanel/TabIcon_Inventory_Over.png" preload="false" />
+  <texture name="TabIcon_Inventory_Selected" file_name="taskpanel/TabIcon_Inventory_Selected.png" preload="false" />
   <texture name="TabIcon_Me_Large" file_name="taskpanel/TabIcon_Me_Large.png" preload="false" />
   <texture name="TabIcon_Me_Off" file_name="taskpanel/TabIcon_Me_Off.png" preload="false" />
   <texture name="TabIcon_Me_Over" file_name="taskpanel/TabIcon_Me_Over.png" preload="false" />
diff --git a/indra/newview/skins/default/xui/en/floater_inventory.xml b/indra/newview/skins/default/xui/en/floater_inventory.xml
index 0f06558dd1f..ace296b4392 100644
--- a/indra/newview/skins/default/xui/en/floater_inventory.xml
+++ b/indra/newview/skins/default/xui/en/floater_inventory.xml
@@ -13,419 +13,24 @@
  single_instance="true"
  title="Inventory"
  width="467">
-    <floater.string
-     name="Title">
-        Inventory
-    </floater.string>
     <floater.string
      name="TitleFetching">
-        Inventory (Fetching [ITEM_COUNT] Items...) [FILTER]
+        Things (Fetching [ITEM_COUNT] Items...) [FILTER]
     </floater.string>
     <floater.string
      name="TitleCompleted">
-        Inventory ([ITEM_COUNT] Items) [FILTER]
-    </floater.string>
-    <floater.string
-     name="Fetched">
-        Fetched
+        Things ([ITEM_COUNT] Items) [FILTER]
     </floater.string>
-    <filter_editor
-     search_button_visible="false"
-     text_pad_left="12"
-     follows="left|top|right"
-     height="16"
-     label="Type here to search"
-     layout="topleft"
-     left="6"
-     name="inventory search editor"
-     top="34"
-     width="455" />
-    <tab_container
-     follows="left|top|right|bottom"
-     height="508"
-     layout="topleft"
-     left_delta="-4"
-     name="inventory filter tabs"
-     tab_position="top"
-     top_pad="4"
-     width="463">
-        <inventory_panel
-         follows="left|top|right|bottom"
-         height="491"
-         label="All Items"
-         layout="topleft"
-         left="1"
-         name="All Items"
-         top="16"
-         width="461" />
-        <inventory_panel
-         follows="left|top|right|bottom"
-         height="491"
-         label="Recent Items"
-         layout="topleft"
-         left_delta="0"
-         name="Recent Items"
-         top_delta="0"
-         width="461" />
-    </tab_container>
-    <menu_bar
-     bg_visible="false"
-     follows="left|top|right"
-     height="18"
-     layout="topleft"
-     left_delta="0"
-     mouse_opaque="false"
-     name="Inventory Menu"
-     top_delta="-38"
-     width="461">
-        <menu
-         height="101"
-         label="File"
-         layout="topleft"
-         left="0"
-         mouse_opaque="false"
-         name="File"
-         tear_off="true"
-         top="-117"
-         width="128">
-            <menu_item_call
-             label="Open"
-             layout="topleft"
-             name="Open">
-                <menu_item_call.on_click
-                 function="Inventory.DoToSelected"
-                 parameter="open" />
-            </menu_item_call>
-            <menu
-             create_jump_keys="true"
-             label="Upload"
-             layout="topleft"
-             name="upload"
-             tear_off="true">
-                <menu_item_call
-                 label="Image (L$[COST])..."
-                 layout="topleft"
-                 name="Upload Image"
-                 shortcut="control|U">
-                    <menu_item_call.on_click
-                     function="File.UploadImage"
-                     parameter="" />
-                    <menu_item_call.on_enable
-                     function="File.EnableUpload" />
-                </menu_item_call>
-                <menu_item_call
-                 label="Sound (L$[COST])..."
-                 layout="topleft"
-                 name="Upload Sound">
-                    <menu_item_call.on_click
-                     function="File.UploadSound"
-                     parameter="" />
-                    <menu_item_call.on_enable
-                     function="File.EnableUpload" />
-                </menu_item_call>
-                <menu_item_call
-                 label="Animation (L$[COST])..."
-                 layout="topleft"
-                 name="Upload Animation">
-                    <menu_item_call.on_click
-                     function="File.UploadAnim"
-                     parameter="" />
-                    <menu_item_call.on_enable
-                     function="File.EnableUpload" />
-                </menu_item_call>
-                <menu_item_call
-                 label="Bulk (L$[COST] per file)..."
-                 layout="topleft"
-                 name="Bulk Upload">
-                    <menu_item_call.on_click
-                     function="File.UploadBulk"
-                     parameter="" />
-                </menu_item_call>
-                <menu_item_separator
-                 layout="topleft" />
-            </menu>
-            <menu_item_separator
-             layout="topleft" />
-            <menu_item_call
-             label="New Window"
-             layout="topleft"
-             name="New Window">
-                <menu_item_call.on_click
-                 function="Inventory.NewWindow" />
-            </menu_item_call>
-            <menu_item_separator
-             layout="topleft"
-             name="separator2" />
-            <menu_item_call
-             label="Show Filters"
-             layout="topleft"
-             name="Show Filters">
-                <menu_item_call.on_click
-                 function="Inventory.ShowFilters" />
-            </menu_item_call>
-            <menu_item_call
-             label="Reset Filters"
-             layout="topleft"
-             name="Reset Current">
-                <menu_item_call.on_click
-                 function="Inventory.ResetFilter" />
-            </menu_item_call>
-            <menu_item_call
-             label="Close All Folders"
-             layout="topleft"
-             name="Close All Folders">
-                <menu_item_call.on_click
-                 function="Inventory.CloseAllFolders" />
-            </menu_item_call>
-            <menu_item_separator
-             layout="topleft"
-             name="separator3" />
-            <menu_item_call
-             label="Empty Trash"
-             layout="topleft"
-             name="Empty Trash">
-                <menu_item_call.on_click
-                 function="Inventory.EmptyTrash" />
-            </menu_item_call>
-            <menu_item_call
-             label="Empty Lost And Found"
-             layout="topleft"
-             name="Empty Lost And Found">
-                <menu_item_call.on_click
-                 function="Inventory.EmptyLostAndFound" />
-            </menu_item_call>
-        </menu>
-        <menu
-         height="121"
-         label="Create"
-         layout="topleft"
-         left="0"
-         mouse_opaque="false"
-         name="Create"
-         tear_off="true"
-         top="-201"
-         width="121">
-            <menu_item_call
-             label="New Folder"
-             layout="topleft"
-             name="New Folder">
-                <menu_item_call.on_click
-                 function="Inventory.DoCreate"
-                 parameter="category" />
-            </menu_item_call>
-            <menu_item_call
-             label="New Script"
-             layout="topleft"
-             name="New Script">
-                <menu_item_call.on_click
-                 function="Inventory.DoCreate"
-                 parameter="lsl" />
-            </menu_item_call>
-            <menu_item_call
-             label="New Note"
-             layout="topleft"
-             name="New Note">
-                <menu_item_call.on_click
-                 function="Inventory.DoCreate"
-                 parameter="notecard" />
-            </menu_item_call>
-            <menu_item_call
-             label="New Gesture"
-             layout="topleft"
-             name="New Gesture">
-                <menu_item_call.on_click
-                 function="Inventory.DoCreate"
-                 parameter="gesture" />
-            </menu_item_call>
-            <menu
-             height="175"
-             label="New Clothes"
-             layout="topleft"
-             left_delta="0"
-             mouse_opaque="false"
-             name="New Clothes"
-             top_pad="514"
-             width="125">
-                <menu_item_call
-                 label="New Shirt"
-                 layout="topleft"
-                 name="New Shirt">
-                    <menu_item_call.on_click
-                     function="Inventory.DoCreate"
-                     parameter="shirt" />
-                </menu_item_call>
-                <menu_item_call
-                 label="New Pants"
-                 layout="topleft"
-                 name="New Pants">
-                    <menu_item_call.on_click
-                     function="Inventory.DoCreate"
-                     parameter="pants" />
-                </menu_item_call>
-                <menu_item_call
-                 label="New Shoes"
-                 layout="topleft"
-                 name="New Shoes">
-                    <menu_item_call.on_click
-                     function="Inventory.DoCreate"
-                     parameter="shoes" />
-                </menu_item_call>
-                <menu_item_call
-                 label="New Socks"
-                 layout="topleft"
-                 name="New Socks">
-                    <menu_item_call.on_click
-                     function="Inventory.DoCreate"
-                     parameter="socks" />
-                </menu_item_call>
-                <menu_item_call
-                 label="New Jacket"
-                 layout="topleft"
-                 name="New Jacket">
-                    <menu_item_call.on_click
-                     function="Inventory.DoCreate"
-                     parameter="jacket" />
-                </menu_item_call>
-                <menu_item_call
-                 label="New Skirt"
-                 layout="topleft"
-                 name="New Skirt">
-                    <menu_item_call.on_click
-                     function="Inventory.DoCreate"
-                     parameter="skirt" />
-                </menu_item_call>
-                <menu_item_call
-                 label="New Gloves"
-                 layout="topleft"
-                 name="New Gloves">
-                    <menu_item_call.on_click
-                     function="Inventory.DoCreate"
-                     parameter="gloves" />
-                </menu_item_call>
-                <menu_item_call
-                 label="New Undershirt"
-                 layout="topleft"
-                 name="New Undershirt">
-                    <menu_item_call.on_click
-                     function="Inventory.DoCreate"
-                     parameter="undershirt" />
-                </menu_item_call>
-                <menu_item_call
-                 label="New Underpants"
-                 layout="topleft"
-                 name="New Underpants">
-                    <menu_item_call.on_click
-                     function="Inventory.DoCreate"
-                     parameter="underpants" />
-                </menu_item_call>
-                <menu_item_call
-                 label="New Alpha"
-                 layout="topleft"
-                 name="New Alpha">
-                    <menu_item_call.on_click
-                     function="Inventory.DoCreate"
-                     parameter="alpha" />
-                </menu_item_call>
-                <menu_item_call
-                 label="New Tattoo"
-                 layout="topleft"
-                 name="New Tattoo">
-                    <menu_item_call.on_click
-                     function="Inventory.DoCreate"
-                     parameter="tattoo" />
-                </menu_item_call>
-            </menu>
-            <menu
-             height="85"
-             label="New Body Parts"
-             layout="topleft"
-             left_delta="0"
-             mouse_opaque="false"
-             name="New Body Parts"
-             top_pad="514"
-             width="118">
-                <menu_item_call
-                 label="New Shape"
-                 layout="topleft"
-                 name="New Shape">
-                    <menu_item_call.on_click
-                     function="Inventory.DoCreate"
-                     parameter="shape" />
-                </menu_item_call>
-                <menu_item_call
-                 label="New Skin"
-                 layout="topleft"
-                 name="New Skin">
-                    <menu_item_call.on_click
-                     function="Inventory.DoCreate"
-                     parameter="skin" />
-                </menu_item_call>
-                <menu_item_call
-                 label="New Hair"
-                 layout="topleft"
-                 name="New Hair">
-                    <menu_item_call.on_click
-                     function="Inventory.DoCreate"
-                     parameter="hair" />
-                </menu_item_call>
-                <menu_item_call
-                 label="New Eyes"
-                 layout="topleft"
-                 name="New Eyes">
-                    <menu_item_call.on_click
-                     function="Inventory.DoCreate"
-                     parameter="eyes" />
-                </menu_item_call>
-            </menu>
-        </menu>
-        <menu
-         height="49"
-         label="Sort"
-         layout="topleft"
-         left="0"
-         mouse_opaque="false"
-         name="Sort"
-         tear_off="true"
-         top="-113"
-         width="118">
-            <menu_item_check
-             control_name="Inventory.SortByName"
-             label="By Name"
-             layout="topleft"
-             name="By Name">
-                <menu_item_check.on_click
-                 function="Inventory.SetSortBy"
-                 parameter="name" />
-            </menu_item_check>
-            <menu_item_check
-             control_name="Inventory.SortByDate"
-             label="By Date"
-             layout="topleft"
-             name="By Date">
-                <menu_item_check.on_click
-                 function="Inventory.SetSortBy"
-                 parameter="date" />
-            </menu_item_check>
-            <menu_item_separator
-             layout="topleft" />
-            <menu_item_check
-             control_name="Inventory.FoldersAlwaysByName"
-             label="Folders Always By Name"
-             layout="topleft"
-             name="Folders Always By Name">
-                <menu_item_check.on_click
-                 function="Inventory.SetSortBy"
-                 parameter="foldersalwaysbyname" />
-            </menu_item_check>
-            <menu_item_check
-             control_name="Inventory.SystemFoldersToTop"
-             label="System Folders To Top"
-             layout="topleft"
-             name="System Folders To Top">
-                <menu_item_check.on_click
-                 function="Inventory.SetSortBy"
-                 parameter="systemfolderstotop" />
-            </menu_item_check>
-        </menu>
-    </menu_bar>
+<panel
+     bottom="560"
+	 class="panel_main_inventory"
+	 filename="panel_main_inventory.xml"
+	 follows="all"
+	 layout="topleft"
+	 left="0"
+	 label="Inventory Panel"
+	 name="Inventory Panel"
+	 top="15"
+	 width="467">
+</panel>
 </floater>
diff --git a/indra/newview/skins/default/xui/en/floater_openobject.xml b/indra/newview/skins/default/xui/en/floater_openobject.xml
index 17f7e9bf67b..1c9fc3893eb 100644
--- a/indra/newview/skins/default/xui/en/floater_openobject.xml
+++ b/indra/newview/skins/default/xui/en/floater_openobject.xml
@@ -25,7 +25,7 @@
      width="284">
         [DESC]:
     </text>
-    <panel_inventory
+    <panel_inventory_object
      background_visible="false"
      draw_border="false"
      follows="all"
diff --git a/indra/newview/skins/default/xui/en/floater_tools.xml b/indra/newview/skins/default/xui/en/floater_tools.xml
index 29fe046ed38..93b50f6b783 100644
--- a/indra/newview/skins/default/xui/en/floater_tools.xml
+++ b/indra/newview/skins/default/xui/en/floater_tools.xml
@@ -2778,7 +2778,7 @@
              left_pad="8"
              name="button permissions"
              width="130" />
-            <panel_inventory
+            <panel_inventory_object
              follows="left|top"
              height="210"
              layout="topleft"
diff --git a/indra/newview/skins/default/xui/en/panel_main_inventory.xml b/indra/newview/skins/default/xui/en/panel_main_inventory.xml
new file mode 100644
index 00000000000..8cebabdcda5
--- /dev/null
+++ b/indra/newview/skins/default/xui/en/panel_main_inventory.xml
@@ -0,0 +1,417 @@
+<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
+<panel
+ background_visible="true"
+ follows="all"
+ height="400"
+ label="Things"
+ layout="topleft"
+ min_height="350"
+ min_width="240"
+ name="inventory panel"
+ width="333">
+    <panel.string
+     name="Title">
+        Things
+    </panel.string>
+    <filter_editor
+     text_pad_left="12"
+     follows="left|top|right"
+	 font="SanSerif"
+     height="20"
+     label="Filter"
+     layout="topleft"
+     left="15"
+     name="inventory search editor"
+     top="34"
+     width="300" />
+    <tab_container
+     follows="left|top|right|bottom"
+     height="320"
+     layout="topleft"
+     left_delta="-4"
+     name="inventory filter tabs"
+     tab_position="top"
+     top_pad="4"
+     width="313">
+        <inventory_panel
+         follows="left|top|right|bottom"
+         border="true"
+         height="310"
+         label="All Items"
+         layout="topleft"
+         left="10"
+         name="All Items"
+         top="16"
+         width="250" />
+        <inventory_panel
+         follows="left|top|right|bottom"
+         border="true"
+         height="310"
+         label="Recent Items"
+         layout="topleft"
+         left_delta="0"
+         name="Recent Items"
+         top_delta="0"
+         width="250" />
+    </tab_container>
+    <menu_bar
+     bg_visible="false"
+     follows="left|top|right"
+     height="18"
+     layout="topleft"
+     left_delta="0"
+     mouse_opaque="false"
+     name="Inventory Menu"
+     top_delta="-38"
+     width="461">
+        <menu
+         height="101"
+         label="File"
+         layout="topleft"
+         left="0"
+         mouse_opaque="false"
+         name="File"
+         tear_off="true"
+         top="-117"
+         width="128">
+            <menu_item_call
+             label="Open"
+             layout="topleft"
+             name="Open">
+                <menu_item_call.on_click
+                 function="Inventory.DoToSelected"
+                 parameter="open" />
+            </menu_item_call>
+            <menu
+             create_jump_keys="true"
+             label="Upload"
+             layout="topleft"
+             name="upload"
+             tear_off="true">
+                <menu_item_call
+                 label="Image (L$[COST])..."
+                 layout="topleft"
+                 name="Upload Image"
+                 shortcut="control|U">
+                    <menu_item_call.on_click
+                     function="File.UploadImage"
+                     parameter="" />
+                    <menu_item_call.on_enable
+                     function="File.EnableUpload" />
+                </menu_item_call>
+                <menu_item_call
+                 label="Sound (L$[COST])..."
+                 layout="topleft"
+                 name="Upload Sound">
+                    <menu_item_call.on_click
+                     function="File.UploadSound"
+                     parameter="" />
+                    <menu_item_call.on_enable
+                     function="File.EnableUpload" />
+                </menu_item_call>
+                <menu_item_call
+                 label="Animation (L$[COST])..."
+                 layout="topleft"
+                 name="Upload Animation">
+                    <menu_item_call.on_click
+                     function="File.UploadAnim"
+                     parameter="" />
+                    <menu_item_call.on_enable
+                     function="File.EnableUpload" />
+                </menu_item_call>
+                <menu_item_call
+                 label="Bulk (L$[COST] per file)..."
+                 layout="topleft"
+                 name="Bulk Upload">
+                    <menu_item_call.on_click
+                     function="File.UploadBulk"
+                     parameter="" />
+                </menu_item_call>
+                <menu_item_separator
+                 layout="topleft" />
+            </menu>
+            <menu_item_separator
+             layout="topleft" />
+            <menu_item_call
+             label="New Window"
+             layout="topleft"
+             name="New Window">
+                <menu_item_call.on_click
+                 function="Inventory.NewWindow" />
+            </menu_item_call>
+            <menu_item_separator
+             layout="topleft"
+             name="separator2" />
+            <menu_item_call
+             label="Show Filters"
+             layout="topleft"
+             name="Show Filters">
+                <menu_item_call.on_click
+                 function="Inventory.ShowFilters" />
+            </menu_item_call>
+            <menu_item_call
+             label="Reset Filters"
+             layout="topleft"
+             name="Reset Current">
+                <menu_item_call.on_click
+                 function="Inventory.ResetFilters" />
+            </menu_item_call>
+            <menu_item_call
+             label="Close All Folders"
+             layout="topleft"
+             name="Close All Folders">
+                <menu_item_call.on_click
+                 function="Inventory.CloseAllFolders" />
+            </menu_item_call>
+            <menu_item_separator
+             layout="topleft"
+             name="separator3" />
+            <menu_item_call
+             label="Empty Trash"
+             layout="topleft"
+             name="Empty Trash">
+                <menu_item_call.on_click
+                 function="Inventory.EmptyTrash" />
+            </menu_item_call>
+            <menu_item_call
+             label="Empty Lost And Found"
+             layout="topleft"
+             name="Empty Lost And Found">
+                <menu_item_call.on_click
+                 function="Inventory.EmptyLostAndFound" />
+            </menu_item_call>
+        </menu>
+        <menu
+         height="121"
+         label="Create"
+         layout="topleft"
+         left="0"
+         mouse_opaque="false"
+         name="Create"
+         tear_off="true"
+         top="-201"
+         width="121">
+            <menu_item_call
+             label="New Folder"
+             layout="topleft"
+             name="New Folder">
+                <menu_item_call.on_click
+                 function="Inventory.DoCreate"
+                 parameter="category" />
+            </menu_item_call>
+            <menu_item_call
+             label="New Script"
+             layout="topleft"
+             name="New Script">
+                <menu_item_call.on_click
+                 function="Inventory.DoCreate"
+                 parameter="lsl" />
+            </menu_item_call>
+            <menu_item_call
+             label="New Note"
+             layout="topleft"
+             name="New Note">
+                <menu_item_call.on_click
+                 function="Inventory.DoCreate"
+                 parameter="notecard" />
+            </menu_item_call>
+            <menu_item_call
+             label="New Gesture"
+             layout="topleft"
+             name="New Gesture">
+                <menu_item_call.on_click
+                 function="Inventory.DoCreate"
+                 parameter="gesture" />
+            </menu_item_call>
+            <menu
+             height="175"
+             label="New Clothes"
+             layout="topleft"
+             left_delta="0"
+             mouse_opaque="false"
+             name="New Clothes"
+             top_pad="514"
+             width="125">
+                <menu_item_call
+                 label="New Shirt"
+                 layout="topleft"
+                 name="New Shirt">
+                    <menu_item_call.on_click
+                     function="Inventory.DoCreate"
+                     parameter="shirt" />
+                </menu_item_call>
+                <menu_item_call
+                 label="New Pants"
+                 layout="topleft"
+                 name="New Pants">
+                    <menu_item_call.on_click
+                     function="Inventory.DoCreate"
+                     parameter="pants" />
+                </menu_item_call>
+                <menu_item_call
+                 label="New Shoes"
+                 layout="topleft"
+                 name="New Shoes">
+                    <menu_item_call.on_click
+                     function="Inventory.DoCreate"
+                     parameter="shoes" />
+                </menu_item_call>
+                <menu_item_call
+                 label="New Socks"
+                 layout="topleft"
+                 name="New Socks">
+                    <menu_item_call.on_click
+                     function="Inventory.DoCreate"
+                     parameter="socks" />
+                </menu_item_call>
+                <menu_item_call
+                 label="New Jacket"
+                 layout="topleft"
+                 name="New Jacket">
+                    <menu_item_call.on_click
+                     function="Inventory.DoCreate"
+                     parameter="jacket" />
+                </menu_item_call>
+                <menu_item_call
+                 label="New Skirt"
+                 layout="topleft"
+                 name="New Skirt">
+                    <menu_item_call.on_click
+                     function="Inventory.DoCreate"
+                     parameter="skirt" />
+                </menu_item_call>
+                <menu_item_call
+                 label="New Gloves"
+                 layout="topleft"
+                 name="New Gloves">
+                    <menu_item_call.on_click
+                     function="Inventory.DoCreate"
+                     parameter="gloves" />
+                </menu_item_call>
+                <menu_item_call
+                 label="New Undershirt"
+                 layout="topleft"
+                 name="New Undershirt">
+                    <menu_item_call.on_click
+                     function="Inventory.DoCreate"
+                     parameter="undershirt" />
+                </menu_item_call>
+                <menu_item_call
+                 label="New Underpants"
+                 layout="topleft"
+                 name="New Underpants">
+                    <menu_item_call.on_click
+                     function="Inventory.DoCreate"
+                     parameter="underpants" />
+                </menu_item_call>
+                <menu_item_call
+                 label="New Alpha"
+                 layout="topleft"
+                 name="New Alpha">
+                    <menu_item_call.on_click
+                     function="Inventory.DoCreate"
+                     parameter="alpha" />
+                </menu_item_call>
+                <menu_item_call
+                 label="New Tattoo"
+                 layout="topleft"
+                 name="New Tattoo">
+                    <menu_item_call.on_click
+                     function="Inventory.DoCreate"
+                     parameter="tattoo" />
+                </menu_item_call>
+            </menu>
+            <menu
+             height="85"
+             label="New Body Parts"
+             layout="topleft"
+             left_delta="0"
+             mouse_opaque="false"
+             name="New Body Parts"
+             top_pad="514"
+             width="118">
+                <menu_item_call
+                 label="New Shape"
+                 layout="topleft"
+                 name="New Shape">
+                    <menu_item_call.on_click
+                     function="Inventory.DoCreate"
+                     parameter="shape" />
+                </menu_item_call>
+                <menu_item_call
+                 label="New Skin"
+                 layout="topleft"
+                 name="New Skin">
+                    <menu_item_call.on_click
+                     function="Inventory.DoCreate"
+                     parameter="skin" />
+                </menu_item_call>
+                <menu_item_call
+                 label="New Hair"
+                 layout="topleft"
+                 name="New Hair">
+                    <menu_item_call.on_click
+                     function="Inventory.DoCreate"
+                     parameter="hair" />
+                </menu_item_call>
+                <menu_item_call
+                 label="New Eyes"
+                 layout="topleft"
+                 name="New Eyes">
+                    <menu_item_call.on_click
+                     function="Inventory.DoCreate"
+                     parameter="eyes" />
+                </menu_item_call>
+            </menu>
+        </menu>
+        <menu
+         height="49"
+         label="Sort"
+         layout="topleft"
+         left="0"
+         mouse_opaque="false"
+         name="Sort"
+         tear_off="true"
+         top="-113"
+         width="118">
+            <menu_item_check
+             control_name="Inventory.SortByName"
+             label="By Name"
+             layout="topleft"
+             name="By Name">
+                <menu_item_check.on_click
+                 function="Inventory.SetSortBy"
+                 parameter="name" />
+            </menu_item_check>
+            <menu_item_check
+             control_name="Inventory.SortByDate"
+             label="By Date"
+             layout="topleft"
+             name="By Date">
+                <menu_item_check.on_click
+                 function="Inventory.SetSortBy"
+                 parameter="date" />
+            </menu_item_check>
+            <menu_item_separator
+             layout="topleft" />
+            <menu_item_check
+             control_name="Inventory.FoldersAlwaysByName"
+             label="Folders Always By Name"
+             layout="topleft"
+             name="Folders Always By Name">
+                <menu_item_check.on_click
+                 function="Inventory.SetSortBy"
+                 parameter="foldersalwaysbyname" />
+            </menu_item_check>
+            <menu_item_check
+             control_name="Inventory.SystemFoldersToTop"
+             label="System Folders To Top"
+             layout="topleft"
+             name="System Folders To Top">
+                <menu_item_check.on_click
+                 function="Inventory.SetSortBy"
+                 parameter="systemfolderstotop" />
+            </menu_item_check>
+        </menu>
+    </menu_bar>
+</panel>
diff --git a/indra/newview/skins/default/xui/en/panel_side_tray.xml b/indra/newview/skins/default/xui/en/panel_side_tray.xml
index 3f64c9c633f..190dbe2b0fe 100644
--- a/indra/newview/skins/default/xui/en/panel_side_tray.xml
+++ b/indra/newview/skins/default/xui/en/panel_side_tray.xml
@@ -1,131 +1,149 @@
-<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
-<!-- Side tray cannot show background because it is always 
-	partially on screen to hold tab buttons. -->
-<side_tray
-  name="sidebar"
-  background_visible="false"
-  mouse_opaque="true"
-  width="333"
-  collapsed="true"
->
-  <!-- Individual tabs must show background to have seemless
-	appearance up to tray panel header word like "Home".
-	Embedded panels are inset by a pixel and so their 
-	backgrounds will not block the world fully. -->
-  <sidetray_tab
-    name="sidebar_home"
-    help_topic="sidebar_home"
-    tab_title="Home"
-    description="Home."
-    image="TabIcon_Open_Off"
-	image_selected="TabIcon_Close_Off"
-    mouse_opaque="false"
-    background_visible="true"
-  >
-      <panel
-        name="panel_home"
-        filename="panel_sidetray_home_tab.xml"
-        label="home"
-      />
-  </sidetray_tab>
-
-  <sidetray_tab
-    name="sidebar_people"
-    help_topic="sidebar_people"
-    tab_title="People"
-    description="Find your friends, contacts and people nearby."
-    image="TabIcon_People_Off"
-    image_selected="TabIcon_People_Selected"
-    mouse_opaque="false"
-    background_visible="true"
-  >
-    <panel_container
-      name="panel_container"
-      width="333"
-    >
-      <panel
-        class="panel_people"
-        name="panel_people"
-        filename="panel_people.xml"
-      />
-      <panel
-        class="panel_profile_view"
-        name="panel_profile_view"
-        filename="panel_profile_view.xml"
-      />
-      <panel
-        class="panel_group_info_sidetray"
-        name="panel_group_info_sidetray"
-        filename="panel_group_info_sidetray.xml"
-        label="Group Info"
-        font="SansSerifBold"
-      />
-      <panel
-        class="panel_block_list_sidetray"
-        name="panel_block_list_sidetray"
-        filename="panel_block_list_sidetray.xml"
-        label="Blocked Residents &amp; Objects"
-        font="SansSerifBold"
-      />
-
-    </panel_container>
-  </sidetray_tab>
-  
-  <sidetray_tab
-    name="sidebar_places"
-    help_topic="sidebar_places"
-    tab_title="Places"
-    label="Places"
-    description="Find places to go and places you&apos;ve visited before."
-    image="TabIcon_Places_Off"
-	image_selected="TabIcon_Places_Selected"
-    mouse_opaque="false"
-    background_visible="true"
-  >
-      <panel
-        class="panel_places"
-        name="panel_places"
-        filename="panel_places.xml"
-        label="Places"
-        font="SansSerifBold"
-      />
-  </sidetray_tab>
-
-  <sidetray_tab
-    name="sidebar_me"
-    help_topic="sidebar_me"
-    tab_title="Me"
-    description="Edit your public profile and Picks."
-    image="TabIcon_Me_Off"
-    image_selected="TabIcon_Me_Selected"
-    mouse_opaque="false"
-    background_visible="true"
-  >
-      <panel
-        class="panel_me_profile_view"
-        name="panel_me_profile"
-        filename="panel_me_profile.xml"
-        label="Me"
-      />
-  </sidetray_tab>
-
-  <sidetray_tab
-    name="sidebar_appearance"
-    help_topic="sidebar_appearance"
-    tab_title="Appearance"
-    description="Change your appearance and current look."
-    image="TabIcon_Appearance_Off"
-    image_selected="TabIcon_Appearance_Selected"
-    mouse_opaque="false"
-    background_visible="true"
-  >
-      <panel
-        class="panel_appearance"
-        name="panel_appearance"
-        filename="panel_appearance.xml"
-        label="Edit Appearance"
-        font="SansSerifBold"
-      />
-  </sidetray_tab>
-
-</side_tray>
+<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
+<!-- Side tray cannot show background because it is always 
+	partially on screen to hold tab buttons. -->
+<side_tray
+  name="sidebar"
+  background_visible="false"
+  mouse_opaque="true"
+  width="333"
+  collapsed="true"
+>
+  <!-- Individual tabs must show background to have seemless
+	appearance up to tray panel header word like "Home".
+	Embedded panels are inset by a pixel and so their 
+	backgrounds will not block the world fully. -->
+  <sidetray_tab
+    name="sidebar_home"
+    help_topic="sidebar_home"
+    tab_title="Home"
+    description="Home."
+    image="TabIcon_Open_Off"
+	image_selected="TabIcon_Close_Off"
+    mouse_opaque="false"
+    background_visible="true"
+  >
+      <panel
+        name="panel_home"
+        filename="panel_sidetray_home_tab.xml"
+        label="home"
+      />
+  </sidetray_tab>
+
+  <sidetray_tab
+    name="sidebar_people"
+    help_topic="sidebar_people"
+    tab_title="People"
+    description="Find your friends, contacts and people nearby."
+    image="TabIcon_People_Off"
+    image_selected="TabIcon_People_Selected"
+    mouse_opaque="false"
+    background_visible="true"
+  >
+    <panel_container
+      name="panel_container"
+      width="333"
+    >
+      <panel
+        class="panel_people"
+        name="panel_people"
+        filename="panel_people.xml"
+      />
+      <panel
+        class="panel_profile_view"
+        name="panel_profile_view"
+        filename="panel_profile_view.xml"
+      />
+      <panel
+        class="panel_group_info_sidetray"
+        name="panel_group_info_sidetray"
+        filename="panel_group_info_sidetray.xml"
+        label="Group Info"
+        font="SansSerifBold"
+      />
+      <panel
+        class="panel_block_list_sidetray"
+        name="panel_block_list_sidetray"
+        filename="panel_block_list_sidetray.xml"
+        label="Blocked Residents &amp; Objects"
+        font="SansSerifBold"
+      />
+
+    </panel_container>
+  </sidetray_tab>
+  
+  <sidetray_tab
+    name="sidebar_places"
+    help_topic="sidebar_places"
+    tab_title="Places"
+    label="Places"
+    description="Find places to go and places you&apos;ve visited before."
+    image="TabIcon_Places_Off"
+	image_selected="TabIcon_Places_Selected"
+    mouse_opaque="false"
+    background_visible="true"
+  >
+      <panel
+        class="panel_places"
+        name="panel_places"
+        filename="panel_places.xml"
+        label="Places"
+        font="SansSerifBold"
+      />
+  </sidetray_tab>
+
+  <sidetray_tab
+    name="sidebar_me"
+    help_topic="sidebar_me"
+    tab_title="Me"
+    description="Edit your public profile and Picks."
+    image="TabIcon_Me_Off"
+    image_selected="TabIcon_Me_Selected"
+    mouse_opaque="false"
+    background_visible="true"
+  >
+      <panel
+        class="panel_me_profile_view"
+        name="panel_me_profile"
+        filename="panel_me_profile.xml"
+        label="Me"
+      />
+  </sidetray_tab>
+
+  <sidetray_tab
+    name="sidebar_appearance"
+    help_topic="sidebar_appearance"
+    tab_title="Appearance"
+    description="Change your appearance and current look."
+    image="TabIcon_Appearance_Off"
+    image_selected="TabIcon_Appearance_Selected"
+    mouse_opaque="false"
+    background_visible="true"
+  >
+      <panel
+        class="panel_appearance"
+        name="panel_appearance"
+        filename="panel_appearance.xml"
+        label="Edit Appearance"
+        font="SansSerifBold"
+      />
+  </sidetray_tab>
+
+  <sidetray_tab
+    name="sidebar_inventory"
+    help_topic="sidebar_inventory"
+    tab_title="Inventory"
+    description="Browse your inventory."
+    image="TabIcon_Inventory_Off"
+    mouse_opaque="false"
+    background_visible="true"
+  >
+      <panel
+        class="sidepanel_inventory"
+        name="sidepanel_inventory"
+        filename="sidepanel_inventory.xml"
+        label="Edit Inventory"
+        font="SansSerifBold"
+      />
+  </sidetray_tab>
+
+</side_tray>
diff --git a/indra/newview/skins/default/xui/en/panel_sidetray_home_tab.xml b/indra/newview/skins/default/xui/en/panel_sidetray_home_tab.xml
index 247054772e1..9636e321870 100644
--- a/indra/newview/skins/default/xui/en/panel_sidetray_home_tab.xml
+++ b/indra/newview/skins/default/xui/en/panel_sidetray_home_tab.xml
@@ -12,7 +12,7 @@
      bg_alpha_color="DkGray2"
      class="panel_sidetray_home_info"
      follows="left|top|right"
-     height="120"
+     height="90"
      layout="topleft"
      left="15"
      top="17"
@@ -42,7 +42,7 @@
          width="20" />
         <text
          follows="left|right|bottom"
-         height="120"
+         height="90"
          layout="topleft"
          left="10"
          mouse_opaque="false"
@@ -59,7 +59,7 @@
      bg_alpha_color="DkGray2"
      class="panel_sidetray_home_info"
      follows="left|top|right"
-     height="120"
+     height="90"
      layout="topleft"
      left="15"
      top_pad="15"
@@ -89,7 +89,7 @@
          image_name="TabIcon_Places_Selected"/>
         <text
          follows="all"
-         height="120"
+         height="90"
          layout="topleft"
          left="10"
          mouse_opaque="false"
@@ -106,7 +106,7 @@
      bg_alpha_color="DkGray2"
      class="panel_sidetray_home_info"
      follows="left|top|right"
-     height="120"
+     height="90"
      layout="topleft"
      left="15"
      top_pad="15"
@@ -136,7 +136,7 @@
          image_name="TabIcon_Me_Selected"/>
         <text
          follows="all"
-         height="120"
+         height="90"
          layout="topleft"
          left="10"
          mouse_opaque="false"
@@ -153,7 +153,7 @@
      bg_alpha_color="DkGray2"
      class="panel_sidetray_home_info"
      follows="left|top|right"
-     height="120"
+     height="90"
      layout="topleft"
      left="15"
      top_pad="15"
@@ -183,7 +183,7 @@
          image_name="TabIcon_Appearance_Selected"/>
         <text
          follows="all"
-         height="120"
+         height="90"
          layout="topleft"
          left="10"
          mouse_opaque="false"
@@ -195,4 +195,51 @@
             Change your appearance and current look.
         </text>
     </panel>
+    <panel
+     background_visible="true"
+     bg_alpha_color="DkGray2"
+     class="panel_sidetray_home_info"
+     follows="left|top|right"
+     height="90"
+     layout="topleft"
+     left="15"
+     top_pad="15"
+     name="sidebar_inventory"
+     width="303">
+        <text
+         follows="left|right|top"
+         font="SansSerifBigBold"
+         height="30"
+         layout="topleft"
+         left="10"
+         mouse_opaque="false"
+         name="tab_name"
+         text_color="EmphasisColor"
+         top="10"
+         value="My Inventory"
+         width="200"
+         word_wrap="true" />
+        <icon
+         follows="top|right"
+         height="20"
+         layout="topleft"
+         name="tab_icon"
+         right="-10"
+         top="10"
+         width="20"
+         image_name="TabIcon_Inventory_Selected"/>
+        <text
+         follows="all"
+         height="90"
+         layout="topleft"
+         left="10"
+         mouse_opaque="false"
+         name="tab_description"
+         right="-10"
+         text_color="white"
+         top="40"
+         word_wrap="true">
+            Browse your inventory.
+        </text>
+    </panel>
 </panel>
diff --git a/indra/newview/skins/default/xui/en/sidepanel_inventory.xml b/indra/newview/skins/default/xui/en/sidepanel_inventory.xml
new file mode 100644
index 00000000000..3b3fbcb936e
--- /dev/null
+++ b/indra/newview/skins/default/xui/en/sidepanel_inventory.xml
@@ -0,0 +1,122 @@
+<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
+<panel
+ background_visible="true"
+ follows="all"
+ height="400"
+ label="Places"
+ layout="topleft"
+ min_height="350"
+ min_width="240"
+ name="objects panel"
+ width="333">
+    <tab_container
+     follows="all"
+     height="360"
+     layout="topleft"
+     left="9"
+     name="Inventory Tabs"
+     tab_position="top"
+     top="30"
+     width="313"
+	 tab_height="0"
+	 visible="true">
+	 <panel
+	      class="panel_main_inventory"
+		  filename="panel_main_inventory.xml"
+		  follows="all"
+		  layout="topleft"
+		  left="0"
+		  name="panel_main_inventory"
+		  top="15"
+		  label=""
+		  height="300"
+		  width="467">
+    <panel
+     height="25"
+     layout="bottomright"
+     left="0"
+     help_topic="objects_button_tab"
+     name="button_panel"
+	 bottom="5"
+     width="313">
+        <button
+         enabled="true"
+         follows="bottom|left"
+         font="SansSerifSmallBold"
+         height="25"
+         label="Info"
+         layout="topleft"
+         left="0"
+         name="info_btn"
+         top="0"
+         width="60" />
+        <button
+         enabled="true"
+         follows="bottom|left"
+         font="SansSerifSmallBold"
+         height="25"
+         label="Share"
+         layout="topleft"
+         left_pad="5"
+         name="share_btn"
+         top="0"
+         width="60" />
+        <button
+         enabled="false"
+         follows="bottom|left"
+         font="SansSerifSmallBold"
+         height="25"
+         label="Wear"
+         layout="topleft"
+         left="130"
+         name="wear_btn"
+         top="0"
+         width="60" />
+        <button
+         enabled="false"
+         follows="bottom|left"
+         font="SansSerifSmallBold"
+         height="25"
+         label="Play"
+         layout="topleft"
+         name="play_btn"
+         left="130"
+         top="0"
+         width="50" />
+        <button
+         enabled="false"
+         follows="bottom|left"
+         font="SansSerifSmallBold"
+         height="25"
+         label="Teleport"
+         layout="topleft"
+         left="130"
+         name="teleport_btn"
+         top="0"
+         width="77" />
+        <button
+         follows="bottom|right"
+         font="SansSerifSmallBold"
+         height="25"
+         label="v"
+         layout="topleft"
+         name="overflow_btn"
+         right="-10"
+         top="0"
+         width="30" />
+    </panel>
+    </panel>
+   </tab_container>
+
+    <panel
+     class="sidepanel_object_info"
+     filename="sidepanel_object_info.xml"
+     follows="all"
+     height="360"
+     layout="topleft"
+     left="0"
+     help_topic="objects_info_tab"
+     name="sidepanel_object_info"
+     top="30"
+     visible="false" />
+</panel>
-- 
GitLab