Index: code/branches/menu/data/gui/layouts/InGameMenu.layout
===================================================================
--- code/branches/menu/data/gui/layouts/InGameMenu.layout	(revision 6024)
+++ code/branches/menu/data/gui/layouts/InGameMenu.layout	(revision 6024)
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<GUILayout >
+    <Window Type="DefaultWindow" Name="orxonox/InGameMenu_RootWindow" >
+        <Property Name="InheritsAlpha" Value="False" />
+        <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
+        <Property Name="UnifiedAreaRect" Value="{{0,0},{0,0},{1,0},{1,0}}" />
+        <Window Type="TaharezLook/Button" Name="orxonox/InGameMenu_MainMenuButton" >
+            <Property Name="Font" Value="BlueHighway-12" />
+            <Property Name="Text" Value="MainMenu" />
+            <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
+            <Property Name="UnifiedAreaRect" Value="{{0.4,0},{0.2,0},{0.6,0},{0.3,0}}" />
+            <Property Name="Alpha" Value="0.7" />
+            <Event Name="Clicked" Function="InGameMenu.button_mainmenu_clicked"/>
+        </Window>
+        <Window Type="TaharezLook/Button" Name="orxonox/InGameMenu_QuitButton" >
+            <Property Name="Font" Value="BlueHighway-12" />
+            <Property Name="Text" Value="Quit" />
+            <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
+            <Property Name="UnifiedAreaRect" Value="{{0.4,0},{0.4,0},{0.6,0},{0.5,0}}" />
+            <Property Name="Alpha" Value="0.7" />
+            <Event Name="Clicked" Function="InGameMenu.button_quit_clicked"/>
+        </Window>
+        <Window Type="TaharezLook/Button" Name="orxonox/InGameMenu_ReturnButton" >
+            <Property Name="Font" Value="BlueHighway-12" />
+            <Property Name="Text" Value="return to Game" />
+            <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
+            <Property Name="UnifiedAreaRect" Value="{{0.4,0},{0.6,0},{0.6,0},{0.7,0}}" />
+            <Property Name="Alpha" Value="0.7" />
+            <Event Name="Clicked" Function="InGameMenu.button_return_clicked"/>
+        </Window>
+    </Window>
+</GUILayout>
Index: code/branches/menu/data/gui/layouts/MainMenu.layout
===================================================================
--- code/branches/menu/data/gui/layouts/MainMenu.layout	(revision 6023)
+++ code/branches/menu/data/gui/layouts/MainMenu.layout	(revision 6024)
@@ -6,4 +6,5 @@
     <Property Name="FrameEnabled" Value="set:true"/>
     <Property Name="BackgroundEnabled" Value="set:false"/>
+    <Property Name="InheritsAlpha" Value="False" />
  
         <Window Type="TaharezLook/Button" Name="orxonox/StandaloneButton">
Index: code/branches/menu/data/gui/layouts/QuestGUI.layout
===================================================================
--- code/branches/menu/data/gui/layouts/QuestGUI.layout	(revision 6023)
+++ code/branches/menu/data/gui/layouts/QuestGUI.layout	(revision 6024)
@@ -6,4 +6,5 @@
     <Property Name="FrameEnabled" Value="set:true"/>
     <Property Name="BackgroundEnabled" Value="set:false"/>
+    <Property Name="InheritsAlpha" Value="False" />
 
         <Window Type="TaharezLook/Titlebar" Name="orxonox/QuestGUI/Title">
Index: code/branches/menu/data/gui/scripts/InGameMenu.lua
===================================================================
--- code/branches/menu/data/gui/scripts/InGameMenu.lua	(revision 6024)
+++ code/branches/menu/data/gui/scripts/InGameMenu.lua	(revision 6024)
@@ -0,0 +1,37 @@
+-- InGameMenu.lua
+
+BasicGUI = require("BasicGUI")
+local P = BasicGUI:new() --inherit everything from the gui package
+if _REQUIREDNAME == nil then
+    InGameMenu = P
+else
+    _G[_REQUIREDNAME] = P
+end
+
+P.filename = "InGameMenu"
+P.layoutString = "InGameMenu.layout"
+
+function P:init()
+end
+
+
+-- events for ingamemenu
+function P.button_quit_clicked(e)
+    orxonox.CommandExecutor:execute("hideGUI InGameMenu")
+    orxonox.CommandExecutor:execute("exit")
+end
+
+function P.button_mainmenu_clicked(e)
+    orxonox.Game:getInstance():popState()
+    orxonox.Game:getInstance():popState()
+    orxonox.Game:getInstance():requestState("mainmenu")
+    orxonox.CommandExecutor:execute("showGUI MainMenu")
+    orxonox.CommandExecutor:execute("hideGUI InGameMenu")
+end
+
+function P.button_return_clicked(e)
+    orxonox.CommandExecutor:execute("hideGUI InGameMenu")
+end
+
+return P
+
Index: code/branches/menu/data/gui/scripts/InitialiseGUI.lua
===================================================================
--- code/branches/menu/data/gui/scripts/InitialiseGUI.lua	(revision 6023)
+++ code/branches/menu/data/gui/scripts/InitialiseGUI.lua	(revision 6024)
@@ -14,4 +14,9 @@
 
 loadedGUIs = {}
+cursorVisibility = {}
+activeSheets = {}
+nrOfActiveSheets = 0
+root = nil
+bShowsCursor = false
 
 -- loads the GUI with the specified filename
@@ -35,6 +40,6 @@
 end
 
-function showGUI(filename, ptr)
-    gui = showGUI(filename)
+function showGUI(filename, bCursorVisible, ptr)
+    gui = showGUI(filename, bCursorVisible)
     gui.overlay = ptr
 end
@@ -42,43 +47,85 @@
 -- shows the specified and loads it if not loaded already
 -- be sure to set the global variable "filename" before calling this function
-function showGUI(filename)
-    if current == nil or current.filename ~= filename then
-        current = loadedGUIs[filename]
-        if current == nil then
-            current = loadGUI(filename)
-        end
-        system:setGUISheet(current.window)
+function showGUI(filename, bCursorVisible)
+--     bCursorVisibile=false
+    if bCursorVisible == nil then
+        cursorVisibility= true
     end
-    current:show()
+
+    if root == nil then
+        root = winMgr:createWindow("TaharezLook/StaticImage", "AbsoluteRootWindow")
+        root:setProperty("Alpha", "0.0")
+        root:setSize(CEGUI.UVector2(CEGUI.UDim(1.0,0),CEGUI.UDim(1.0,0)))
+        system:setGUISheet(root)
+    end
+
+    local currentGUI = loadedGUIs[filename]
+    if(currentGUI == nil) then
+        currentGUI = loadGUI(filename)
+    end
+
+    if(root:isChild(currentGUI.window)) then
+        root:removeChildWindow(currentGUI.window)
+    end
+    root:addChildWindow(currentGUI.window)
+
+    if bCursorVisible then
+        showCursor()
+    else
+        hideCursor()
+    end
+    cursorVisibility[filename]=bCursorVisible
+    
+    nrOfActiveSheets = nrOfActiveSheets + 1
+    table.insert(activeSheets, filename)
+    activeSheets[nrOfActiveSheets] = filename
+    
+    currentGUI:show()
     showing = true
-    return current
-end
-
-function toggleGUI()
-    if showing == true then
-        current:hide()
-        cursor:hide()
-        showing = false
-    else
-        current:show()
-        cursor:show()
-        showing = true
-    end
-    return showing
+    return currentGUI
 end
 
 function hideCursor()
-    cursor:hide()
+    if bShowsCursor==true then
+        bShowsCursor=false
+        cursor:hide()
+    end
 end
 
 function showCursor()
-    cursor:show()
+    if bShowsCursor==false then
+        bShowsCursor=true
+        cursor:show()
+    end
 end
 
 function hideGUI(filename)
-    current = loadedGUIs[filename]
-    if current ~= nil then
-        current:hide()
-        showing = false
+    local currentGUI = loadedGUIs[filename]
+    if currentGUI == nil then
+        return
     end
+    currentGUI:hide()
+    root:removeChildWindow(currentGUI.window)
+    showing = false
+    i=1
+    while activeSheets[i] do
+        if activeSheets[i+1] == nil then
+            if activeSheets[i-1] ~= nil then
+                if cursorVisibility[ activeSheets[i-1] ] == true then
+                    showCursor()
+                else
+                    hideCursor()
+                end
+            else
+                hideCursor()
+            end
+        end
+        if activeSheets[i] == filename then
+            table.remove( activeSheets, i )
+            nrOfActiveSheets = nrOfActiveSheets-1
+        else
+            i = i+1
+        end
+    end
+    cursorVisibility[filename] = nil -- remove the cursor visibility of the current gui from the table
 end
Index: code/branches/menu/data/gui/scripts/MainMenu.lua
===================================================================
--- code/branches/menu/data/gui/scripts/MainMenu.lua	(revision 6023)
+++ code/branches/menu/data/gui/scripts/MainMenu.lua	(revision 6024)
@@ -50,5 +50,5 @@
         orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw")
         orxonox.CommandExecutor:execute("startGame")
-        toggleGUI()
+        hideGUI(P.filename)
     end
 end
@@ -59,5 +59,5 @@
         orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw")
         orxonox.CommandExecutor:execute("startServer")
-        toggleGUI()
+        hideGUI(P.filename)
     end
 end
@@ -68,5 +68,5 @@
         orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw")
         orxonox.CommandExecutor:execute("startDedicated")
-        toggleGUI()
+        hideGUI(P.filename)
     end
 end
@@ -77,5 +77,6 @@
         orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw")
         orxonox.CommandExecutor:execute("startClient")
-        toggleGUI()
+        hideGUI(P.filename)
+
     end
 end
Index: code/branches/menu/src/libraries/core/CMakeLists.txt
===================================================================
--- code/branches/menu/src/libraries/core/CMakeLists.txt	(revision 6023)
+++ code/branches/menu/src/libraries/core/CMakeLists.txt	(revision 6024)
@@ -85,4 +85,5 @@
   TOLUA_FILES
     CommandExecutor.h
+    Game.h
     Loader.h
     LuaState.h
Index: code/branches/menu/src/libraries/core/GUIManager.cc
===================================================================
--- code/branches/menu/src/libraries/core/GUIManager.cc	(revision 6023)
+++ code/branches/menu/src/libraries/core/GUIManager.cc	(revision 6024)
@@ -50,8 +50,11 @@
 
 #include "util/Clock.h"
+#include "util/Convert.h"
 #include "util/Debug.h"
 #include "util/Exception.h"
 #include "util/OrxAssert.h"
+#include "ConsoleCommand.h"
 #include "Core.h"
+#include "input/InputManager.h"
 #include "LuaState.h"
 #include "PathConfig.h"
@@ -86,4 +89,7 @@
     GUIManager* GUIManager::singletonPtr_s = 0;
 
+    SetConsoleCommandShortcut(GUIManager, showGUI).accessLevel(AccessLevel::User).defaultValue(1, true);
+    SetConsoleCommandShortcut(GUIManager, hideGUI).accessLevel(AccessLevel::User);
+
     /**
     @brief
@@ -204,7 +210,51 @@
         For more details check out loadGUI_2.lua where the function presides.
     */
-    void GUIManager::showGUI(const std::string& name)
-    {
-        this->luaState_->doString("showGUI(\"" + name + "\")", rootFileInfo_);
+    /*static*/ void GUIManager::showGUI(const std::string& name, bool showCursor)
+    {
+        std::pair<std::set<std::string>::iterator,bool> result = GUIManager::getInstance().showingGUIs_.insert(name);
+        if(result.second == false) //!< GUI already showing.
+            return;
+        if(GUIManager::getInstance().showingGUIs_.size() == 1 && result.second == true) //!< If it's the first GUI.
+        {
+//             GUIManager::getInstance().executeCode("showCursor()");
+            InputManager::getInstance().enterState("guiMouseOnly");
+        }
+        GUIManager::getInstance().executeCode("showGUI(\"" + name + "\", " + multi_cast<std::string>(showCursor) + ")");
+    }
+
+    /**
+    @brief
+        Hack-ish. Needed for GUIOverlay.
+    */
+    void GUIManager::showGUIExtra(const std::string& name, const std::string& ptr, bool showCursor)
+    {
+        std::pair<std::set<std::string>::iterator,bool> result = this->showingGUIs_.insert(name);
+        if(result.second == false) //!< GUI already showing.
+            return;
+        if(this->showingGUIs_.size() == 1 && result.second == true) //!< If it's the first GUI.
+        {
+            this->executeCode("showCursor()");
+            InputManager::getInstance().enterState("guiMouseOnly");
+        }
+        this->executeCode("showGUI(\"" + name + "\", " + multi_cast<std::string>(showCursor) + ", " + ptr + ")");
+    }
+
+    /**
+    @brief
+        Hides specified GUI.
+    @param name
+        The name of the GUI.
+    */
+    /*static*/ void GUIManager::hideGUI(const std::string& name)
+    {
+        bool present = GUIManager::getInstance().showingGUIs_.erase(name);
+        if(!present) //!< If there was nothing to erase.
+            return;
+        GUIManager::getInstance().executeCode("hideGUI(\"" + name + "\")");
+        if(GUIManager::getInstance().showingGUIs_.size() == 0)
+        {
+            GUIManager::getInstance().executeCode("hideCursor()");
+            InputManager::getInstance().leaveState("guiMouseOnly");
+        }
     }
 
Index: code/branches/menu/src/libraries/core/GUIManager.h
===================================================================
--- code/branches/menu/src/libraries/core/GUIManager.h	(revision 6023)
+++ code/branches/menu/src/libraries/core/GUIManager.h	(revision 6024)
@@ -34,4 +34,5 @@
 
 #include <map>
+#include <set>
 #include <string>
 #include <CEGUIForwardRefs.h>
@@ -65,8 +66,9 @@
         ~GUIManager();
 
-        void update(const Clock& time);
+        void update(const Clock& time); 
 
-        void showGUI(const std::string& name);
-        void executeCode(const std::string& str);
+        static void showGUI(const std::string& name, bool showCursor=true);
+        void showGUIExtra(const std::string& name, const std::string& ptr, bool showCursor=true);
+        static void hideGUI(const std::string& name);
 
         void setCamera(Ogre::Camera* camera);
@@ -82,4 +84,8 @@
     private:
         GUIManager(const GUIManager& instance); //!< private and undefined copy c'tor (this is a singleton class)
+
+        std::set<std::string> showingGUIs_; //!< Keeps track of all the GUIs that are currently showing.
+
+        void executeCode(const std::string& str);
 
         // keyHandler functions
Index: code/branches/menu/src/libraries/core/Game.h
===================================================================
--- code/branches/menu/src/libraries/core/Game.h	(revision 6023)
+++ code/branches/menu/src/libraries/core/Game.h	(revision 6024)
@@ -58,7 +58,8 @@
 #define DeclareGameState(className, stateName, bIgnoreTickTime, bGraphicsMode) \
     static bool BOOST_PP_CAT(bGameStateDummy_##className, __LINE__) = orxonox::Game::declareGameState<className>(#className, stateName, bIgnoreTickTime, bGraphicsMode)
-
+// tolua_begin
 namespace orxonox
 {
+// tolua_end
     class GameConfiguration;
 
@@ -78,6 +79,9 @@
         You should only create this singleton once because it owns the Core class! (see remark there)
     */
-    class _CoreExport Game : public Singleton<Game>
+// tolua_begin
+    class _CoreExport Game
+        : public Singleton<Game>
     {
+// tolua_end
         friend class Singleton<Game>;
         typedef std::vector<shared_ptr<GameState> > GameStateVector;
@@ -95,7 +99,9 @@
         void stop();
 
-        void requestState(const std::string& name);
-        void requestStates(const std::string& names);
-        void popState();
+        static Game& getInstance(){ return Singleton<Game>::getInstance(); } // tolua_export
+
+        void requestState(const std::string& name); //tolua_export
+        void requestStates(const std::string& names); //tolua_export
+        void popState(); //tolua_export
 
         const Clock& getGameClock() { return *this->gameClock_; }
@@ -183,5 +189,5 @@
         static std::map<std::string, GameStateInfo> gameStateDeclarations_s;
         static Game* singletonPtr_s;        //!< Pointer to the Singleton
-    };
+    }; //tolua_export
 
     template <class T>
@@ -209,5 +215,5 @@
         return true;
     }
-}
+} //tolua_export
 
 #endif /* _Game_H__ */
Index: code/branches/menu/src/libraries/core/LuaState.cc
===================================================================
--- code/branches/menu/src/libraries/core/LuaState.cc	(revision 6023)
+++ code/branches/menu/src/libraries/core/LuaState.cc	(revision 6024)
@@ -164,5 +164,5 @@
             if (sourceFileInfo != NULL)
                 origin = " originating from " + sourceFileInfo_->filename;
-            COUT(2) << "Error in Lua-script" << origin << ": " << lua_tostring(luaState_, -1) << std::endl;
+            COUT(1) << "Error in Lua-script" << origin << ": " << lua_tostring(luaState_, -1) << std::endl;
             // return value is nil
             lua_pushnil(luaState_);
Index: code/branches/menu/src/modules/overlays/GUIOverlay.cc
===================================================================
--- code/branches/menu/src/modules/overlays/GUIOverlay.cc	(revision 6023)
+++ code/branches/menu/src/modules/overlays/GUIOverlay.cc	(revision 6024)
@@ -72,13 +72,10 @@
             out << reinterpret_cast<long>(this);
             str = out.str();
-            GUIManager::getInstance().executeCode("showCursor()");
-            InputManager::getInstance().enterState("guiMouseOnly");
-            GUIManager::getInstance().executeCode("showGUI(\"" + this->guiName_ + "\", " + str + ")");
+            COUT(1) << "GUIManager ptr: " << str << std::endl;
+            GUIManager::getInstance().showGUIExtra(this->guiName_, str);
         }
         else
         {
-            GUIManager::getInstance().executeCode("hideGUI(\"" + this->guiName_ + "\")");
-            GUIManager::getInstance().executeCode("hideCursor()");
-            InputManager::getInstance().leaveState("guiMouseOnly");
+            GUIManager::hideGUI(this->guiName_);
         }
     }
Index: code/branches/menu/src/orxonox/gamestates/GSGraphics.cc
===================================================================
--- code/branches/menu/src/orxonox/gamestates/GSGraphics.cc	(revision 6023)
+++ code/branches/menu/src/orxonox/gamestates/GSGraphics.cc	(revision 6024)
@@ -64,6 +64,5 @@
     void GSGraphics::activate()
     {
-        // add console command to toggle GUI
-        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSGraphics::toggleGUI, this), "toggleGUI"));
+        
     }
 
@@ -78,16 +77,4 @@
     }
 
-    /**
-    @brief
-        Toggles the visibility of the current GUI
-
-        This function just executes a Lua function in the main script of the GUI by accessing the GUIManager.
-        For more details on this function check out the Lua code.
-    */
-    void GSGraphics::toggleGUI()
-    {
-        GUIManager::getInstance().executeCode("toggleGUI()");
-    }
-
     void GSGraphics::update(const Clock& time)
     {
Index: code/branches/menu/src/orxonox/gamestates/GSGraphics.h
===================================================================
--- code/branches/menu/src/orxonox/gamestates/GSGraphics.h	(revision 6023)
+++ code/branches/menu/src/orxonox/gamestates/GSGraphics.h	(revision 6024)
@@ -57,6 +57,4 @@
         void update(const Clock& time);
 
-        void toggleGUI();
-
     private:
     };
Index: code/branches/menu/src/orxonox/gamestates/GSLevel.cc
===================================================================
--- code/branches/menu/src/orxonox/gamestates/GSLevel.cc	(revision 6023)
+++ code/branches/menu/src/orxonox/gamestates/GSLevel.cc	(revision 6024)
@@ -101,13 +101,9 @@
         if (show)
         {
-            GUIManager::getInstance().showGUI("inGameTest");
-            GUIManager::getInstance().executeCode("showCursor()");
-            InputManager::getInstance().enterState("guiMouseOnly");
+            GUIManager::showGUI("inGameTest");
         }
         else
         {
-            GUIManager::getInstance().executeCode("hideGUI(\"inGameTest\")");
-            GUIManager::getInstance().executeCode("hideCursor()");
-            InputManager::getInstance().leaveState("guiMouseOnly");
+            GUIManager::hideGUI("inGameTest");
         }
     }
Index: code/branches/menu/src/orxonox/gamestates/GSMainMenu.cc
===================================================================
--- code/branches/menu/src/orxonox/gamestates/GSMainMenu.cc	(revision 6023)
+++ code/branches/menu/src/orxonox/gamestates/GSMainMenu.cc	(revision 6024)
@@ -82,5 +82,5 @@
     {
         // show main menu
-        GUIManager::getInstance().showGUI("MainMenu");
+        GUIManager::getInstance().showGUI("MainMenu", false);
         GUIManager::getInstance().setCamera(this->camera_);
         GraphicsManager::getInstance().setCamera(this->camera_);
@@ -113,4 +113,5 @@
 
         GUIManager::getInstance().setCamera(0);
+        GUIManager::hideGUI("MainMenu");
         GraphicsManager::getInstance().setCamera(0);
     }
Index: code/branches/menu/src/orxonox/pickup/PickupInventory.cc
===================================================================
--- code/branches/menu/src/orxonox/pickup/PickupInventory.cc	(revision 6023)
+++ code/branches/menu/src/orxonox/pickup/PickupInventory.cc	(revision 6024)
@@ -86,13 +86,9 @@
     {
         if(PickupInventory::getSingleton()->isVisible()) {
-            GUIManager::getInstance().executeCode("hideGUI(\"PickupInventory\")");
-            GUIManager::getInstance().executeCode("hideCursor()");
-            InputManager::getInstance().leaveState("guiMouseOnly");
-        }
-        else
-        {
-            GUIManager::getInstance().showGUI("PickupInventory");
-            GUIManager::getInstance().executeCode("showCursor()");
-            InputManager::getInstance().enterState("guiMouseOnly");
+            GUIManager::hideGUI("PickupInventory");
+        }
+        else
+        {
+            GUIManager::showGUI("PickupInventory");
         }
         PickupInventory::getSingleton()->setVisible(!PickupInventory::getSingleton()->isVisible());
Index: code/branches/menu/src/orxonox/pickup/PickupSpawner.cc
===================================================================
--- code/branches/menu/src/orxonox/pickup/PickupSpawner.cc	(revision 6023)
+++ code/branches/menu/src/orxonox/pickup/PickupSpawner.cc	(revision 6024)
@@ -96,6 +96,6 @@
         //  & load the GUI itself too, along with some empty windows
         //   = even less delays
-        GUIManager::getInstance().showGUI("PickupInventory");
-        GUIManager::getInstance().executeCode("hideGUI(\"PickupInventory\")");
+        GUIManager::showGUI("PickupInventory");
+        GUIManager::hideGUI("PickupInventory");
         PickupInventory::getSingleton();
     }
