/* Initialisiserung unten */ 
var tooltipTemplate = $.template('<b>${word}</b><hr>${description}<br /><br />(Klicken Sie auf den Begriff, um die komplette Erkl&auml;rung zu lesen)');
var requestUrl = "/fileadmin/glossar.php?";
var waitingContent = "<img src='./img/loadingAnimation.gif'>loading"

var G16customFetcher = function(url) {
    var wordList = new Array();
    var fetchedDescriptions = new Array();
    var requestUrl = url;

    this.fetchWords = function(){
          $.ajax({
               async: false,
               dataType: "json",
               url: requestUrl+"action=words",
               success: function(html){
                  wordList = html;
               }
            });
           return wordList;
       }

   this.fetchDescription = function(){
          var word = this.innerHTML;
          var newFetched = {
               template_before: "<div id='LiveGlossar_"+word+"' class='LiveGlossarToolTip'>",
               content:waitingContent,
               template_after: "</div>",
               get: function(){
                  return this.template_before+this.content+this.template_after;
               }

            }
          if (fetchedDescriptions[word] == null){
            $.getJSON(requestUrl+"action=description&word="+word,function(data){
                 newFetched.content = "";
                 data.word = word;
                 newFetched.content = tooltipTemplate.apply(data);
                 fetchedDescriptions[word] = newFetched;
                 $("#LiveGlossar_"+word).html(newFetched.content);
            });
            return newFetched.get();
          }
          else{
             return fetchedDescriptions[word].get();
          }

    }
 }
 
 
 

   $("document").ready(function(){
          var wordFetcher = new G16customFetcher(requestUrl);
          $("div#col3").LiveGlossar({
                              descriptionFetcher: wordFetcher.fetchDescription,
                              glossarWords: wordFetcher.fetchWords,
                              ignoreTags:["a","h1"],
                              replaceAll:true,
                              tooltipOptions:{
                               track:true
                               
                              }
                             }).each(function(){
                                var l = document.createElement("a");
                                l.href=requestUrl+"word="+this.innerHTML;
                                l.setAttribute("class", "thickbox");
                                $(this).wrap(l);
                             })

       });

