  L.TileLayer.TileCache=L.TileLayer.extend({getTileUrl:function(a,b){function e(a,b){a=String(a);var c=[];for(var d=0;d<b;++d)c.push("0");return c.join("").substring(0,b-a.length)+a}var c=this.options.subdomains,d=(a.x+a.y)%c.length;s=this.options.subdomains[d];var f=this._getOffsetZoom(b);var g=e(parseInt(a.x/1e6),3)+"/"+e(parseInt(a.x/1e3)%1e3,3)+"/"+e(parseInt(a.x)%1e3,3);var h=Math.pow(2,f)-1-a.y;var i=e(parseInt(h/1e6),3)+"/"+e(parseInt(h/1e3)%1e3,3)+"/"+e(parseInt(h)%1e3,3);var j=L.Util.template(this._url,L.Util.extend({s:s,z:f,x:g,y:i},this.options));return j}});
  Groundspeak.Map.MapLayers.unshift(
  {tileUrl:"http://mt.google.com/vt?&x={x}&y={y}&z={z}",name:"googlemaps",alt:"Google maps",attribution:"Google maps",subdomains:"1234",tileSize:256,minZoom:0,maxZoom:22},
  {tileUrl:"http://mt.google.com/vt?lyrs=y&x={x}&y={y}&z={z}&scaleControl=true",name:"googlemapshyb",alt:"Google hybrid",attribution:"Google hybrid",subdomains:"1234",tileSize:256,minZoom:0,maxZoom:22},
  {tileUrl:"http://mt.google.com/vt?lyrs=s&x={x}&y={y}&z={z}&scaleControl=true",name:"googlemapssat",alt:"Google satelit",attribution:"Google satelit",subdomains:"1234",tileSize:256,minZoom:0,maxZoom:22},
  {tileUrl:"http://services.tmapserver.cz/ftiles/gm/shc/{z}/{x}/{y}.png",name:"shocart",alt:"Shocart turistická",attribution:"© SHOCart, spol. s r. o. a T-MAPY spol. s r.o.",tileSize:256,minZoom:9,maxZoom:15},
  {tileUrl:"http://mt.google.com/vt?lyrs=p&x={x}&y={y}&z={z}",name:"googlemapssat",alt:"Google terrain",attribution:"Google terrain",subdomains:"1234",tileSize:256,minZoom:0,maxZoom:22},
  {tileUrl:"http://b.freemap.sk/data/layers/presets/T/{z}/{x}/{y}.jpeg",name:"freemapsk",alt:"Freemap SK",attribution:"FreeMapSk",tileSize:256,minZoom:0,maxZoom:16},
  {tileUrl:"http://b.freemap.sk/data/layers/presets/C/{z}/{x}/{y}.jpeg",name:"freemapskc",alt:"Freemap Cyklo",attribution:"FreeMapSkc",tileSize:256,minZoom:0,maxZoom:16}
    
  );
  for (var a = {}, b = [], c = 0, d = Groundspeak.Map.MapLayers.length; c < d; c++)
  {
  var e = Groundspeak.Map.MapLayers[c];
    g = (e.layerType == "TileCache") ? new L.TileLayer.TileCache(e.tileUrl, e) : new L.TileLayer(e.tileUrl, e);
    b.push(g);
    a[e.alt] = g;
  }
  a = new L.Control.Layers(a);
  MapSettings.Map.removeLayer(MapSettings.Map._layers[15]);
  $("a[title=Layers]").parent().remove();
  MapSettings.Map.addControl(a);
  $(a._form.getElementsByTagName("input")[0]).click();
 