Index: code/branches/gui/src/core/Shell.cc
===================================================================
--- code/branches/gui/src/core/Shell.cc	(revision 1640)
+++ code/branches/gui/src/core/Shell.cc	(revision 1641)
@@ -33,7 +33,4 @@
 #include "Core.h"
 #include "ConsoleCommand.h"
-#include "input/InputInterfaces.h"
-#include "input/SimpleInputState.h"
-#include "input/InputManager.h"
 
 #define SHELL_UPDATE_LISTENERS(function) \
@@ -61,5 +58,4 @@
         this->inputBuffer_ = new InputBuffer();
         this->configureInputBuffer();
-        InputManager::createSimpleInputState("console", 40)->setKeyHandler(this->inputBuffer_);
 
         this->outputBuffer_.registerListener(this);
@@ -70,10 +66,6 @@
     Shell::~Shell()
     {
-        SimpleInputState * inputState = dynamic_cast<SimpleInputState*>(InputManager::getState("console"));
-        if (inputState)
-        {
-            inputState->removeAndDestroyAllHandlers();
-            InputManager::destroyState("console");
-        }
+        if (this->inputBuffer_)
+            delete this->inputBuffer_;
     }
 
Index: code/branches/gui/src/core/Shell.h
===================================================================
--- code/branches/gui/src/core/Shell.h	(revision 1640)
+++ code/branches/gui/src/core/Shell.h	(revision 1641)
@@ -71,6 +71,6 @@
             void unregisterListener(ShellListener* listener);
 
-            inline InputBuffer& getInputBuffer()
-                { return (*this->inputBuffer_); }
+            inline InputBuffer* getInputBuffer()
+                { return this->inputBuffer_; }
             inline OutputBuffer& getOutputBuffer()
                 { return this->outputBuffer_; }
Index: code/branches/gui/src/core/input/ExtendedInputState.cc
===================================================================
--- code/branches/gui/src/core/input/ExtendedInputState.cc	(revision 1640)
+++ code/branches/gui/src/core/input/ExtendedInputState.cc	(revision 1641)
@@ -118,23 +118,23 @@
     }
 
-    void ExtendedInputState::joyStickButtonPressed(unsigned int joyStickID, unsigned int button)
+    void ExtendedInputState::joyStickButtonPressed(unsigned int joyStickID, JoyStickButton::Enum id)
     {
         assert(joyStickID < joyStickHandlers_.size());
         for (unsigned int i = 0; i < joyStickHandlers_[joyStickID].size(); i++)
-            joyStickHandlers_[joyStickID][i]->joyStickButtonPressed(joyStickID, button);
-    }
-
-    void ExtendedInputState::joyStickButtonReleased(unsigned int joyStickID, unsigned int button)
+            joyStickHandlers_[joyStickID][i]->joyStickButtonPressed(joyStickID, id);
+    }
+
+    void ExtendedInputState::joyStickButtonReleased(unsigned int joyStickID, JoyStickButton::Enum id)
     {
         assert(joyStickID < joyStickHandlers_.size());
         for (unsigned int i = 0; i < joyStickHandlers_[joyStickID].size(); i++)
-            joyStickHandlers_[joyStickID][i]->joyStickButtonReleased(joyStickID, button);
-    }
-
-    void ExtendedInputState::joyStickButtonHeld(unsigned int joyStickID, unsigned int button)
+            joyStickHandlers_[joyStickID][i]->joyStickButtonReleased(joyStickID, id);
+    }
+
+    void ExtendedInputState::joyStickButtonHeld(unsigned int joyStickID, JoyStickButton::Enum id)
     {
         assert(joyStickID < joyStickHandlers_.size());
         for (unsigned int i = 0; i < joyStickHandlers_[joyStickID].size(); i++)
-            joyStickHandlers_[joyStickID][i]->joyStickButtonHeld(joyStickID, button);
+            joyStickHandlers_[joyStickID][i]->joyStickButtonHeld(joyStickID, id);
     }
 
Index: code/branches/gui/src/core/input/ExtendedInputState.h
===================================================================
--- code/branches/gui/src/core/input/ExtendedInputState.h	(revision 1640)
+++ code/branches/gui/src/core/input/ExtendedInputState.h	(revision 1641)
@@ -81,7 +81,7 @@
         void mouseScrolled      (int abs, int rel);
 
-        void joyStickButtonPressed (unsigned int joyStickID, unsigned int button);
-        void joyStickButtonReleased(unsigned int joyStickID, unsigned int button);
-        void joyStickButtonHeld    (unsigned int joyStickID, unsigned int button);
+        void joyStickButtonPressed (unsigned int joyStickID, JoyStickButton::Enum id);
+        void joyStickButtonReleased(unsigned int joyStickID, JoyStickButton::Enum id);
+        void joyStickButtonHeld    (unsigned int joyStickID, JoyStickButton::Enum id);
         void joyStickAxisMoved     (unsigned int joyStickID, unsigned int axis, float value);        void updateTickables();
 
Index: code/branches/gui/src/core/input/InputBuffer.h
===================================================================
--- code/branches/gui/src/core/input/InputBuffer.h	(revision 1640)
+++ code/branches/gui/src/core/input/InputBuffer.h	(revision 1641)
@@ -171,5 +171,5 @@
 
             void tickInput(float dt);
-            void tickInput(float dt, int device) { }
+            void tickKey(float dt) { }
 
             std::string buffer_;
Index: code/branches/gui/src/core/input/InputInterfaces.h
===================================================================
--- code/branches/gui/src/core/input/InputInterfaces.h	(revision 1640)
+++ code/branches/gui/src/core/input/InputInterfaces.h	(revision 1641)
@@ -213,4 +213,31 @@
     }
 
+    namespace JoyStickButton
+    {
+        enum Enum
+        {
+            Button0       =  0, Button1       =  1, Button2       =  2, Button3       =  3,
+            Button4       =  4, Button5       =  5, Button6       =  6, Button7       =  7,
+            Button8       =  8, Button9       =  9, Button10      = 10, Button11      = 11,
+            Button12      = 12, Button13      = 13, Button14      = 14, Button15      = 15,
+            Button16      = 16, Button17      = 17, Button18      = 18, Button19      = 19,
+            Button20      = 20, Button21      = 21, Button22      = 22, Button23      = 23,
+            Button24      = 24, Button25      = 25, Button26      = 26, Button27      = 27,
+            Button28      = 28, Button29      = 29, Button30      = 30, Button31      = 31,
+
+            POV0North     = 32, POV0South     = 33, POV0East      = 34, POV0West      = 35,
+            POV0NorthEast = 36, POV0SouthEast = 37, POV0NorthWest = 38, POV0SouthWest = 39,
+
+            POV1North     = 40, POV1South     = 41, POV1East      = 42, POV1West      = 43,
+            POV1NorthEast = 44, POV1SouthEast = 45, POV1NorthWest = 46, POV1SouthWest = 47,
+
+            POV2North     = 48, POV2South     = 49, POV2East      = 50, POV2West      = 51,
+            POV2NorthEast = 52, POV2SouthEast = 53, POV2NorthWest = 54, POV2SouthWest = 55,
+
+            POV3North     = 56, POV3South     = 57, POV3East      = 58, POV3West      = 59,
+            POV3NorthEast = 60, POV3SouthEast = 61, POV3NorthWest = 62, POV3SouthWest = 63,
+        };
+    }
+
     namespace KeyboardModifier
     {
@@ -259,31 +286,4 @@
     };
 
-    //typedef OIS::MouseState MouseState;
-
-    /*class _CoreExport JoyStickState
-    {
-    public:
-        JoyStickState(const OIS::JoyStickState& state, int ID) : OIS::JoyStickState(state), mJoyStickID(ID) { }
-        JoyStickState() { clear(); }
-        int mJoyStickID;
-        JoyStickState() { clear(); }
-
-        std::vector<bool> mButtons;
-        int axes[16];
-        std::vector<Vector3> mVectors;
-    };*/
-
-    /**
-    @brief
-        Helper struct to determine which handlers of an object (can implement
-        multiple handlers) are active.
-    */
-    //struct HandlerState
-    //{
-    //    HandlerState() : keyboard(false), mouse(false) { }
-    //    bool keyboard;
-    //    bool mouse;
-    //    std::vector<bool> joySticks;
-    //};
 
     class _CoreExport InputTickable
@@ -292,5 +292,4 @@
         virtual ~InputTickable() { }
         virtual void tickInput(float dt) = 0;
-        //virtual void tickInput(float dt, unsigned int device) = 0;
     };
 
@@ -306,5 +305,5 @@
         virtual void keyReleased(const KeyEvent& evt) = 0;
         virtual void keyHeld    (const KeyEvent& evt) = 0;
-        virtual void tickKey    (float dt) { }
+        virtual void tickKey    (float dt) = 0;
     };
 
@@ -322,5 +321,5 @@
         virtual void mouseMoved         (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) = 0;
         virtual void mouseScrolled      (int abs, int rel)     = 0;
-        virtual void tickMouse          (float dt) { }
+        virtual void tickMouse          (float dt) = 0;
     };
 
@@ -334,10 +333,9 @@
     public:
         virtual ~JoyStickHandler() { }
-        virtual void joyStickButtonPressed (unsigned int joyStickID, unsigned int button) = 0;
-        virtual void joyStickButtonReleased(unsigned int joyStickID, unsigned int button) = 0;
-        virtual void joyStickButtonHeld    (unsigned int joyStickID, unsigned int button) = 0;
+        virtual void joyStickButtonPressed (unsigned int joyStickID, JoyStickButton::Enum id) = 0;
+        virtual void joyStickButtonReleased(unsigned int joyStickID, JoyStickButton::Enum id) = 0;
+        virtual void joyStickButtonHeld    (unsigned int joyStickID, JoyStickButton::Enum id) = 0;
         virtual void joyStickAxisMoved     (unsigned int joyStickID, unsigned int axis, float value) = 0;
-        //virtual bool joyStickVector3Moved  (unsigned int joyStickID, unsigned int index /*, fill list*/) {return true;}
-        virtual void tickJoyStick          (float dt, unsigned int device) { }
+        virtual void tickJoyStick          (float dt, unsigned int joyStick) = 0;
     };
 
@@ -346,5 +344,7 @@
     private:
         void tickInput(float dt) { }
-        void tickInput(float dt, unsigned int device) { }
+        void tickJoyStick(float dt, unsigned int joyStick) { }
+        void tickMouse(float dt) { }
+        void tickKey(float dt) { }
 
         void keyPressed (const KeyEvent& evt) { }
@@ -358,7 +358,7 @@
         void mouseScrolled      (int abs, int rel) { }
 
-        void joyStickButtonPressed (unsigned int joyStickID, unsigned int button) { }
-        void joyStickButtonReleased(unsigned int joyStickID, unsigned int button) { }
-        void joyStickButtonHeld    (unsigned int joyStickID, unsigned int button) { }
+        void joyStickButtonPressed (unsigned int joyStickID, JoyStickButton::Enum id) { }
+        void joyStickButtonReleased(unsigned int joyStickID, JoyStickButton::Enum id) { }
+        void joyStickButtonHeld    (unsigned int joyStickID, JoyStickButton::Enum id) { }
         void joyStickAxisMoved     (unsigned int joyStickID, unsigned int axis, float value) { }
     };
Index: code/branches/gui/src/core/input/InputManager.cc
===================================================================
--- code/branches/gui/src/core/input/InputManager.cc	(revision 1640)
+++ code/branches/gui/src/core/input/InputManager.cc	(revision 1641)
@@ -91,5 +91,16 @@
     /**
     @brief
+        Destructor itself only called at the end of the program, after main.
+        Instance gets registered for destruction with atexit(.).
+    */
+    InputManager::~InputManager()
+    {
+        _destroy();
+    }
+
+    /**
+    @brief
         The one instance of the InputManager is stored in this function.
+        Only for internal use. Public Interface ist static.
     @return
         A reference to the only instance of the InputManager
@@ -99,13 +110,4 @@
         static InputManager theOnlyInstance;
         return theOnlyInstance;
-    }
-
-    /**
-    @brief
-        Destructor only called at the end of the program, after main.
-    */
-    InputManager::~InputManager()
-    {
-        _destroy();
     }
 
@@ -133,5 +135,5 @@
         {
             CCOUT(3) << "Initialising Input System..." << std::endl;
-            CCOUT(ORX_DEBUG) << "Initialising OIS components..." << std::endl;
+            CCOUT(4) << "Initialising OIS components..." << std::endl;
 
             OIS::ParamList paramList;
@@ -180,9 +182,4 @@
             CCOUT(ORX_DEBUG) << "Initialising OIS components done." << std::endl;
 
-            // InputManager holds the input buffer --> create one and add it.
-            //buffer_ = new InputBuffer();
-            //addKeyHandler(buffer_, "buffer");
-            //Shell::getInstance().setInputBuffer(buffer_);
-
             setConfigValues();
 
@@ -204,9 +201,9 @@
             _updateActiveStates();
 
-            CCOUT(ORX_DEBUG) << "Initialising complete." << std::endl;
+            CCOUT(3) << "Initialising complete." << std::endl;
         }
         else
         {
-            CCOUT(ORX_WARNING) << "Warning: OIS compoments already initialised, skipping" << std::endl;
+            CCOUT(2) << "Warning: OIS compoments already initialised, skipping" << std::endl;
         }
         return true;
@@ -333,4 +330,12 @@
     }
 
+    /**
+    @brief
+        Sets the size of all the different lists that are dependent on the number
+        of joy stick devices created.
+    @remarks
+        No matter whether there are a mouse and/or keyboard, they will always
+        occupy 2 places in the device number dependent lists.
+    */
     void InputManager::_redimensionLists()
     {
@@ -356,5 +361,5 @@
         activeStatesTop_.resize(devicesNum_);
 
-        // inform all registered states
+        // inform all states
         for (std::map<int, InputState*>::const_iterator it = inputStatesByPriority_.begin();
             it != inputStatesByPriority_.end(); ++it)
@@ -364,9 +369,10 @@
     /**
     @brief
-        Sets the configurable values. Use keybindings.ini as file..
+        Sets the configurable values.
+        This mainly concerns joy stick calibrations.
     */
     void InputManager::setConfigValues()
     {
-        if (joySticksSize_)
+        if (joySticksSize_ > 0)
         {
             std::vector<MultiTypeMath> coeffPos;
@@ -386,5 +392,5 @@
             if (!cont)
             {
-                cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), "CoeffPos", coeffPos);
+                cont = new ConfigValueContainer(CFT_Settings, getIdentifier(), "CoeffPos", coeffPos);
                 getIdentifier()->addConfigValueContainer("CoeffPos", cont);
             }
@@ -394,5 +400,5 @@
             if (!cont)
             {
-                cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), "CoeffNeg", coeffNeg);
+                cont = new ConfigValueContainer(CFT_Settings, getIdentifier(), "CoeffNeg", coeffNeg);
                 getIdentifier()->addConfigValueContainer("CoeffNeg", cont);
             }
@@ -402,5 +408,5 @@
             if (!cont)
             {
-                cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), "Zero", zero);
+                cont = new ConfigValueContainer(CFT_Settings, getIdentifier(), "Zero", zero);
                 getIdentifier()->addConfigValueContainer("Zero", cont);
             }
@@ -425,5 +431,6 @@
     /**
     @brief
-        Destroys all the created input devices and sets the InputManager to construction state.
+        Destroys all the created input devices. InputManager will be ready for a
+        new initialisation.
     */
     void InputManager::_destroy()
@@ -431,39 +438,49 @@
         if (inputSystem_)
         {
-            CCOUT(ORX_DEBUG) << "Destroying ..." << std::endl;
-
-            // kick all active states 'nicely'
-            for (std::map<int, InputState*>::reverse_iterator rit = activeStates_.rbegin();
-                rit != activeStates_.rend(); ++rit)
-                (*rit).second->onLeave();
-            activeStates_.clear();
-
-            // destroy our own states
-            stateEmpty_->removeAndDestroyAllHandlers();
-            stateCalibrator_->removeAndDestroyAllHandlers();
-            stateDetector_->removeAndDestroyAllHandlers();
-            _destroyState(stateEmpty_);
-            _destroyState(stateCalibrator_);
-            _destroyState(stateDetector_);
-            stateEmpty_ = 0;
-            stateCalibrator_ = 0;
-            stateDetector_ = 0;
-
-            // we don't remove the other states yet because the singleton might still exist.
-            // So people can still removeAndDestroy their states
-            //inputStatesByName_.clear();
-            //inputStatesByPriority_.clear();
-
-            // destroy the devices
-            _destroyKeyboard();
-            _destroyMouse();
-            _destroyJoySticks();
-
-            _redimensionLists();
-
-            OIS::InputManager::destroyInputSystem(inputSystem_);
-            inputSystem_ = 0;
-
-            CCOUT(ORX_DEBUG) << "Destroying done." << std::endl;
+            try
+            {
+                CCOUT(3) << "Destroying ..." << std::endl;
+
+                // clear our own states
+                stateEmpty_->removeAndDestroyAllHandlers();
+                stateCalibrator_->removeAndDestroyAllHandlers();
+                stateDetector_->removeAndDestroyAllHandlers();
+
+                // kick all active states 'nicely'
+                for (std::map<int, InputState*>::reverse_iterator rit = activeStates_.rbegin();
+                    rit != activeStates_.rend(); ++rit)
+                {
+                    (*rit).second->onLeave();
+                }
+                activeStates_.clear();
+                _updateActiveStates();
+
+                // destroy all input states
+                while (inputStatesByPriority_.size() > 0)
+                {
+                    _destroyState((*inputStatesByPriority_.rbegin()).second);
+                }
+
+                stateEmpty_ = 0;
+                stateCalibrator_ = 0;
+                stateDetector_ = 0;
+
+                // destroy the devices
+                _destroyKeyboard();
+                _destroyMouse();
+                _destroyJoySticks();
+
+                // 0 joy sticks now
+                _redimensionLists();
+
+                OIS::InputManager::destroyInputSystem(inputSystem_);
+                inputSystem_ = 0;
+
+                CCOUT(3) << "Destroying done." << std::endl;
+            }
+            catch (OIS::Exception& ex)
+            {
+                CCOUT(1) << "An exception has occured while destroying:\n" << ex.what() << std::endl;
+            }
         }
     }
@@ -479,5 +496,5 @@
         keyboard_ = 0;
         keysDown_.clear();
-        CCOUT(ORX_DEBUG) << "Keyboard destroyed." << std::endl;
+        CCOUT(4) << "Keyboard destroyed." << std::endl;
     }
 
@@ -492,5 +509,5 @@
         mouse_ = 0;
         mouseButtonsDown_.clear();
-        CCOUT(ORX_DEBUG) << "Mouse destroyed." << std::endl;
+        CCOUT(4) << "Mouse destroyed." << std::endl;
     }
 
@@ -510,5 +527,5 @@
             joySticks_.clear();
         }
-        CCOUT(ORX_DEBUG) << "Joy sticks destroyed." << std::endl;
+        CCOUT(4) << "Joy sticks destroyed." << std::endl;
     }
 
@@ -597,4 +614,9 @@
     }
 
+    /**
+    @brief
+        Updates the currently active states (according to activeStates_) for each device.
+        Also, a list of all active states (no duplicates!) is compiled for the general tick.
+    */
     void InputManager::_updateActiveStates()
     {
@@ -616,4 +638,8 @@
     }
 
+    /**
+    @brief
+        Processes the accumultated data for the joy stick calibration.
+    */
     void InputManager::_completeCalibration()
     {
@@ -676,4 +702,5 @@
         // restore old input state
         requestLeaveState("calibrator");
+        bCalibrating_ = false;
     }
 
@@ -822,4 +849,8 @@
     // ###### Joy Stick Events ######
 
+    /**
+    @brief
+        Returns the joy stick ID (orxonox) according to a OIS::JoyStickEvent
+    */
     inline unsigned int InputManager::_getJoystick(const OIS::JoyStickEvent& arg)
     {
@@ -839,12 +870,12 @@
 
         // check whether the button already is in the list (can happen when focus was lost)
-        std::vector<int>& buttonsDown = joyStickButtonsDown_[iJoyStick];
+        std::vector<JoyStickButton::Enum>& buttonsDown = joyStickButtonsDown_[iJoyStick];
         unsigned int iButton = 0;
         while (iButton < buttonsDown.size() && buttonsDown[iButton] != button)
             iButton++;
         if (iButton == buttonsDown.size())
-            buttonsDown.push_back(button);
-
-        activeStatesTop_[2 + iJoyStick]->joyStickButtonPressed(iJoyStick, button);
+            buttonsDown.push_back((JoyStickButton::Enum)button);
+
+        activeStatesTop_[2 + iJoyStick]->joyStickButtonPressed(iJoyStick, (JoyStickButton::Enum)button);
 
         return true;
@@ -856,5 +887,5 @@
 
         // remove the button from the joyStickButtonsDown_ list
-        std::vector<int>& buttonsDown = joyStickButtonsDown_[iJoyStick];
+        std::vector<JoyStickButton::Enum>& buttonsDown = joyStickButtonsDown_[iJoyStick];
         for (unsigned int iButton = 0; iButton < buttonsDown.size(); iButton++)
         {
@@ -866,9 +897,14 @@
         }
 
-        activeStatesTop_[2 + iJoyStick]->joyStickButtonReleased(iJoyStick, button);
+        activeStatesTop_[2 + iJoyStick]->joyStickButtonReleased(iJoyStick, (JoyStickButton::Enum)button);
 
         return true;
     }
 
+    /**
+    @brief
+        Calls the states for a particular axis with our enumeration.
+        Used by OIS sliders and OIS axes.
+    */
     void InputManager::_fireAxis(unsigned int iJoyStick, int axis, int value)
     {
@@ -919,4 +955,5 @@
 
         // translate the POV into 8 simple buttons
+
         int lastState = povStates_[iJoyStick][id];
         if (lastState & OIS::Pov::North)
@@ -959,19 +996,4 @@
     }
 
-    bool InputManager::initialiseKeyboard()
-    {
-        return _getInstance()._initialiseKeyboard();
-    }
-
-    bool InputManager::initialiseMouse()
-    {
-        return _getInstance()._initialiseMouse();
-    }
-
-    bool InputManager::initialiseJoySticks()
-    {
-        return _getInstance()._initialiseJoySticks();
-    }
-
     int InputManager::numberOfKeyboards()
     {
@@ -1030,19 +1052,4 @@
     {
         _getInstance()._destroy();
-    }
-
-    void InputManager::destroyKeyboard()
-    {
-        return _getInstance()._destroyKeyboard();
-    }
-
-    void InputManager::destroyMouse()
-    {
-        return _getInstance()._destroyMouse();
-    }
-
-    void InputManager::destroyJoySticks()
-    {
-        return _getInstance()._destroyJoySticks();
     }
 
@@ -1068,4 +1075,14 @@
     }
 
+    /**
+    @brief
+        Method for easily storing a string with the command executor. It is used by the
+        KeyDetector to get assign commands. The KeyDetector simply executes
+        the command 'storeKeyStroke myName' for each button/axis.
+    @remarks
+        This is only a temporary hack until we thourouhgly support multiple KeyBinders.
+    @param name
+        The name of the button/axis.
+    */
     void InputManager::storeKeyStroke(const std::string& name)
     {
@@ -1075,4 +1092,11 @@
     }
 
+    /**
+    @brief
+        Assigns a command string to a key/button/axis. The name is determined via KeyDetector
+        and InputManager::storeKeyStroke(.).
+    @param command
+        Command string that can be executed by the CommandExecutor
+    */
     void InputManager::keyBind(const std::string& command)
     {
@@ -1082,6 +1106,11 @@
     }
 
+    /**
+    @brief
+        Starts joy stick calibration.
+    */
     void InputManager::calibrate()
     {
+        _getInstance().bCalibrating_ = true;
         requestEnterState("calibrator");
     }
@@ -1101,6 +1130,8 @@
     @param name
         Unique name of the handler.
+    @param priority
+        Unique integer number. Higher means more prioritised.
     @return
-        True if added, false if name already existed.
+        True if added, false if name or priority already existed.
     */
     bool InputManager::_configureInputState(InputState* state, const std::string& name, int priority)
@@ -1134,4 +1165,8 @@
     }
 
+    /**
+    @brief
+        Returns a new SimpleInputState and configures it first.
+    */
     SimpleInputState* InputManager::createSimpleInputState(const std::string &name, int priority)
     {
@@ -1146,4 +1181,8 @@
     }
 
+    /**
+    @brief
+        Returns a new ExtendedInputState and configures it first.
+    */
     ExtendedInputState* InputManager::createExtendedInputState(const std::string &name, int priority)
     {
@@ -1160,9 +1199,11 @@
     /**
     @brief
-        Removes a Key handler from the list.
+        Removes an input state internally.
     @param name
-        Unique name of the handler.
+        Name of the handler.
     @return
         True if removal was successful, false if name was not found.
+    @remarks
+        You can't remove the internal states "empty", "calibrator" and "detector".
     */
     bool InputManager::destroyState(const std::string& name)
@@ -1184,7 +1225,7 @@
     /**
     @brief
-        Returns the pointer to a handler.
+        Returns the pointer to the requested InputState.
     @param name
-        Unique name of the handler.
+        Unique name of the state.
     @return
         Pointer to the instance, 0 if name was not found.
@@ -1201,7 +1242,7 @@
     /**
     @brief
-        Returns the current input handling method
+        Returns the current input state (there might be others active too!)
     @return
-        The current input mode.
+        The current highest prioritised active input state.
     */
     InputState* InputManager::getCurrentState()
@@ -1212,7 +1253,8 @@
     /**
     @brief
-        Enables a specific key handler that has already been added.
+        Activates a specific input state.
+        It might not be really activated if the priority is too low!
     @param name
-        Unique name of the handler.
+        Unique name of the state.
     @return
         False if name was not found, true otherwise.
@@ -1230,4 +1272,12 @@
     }
 
+    /**
+    @brief
+        Deactivates a specific input state.
+    @param name
+        Unique name of the state.
+    @return
+        False if name was not found, true otherwise.
+    */
     bool InputManager::requestLeaveState(const std::string& name)
     {
Index: code/branches/gui/src/core/input/InputManager.h
===================================================================
--- code/branches/gui/src/core/input/InputManager.h	(revision 1640)
+++ code/branches/gui/src/core/input/InputManager.h	(revision 1641)
@@ -90,7 +90,4 @@
         static bool initialise(const size_t windowHnd, int windowWidth, int windowHeight,
                                bool createKeyboard = true, bool createMouse = true, bool createJoySticks = false);
-        static bool initialiseKeyboard();
-        static bool initialiseMouse();
-        static bool initialiseJoySticks();
         static int  numberOfKeyboards();
         static int  numberOfMice();
@@ -98,7 +95,4 @@
 
         static void destroy();
-        static void destroyKeyboard();
-        static void destroyMouse();
-        static void destroyJoySticks();
 
         //static bool isModifierDown(KeyboardModifier::Enum modifier);
@@ -119,5 +113,4 @@
         static ExtendedInputState* createExtendedInputState(const std::string& name, int priority);
         static bool destroyState (const std::string& name);
-        //static bool removeState (const std::string& name);
         static InputState* getState       (const std::string& name);
         static InputState* getCurrentState();
@@ -171,46 +164,44 @@
 
     private: // variables
-        OIS::InputManager*                          inputSystem_;     //!< OIS input manager
-        OIS::Keyboard*                              keyboard_;        //!< OIS mouse
-        OIS::Mouse*                                 mouse_;           //!< OIS keyboard
-        std::vector<OIS::JoyStick*>                 joySticks_;       //!< OIS joy sticks
-        unsigned int                                joySticksSize_;
-        unsigned int                                devicesNum_;
+        OIS::InputManager*                  inputSystem_;          //!< OIS input manager
+        OIS::Keyboard*                      keyboard_;             //!< OIS mouse
+        OIS::Mouse*                         mouse_;                //!< OIS keyboard
+        std::vector<OIS::JoyStick*>         joySticks_;            //!< OIS joy sticks
+        unsigned int                        joySticksSize_;
+        unsigned int                        devicesNum_;
 
         // some internally handled states
-        SimpleInputState*                                 stateDetector_;   //!< KeyDetector instance
-        SimpleInputState*                                 stateCalibrator_;
-        SimpleInputState*                                 stateEmpty_;
-
-        std::map<std::string, InputState*>          inputStatesByName_;
-        std::map<int, InputState*>                  inputStatesByPriority_;
-
-        std::vector<InputState*> stateEnterRequests_;                  //!< Request to enter a new state
-        std::vector<InputState*> stateLeaveRequests_;                    //!< Request to leave the current state
-
-        std::map<int, InputState*> activeStates_;
-        std::vector<InputState*>   activeStatesTop_;    //!< Current input states for joy stick events.
-        std::vector<InputState*>   activeStatesTicked_;    //!< Current input states for joy stick events.
+        SimpleInputState*                   stateDetector_;        //!< KeyDetector instance
+        SimpleInputState*                   stateCalibrator_;
+        SimpleInputState*                   stateEmpty_;
+
+        std::map<std::string, InputState*>  inputStatesByName_;
+        std::map<int, InputState*>          inputStatesByPriority_;
+
+        std::vector<InputState*>            stateEnterRequests_;   //!< Request to enter a new state
+        std::vector<InputState*>            stateLeaveRequests_;   //!< Request to leave the current state
+
+        std::map<int, InputState*>          activeStates_;
+        std::vector<InputState*>            activeStatesTop_;      //!< Current input states for joy stick events.
+        std::vector<InputState*>            activeStatesTicked_;   //!< Current input states for joy stick events.
 
         // joystick calibration
         //std::vector<int> marginalsMaxConfig_;
         //std::vector<int> marginalsMinConfig_;
-        int marginalsMax_[24];
-        int marginalsMin_[24];
-        bool bCalibrated_;
-        bool bCalibrating_;
-
-        unsigned int keyboardModifiers_;           //!< Bit mask representing keyboard modifiers
-        //! Keeps track of the joy stick POV states
-        std::vector<POVStates>                      povStates_;
-        //! Keeps track of the possibly two slider axes
-        std::vector<SliderStates>                   sliderStates_;
-        std::vector<JoyStickCalibration>            joySticksCalibration_;
-
-        std::vector<Key>                            keysDown_;
-        std::vector<MouseButton::Enum>              mouseButtonsDown_;
-        std::vector<std::vector<int> >              joyStickButtonsDown_;
-
-        static std::string                          bindingCommmandString_s;
+        int                                 marginalsMax_[24];
+        int                                 marginalsMin_[24];
+        bool                                bCalibrated_;
+        bool                                bCalibrating_;
+
+        unsigned int                        keyboardModifiers_;    //!< Bit mask representing keyboard modifiers.
+        std::vector<POVStates>              povStates_;            //!< Keeps track of the joy stick POV states.
+        std::vector<SliderStates>           sliderStates_;         //!< Keeps track of the possibly two slider axes.
+        std::vector<JoyStickCalibration>    joySticksCalibration_; 
+
+        std::vector<Key>                    keysDown_;
+        std::vector<MouseButton::Enum>      mouseButtonsDown_;
+        std::vector<std::vector<JoyStickButton::Enum> >  joyStickButtonsDown_;
+
+        static std::string                  bindingCommmandString_s;
     };
 
Index: code/branches/gui/src/core/input/InputState.h
===================================================================
--- code/branches/gui/src/core/input/InputState.h	(revision 1640)
+++ code/branches/gui/src/core/input/InputState.h	(revision 1641)
@@ -84,7 +84,7 @@
         virtual void mouseScrolled      (int abs, int rel) = 0;
 
-        virtual void joyStickButtonPressed (unsigned int joyStickID, unsigned int button) = 0;
-        virtual void joyStickButtonReleased(unsigned int joyStickID, unsigned int button) = 0;
-        virtual void joyStickButtonHeld    (unsigned int joyStickID, unsigned int button) = 0;
+        virtual void joyStickButtonPressed (unsigned int joyStickID, JoyStickButton::Enum id) = 0;
+        virtual void joyStickButtonReleased(unsigned int joyStickID, JoyStickButton::Enum id) = 0;
+        virtual void joyStickButtonHeld    (unsigned int joyStickID, JoyStickButton::Enum id) = 0;
         virtual void joyStickAxisMoved     (unsigned int joyStickID, unsigned int axis, float value) = 0;
 
Index: code/branches/gui/src/core/input/KeyBinder.cc
===================================================================
--- code/branches/gui/src/core/input/KeyBinder.cc	(revision 1640)
+++ code/branches/gui/src/core/input/KeyBinder.cc	(revision 1641)
@@ -374,5 +374,5 @@
     }
 
-    void KeyBinder::tickJoyStick(float dt, int device)
+    void KeyBinder::tickJoyStick(float dt, unsigned int joyStick)
     {
         tickDevices(8, nHalfAxes_s);
@@ -448,12 +448,12 @@
 
 
-    void KeyBinder::joyStickButtonPressed (unsigned int joyStickID, unsigned int button)
-    { joyStickButtons_[button].execute(KeybindMode::OnPress); }
-
-    void KeyBinder::joyStickButtonReleased(unsigned int joyStickID, unsigned int button)
-    { joyStickButtons_[button].execute(KeybindMode::OnRelease); }
-
-    void KeyBinder::joyStickButtonHeld    (unsigned int joyStickID, unsigned int button)
-    { joyStickButtons_[button].execute(KeybindMode::OnHold); }
+    void KeyBinder::joyStickButtonPressed (unsigned int joyStickID, JoyStickButton::Enum id)
+    { joyStickButtons_[id].execute(KeybindMode::OnPress); }
+
+    void KeyBinder::joyStickButtonReleased(unsigned int joyStickID, JoyStickButton::Enum id)
+    { joyStickButtons_[id].execute(KeybindMode::OnRelease); }
+
+    void KeyBinder::joyStickButtonHeld    (unsigned int joyStickID, JoyStickButton::Enum id)
+    { joyStickButtons_[id].execute(KeybindMode::OnHold); }
 
     /**
Index: code/branches/gui/src/core/input/KeyBinder.h
===================================================================
--- code/branches/gui/src/core/input/KeyBinder.h	(revision 1640)
+++ code/branches/gui/src/core/input/KeyBinder.h	(revision 1641)
@@ -68,5 +68,5 @@
         void tickKey(float dt) { }
         void tickMouse(float dt);
-        void tickJoyStick(float dt, int device);
+        void tickJoyStick(float dt, unsigned int joyStick);
         void tickDevices(unsigned int begin, unsigned int end);
 
@@ -83,7 +83,7 @@
         void mouseScrolled      (int abs, int rel);
 
-        void joyStickButtonPressed (unsigned int joyStickID, unsigned int button);
-        void joyStickButtonReleased(unsigned int joyStickID, unsigned int button);
-        void joyStickButtonHeld    (unsigned int joyStickID, unsigned int button);
+        void joyStickButtonPressed (unsigned int joyStickID, JoyStickButton::Enum id);
+        void joyStickButtonReleased(unsigned int joyStickID, JoyStickButton::Enum id);
+        void joyStickButtonHeld    (unsigned int joyStickID, JoyStickButton::Enum id);
         void joyStickAxisMoved     (unsigned int joyStickID, unsigned int axis, float value);
 
Index: code/branches/gui/src/core/input/SimpleInputState.cc
===================================================================
--- code/branches/gui/src/core/input/SimpleInputState.cc	(revision 1640)
+++ code/branches/gui/src/core/input/SimpleInputState.cc	(revision 1641)
@@ -123,23 +123,23 @@
     }
 
-    void SimpleInputState::joyStickButtonPressed(unsigned int joyStickID, unsigned int button)
-    {
-        assert(joyStickID < joyStickHandler_.size());
-        if (joyStickHandler_[joyStickID])
-            joyStickHandler_[joyStickID]->joyStickButtonPressed(joyStickID, button);
-    }
-
-    void SimpleInputState::joyStickButtonReleased(unsigned int joyStickID, unsigned int button)
-    {
-        assert(joyStickID < joyStickHandler_.size());
-        if (joyStickHandler_[joyStickID])
-            joyStickHandler_[joyStickID]->joyStickButtonReleased(joyStickID, button);
-    }
-
-    void SimpleInputState::joyStickButtonHeld(unsigned int joyStickID, unsigned int button)
-    {
-        assert(joyStickID < joyStickHandler_.size());
-        if (joyStickHandler_[joyStickID])
-            joyStickHandler_[joyStickID]->joyStickButtonHeld(joyStickID, button);
+    void SimpleInputState::joyStickButtonPressed(unsigned int joyStickID, JoyStickButton::Enum id)
+    {
+        assert(joyStickID < joyStickHandler_.size());
+        if (joyStickHandler_[joyStickID])
+            joyStickHandler_[joyStickID]->joyStickButtonPressed(joyStickID, id);
+    }
+
+    void SimpleInputState::joyStickButtonReleased(unsigned int joyStickID, JoyStickButton::Enum id)
+    {
+        assert(joyStickID < joyStickHandler_.size());
+        if (joyStickHandler_[joyStickID])
+            joyStickHandler_[joyStickID]->joyStickButtonReleased(joyStickID, id);
+    }
+
+    void SimpleInputState::joyStickButtonHeld(unsigned int joyStickID, JoyStickButton::Enum id)
+    {
+        assert(joyStickID < joyStickHandler_.size());
+        if (joyStickHandler_[joyStickID])
+            joyStickHandler_[joyStickID]->joyStickButtonHeld(joyStickID, id);
     }
 
Index: code/branches/gui/src/core/input/SimpleInputState.h
===================================================================
--- code/branches/gui/src/core/input/SimpleInputState.h	(revision 1640)
+++ code/branches/gui/src/core/input/SimpleInputState.h	(revision 1641)
@@ -72,7 +72,7 @@
         void mouseScrolled      (int abs, int rel);
 
-        void joyStickButtonPressed (unsigned int joyStickID, unsigned int button);
-        void joyStickButtonReleased(unsigned int joyStickID, unsigned int button);
-        void joyStickButtonHeld    (unsigned int joyStickID, unsigned int button);
+        void joyStickButtonPressed (unsigned int joyStickID, JoyStickButton::Enum id);
+        void joyStickButtonReleased(unsigned int joyStickID, JoyStickButton::Enum id);
+        void joyStickButtonHeld    (unsigned int joyStickID, JoyStickButton::Enum id);
         void joyStickAxisMoved     (unsigned int joyStickID, unsigned int axis, float value);
 
Index: code/branches/gui/src/orxonox/GraphicsEngine.cc
===================================================================
--- code/branches/gui/src/orxonox/GraphicsEngine.cc	(revision 1640)
+++ code/branches/gui/src/orxonox/GraphicsEngine.cc	(revision 1641)
@@ -22,6 +22,7 @@
  *   Author:
  *      Reto Grieder
+ *      Benjamin Knecht <beni_at_orxonox.net>, (C) 2007
  *   Co-authors:
- *      Benjamin Knecht <beni_at_orxonox.net>, (C) 2007, Felix Schulthess
+ *      Felix Schulthess
  *
  */
@@ -89,4 +90,5 @@
         RegisterObject(GraphicsEngine);
 
+        assert(singletonRef_s == 0);
         singletonRef_s = this;
 
@@ -305,8 +307,6 @@
         //Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
 
-        // create a full screen viewport in which to render the scene and the loading screen
-        // The GUI uses its own one to be able to render on top of everything.
-        // That explains why the Z order here is only 1 and not 0 (top most)
-        this->viewport_ = this->renderWindow_->addViewport(0, 1);
+        // create a full screen viewport
+        this->viewport_ = this->renderWindow_->addViewport(0, 0);
 
         return true;
Index: code/branches/gui/src/orxonox/GraphicsEngine.h
===================================================================
--- code/branches/gui/src/orxonox/GraphicsEngine.h	(revision 1640)
+++ code/branches/gui/src/orxonox/GraphicsEngine.h	(revision 1641)
@@ -22,6 +22,7 @@
  *   Author:
  *      Reto Grieder
+ *      Benjamin Knecht <beni_at_orxonox.net>, (C) 2007
  *   Co-authors:
- *      Benjamin Knecht <beni_at_orxonox.net>, (C) 2007, Felix Schulthess
+ *      Felix Schulthess
  *
  */
@@ -88,5 +89,5 @@
 
         static GraphicsEngine& getSingleton();
-        static GraphicsEngine* getSingletonPtr() { return &getSingleton(); }
+        static GraphicsEngine* getSingletonPtr() { return singletonRef_s; }
 
     private:
Index: code/branches/gui/src/orxonox/Orxonox.cc
===================================================================
--- code/branches/gui/src/orxonox/Orxonox.cc	(revision 1640)
+++ code/branches/gui/src/orxonox/Orxonox.cc	(revision 1641)
@@ -300,5 +300,5 @@
   }
 
-  void Orxonox::loadGame(const std::string& name)
+  /*static*/ void Orxonox::loadGame(const std::string& name)
   {
       const GameMode& mode = Settings::getGameMode(name);
Index: code/branches/gui/src/orxonox/gui/GUIManager.h
===================================================================
--- code/branches/gui/src/orxonox/gui/GUIManager.h	(revision 1640)
+++ code/branches/gui/src/orxonox/gui/GUIManager.h	(revision 1641)
@@ -103,4 +103,6 @@
 
         void tickInput(float dt) { }
+        void tickKey(float dt) { }
+        void tickMouse(float dt) { }
 
         void loadScenes();
Index: code/branches/gui/src/orxonox/gui/OgreCEGUIRenderer.cpp
===================================================================
--- code/branches/gui/src/orxonox/gui/OgreCEGUIRenderer.cpp	(revision 1640)
+++ code/branches/gui/src/orxonox/gui/OgreCEGUIRenderer.cpp	(revision 1641)
@@ -191,6 +191,7 @@
     // GUI (uses its own viewport to be able render on top of all viewports).
     // But since we don't use overlays in the GUI, it doesn't matter.
-    //if (d_render_sys->_getViewport()->getOverlaysEnabled() && !d_quadlist.empty())
-    if (!d_quadlist.empty())
+    // ORXONOX REVERT: Changes are not in place anymore, but might be in the future!
+    if (d_render_sys->_getViewport()->getOverlaysEnabled() && !d_quadlist.empty())
+    //if (!d_quadlist.empty())
     {
         /// Quad list needs to be sorted and thus the vertex buffer rebuilt. If not, we can
@@ -493,6 +494,7 @@
     // GUI (uses its own viewport to be able render on top of all viewports).
     // But since we don't use overlays in the GUI, it doesn't matter.
-    //if (d_render_sys->_getViewport()->getOverlaysEnabled())
-    if (true)
+    // ORXONOX REVERT: Changes are not in place anymore, but might be in the future!
+    if (d_render_sys->_getViewport()->getOverlaysEnabled())
+    //if (true)
     {
         z = -1 + z;
Index: code/branches/gui/src/orxonox/overlays/console/InGameConsole.cc
===================================================================
--- code/branches/gui/src/orxonox/overlays/console/InGameConsole.cc	(revision 1640)
+++ code/branches/gui/src/orxonox/overlays/console/InGameConsole.cc	(revision 1641)
@@ -46,4 +46,6 @@
 #include "core/ConsoleCommand.h"
 #include "core/input/InputManager.h"
+#include "core/input/SimpleInputState.h"
+#include "core/input/InputBuffer.h"
 #include "GraphicsEngine.h"
 
@@ -66,7 +68,4 @@
         , consoleOverlayBorder_(0)
         , consoleOverlayTextAreas_(0)
-        , emptySceneManager_(0)
-        , emptyCamera_(0)
-        , viewport_(0)
     {
         RegisterObject(InGameConsole);
@@ -118,4 +117,7 @@
     void InGameConsole::initialise()
     {
+        // create the corresponding input state
+        InputManager::createSimpleInputState("console", 40)->setKeyHandler(Shell::getInstance().getInputBuffer());
+
         // create overlay and elements
         Ogre::OverlayManager* ovMan = Ogre::OverlayManager::getSingletonPtr();
@@ -195,12 +197,4 @@
         Shell::getInstance().addOutputLevel(true);
 
-        // create a sceneManager in order to render in our own viewport
-        this->emptySceneManager_ = Ogre::Root::getSingleton()
-            .createSceneManager(Ogre::ST_GENERIC, "Console/EmptySceneManager");
-        this->emptyCamera_ = this->emptySceneManager_->createCamera("Console/EmptyCamera");
-        this->viewport_ = GraphicsEngine::getSingleton().getRenderWindow()->addViewport(emptyCamera_, 10);
-        this->viewport_->setOverlaysEnabled(true);
-        this->viewport_->setClearEveryFrame(false);
-
         COUT(4) << "Info: InGameConsole initialized" << std::endl;
     }
@@ -211,4 +205,11 @@
     void InGameConsole::destroy()
     {
+        this->deactivate();
+
+        // destroy the input state previously created
+        SimpleInputState * inputState = dynamic_cast<SimpleInputState*>(InputManager::getState("console"));
+        if (inputState)
+            InputManager::destroyState("console");
+
         Ogre::OverlayManager* ovMan = Ogre::OverlayManager::getSingletonPtr();
         if (ovMan)
@@ -467,8 +468,8 @@
                 if (output.size() > this->maxCharsPerLine_)
                 {
-                    if (Shell::getInstance().getInputBuffer().getCursorPosition() < this->inputWindowStart_)
-                        this->inputWindowStart_ = Shell::getInstance().getInputBuffer().getCursorPosition();
-                    else if (Shell::getInstance().getInputBuffer().getCursorPosition() >= (this->inputWindowStart_ + this->maxCharsPerLine_ - 1))
-                        this->inputWindowStart_ = Shell::getInstance().getInputBuffer().getCursorPosition() - this->maxCharsPerLine_ + 1;
+                    if (Shell::getInstance().getInputBuffer()->getCursorPosition() < this->inputWindowStart_)
+                        this->inputWindowStart_ = Shell::getInstance().getInputBuffer()->getCursorPosition();
+                    else if (Shell::getInstance().getInputBuffer()->getCursorPosition() >= (this->inputWindowStart_ + this->maxCharsPerLine_ - 1))
+                        this->inputWindowStart_ = Shell::getInstance().getInputBuffer()->getCursorPosition() - this->maxCharsPerLine_ + 1;
 
                     output = output.substr(this->inputWindowStart_, this->maxCharsPerLine_);
Index: code/branches/gui/src/orxonox/overlays/console/InGameConsole.h
===================================================================
--- code/branches/gui/src/orxonox/overlays/console/InGameConsole.h	(revision 1640)
+++ code/branches/gui/src/orxonox/overlays/console/InGameConsole.h	(revision 1641)
@@ -100,8 +100,4 @@
         Ogre::TextAreaOverlayElement** consoleOverlayTextAreas_;
 
-        Ogre::SceneManager* emptySceneManager_;     //!< dummy SceneManager to render overlays in empty windows
-        Ogre::Camera*       emptyCamera_;           //!< dummy camera to render overlays in empty windows
-        Ogre::Viewport*     viewport_;
-
         // config values
         float relativeWidth;
