requirejs.config({
  baseUrl: '../js/src'
});
          // here alwaysmenu instead of normal menu, then + alwaysEntry
require(['containermenu','menu/item', 'menu/prefix', 'menu/lengthField', 'selectMenu', 'hint/item', 'hint/lengthField',
'container/container', 'container/containeritem'
  ],
function (containerMenuClass, itemClass, prefixClass, lengthFieldClass, selectMenuClass, hintItemClass, hintLengthField, containerClass, containerItemClass) {

  /**
   * Create own menu item class.
   */
  var OwnMenuItemClass = {
    create : function (params) {
      return Object.create(itemClass).upgradeTo(this)._init(params);
    },

    // content function
    content : function (content) {
      if (arguments.length === 1) {
        this._content = content;
      };
      return this._content;
    },

    // enter or click
    onclick : function () {
      console.log(this._name);
    },

    // right arrow
    further : function () {
      console.log("Further: " + this._name);
    },

    // initialize item
    _init : function (params) {
      if (params[0] === undefined)
    throw new Error("Missing parameters");

      this._name = params[0];
      this._content = document.createTextNode(this._name);
      this._lcField = ' ' + this.content().textContent.toLowerCase();
      this._i=0;
      return this;
    }
  };


  /**
   * Create own conainerItem class.
   */
  var OwnContainerItemClass = {
    create : function () {
      var obj = containerItemClass.create()
        .upgradeTo(this);
        //._init();
      obj.value="";
      return obj;
    },
    add : function (letter) {
      this.value+=letter;
    },
    clear : function () {
      this.value = "";
    },
    further : function () {
      this.value = this.value + this.value;
    },
    onclick : function () {
      console.log('ContainerItem' + this.value);
      console.log(this._i);
      this._menu.limit(this._i);
      this._menu.show();
    },
    element : function () {
      // already defined
      if (this._el !== undefined) return this._el;
      
      // Create list item
      const li = document.createElement("li");
      li.innerHTML="CI";
  
      // Connect action
      if (this["onclick"] !== undefined) {
        li["onclick"] = this.onclick.bind(this);
      };    
      return this._el = li;
    }
  };
  //List of items.
  var ExampleItemList = new Array;
  ExampleItemList.push(OwnContainerItemClass.create());
  ExampleItemList.push(OwnContainerItemClass.create());
  ExampleItemList[0].value = "Example Item 1";
  ExampleItemList[0]._i = 3;
  ExampleItemList[1]._i = 4;

  //Own container class.
  var OwnContainerClass = {
    create : function (listOfContainerItems, params) {
      console.log(containerClass);
      return containerClass.create(listOfContainerItems, params)
        .upgradeTo(this);
    }
    //Dont know what you would want to add though
    // You could add the containerItemClass parameter here *if* you really wanted to.
  };

  /**
   * Create own menu class.
   */
  
  var OwnMenu = {
    create : function (list) {
      const params = {
        itemClass : OwnMenuItemClass,
        prefixClass : prefixClass,
        lengthFieldClass : lengthFieldClass,
        containerClass : OwnContainerClass,
        containerItemClass : OwnContainerItemClass
      };
      console.log("Am now in OwnMenu create",containerMenuClass);
      console.log(ExampleItemList); // we learn, that it definetly has all the functions defined in alwaysmenu.js
      var obj = containerMenuClass.create(list,params,ExampleItemList)
          .upgradeTo(this);
          //._init(list, params);
      obj._firstActive = true;
      console.log("OwnMenu Element",obj._el);
      return obj;
    }
  };

  var list = [
    ["Constituency"],
    ["Lemma"],
    ["Morphology"],
    ["Part-of-Speech"],
    ["Syntax"]
  ];

  /**
  var list = [
    ['Titel', 'title', 'string'],
    ['Untertitel', 'subTitle', 'string'],
    ['Beschreibung', 'desc', 'string'],
    ['Veröffentlichungsdatum', 'pubDate', 'date'],
    ['Länge', 'length', 'integer'],
    ['Autor', 'author', 'string'],
    ['Genre', 'genre', 'string'],
    ['corpusID', 'corpusID', 'string'],
    ['docID', 'docID', 'string'],
    ['textID', 'textID', 'string']
  ];
  */

  var menu = OwnMenu.create(list);

  /** 
  var largeMenu = OwnMenu.create([
    // http://www.ids-mannheim.de/cosmas2/projekt/referenz/stts/morph.html
    // http://nachhalt.sfb632.uni-potsdam.de/owl-docu/stts.html
    // "$.", "$(", "$,"
    ["ADJA","ADJA ", "Attributive Adjective"],
    ["ADJD","ADJD ", "Predicative Adjective"],
    ["ADV","ADV ", "Adverb"],
    ["APPO","APPO ", "Postposition"],
    ["APPR","APPR ", "Preposition"],
    ["APPRART","APPRART ", "Preposition with Determiner"],
    ["APZR","APZR ","Right Circumposition"],
    ["ART","ART ", "Determiner"],
    ["CARD","CARD ", "Cardinal Number"],
    ["FM","FM ", "Foreign Material"],
    ["ITJ","ITJ ", "Interjection"],
    ["KOKOM","KOKOM ", "Comparison Particle"],
    ["KON","KON ", "Coordinating Conjuncion"],
    ["KOUI","KOUI ", "Subordinating Conjunction with 'zu'"],
    ["KOUS","KOUS ", "Subordinating Conjunction with Sentence"],
    ["NE","NE ", "Named Entity"],
    ["NN","NN ", "Normal Nomina"],
    ["PAV", "PAV ", "Pronominal Adverb"],
    ["PDAT","PDAT ","Attributive Demonstrative Pronoun"],
    ["PDS","PDS ", "Substitutive Demonstrative Pronoun"],
    ["PIAT","PIAT ", "Attributive Indefinite Pronoun without Determiner"],
    ["PIDAT","PIDAT ", "Attributive Indefinite Pronoun with Determiner"],
    ["PIS","PIS ", "Substitutive Indefinite Pronoun"],
    ["PPER","PPER ", "Personal Pronoun"],
    ["PPOSAT","PPOSAT ", "Attributive Possessive Pronoun"],
    ["PPOSS","PPOSS ", "Substitutive Possessive Pronoun"],
    ["PRELAT","PRELAT ", "Attributive Relative Pronoun"],
    ["PRELS","PRELS ", "Substitutive Relative Pronoun"],
    ["PRF","PRF ", "Reflexive Pronoun"],
    ["PROAV","PROAV ", "Pronominal Adverb"],
    ["PTKA","PTKA ","Particle with Adjective"],
    ["PTKANT","PTKANT ", "Answering Particle"],
    ["PTKNEG","PTKNEG ", "Negation Particle"],
    ["PTKVZ","PTKVZ ", "Separated Verbal Particle"],
    ["PTKZU","PTKZU ", "'zu' Particle"],
    ["PWAT","PWAT ", "Attributive Interrogative Pronoun"],
    ["PWAV","PWAV ", "Adverbial Interrogative Pronoun"],
    ["PWS","PWS ", "Substitutive Interrogative Pronoun"],
    ["TRUNC","TRUNC ","Truncated"],
    ["VAFIN","VAFIN ", "Auxiliary Finite Verb"],
    ["VAIMP","VAIMP ", "Auxiliary Finite Imperative Verb"],
    ["VAINF","VAINF ", "Auxiliary Infinite Verb"],
    ["VAPP","VAPP ", "Auxiliary Perfect Participle"],
    ["VMFIN","VMFIN ", "Modal Finite Verb"],
    ["VMINF","VMINF ", "Modal Infinite Verb"],
    ["VMPP","VMPP ", "Modal Perfect Participle"],
    ["VVFIN","VVFIN ","Finite Verb"],
    ["VVIMP","VVIMP ", "Finite Imperative Verb"],
    ["VVINF","VVINF ", "Infinite Verb"],
    ["VVIZU","VVIZU ", "Infinite Verb with 'zu'"],
    ["VVPP","VVPP ", "Perfect Participle"],
    ["XY", "XY ", "Non-Word"]
  ]);
  */
  document.getElementById('menu').appendChild(menu.element());
  //document.getElementById('largemenu').appendChild(largeMenu.element());

  menu.limit(3).show(3);
  menu.focus();
  
  //largeMenu.limit(8).show(3);
});
