if( typeof gCLIVEMAP == 'undefined' ){
  
  var CLiveMapLinkRegistration = Class.create();
  CLiveMapLinkRegistration.prototype= {
    initialize: function() {
      this.links = new Array();
      this.options = "";
    },
    addLink: function( element ){
      this.links.push( element );
    },
    addLinkId: function( id ){
      if( $(id) ) this.addLink( $(id) );
    },
    addOption: function( parameter, value ){
      this.removeOption(parameter); 
      var option = parameter+'='+value+'&';
      for( var i = 0; i < this.links.length; ++i ){
        this.links[i].href += option;
      }
      this.options += option;
    },
    removeOption: function( parameter ){
      for( var i = 0; i < this.links.length; ++i ){
        var idxbegin = this.links[i].href.indexOf(parameter);
        while( idxbegin != -1 ){
          var idxend = this.links[i].href.indexOf('&', idxbegin);
          var newURL = this.links[i].href.substring( 0, idxbegin ) + this.links[i].href.substring( idxend + 1 );
          this.links[i].href = newURL;
          idxbegin = this.links[i].href.indexOf(parameter);
        }
      }
      var idxbegin = this.options.indexOf(parameter);
      while( idxbegin != -1 ){
        var idxend = this.options.indexOf('&', idxbegin);
        var newURL = this.options.substring( 0, idxbegin ) + this.options.substring( idxend + 1 );
        this.options = newURL;
        idxbegin = this.options.indexOf(parameter);
      }
    }
  }
  var gLiveMapLinkRegistration = new CLiveMapLinkRegistration;
  
  var CLiveMapObjects = new Object();

  var gCLIVEMAP = 'defined';
  
  var gLiveMapReferenceCount = gLiveMapReferenceCount?gLiveMapReferenceCount:0;
  
  /**
   * @brief Abstract basis class for visualization of static Locations on a Map
   **/
  var CLiveMap = Class.create();
  CLiveMap.prototype = {
    initialize: function( maindiv ) {
      this.refcount = gLiveMapReferenceCount;
      gLiveMapReferenceCount++;
      this.maindiv = maindiv;
      this.width = parseInt(this.maindiv.style.width);
      this.height = parseInt(this.maindiv.style.height);
      this.lookstops = new CLookStops();
      this.lookpois = new CLookPois();
      this.looktrains = new CLookTrains();
      this.lookpois.setMainDiv(this.addDivElem(this.getElemName('pois'),this.maindiv));
      this.lookstops.setMainDiv(this.addDivElem(this.getElemName('stops'),this.maindiv));
      this.looktrains.setMainDiv(this.addDivElem(this.getElemName('trains'),this.maindiv));
      var mousediv = this.addDivElem(this.getElemName('mouse'),this.maindiv);
      mousediv.style.zIndex = 20;
      this.mousemanager = new CLookMouse(mousediv);
      this.lookpois.setMouseManager(this.mousemanager);
      this.lookstops.setMouseManager(this.mousemanager);
      this.looktrains.setMouseManager(this.mousemanager);
    },
    changetrainproductclass: function(currprod,boolval){
      if(boolval) 
        gLiveMapLinkRegistration.addOption("lookprodtrainchecked_" + currprod, "yes");
      else
        gLiveMapLinkRegistration.removeOption("lookprodtrainchecked_" + currprod);
      this.looktrains.setProductClass(currprod,boolval);
      this.looktrains.show();
    },
    changestopproductclass: function(currprod,boolval){
      if(boolval) 
        gLiveMapLinkRegistration.addOption("lookprodstopchecked_" + currprod, "yes");
      else
        gLiveMapLinkRegistration.removeOption("lookprodstopchecked_" + currprod);
      this.lookstops.setProductClass(currprod,boolval);
      this.lookstops.show();
    },
    changeshowstopnames: function(boolval){
      if(boolval) 
        gLiveMapLinkRegistration.addOption("lookoptionchecked_1", "yes");
      else
        gLiveMapLinkRegistration.removeOption("lookoptionchecked_1");
      this.lookstops.setShowStopNames(boolval);
      this.lookstops.show();
    },
    changeshowtrainnames: function(boolval){
      if(boolval) 
        gLiveMapLinkRegistration.addOption("lookoptionchecked_2", "yes");
      else
        gLiveMapLinkRegistration.removeOption("lookoptionchecked_2");
      this.looktrains.setShowNames(boolval);
      this.looktrains.show();
    },
    changeshowtrainends: function(boolval){
      if(boolval) 
        gLiveMapLinkRegistration.addOption("lookoptionchecked_3", "yes");
      else
        gLiveMapLinkRegistration.removeOption("lookoptionchecked_3");
      this.looktrains.setShowDestination(boolval);
      this.looktrains.show();
    },
    startanimation: function(){
      this.looktrains.startanimation();
    },
    stopanimation: function(){
      this.looktrains.stopanimation();
    },
    changepois: function(currpoi,boolval){
      if(boolval) 
        gLiveMapLinkRegistration.addOption("lookpoichecked_" + currpoi, "yes");
      else
        gLiveMapLinkRegistration.removeOption("lookpoichecked_" + currpoi);
      if( boolval == true )
        this.lookpois.show(currpoi);
      else
        this.lookpois.clear(currpoi);
    },
    addDivElem: function( divname, parentelem ){
      var elem = CNodes.getElem( 'div', divname, 'absolute', 'block',
                                 0, 0, this.width, this.height );
      parentelem.appendChild(elem);
      return $( divname );
    },
    getElemName: function( shortname ){
      return 'CLiveMap_' + this.refcount + '_' + shortname;
    }
  }
}

