function updateScale(evt) {
  /* 
  var scale = this.getScale();
  var size = this.getSize();
  var factor = 25.4/72.0*1e-6*scale;
  var xkm = (size.w*factor).toFixed(3)
  var ykm = (size.h*factor).toFixed(3)
  var e = document.getElementById('currentscale');
  e.innerHTML = scale.toFixed(0) + ", "+xkm+"&times;"+ykm+" km<sup style='font-size:smaller'>2</sup>";
  UpdateLocation.call(this, evt);
  */
}
function updateLocation(evt) {
  var lonlat = map.getCenter();
  var langindex;
  if (cmaplang == "svk") langindex="index_svk.html";
  if (cmaplang == "eng") langindex="index.html";
  lonlat.transform(map.baseLayer.projection,p4326);
  /*
    var href = ""+location.protocol+"//"
    + location.hostname
    + (location.port ? ":"+location.port : "") 
    + "/" //+ location.pathname
  */    

  var href = URLpath + langindex + "?lon="+lonlat.lon.toFixed(5)
    + "&lat="+lonlat.lat.toFixed(5)
    + "&zoom="+map.getZoom()
    + "&layer="+map.baseLayer.name
    ;
  document.getElementById('linktext').innerHTML='<a href="'+ href + '" target="_blank">' + href +'</a>';
  
}
   
Proj4js.defs["EPSG:102067"]="+title=JTSK (Timar LCC approx.) +proj=lcc +lat_1=47.605 +lat_2=49.225 +lat_0=59.83349 +lon_0=24.83333  +x_0=4.7 +y_0=0 +ellps=bessel +towgs84=589,76,480";
var p4326 = new OpenLayers.Projection("EPSG:4326");
var p900913 = new OpenLayers.Projection("EPSG:900913");
var p102067 = new OpenLayers.Projection("EPSG:102067");
var roundrobin=-1;    //server load balancing - predefined layers
var roundrobin2=-1;   //server load balancing - custom layers

var sizeiconOL = new OpenLayers.Size(12,20);
var offseticonOL = new OpenLayers.Pixel(-(sizeiconOL.w/2), -sizeiconOL.h);
var yellowiconOL = new OpenLayers.Icon('http://cmaps.gpsteam.eu/pic/yellow.png',sizeiconOL,offseticonOL);
var blueiconOL = new OpenLayers.Icon('http://cmaps.gpsteam.eu/pic/blue.png',sizeiconOL,offseticonOL);
var rediconOL = new OpenLayers.Icon('http://cmaps.gpsteam.eu/pic/red.png',sizeiconOL,offseticonOL);
var greeniconOL = new OpenLayers.Icon('http://cmaps.gpsteam.eu/pic/green.png',sizeiconOL,offseticonOL);
var popupOL;

//var mouseposElem = {element: document.getElementById('mousepos')};
var options = {
   controls: [new OpenLayers.Control.Navigation(),
	     new OpenLayers.Control.LayerSwitcher(),
 	     new OpenLayers.Control.PanZoomBar()]
		};

//new OpenLayers.Control.MousePosition(mouseposElem)
//,new OpenLayers.Control.MouseDefaults()



var mcontrol = new OpenLayers.Control();
OpenLayers.Util.extend(mcontrol, {
                    draw: function () {
                        // this Handler.Box will intercept the shift-mousedown
                        // before Control.MouseDefault gets to see it
                        this.box = new OpenLayers.Handler.Box(mcontrol,
                            {"done": this.notice},
                            {keyMask: OpenLayers.Handler.MOD_SHIFT});
                        this.box.activate();
                    },

                    notice: function (bounds) {
                      
                      var ll = map.getLonLatFromPixel(new OpenLayers.Pixel(bounds.left, bounds.bottom)); 
                      var ur = map.getLonLatFromPixel(new OpenLayers.Pixel(bounds.right, bounds.top)); 
                      var mbounds = new OpenLayers.Bounds();
                      mbounds.extend(ll);
		      mbounds.extend(ur);


                      if (document.form2.showedited.checked) gpxTrack.selectPoints(mbounds);
                       else map.zoomToExtent(mbounds);

                    }
                });




function getNLCmercator (bounds) {
    var res = this.map.getResolution();
    var x = Math.round ((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
    var y = Math.round ((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
    var z = this.map.getZoom();
   
    
   


    if ((z<14)||(z>15)) 
     {
     return getDefaultBaseLayer(z,x,y);
     }
    else
    return "http://gpsteam.eu/cache/nlcmm/"+z+"/"+y+"/"+x+".png";
}


function getNLCmercatorTR (bounds) {
    var res = this.map.getResolution();
    var x = Math.round ((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
    var y = Math.round ((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
    var z = this.map.getZoom();
   
    if ((z<14)||(z>16)) return "http://cmaps.gpsteam.eu/pic/transparent256.png";
    return "http://gpsteam.eu/cache/nlcml/"+z+"/"+x+"/"+y+".png";
}


function getTZTgpsforum (bounds) {
    var res = this.map.getResolution();
    var x = Math.round ((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
    var y = Math.round ((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
    var z = this.map.getZoom();
   
    if ((z<13)||(z>16)) return "http://cmaps.gpsteam.eu/pic/transparent256.png";
    return "http://gpsteam.eu/cache/tzt/"+z+"/"+x+"/"+y+".png";
}


function getcontoursSK (bounds) {
    var res = this.map.getResolution();
    var x = Math.round ((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
    var y = Math.round ((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
    var z = this.map.getZoom();

    var curProj= map.baseLayer.projection;
    if ((z<13)||(z>15)||(curProj.equals(p102067)))  return "http://cmaps.gpsteam.eu/pic/transparent256.png";
    return "http://gpsteam.eu/cache/vrst/"+z+"/"+y+"/"+x+".png";
}


function getFMcontoursSK (bounds) {
    var res = this.map.getResolution();
    var x = Math.round ((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
    var y = Math.round ((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
    var z = this.map.getZoom();

    var curProj= map.baseLayer.projection;
    if ((z<12)||(z>16)||(curProj.equals(p102067)))  return "http://cmaps.gpsteam.eu/pic/transparent256.png";
    return "http://www.freemap.sk/layers/contours/?/"+z+"/"+x+"/"+y;
}


function getFMtrailsSK (bounds) {
    var res = this.map.getResolution();
    var x = Math.round ((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
    var y = Math.round ((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
    var z = this.map.getZoom();

    var curProj= map.baseLayer.projection;
    if ((z<8)||(z>16)||(curProj.equals(p102067)))  return "http://cmaps.gpsteam.eu/pic/transparent256.png";
    return "http://www.freemap.sk/layers/trails/?/"+z+"/"+x+"/"+y;
}




function getcontoursDEAT (bounds) {
    var res = this.map.getResolution();
    var x = Math.round ((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
    var y = Math.round ((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
    var z = this.map.getZoom();

    var curProj= map.baseLayer.projection;
    if ((z<8)||(z>15)||(curProj.equals(p102067)))  return "http://cmaps.gpsteam.eu/pic/transparent256.png";
    //http://www.wanderreitkarte.de/hills/15/17493/11639.png
    //other source  http://topo.gvf.ve.it/cont/12/2216/1377.png    zoom 1-19
    return "http://www.wanderreitkarte.de/hills/"+z+"/"+x+"/"+y+".png";
}


function getreitwander (bounds) {
    var res = this.map.getResolution();
    var x = Math.round ((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
    var y = Math.round ((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
    var z = this.map.getZoom();

    var curProj= map.baseLayer.projection;
    if ((z<7)||(z>18)||(curProj.equals(p102067)))  return "http://cmaps.gpsteam.eu/pic/transparent256.png";
    //http://www.wanderreitkarte.de/topo/14/8752/5818.png
    return "http://www.wanderreitkarte.de/topo/"+z+"/"+x+"/"+y+".png";
}



function getHillshading (bounds) {
    var res = this.map.getResolution();
    var x = Math.round ((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
    var y = Math.round ((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
    var z = this.map.getZoom();

    var curProj= map.baseLayer.projection;
    if ((z<0)||(z>15)||(curProj.equals(p102067)))  return "http://cmaps.gpsteam.eu/pic/transparent256.png";
    //http://toolserver.org/~cmarqu/hill/15/17684/10977.png
    return "http://toolserver.org/~cmarqu/hill/"+z+"/"+x+"/"+y+".png";
}


function getopenpiste (bounds) {
    var res = this.map.getResolution();
    var x = Math.round((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
    var y = Math.round((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
    var z = this.map.getZoom();

    var curProj= map.baseLayer.projection;
    if ((z<-1)||(z>19)||(curProj.equals(p102067)))  return "http://cmaps.gpsteam.eu/pic/transparent256.png";
    //http://openpistemap.org/tiles/contours/12/2126/1456.png
    //http://openpistemap.org/tiles/nocontours/12/2126/1457.png
    return "http://tiles.openpistemap.org/contours/"+z+"/"+x+"/"+y+".png";
}


function getURLtemplate (bounds) {
        var res = this.map.getResolution();
        var x = Math.round((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
        var y = Math.round((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
        var z = this.map.getZoom();

       //URL examples:      
       //"http://www.jedna.sk/maps(X)/(Y)/(Z).jpg";
       //"http://(A|B|C|D).www.jedna.sk/maps(X)/(Y)/(Z).jpg";               link with server load balancing

       var extlink = this.url;  //zlozeny url string z parametru definicie vrstvy
       var linkarr=extlink.split("@");
       var link = linkarr[2];
       var layertype=linkarr[3];
       var minzoomlevel=parseInt(linkarr[0]);
       var maxzoomlevel=parseInt(linkarr[1]);
       

     
       link=link.replace("(X)",x);
       link=link.replace("(Y)",y);
       link=link.replace("(Z)",z);
       myregexp = new RegExp('\\((.)*(\\|)*(.)*\\)');
       sarr=link.match(myregexp);
    

      if (sarr != null) 
       {
       sstr=sarr[0];
       sstrv=sstr.replace("(","");
       sstrv=sstrv.replace(")","");
      
     
       var sarr2=sstrv.split("|");
       sarr2len=sarr2.length-1; 

       if (roundrobin2>=sarr2len) roundrobin2=-1;
       roundrobin2++;
     
       outelement=sarr2[roundrobin2];
       link=link.replace(sstr,outelement);
       }


      if ( ((z<minzoomlevel)||(z>maxzoomlevel)) && (layertype=='over') ) link = "http://cmaps.gpsteam.eu/pic/transparent256.png";
      if ( ((z<minzoomlevel)||(z>maxzoomlevel)) && (layertype=='base') ) link =  getDefaultBaseLayer(z,x,y);
      
      return link;
    
    }


function getDefaultBaseLayer(cz,cx,cy)
    {
     //default base layer: OSM cycle map
        var link; 
        var schar="a";
        if (roundrobin>=2) roundrobin=-1;
        roundrobin++;

 
        switch (roundrobin)
  	 {
         case 0:
          schar="a";
	  break;
	 case 1:
          schar="b";
	  break;
	 case 2:
          schar="c";
	  break;
          }
        link =  "http://" + schar +".andy.sandbox.cloudmade.com/tiles/cycle/"+cz+"/"+cx+"/"+cy+".png";
        return link;
    }



function AddCustomLayer(newlayername,newlayerurl,newlayertype,newlayermaxzoom,newlayerminzoom) {




    if (newlayername.lastIndexOf(" ")!=-1)
      {
      if (cmaplang == "svk") msgshow("V mene vrstvy sa nesmú vyskytovať medzery.");
      if (cmaplang == "eng") msgshow("Blank spaces are not allowed in Layer name.");
      fsub=false;   
      return;
      }





//http://tiles.openpistemap.org/contours/(Z)/(X)/(Y).png
//OSM mapnik: http://(a|b|c).tile.openstreetmap.org/(Z)/(X)/(Y).png

if (newlayertype=='base') 
 {
 var newlayer = new OpenLayers.Layer.XYZ(
                newlayername,newlayerminzoom + "@" + newlayermaxzoom + "@" + newlayerurl + "@" + newlayertype,
                {
                 projection: p900913, 
                'sphericalMercator': true,
                'getURL':getURLtemplate,
                numZoomLevels: parseInt(newlayermaxzoom)+1,
                 visibility: false,
	        'isBaseLayer': true
                });   
 }
else
 {
 var newlayer = new OpenLayers.Layer.XYZ(
                newlayername,newlayerminzoom + "@" + newlayermaxzoom + "@" + newlayerurl + "@" + newlayertype,
                {
                 projection: p900913, 
                'sphericalMercator': true,
                'getURL':getURLtemplate,
                 visibility: true,
	        'isBaseLayer': false
                });   
 } 

map.addLayers([newlayer]);
}






OpenLayers.Util.onImageLoadErrorColor = "transparent";




          var map = new OpenLayers.Map('map', options);

          var lc =  new OpenLayers.Layer.NLCSK("NLC_SK_jtsk",
                       "",
                       { projection: p102067,
                         units: 'm',
                         resolutions: [529.16796875,6.6147182,2.6458082],
			 maxExtent: new OpenLayers.Bounds(-646043,-1521447,-104175,-979579),
                         restrictedExtent: new OpenLayers.Bounds(-592546,-1336183,-164086,-1131751),
                         maxResolution: 529.16796875,
                         numZoomLevels: 3,
                         attribution: "Map &copy; <a href='http://www.nlcsk.org/' target='_blank'>NLC Zvolen</a>"
                          });
     
        //create Google Mercator layers
            var gmap = new OpenLayers.Layer.Google(
                "Google_Streets",
                {'sphericalMercator': true,
                 projection: p900913,
                 units: "m",
                 numZoomLevels: 20,
                 maxResolution: 156543.0339,
                 maxExtent: new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508.34)
                                            });
             
           var gsat = new OpenLayers.Layer.Google(
                "Google_Satelite",
                {'sphericalMercator': true,
                 type: G_SATELLITE_MAP,
                 projection: p900913,
                 units: "m",
                 numZoomLevels: 19,
                 maxResolution: 156543.0339,
                 maxExtent: new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508.34)
                                            });


	   
           var ghyb = new OpenLayers.Layer.Google(
                "Google_Hybrid",
                {'sphericalMercator': true,
                 type: G_HYBRID_MAP,
                 projection: p900913,
                 units: "m",
                 numZoomLevels: 18,
                 maxResolution: 156543.0339,
                 maxExtent: new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508.34)
                                            });


               
           var gter = new OpenLayers.Layer.Google(
                "Google_Terrain",
                {'sphericalMercator': true,
                 type: G_PHYSICAL_MAP,
                 projection: p900913,
                 units: "m",
                 numZoomLevels: 16,
                 maxResolution: 156543.0339,
                 maxExtent: new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508.34)
                                            });
          
           var layerCycle = new OpenLayers.Layer.OSM.CycleMap(
                "OSM_CycleMap",
                {projection: p900913,
                 units: "m"
					    });



            var relcontDEAT = new OpenLayers.Layer.XYZ(
               "ReliefContours_DE_AT_CH_IT","",
                {
                numZoomLevels: 16,
                maxResolution: 156543.0339,
                projection: p900913, 
                attribution: "Contours and relief data <a href='http://srtm.csi.cgiar.org/' target='_blank'>CIAT</a>",
                'sphericalMercator': true,
                'getURL':getcontoursDEAT
                });

            
            var opiste = new OpenLayers.Layer.XYZ(
                "OpenPisteMap","",
                {
                 numZoomLevels: 16,
                 maxResolution: 156543.0339,
                 projection: p900913, 
                'sphericalMercator': true,
                'getURL':getopenpiste,
                 attribution: "Data CC-By-SA by <a href='http://openstreetmap.org/' target='_blank'>OpenStreetMap</a>"
                });
          

            var NLCmercator = new OpenLayers.Layer.XYZ(
                "NLC_SK","",
                {
                 numZoomLevels: 16,
                 maxResolution: 156543.0339,
                 projection: p900913, 
                'sphericalMercator': true,
                'getURL':getNLCmercator,
                attribution: "Zoom 0-13 Data CC-By-SA by <a href='http://openstreetmap.org/' target='_blank'>OpenStreetMap</a> <br> Zoom 14-15 Map &copy; <a href='http://www.nlcsk.org/' target='_blank'>NLC Zvolen</a>"
                });
          
           
            var TZTgpsforum = new OpenLayers.Layer.XYZ(
                "GPSforum_HikingPaths_SK","",
                {
                 projection: p900913, 
                'sphericalMercator': true,
                'getURL':getTZTgpsforum ,
                 visibility: false,
	        'isBaseLayer': false,
                attribution: "HikingPaths: <a href='http://www.gpsforum.sk' target='_blank'>GPSforum</a>"
                });            
 


            var NLCmercatorTR = new OpenLayers.Layer.XYZ(
                "NLC_SK","",
                {
                 projection: p900913, 
                'sphericalMercator': true,
                'getURL':getNLCmercatorTR,
                 visibility: false,
	        'isBaseLayer': false,
                attribution: "Lesne cesty &copy; <a href='http://www.nlcsk.org/' target='_blank'>NLC Zvolen</a>"
                });            
 
  
             var contSK = new OpenLayers.Layer.XYZ(
               "GPSteam_Contours_SK","",
                {
               projection: p900913, 
               'sphericalMercator': true,
               visibility: false,
	       'isBaseLayer': false,
               'getURL':getcontoursSK,
               'attribution': "Contours: based on SRTM3 data"
                });


        
             var FMcontSK = new OpenLayers.Layer.XYZ(
               "FREEMAP_Contours_SK","",
                {
               projection: p900913, 
               'sphericalMercator': true,
               visibility: false,
	       'isBaseLayer': false,
               'getURL':getFMcontoursSK,
               'attribution': "Contours: <a href='http://www.freemap.sk' target='_blank'>Freemap Slovakia</a>"
                });


             var FMtrailsSK = new OpenLayers.Layer.XYZ(
               "FREEMAP_HikingPaths_SK","",
                {
               projection: p900913, 
               'sphericalMercator': true,
               visibility: false,
	       'isBaseLayer': false,
               'getURL':getFMtrailsSK,
               'attribution': "HikingPaths: <a href='http://www.freemap.sk' target='_blank'>Freemap Slovakia</a>"
                });


             
	     var RWkarte = new OpenLayers.Layer.XYZ(
               "ReitWanderKarte_DE_AT_CH_IT","",
                {
               projection: p900913, 
               'sphericalMercator': true,
               visibility: false,
	       'isBaseLayer': false,
               'getURL':getreitwander,
               attribution: "Data CC-By-SA by <a href='http://openstreetmap.org/' target='_blank'>OpenStreetMap</a>"
                });


	     var Hillshading = new OpenLayers.Layer.XYZ(
               "Hillshading","",
                {
               projection: p900913, 
               'sphericalMercator': true,
               visibility: false,
	       'isBaseLayer': false,
               'getURL':getHillshading,
               attribution: "Hillshading by <a href='http://hikebikemap.de'>Hike & Bike Map</a>"
                });

            
           map.addControl(mcontrol);
           map.addControl(new OpenLayers.Control.Attribution({separator:"<br>"}));

           map.addLayers([gter,gmap,gsat,ghyb,layerCycle,relcontDEAT,opiste,NLCmercator,lc,NLCmercatorTR,TZTgpsforum,FMtrailsSK,contSK,FMcontSK,Hillshading,RWkarte]);
      

           map.events.register("moveend", map, function() {
              if (document.form8.showAWS.checked) getAWSdata();
            });
           

           /* rightclick,leftclick - nefunkcne v IE8
             map.div.oncontextmenu = function noContextMenu(e) {
             if (OpenLayers.Event.isRightClick(e)){
                 //alert("Right button click"); // Add the right click menu here
              }
             return false; //cancel the right click of brower
            }; 
            */


//-----------------------------------------------------------------------------
        //vektorove vrstvy

             

        //layer 4 profile - moving marker
        var vectorLayerP = new OpenLayers.Layer.Vector("ProfilBod",{
				 displayInLayerSwitcher: false
        	                 });
     
         map.addLayer(vectorLayerP);     
        



       //track data: vectorLayer - spherical mercator ,  vectorLayer2 - JTSK

        var vectorLayer = new OpenLayers.Layer.Vector("Vector Spheme",{ 
				 displayInLayerSwitcher: false,
        	                 projection: p900913
                    		      });
                         
	map.addLayer(vectorLayer); 

	var vectorLayer2 = new OpenLayers.Layer.Vector("Vector JTSK",{
				 displayInLayerSwitcher: false,
        	                 projection: p102067,
				 visibility: false
	                         });
	map.addLayer(vectorLayer2); 

         
       
    

        var options = {
	  minResolution: 0.4,
	  maxResolution: 150000,
          displayInLayerSwitcher: false
	};



	var markers = new OpenLayers.Layer.Markers("GPX points",options);
	var vectors = new OpenLayers.Layer.Vector("Lines", options);
	
	map.addLayer(vectors);
	map.addLayer(markers);
	gpxTrack = new GpxTrack(map, {"markers":markers, "vectors": vectors});

	gpxTrack.setVisibility(false);
 


        //layer 4 data from integrated external sources (trasy.gpsteam.eu)
        var MarkersLayerEXT = new OpenLayers.Layer.Markers("ExternalMarkers",{
				 displayInLayerSwitcher: false
        	                 });

        map.addLayer(MarkersLayerEXT); 
//-----------------------------------------------------------------------------
  


function sizeMap(deltaPx) { 
  var e = document.getElementById('map');
  var h = e.style.height;
  if( h=='' ) h = window.getComputedStyle(e, null).height;
  var height = parseInt(h)+deltaPx;
  if( height<100 ) return;
  e.style.height = ""+ height + 'px';
  map.updateSize();
};


function windowsize()
{
var frameWidth;
var frameHeight;
if (self.innerWidth) {
      frameWidth = self.innerWidth;
      frameHeight = self.innerHeight;
     }
     else if (document.documentElement && document.documentElement.clientWidth) {
       frameWidth = document.documentElement.clientWidth;
       frameHeight = document.documentElement.clientHeight;
       }
       else if (document.body) {
        frameWidth = document.body.clientWidth;
        frameHeight = document.body.clientHeight;
        }

var TArray2= new Array();
TArray2[0] = frameWidth;
TArray2[1] = frameHeight;
return TArray2;

}


function mapFullsize() {
  

  var WS = windowsize();
  var maph = WS[1]-2;
  document.getElementById('map').style.height = ""+maph+"px";
  //document.getElementById('map').style.height = "400px";
}
// parse URL parameters for lat, lon and zoom
var floatreString = "([-]?[0-9]+([.][0-9]+)?)($|&)";
var paramDef = {
  lat : [new RegExp("[?&]lat="+floatreString), null],
  lon : [new RegExp("[?&]lon="+floatreString),  null],
  zoom : [new RegExp("[?&]zoom=([0-9]|1[0-9])($|&)"), null],
  maph : [new RegExp("[?&]maph=([0-9][0-9][0-9][0-9]?)($|&)"), null],
  layer : [new RegExp("[?&]layer=([-_a-zA-Z0-9]+)($|&)"), "null"],
  urlgpx : [new RegExp("[?&]gpx=(.+)($|&)"), null],
  urlplt : [new RegExp("[?&]plt=(.+)($|&)"), null],
  urlbikely : [new RegExp("[?&]bikely=(.+)($|&)"), null],
  urlbikemap : [new RegExp("[?&]bikemap=([0-9]+)($|&)"), null],
  urlgpstour : [new RegExp("[?&]gpstour=([0-9]+)($|&)"), null],
  urlgpsaw : [new RegExp("[?&]gpsaw=(.+)($|&)"), null]
};
var params = {};
for(key in paramDef) {
  var m = location.search.match(paramDef[key][0]);
  eval("var "+key+" = (m==null) ? paramDef[key][1] : m[1]");
 };


// initialize the map coordinates, zoom, size and layer from the URL
// parameters or from defaults. For the coordinates we remember
// whether we used the default. If yes, a track just loaded is allowed
// to override the settings to zoom to its extend.
if( lat && lon ) {
  lonlatIsDefault = false;
  var lonlat = new OpenLayers.LonLat(lon, lat);
} else {
  lonlatIsDefault = true;
  var lonlat = new OpenLayers.LonLat(19.145297,48.735365);
}


if( zoom ) {
  zoomIsDefault = false;
  zoom = parseInt(zoom);
} else {
  zoomIsDefault = true;
  zoom = 5;
  if (cmaplang == "svk") zoom = 14;
}


mapFullsize();

//map.events.register("zoomend", map, updateScale);
map.events.register("moveend", map, updateLocation);




// TODO: Arrrgh, need to call map-center anyway so that GpxTrack, when
// initialized, can immediately register the popup with the map. Need
// to change this to lazy popup-initialization, but since Javascript
// does not have private members and compilation, this can become
// tedious.
lonlat.transform(p4326,map.baseLayer.projection);
map.setCenter(lonlat, zoom, false, false);

if (cmaplang == "svk")
 {
 var l = map.getLayersByName("NLC_SK");
 if( l && l.length>0 ) map.setBaseLayer(l[0]);
 map.zoomTo(zoom);
 }

if (layer) 
 {
 var l = map.getLayersByName(layer);
 if( l && l.length>0 ) map.setBaseLayer(l[0]);
 map.zoomTo(zoom);
 }



//load GPS data from URL link
if (!(urlplt==null)) {urlwebloaddata("plt","http://" + urlplt);map.zoomTo(11);}
if (!(urlgpx==null)) {urlwebloaddata("gpx","http://" + urlgpx);map.zoomTo(11);}
if (!(urlbikely==null)) {urlwebloaddata("bikely",urlbikely);map.zoomTo(11);}
if (!(urlbikemap==null)) {urlwebloaddata("bikemap",urlbikemap);map.zoomTo(11);}
if (!(urlgpstour==null)) {urlwebloaddata("gpstour",urlgpstour);map.zoomTo(11);}
if (!(urlgpsaw==null)) {urlwebloaddata("gpsaw",urlgpsaw);map.zoomTo(11);}


if (!(zoomIsDefault)) map.zoomTo(zoom);
