/**
 * <layer name="info" url="http://..."
 *        maxInfoWindowWidth=384
 *        infoWindowTabTitle="Bericht ">
 *   <zoom level=z
 *         iconSizeReport=r iconSizeWordless=w
 *         lineWidth=w lineColor=c lineOpacity
 *         areaColor=c/>
 *   </zoom>
 * </layer>
 */

function hbLayer (layerSettings, map)
{
  var thisLayer = this;
  
  this.reportsByLang = new Object ();
  this.rssItemsByLang = new Object ();
  this.readerByLang = new Object ();
  this.infosByLang = new Object ();
  this.titleByLang = new Object ();
  this.infoWindowSettingsByLang = new Object ();
  this.isInitializedByLang = new Object ();
  
  this.reader = null;
  this.reports = new Array ();
  this.rssItems = new Array ();
  this.infos = new Object ();
  this.isInitialized = function () {return false;};
  this.language = null;
  this.languageDependent = false;
  this.pubDate = new Date (0);

  this.name = null;
  this.visible = false;
  this.retryTimeout = 5000;

  this.zoomSettings = new Object ();
  this.zoomSettings ["point"] = new Array ();
  this.zoomSettings ["line"] = new Array ();
  this.zoomSettings ["area"] = new Array ();

  this.infoWindowSettings = new Object ();
  this.infoWindowSettings ["maxWidth"] = 384;
  this.infoWindowSettings ["tabTitle"] = "Bericht ";

  this.map = map;
  var mgrOptions = { borderPadding: 0, trackMarkers: false };
  this.markerMgr = new MarkerManager (this.map.map, mgrOptions);
  this.overlayMgr = new hbOverlayManager (this.map.map, mgrOptions);
  this.tile = null;
  this.globalOverlay = null;
  this.screenOverlay = null;
  this.parseSettings (layerSettings);
  this.filter = new hbFilterSpec (null);
  this.filter.layername = this.name;
  this.instandReload = false;
  this.synchronWithMap = false;
  this.isUnfoldEnabled = false;
  this.unfoldMinZoom = 0;

  if (null == this.reader)
  {
    this.setForCurrentLanguage ("isInitialized", function () {return true;});
  }
  else
  {
    this.setForCurrentLanguage ("isInitialized", function () {return false;});
  }
}

hbLayer.prototype.strToPane = function (str)
{
  if (str == "G_MAP_MAP_PANE")
  {
    return G_MAP_MAP_PANE;
  }
  else if (str == "G_MAP_MARKER_SHADOW_PANE")
  {
    return G_MAP_MARKER_SHADOW_PANE;
  }
  else if (str == "G_MAP_MARKER_PANE")
  {
    return G_MAP_MARKER_PANE;
  }
  else if (str == "G_MAP_FLOAT_SHADOW_PANE")
  {
    return G_MAP_FLOAT_SHADOW_PANE;
  }
  else if (str == "G_MAP_MARKER_MOUSE_TARGET_PANE")
  {
    return G_MAP_MARKER_MOUSE_TARGET_PANE;
  }
  else if (str == "G_MAP_FLOAT_PANE")
  {
    return G_MAP_FLOAT_PANE;
  }

  return null;
}

hbLayer.prototype.parseSettings = function (settings)
{
  this.name = settings ["name"];
  var thisLayer = this;
  
  if ("maxInfoWindowWidth" in settings)
  {
    this.infoWindowSettings ["maxWidth"] = settings ["maxInfoWindowWidth"];
  }

  if (settings ["url"])
  {
    this.reader = new hbXmlReader (settings ["url"], false, thisLayer.handleReload, thisLayer);

    if (settings ["channel"])
    {
      /*if (!language)
      {
        this.setLanguage (settings ["channel"] [0] ["language"]);
      }
      else
      {
        this.setLanguage (language);
      }*/
      this.setLanguage (dictionary.activeLanguage);

      for (var l = 0; l < settings ["channel"].length; ++l)
      {
        var lang = settings ["channel"] [l] ["language"];
        this.titleByLang [lang] = settings ["channel"] [l] ["title"];
      }
    }
  }
  else if (settings ["channel"])
  {
    this.languageDependent = true;

    for (var l = 0; l < settings ["channel"].length; ++l)
    {
      var lang = settings ["channel"] [l] ["language"];
      this.readerByLang [lang] = new hbXmlReader (settings ["channel"] [l] ["url"], false, thisLayer.handleReload, thisLayer);
      this.reportsByLang [lang] = new Array ();
      this.rssItemsByLang [lang] = new Array ();
      this.infosByLang [lang] = new Object ();
      this.titleByLang [lang] = settings ["channel"] [l] ["title"];
      this.infoWindowSettingsByLang [lang] = new Object ();
      this.infoWindowSettingsByLang [lang] ["maxWidth"] = this.infoWindowSettings ["maxWidth"];
      this.infoWindowSettingsByLang [lang] ["tabTitle"] = settings ["channel"] [l] ["infoWindowTabTitle"];
      this.isInitializedByLang [lang] = function () {return false;};
    }

/*    if (!language)
    {
      this.setLanguage (settings ["channel"] [0] ["language"]);
    }
    else
    {
      this.setLanguage (language);
    }*/
    this.setLanguage (dictionary.activeLanguage);
  }

  this.setZoomSettings (settings, "point");
  this.setZoomSettings (settings, "line");
  this.setZoomSettings (settings, "area");

  if ("zoom" in settings)
  {
    var zoomArray = settings ["zoom"];
    var orderedZoom = new Array ();

    for (var zoomIndex = 0; zoomIndex < zoomArray.length; ++zoomIndex)
    {
      orderedZoom [zoomArray [zoomIndex] ["level"]] = zoomArray [zoomIndex];
    }

    this.setZoomSettings (orderedZoom, "point");
    this.setZoomSettings (orderedZoom, "line");
    this.setZoomSettings (orderedZoom, "area");
  }

  if ("tile" in settings)
  {
    var tileSettings = settings ["tile"];
    var tileUrl = tileSettings [0] ["url"];
    var png = tileUrl.toLowerCase ().lastIndexOf (".png");
    var isAPng = (png < tileUrl.length - 4) ? false : true;

    this.tile = new GTileLayerOverlay (new hbTileLayer (
        null,
        0,
        17,
        {opacity: tileSettings [0] ["opacity"],
         isPng: isAPng,
         tileUrlTemplate: tileUrl}));
  }

  if ("globalOverlay" in settings)
  {
    var globalOverlaySettings = settings ["globalOverlay"];
    var opacity = parseFloat (globalOverlaySettings [0] ["opacity"]);
    var url = globalOverlaySettings [0] ["url"];
    var bounds = new GLatLngBounds (
        new GLatLng (parseFloat (globalOverlaySettings [0] ["bounds_sw.lat"]), parseFloat (globalOverlaySettings [0] ["bounds_sw.lng"])),
        new GLatLng (parseFloat (globalOverlaySettings [0] ["bounds_ne.lat"]), parseFloat (globalOverlaySettings [0] ["bounds_ne.lng"])));
    this.globalOverlay = new hbGlobalOverlay (url, bounds, opacity);
  }

  if ("screenOverlay" in settings)
  {
    var screenOverlaySettings = settings ["screenOverlay"];
    var opacity = parseFloat (screenOverlaySettings [0] ["opacity"]);
    var url = screenOverlaySettings [0] ["url"];
    var pane = this.strToPane (screenOverlaySettings [0] ["pane"]);
    var size = new GScreenSize (parseFloat (screenOverlaySettings [0] ["size.x"]), parseFloat (screenOverlaySettings [0] ["size.y"]), screenOverlaySettings [0] ["sizeUnit"], screenOverlaySettings [0] ["sizeUnit"]);
    var screenXY = new Object ();

    if (screenOverlaySettings [0] ["screen.top"])
    {
      screenXY.top = parseFloat (screenOverlaySettings [0] ["screen.top"]);
      screenXY.topUnit = "pixels";
      
      if (screenOverlaySettings [0] ["screen.top.unit"])
      {
        screenXY.topUnit = screenOverlaySettings [0] ["screen.top.unit"];
      }
    }
    if (screenOverlaySettings [0] ["screen.bottom"])
    {
      screenXY.bottom = parseFloat (screenOverlaySettings [0] ["screen.bottom"]);
      screenXY.bottomUnit = "pixels";
      
      if (screenOverlaySettings [0] ["screen.bottom.unit"])
      {
        screenXY.bottomUnit = screenOverlaySettings [0] ["screen.bottom.unit"];
      }
    }
    if (screenOverlaySettings [0] ["screen.left"])
    {
      screenXY.left = parseFloat (screenOverlaySettings [0] ["screen.left"]);
      screenXY.leftUnit = "pixels";
      
      if (screenOverlaySettings [0] ["screen.left.unit"])
      {
        screenXY.leftUnit = screenOverlaySettings [0] ["screen.left.unit"];
      }
    }
    if (screenOverlaySettings [0] ["screen.right"])
    {
      screenXY.right = parseFloat (screenOverlaySettings [0] ["screen.right"]);
      screenXY.rightUnit = "pixels";
      
      if (screenOverlaySettings [0] ["screen.right.unit"])
      {
        screenXY.rightUnit = screenOverlaySettings [0] ["screen.right.unit"];
      }
    }

    this.screenOverlay = new hbScreenOverlay (url, screenXY, size, pane, opacity);
  }

  if ("info" in settings)
  {
    var _infos = new Object ();
    var listed = settings ["info"];

    for (var l = 0; l < listed.length; ++l)
    {
      _infos [listed [l] ["elementName"]] = 0.0;
    }

    this.setForCurrentLanguage ("infos", _infos);
  }

  if ("type" in settings)
  {
    this.type = settings ["type"];
  }
}

hbLayer.prototype.setZoomSettings = function (src, attrName)
{
  if (attrName in src)
  {
    var zoomArray = src [attrName] [0] ["zoom"];
    var orderedZoom = new Array ();

    for (var zoomIndex = 0; zoomIndex < zoomArray.length; ++zoomIndex)
    {
      orderedZoom [zoomArray [zoomIndex] ["level"]] = zoomArray [zoomIndex];
    }

    var lastZoom = null;
    var lastValue = null;
    var currentSetting = null;

    for (var i = 0; i < orderedZoom.length; ++i)
    {
      if (orderedZoom [i])
      {
        var value = orderedZoom [i];
        var zoom  = parseInt (orderedZoom [i] ["level"]);

        if (    (false == hbLayer.prototype.equals (value, lastValue))
             || (zoom != 1 + lastZoom))
        {
          if (null != currentSetting)
          {
            currentSetting ["maxZoom"] = lastZoom;
            this.zoomSettings [attrName].push (currentSetting);
          }

          currentSetting = {"minZoom": zoom, "maxZoom": zoom, "value": value};
        }

        lastZoom = zoom;
        lastValue = value;
      }
    }

    if (null != currentSetting)
    {
      currentSetting ["maxZoom"] = lastZoom;
      this.zoomSettings [attrName].push (currentSetting);
    }
  }
}

hbLayer.prototype.equals = function (first, second)
{
  if (first == second)
  {
    return true;
  }

  if (null == second)
  {
    return false;
  }

  var propsInFirst = 0;

  for (var name in first)
  {
    ++propsInFirst;

    if (name != "level")
    {
      if (first [name] != second [name])
      {
        return false;
      }
    }
  }

  var propsInSecond = 0;

  for (var name in second)
  {
    ++propsInSecond;
  }

  if (propsInFirst != propsInSecond)
  {
    return false;
  }

  return true;
}

hbLayer.prototype.getTitle = function ()
{
  return this.titleByLang [this.language];
}

hbLayer.prototype.setForCurrentLanguage = function (property, value)
{
  this [property + "ByLang"] [this.language] = value;
  this [property] = this [property + "ByLang"] [this.language];
}

hbLayer.prototype.setLanguage = function (lang)
{
  if (this.language != lang)
  {
    this.language = lang;

    if (this.languageDependent)
    {
      if (this.visible)
      {
        this.hide ();
      }

      this.reports = this.reportsByLang [this.language];
      this.rssItems = this.rssItemsByLang [this.language];
      this.reader = this.readerByLang [this.language];
      this.infos = this.infosByLang [this.language];
      this.infoWindowSettings = this.infoWindowSettingsByLang [this.language];
      this.isInitialized = this.isInitializedByLang [this.language];
      this.synchronWithMap = false;

      if (this.isInitialized ())
      {
        if ((undefined != this.onReloadFct) && (null != this.onReloadFct))
        {
          if ((undefined != this.onReloadObject) && (null != this.onReloadObject))
          {
            this.onReloadFct.call (this.onReloadObject);
          }
          else
          {
            this.onReloadFct ();
          }
        }
      }
      else if (true == this.instandReload)
      {
        if (null == this.reader)
        {
          this.setForCurrentLanguage ('isInitialized', function () {return true;});
        }
        else
        {
          this.reader.read ();
        }
      }
    }
  }
}

hbLayer.prototype.reload = function ()
{
  for (var i in this.isInitializedByLang)
  {
    this.isInitializedByLang [i] = function () {return false;}; 
  }

  this.setForCurrentLanguage ('isInitialized', function () {return false;});

  this.synchronWithMap = false;

  if (true == this.instandReload)
  {
    if (null == this.reader)
    {
      for (var i in this.isInitializedByLang)
      {
        this.isInitializedByLang [i] = function () {return true;}; 
      }

      this.setForCurrentLanguage ('isInitialized', function () {return true;});
    }
    else
    {
      this.reader.read ();
    }
  }
}

hbLayer.prototype.handleReload = function ()
{
  this.markerMgr.clearMarkers ();
  this.overlayMgr.clearOverlays ();

  for (var r = 0; r < this.reports.length; ++r)
  {
    this.reports [r].destroy ();
  }

  for (var r = 0; r < this.rssItems.length; ++r)
  {
    this.rssItems [r].destroy ();
  }

  this.reports.length = 0;
  this.rssItems.length = 0;
  var rss = this.reader.getContent ();

  if ((null != rss) && ("rss" == rss.getType ()))
  {
    if ("channel" in rss)
    {
      var channels = rss ["channel"];

      if ("0" in channels)
      {
        this.pubDate = new Date (parseInt (channels ["0"] ["pubDate"] [0].getText (), 10));

        if ("item" in channels ["0"])
        {
          var items = channels ["0"] ["item"];

          for (var item in items)
          {
            if (    (false == "guid" in items [item])
                 || (false == "hb:popup" in items [item])
                 || (false == "hb:icon" in items [item])
                 || (false == "georss:point" in items [item])
                 || (    (true == "georss:line" in items [item])
                      && (true == "georss:polygon" in items [item])))
            {
              continue;
            }

            var guids     = items [item] ["guid"];
            var popups    = items [item] ["hb:popup"];
            var titles    = items [item] ["title"];
            var messages  = items [item] ["hb:message"];
            var links     = items [item] ["hb:link"];
            var urls      = items [item] ["hb:url"];
            var icons     = items [item] ["hb:icon"];
            var minZooms  = items [item] ["hb:minZoom"];
            var maxZooms  = items [item] ["hb:maxZoom"];
            var polygons  = items [item] ["georss:polygon"];
            var polylines = items [item] ["georss:line"];
            var points    = items [item] ["georss:point"];
            var startTime = items [item] ["hb:startTime"];
            var stopTime  = items [item] ["hb:stopTime"];

            if (    (0 == guids.length)
                 || (0 == popups.length)
                 || (0 == titles.length)
                 || (0 == icons.length)
                 || (0 == points.length))
            {
              continue;
            }

            var messageTexts = new Array ();

            if (messages)
            {
              for (var messageIndex = 0; messageIndex < messages.length; ++messageIndex)
              {
                messageTexts.push (messages [messageIndex].getText () + "<br>&nbsp;");
              }
            }

            var linkUrls = new Array ();
            var linkTitles = new Array ();

            if (links)
            {
              for (var linkIndex = 0; linkIndex < links.length; ++linkIndex)
              {
                linkUrls.push (links [linkIndex].getText ());
                linkTitles.push (links [linkIndex] ["title"]);
              }
            }

            var extUrls = new Array ();

            if (urls)
            {
              for (var urlIndex = 0; urlIndex < urls.length; ++urlIndex)
              {
                extUrls.push (urls [urlIndex].getText ());
              }
            }

            var pointCoord = points [0].getText ().replace (/,/g, '.').split (" ");

            if (2 > pointCoord.length)
            {
              continue;
            }

            var point = new GLatLng (parseFloat (pointCoord [0]), parseFloat (pointCoord [1]));
            var lines = new Array ();
            var areas = new Array ();

            var wordlessTokens = new Array ();

            if ("hb:wordless" in items [item])
            {
              var wordless  = items [item] ["hb:wordless"];

              for (wl in wordless)
              {
                if (    (true == "georss:point" in wordless [wl])
                     || (true == "hb:icon" in wordless [wl]))
                {
                  var wlIcons     = wordless [wl] ["hb:icon"];
                  var wlPoints    = wordless [wl] ["georss:point"];

                  if (    (0 == wlIcons.length)
                       || (0 == wlPoints.length))
                  {
                    continue;
                  }

                  var pointCoord = wlPoints [0].getText ().replace (/,/g, '.').split (" ");

                  if (2 > pointCoord.length)
                  {
                    continue;
                  }

                  wordlessTokens.push (new hbToken (
                      wlIcons [0],
                      new GLatLng (parseFloat (pointCoord [0]), parseFloat (pointCoord [1])),
                      this.zoomSettings ["point"],
                      wordless [wl] ["visible"],
                      wordless [wl] ["resizable"],
                      wordless [wl] ["hb:minZoom"],
                      wordless [wl] ["hb:maxZoom"],
                      wordless [wl] ["resizable"] ? popups [0].getText () : null));
                }
                else if (true == "georss:line" in wordless [wl])
                {
                  var wlPoints    = wordless [wl] ["georss:line"];

                  if (0 == wlPoints.length)
                  {
                    continue;
                  }

                  var lineCoords = wlPoints [0].getText ().replace (/,/g, '.').split (" ");

                  if (0 != lineCoords.length % 2)
                  {
                    --lineCoords.length;
                  }

                  var linePoints = new Array (lineCoords.length / 2);

                  for (var i = 0; i < lineCoords.length / 2; ++i)
                  {
                    linePoints [i] = new GLatLng (parseFloat (lineCoords [2 * i]),
                                                  parseFloat (lineCoords [2 * i + 1]));
                  }

                  lines.push (new hbLine (
                    linePoints,
                    this.zoomSettings ["line"],
                    wordless [wl] ["georss:line"] ["color"],
                    wordless [wl] ["visible"]));
                }
              }
            }

            var reportInfo = new Object ();

            for (var i in this.infos)
            {
              var info = items [item] [i];

              if (info && (0 != info.length))
              {
                reportInfo [i] = parseFloat (info [0].getText ());
              }
            }

            if (null != polygons)
            {
              for (var pg = 0; pg < polygons.length; ++pg)
              {
                var coordText = polygons [pg].getText ();
                var areaCoords = coordText.replace (/,/g, '.').split (" ");

                if (0 != areaCoords.length % 2)
                {
                  --areaCoords.length;
                }

                var areaPoints = new Array (areaCoords.length / 2);

                for (var i = 0; i < areaCoords.length / 2; ++i)
                {
                  areaPoints [i] = new GLatLng (parseFloat (areaCoords [2 * i]),
                                                parseFloat (areaCoords [2 * i + 1]));
                }

                areas.push (new hbArea (
                    areaPoints,
                    this.zoomSettings ["area"]));
              }
            }
            if (null != polylines)
            {
              for (var pl = 0; pl < polylines.length; ++pl)
              {
                var lineCoords = polylines [pl].getText ().replace (/,/g, '.').split (" ");

                if (0 != lineCoords.length % 2)
                {
                  --lineCoords.length;
                }

                var linePoints = new Array (lineCoords.length / 2);

                for (var i = 0; i < lineCoords.length / 2; ++i)
                {
                  linePoints [i] = new GLatLng (parseFloat (lineCoords [2 * i]),
                                                parseFloat (lineCoords [2 * i + 1]));
                }

                lines.push (new hbLine (
                  linePoints,
                  this.zoomSettings ["line"],
                  polylines [pl] ["color"]));
              }
            }

            this.reports.push (new hbReport (
                guids [0].getText (),
                popups [0].getText (),
                titles [0].getText (),
                messageTexts,
                linkUrls,
                linkTitles,
                point,
                icons [0],
                minZooms ? minZooms [0] : null,
                maxZooms ? maxZooms [0] : null,
                wordlessTokens,
                lines,
                areas,
                startTime,
                stopTime,
                reportInfo,
                parseInt (item, 10),
                this.zoomSettings ["point"],
                this.infoWindowSettings,
                extUrls,
                this.isUnfoldEnabled,
                this.unfoldMinZoom));
          }
        }
      }
      if ("1" in channels)
      {
        if ("item" in channels ["1"])
        {
          var items = channels ["1"] ["item"];

          for (var item in items)
          {
            if (    (false == "title" in items [item])
                 || (false == "hb:icon" in items [item]))
            {
              continue;
            }
            
            var guids     = items [item] ["hb:RefId"];
            var msgIndex  = items [item] ["hb:RefIndex"];
            var titles    = items [item] ["title"];
            var messages  = items [item] ["hb:message"];
            var icons     = items [item] ["hb:icon"];
            var startTime = items [item] ["hb:startTime"];
            var stopTime  = items [item] ["hb:stopTime"];

            if (    (0 == guids.length)
                 || (0 == titles.length)
                 || (0 == icons.length))
            {
              continue;
            }

            this.rssItems.push (new hbRSSItem (
                guids [0].getText (),
                msgIndex ? msgIndex [0].getText () : "",
                titles [0].getText (),
                messages ? messages [0].getText () : "",
                icons [0].getText (),
                startTime,
                stopTime,
                parseInt (item, 10)));
          }
        }
      }
    }
  }

  this.setForCurrentLanguage ("isInitialized", function () {return true;});
 // this.map.showFeedInfo ();

  if ((undefined != this.onReloadFct) && (null != this.onReloadFct))
  {
    if ((undefined != this.onReloadObject) && (null != this.onReloadObject))
    {
      this.onReloadFct.call (this.onReloadObject);
    }
    else
    {
      this.onReloadFct ();
    }
  }
}

hbLayer.prototype.getInfo = function ()
{
  for (var i in this.infos)
  {
    this.infos [i] = 0.0;
  }

  for (var report = 0; report < this.reports.length; ++report)
  {
    var show = true;

    if (this.filter)
    {
      show = this.filter.filter (this.reports [report]);
    }

    if (show)
    {
      for (var i in this.infos)
      {
        this.infos [i] += parseFloat (this.reports [report].info [i]);
      }
    }
  }

  return this.infos;
}

hbLayer.prototype.show = function ()
{
  if ((false == this.synchronWithMap) || (false == this.visible) || (false == this.isInitialized ()))
  {
    this.visible = true;
    this.deferredShow ();
  }
}

hbLayer.prototype.hide = function ()
{
  if (true == this.visible)
  {
    this.visible = false;
    this.deferredHide ();
  }
}

hbLayer.prototype.deferredShow = function ()
{
  if (false == this.visible)
  {
    return;
  }

  if (false == this.isInitialized ())
  {
    if (null == this.reader)
    {
      this.setForCurrentLanguage ("isInitialized", function () {return true;});
    }
    else
    {
      this.reader.read ();
      var thisLayer = this;
      setTimeout (function () {thisLayer.deferredShow ()}, 1000);
      return;
    }
  }

  if (null != this.tile)
  {
    map.map.addOverlay (this.tile);
  }

  if (null != this.globalOverlay)
  {
    map.map.addOverlay (this.globalOverlay);
  }

  if (null != this.screenOverlay)
  {
    map.map.addOverlay (this.screenOverlay);
  }

  for (var report = 0; report < this.reports.length; ++report)
  {
    var show = true;

    if (this.filter)
    {
      show = this.filter.filter (this.reports [report]);
    }

    if (show)
    {
      this.reports [report].addMarkers (this.markerMgr);
      this.reports [report].addOverlays (this.overlayMgr);
    }
  }

  this.markerMgr.refresh ();
  this.overlayMgr.refresh ();

  if (null != this.tile)
  {
    this.tile.show ();
  }

//  this.map.showFeedInfo ();
  this.synchronWithMap = true;
}

hbLayer.prototype.deferredHide = function ()
{
  if (true == this.visible)
  {
    return;
  }

  if (false == this.isInitialized ())
  {
    var thisLayer = this;
    setTimeout (function () {thisLayer.deferredHide ()}, 1000);
    return;
  }

  if (null != this.tile)
  {
    this.tile.hide ();
    map.map.removeOverlay (this.tile);
  }

  if (null != this.globalOverlay)
  {
    map.map.removeOverlay (this.globalOverlay);
  }

  if (null != this.screenOverlay)
  {
    map.map.removeOverlay (this.screenOverlay);
  }

  this.markerMgr.clearMarkers ();
  this.overlayMgr.clearOverlays ();

  this.visible = false;
}

hbLayer.prototype.getReport = function (reportId)
{
  for (var r = 0; r < this.reports.length; ++r)
  {
    var hasReport = this.reports [r].hasId (reportId)

    if (true == hasReport)
    {
      return this.reports [r];
    }
  }

  return null;
}

hbLayer.prototype.isVisible = function ()
{
  return this.visible;
}

hbLayer.prototype.setFilter = function (filterObj)
{
  if (!filterObj.equals (this.filter))
  {
    this.filter = filterObj;
    this.hide ();

    if ((undefined != this.onReloadFct) && (null != this.onReloadFct))
    {
      if ((undefined != this.onReloadObject) && (null != this.onReloadObject))
      {
        this.onReloadFct.call (this.onReloadObject);
      }
      else
      {
        this.onReloadFct ();
      }
    }
  }
}

hbLayer.prototype.onReload = function (callback, callbackObject)
{
  this.onReloadFct = callback;
  this.onReloadObject = callbackObject;
}

hbLayer.prototype.keepLoaded = function (yesOrNo)
{
  this.instandReload = yesOrNo;
  
  if ((true == this.instandReload) && (false == this.isInitialized ()))
  {
    this.reload ();
  }
}

hbLayer.prototype.unfoldEnabled = function (yesorno, minZoom)
{
  this.isUnfoldEnabled = yesorno;
  this.unfoldMinZoom = minZoom;

  for (var r = 0; r < this.reports.length; ++r)
  {
    this.reports [r].unfoldEnabled (yesorno, minZoom, this.markerMgr);
  }

  this.markerMgr.refresh ();
}