#include "Menu.h"
 
+#include "Animation.h"
 #include "../loader/Interpreter.h"
 #include "../loader/TypeDescription.h"
 
        td.AddField("disabledFont", FieldDescription(((char *)&p.disabledFont) - ((char *)&p), Font::TYPE_ID).SetReferenced().SetDescription("the font for disabled entries"));
        td.AddField("cursor", FieldDescription(((char *)&p.cursor) - ((char *)&p), Sprite::TYPE_ID).SetReferenced().SetDescription("the cursor sprite indicating the current selection"));
        td.AddField("selectedCursor", FieldDescription(((char *)&p.selectedCursor) - ((char *)&p), Sprite::TYPE_ID).SetReferenced().SetDescription("the cursor sprite used when fixating a selection"));
+       td.AddField("cursorAnimation", FieldDescription(((char *)&p.cursorAnimation) - ((char *)&p), Animation::TYPE_ID).SetReferenced().SetDescription("an animation for the cursor sprite"));
+       td.AddField("selectedCursorAnimation", FieldDescription(((char *)&p.selectedCursorAnimation) - ((char *)&p), Animation::TYPE_ID).SetReferenced().SetDescription("an animation for the selected cursor"));
        td.AddField("charsPerEntry", FieldDescription(((char *)&p.charsPerEntry) - ((char *)&p), Interpreter::NUMBER_ID).SetDescription("width of an entry in characters"));
        td.AddField("rows", FieldDescription(((char *)&p.rows) - ((char *)&p), Interpreter::NUMBER_ID).SetDescription("number of visible rows"));
        td.AddField("rowGap", FieldDescription(((char *)&p.rowGap) - ((char *)&p), Interpreter::NUMBER_ID).SetDescription("space between rows in pixles"));
 
 #ifndef GRAPHICS_MENU_H_
 #define GRAPHICS_MENU_H_
 
+namespace app {
+       class Application;
+       class State;
+}
+
+#include "Animation.h"
 #include "Font.h"
 #include "Sprite.h"
 #include "../math/Vector.h"
        const Font *disabledFont;
        const Sprite *cursor;
        const Sprite *selectedCursor;
+       const Animation *cursorAnimation;
+       const Animation *selectedCursorAnimation;
        int charsPerEntry;
        int rows;
        int rowGap;
 
        MenuProperties()
        : font(0), disabledFont(0), cursor(0), selectedCursor(0)
+       , cursorAnimation(0), selectedCursorAnimation(0)
        , charsPerEntry(0), rows(1), rowGap(0)
        , iconSpace(0), cols(1), colGap(0)
        , charsPerNumber(0), charsPerAdditionalText(0)
        void Clear() { entries.clear(); }
        void ClearEntry(int at) { entries[at] = Entry(0, T(), false); }
 
+       void StartAnimation(app::Application &ctrl);
+       void StartAnimation(app::State &ctrl);
+       void StopAnimation();
+
        void Draw(SDL_Surface *dest, const math::Vector<int> &position) const;
 
 private:
        int GetRow(int index) const { return index / cols; }
        int GetCol(int index) const { return index % cols; }
 
+       void DrawCursor(SDL_Surface *, const math::Vector<int> &) const;
+       void DrawSelectedCursor(SDL_Surface *, const math::Vector<int> &) const;
+
 private:
        struct Entry {
                Entry(const char *title, const T &value, bool enabled = true, const Sprite *icon = 0, int number = 0, const char *additionalText = 0)
                T value;
                bool enabled;
        };
+       AnimationRunner animation;
+       AnimationRunner selectedAnimation;
        std::vector<Entry> entries;
        int selected;
        int secondarySelection;
 template<class T>
 Menu<T>::Menu(const MenuProperties &p)
 : MenuProperties(p)
+, animation(cursorAnimation)
+, selectedAnimation(selectedCursorAnimation)
 , selected(0)
 , secondarySelection(0)
 , topRow(0)
 }
 
 
+template<class T>
+void Menu<T>::StartAnimation(app::Application &ctrl) {
+       if (cursorAnimation) {
+               animation.Start(ctrl);
+       }
+       if (selectedCursorAnimation) {
+               selectedAnimation.Start(ctrl);
+       }
+}
+
+template<class T>
+void Menu<T>::StartAnimation(app::State &ctrl) {
+       if (cursorAnimation) {
+               animation.Start(ctrl);
+       }
+       if (selectedCursorAnimation) {
+               selectedAnimation.Start(ctrl);
+       }
+}
+
+template<class T>
+void Menu<T>::StopAnimation() {
+       animation.Stop();
+       selectedAnimation.Stop();
+}
+
+
 template<class T>
 void Menu<T>::Draw(SDL_Surface *dest, const math::Vector<int> &position) const {
        int start(topRow * cols);
                case STATE_INACTIVE:
                        break;
                case STATE_ACTIVE:
-                       cursor->Draw(dest, position + cursorOffset);
+                       DrawCursor(dest, position + cursorOffset);
                        break;
                case STATE_SELECTED:
-                       selectedCursor->Draw(dest, position + cursorOffset);
+                       DrawSelectedCursor(dest, position + cursorOffset);
                        break;
                case STATE_DUAL:
-                       cursor->Draw(dest, position + cursorOffset
+                       DrawCursor(dest, position + cursorOffset
                                        - math::Vector<int>(selectedCursor->Width(), 0));
                        if (secondarySelection >= start && secondarySelection <= end) {
                                math::Vector<int> secondaryOffset(
                                                (secondarySelection % cols) * (ColWidth() + colGap) - cursor->Width(),
                                                ((secondarySelection - start) / cols) * RowHeight());
-                               selectedCursor->Draw(dest, position + secondaryOffset);
+                               DrawSelectedCursor(dest, position + secondaryOffset);
                        }
                        break;
        }
 }
 
+template<class T>
+void Menu<T>::DrawCursor(
+               SDL_Surface *dest,
+               const math::Vector<int> &position) const {
+       if (animation.Running()) {
+               animation.Draw(dest, position);
+       } else {
+               cursor->Draw(dest, position);
+       }
+}
+
+template<class T>
+void Menu<T>::DrawSelectedCursor(
+               SDL_Surface *dest,
+               const math::Vector<int> &position) const {
+       if (selectedAnimation.Running()) {
+               selectedAnimation.Draw(dest, position);
+       } else {
+               selectedCursor->Draw(dest, position);
+       }
+}
+
 }
 
 #endif
 
 
 void CapsuleFeedMenu::OnEnterState(SDL_Surface *) {
        menu.SetSelected();
+       menu.StartAnimation(Ctrl());
        itemMenu.SetActive();
+       itemMenu.StartAnimation(Ctrl());
 }
 
 void CapsuleFeedMenu::LoadInventory() {
 
 
 
 void CapsuleMenu::OnEnterState(SDL_Surface *) {
-
+       menu.StartAnimation(Ctrl());
 }
 
 void CapsuleMenu::OnExitState(SDL_Surface *) {
 
 
 
 void ConfigMenu::OnEnterState(SDL_Surface *) {
-
+       configMenu.StartAnimation(Ctrl());
 }
 
 void ConfigMenu::OnExitState(SDL_Surface *) {
 
 
 
 void EquipMenu::OnEnterState(SDL_Surface *) {
+       actionMenu.StartAnimation(Ctrl());
        equipmentMenu.SetInactive();
+       equipmentMenu.StartAnimation(Ctrl());
        inventoryMenu.SetInactive();
+       inventoryMenu.StartAnimation(Ctrl());
 }
 
 void EquipMenu::OnExitState(SDL_Surface *) {
 
 
 void InventoryMenu::OnEnterState(SDL_Surface *) {
        menu.SetSelected();
+       menu.StartAnimation(Ctrl());
        LoadInventory();
+       itemMenu.StartAnimation(Ctrl());
 }
 
 void InventoryMenu::LoadInventory() {
 
 
 
 void PartyMenu::OnEnterState(SDL_Surface *) {
-
+       mainMenu.StartAnimation(Ctrl());
 }
 
 void PartyMenu::OnExitState(SDL_Surface *) {
 
 
 void ScenarioMenu::OnEnterState(SDL_Surface *) {
        LoadItems();
+       itemMenu.StartAnimation(Ctrl());
 }
 
 void ScenarioMenu::LoadItems() {
 
        SDL_SetAlpha(highlight, SDL_SRCALPHA|SDL_RLEACCEL, 0x20);
 
        actionMenu.SetSelected();
+       actionMenu.StartAnimation(Ctrl());
        LoadSpells();
+       spellMenu.StartAnimation(Ctrl());
 }
 
 void SpellMenu::LoadSpells() {
 
 
 
 void StatusMenu::OnEnterState(SDL_Surface *) {
-
+       menu.StartAnimation(Ctrl());
 }
 
 void StatusMenu::OnExitState(SDL_Surface *) {
 
        image: :"menu-cursor-active.png",
        size: <32, 18>
 }
+SimpleAnimation menuCursorAnimation {
+       sprite: menuCursor,
+       frametime: fourFramesTime,
+       framecount: 6,
+       repeat: true
+}
+SimpleAnimation menuActiveCursorAnimation {
+       sprite: menuActiveCursor,
+       frametime: fourFramesTime,
+       framecount: 5,
+       repeat: true
+}
 
 export MenuResources menuResources {
        menubg: Texture {
                rowGap: 8,
                colGap: 32,
                cursor: menuCursor,
+               cursorAnimation: menuCursorAnimation,
                font: menuFont,
                disabledFont: menuInactiveFont,
                wrapX: true,
                charsPerEntry: 6,
                colGap: 16,
                cursor: menuCursor,
+               cursorAnimation: menuCursorAnimation,
                font: menuFont,
                wrapX: true
        },
                colGap: 16,
                cursor: menuCursor,
                selectedCursor: menuActiveCursor,
+               cursorAnimation: menuCursorAnimation,
+               selectedCursorAnimation: menuActiveCursorAnimation,
                font: menuFont,
                wrapX: true,
                wrapY: true
                rowGap: 8,
                cursor: menuCursor,
                selectedCursor: menuActiveCursor,
+               cursorAnimation: menuCursorAnimation,
+               selectedCursorAnimation: menuActiveCursorAnimation,
                font: menuFont,
                disabledFont: menuInactiveFont,
                iconSpace: 16,
                colGap: 48,
                cursor: menuCursor,
                selectedCursor: menuActiveCursor,
+               cursorAnimation: menuCursorAnimation,
+               selectedCursorAnimation: menuActiveCursorAnimation,
                font: menuFont,
                disabledFont: menuInactiveFont,
                charsPerNumber: 2,
                rowGap: 8,
                cursor: menuCursor,
                selectedCursor: menuActiveCursor,
+               cursorAnimation: menuCursorAnimation,
+               selectedCursorAnimation: menuActiveCursorAnimation,
                font: menuFont
        },
        equipmentMenu: MenuProperties {
                rowGap: 16,
                cursor: menuCursor,
                selectedCursor: menuActiveCursor,
+               cursorAnimation: menuCursorAnimation,
+               selectedCursorAnimation: menuActiveCursorAnimation,
                font: normalFont,
                iconSpace: 16,
                wrapY: true
                charsPerEntry: 8,
                rowGap: 32,
                cursor: menuCursor,
+               cursorAnimation: menuCursorAnimation,
                font: menuFont,
                wrapY: true
        },
                charsPerEntry: 14,
                rowGap: 8,
                cursor: menuCursor,
+               cursorAnimation: menuCursorAnimation,
                font: menuFont
        },
        scenarioMenuHeadline: "SCENARIO ITEM",
                charsPerEntry: 7,
                cursor: menuCursor,
                selectedCursor: menuActiveCursor,
+               cursorAnimation: menuCursorAnimation,
+               selectedCursorAnimation: menuActiveCursorAnimation,
                font: menuFont,
                thirdColumnHack: 2
        },
                colGap: 32,
                cursor: menuCursor,
                selectedCursor: menuActiveCursor,
+               cursorAnimation: menuCursorAnimation,
+               selectedCursorAnimation: menuActiveCursorAnimation,
                font: menuFont
        },
        capsuleFeedLabel: "FEED",