﻿      var gmarkers = [];
      var gicons = [];

      var myicon1 = new Image(26, 43);
      var myicon2 = new Image(26, 43);
	  var myicon3 = new Image(26, 43);
      var myicon4 = new Image(26, 43);
	  
	  if(location.hostname != 'iportal.cezdata.corp')  {
		myicon1 = '/edee/content/sysutf/reg/img/markers/projekt1.gif';
        myicon2 = '/edee/content/sysutf/reg/img/markers/projekt2.gif';
        myicon3 = '/edee/content/sysutf/reg/img/markers/projekt3.gif';
        myicon4 = '/edee/content/sysutf/reg/img/markers/projekt4.gif';
	  } else {
		myicon1 = '/edee/content/sysutf/reg/img/markers/projekt1.gif';
        myicon2 = '/edee/content/sysutf/reg/img/markers/projekt2.gif';
        myicon3 = '/edee/content/sysutf/reg/img/markers/projekt3.gif';
        myicon4 = '/edee/content/sysutf/reg/img/markers/projekt4.gif';
	  }

      gicons["hriste"] = new GIcon(G_DEFAULT_ICON,myicon3);
      gicons["energie"] = new GIcon(G_DEFAULT_ICON,myicon2);
      gicons["nemocnice"] = new GIcon(G_DEFAULT_ICON,myicon1);
      gicons["cyklostezka"] = new GIcon(G_DEFAULT_ICON,myicon4);

      // A function to create the marker and set up the event window
      function createMarker(point,name,html,category) {
        var marker = new GMarker(point,{icon: gicons[category], hide: true});

        marker.mycategory = category;
        marker.myname = name;


	GEvent.addListener(marker, 'click', function(){ 
		map.setCenter(point, 7);
		marker.openExtInfoWindow(map,
                                         "simple_example_window",
                                         html,
                                         {beakOffset: 3}
                                        );
          jQuery("div[id='simple_example_window_contents']").css("margin-left","160px");
          jQuery("div[id='simple_example_window_contents']").css("margin-top","56px");
	});

//        GEvent.addListener(marker, "click", function() {
//          marker.openInfoWindowHtml(html);
//        });
        gmarkers.push(marker);
        return marker;
      }

      // == shows all markers of a particular category, and ensures the checkbox is checked ==
      function show(category) {
//        alert(gmarkers.length);
        for (var i=0; i<gmarkers.length; i++) {
          if (gmarkers[i].mycategory == category) {
            gmarkers[i].show();
          }
        }
      }

      // == hides all markers of a particular category, and ensures the checkbox is cleared ==
      function hide(category) {

        for (var i=0; i<gmarkers.length; i++) {
          if (gmarkers[i].mycategory == category) {
            gmarkers[i].hide();
          }
        }
        map.closeInfoWindow();
      }     

      // == a checkbox has been clicked ==
      function boxclick(box,category) {
        if (box.checked) {
          show(category);
        } else {
          hide(category);
        }
      }

      function myclick(i) {
        GEvent.trigger(gmarkers[i],"click");
      }

      // create the map
      var map = new GMap2(document.getElementById("apimap"));
      map.addControl(new GLargeMapControl3D());
      map.addControl(new GMapTypeControl());
      map.enableScrollWheelZoom();
      map.enableContinuousZoom();
	    map.addControl(new GScaleControl());
      map.setCenter(new GLatLng(49.793785, 15.459565), 7);                // Parametry vycentrovani a prvotniho zazoomovani

      // Read the data
      // === Define the function thats going to process the JSON file ===
      process_it = function(doc) {
        // === Parse the JSON document === 
        var jsonData = eval('(' + doc + ')');

        // === Plot the markers ===
        for (var i=0; i<jsonData.markers.length; i++) {
          var point = new GLatLng(jsonData.markers[i].gpsx, jsonData.markers[i].gpsy);
          var address = jsonData.markers[i].address;
          var region = jsonData.markers[i].region;
          var name = jsonData.markers[i].name;
          var phone = jsonData.markers[i].phone;
          var detailurl = jsonData.markers[i].detailurl;
          var category = jsonData.markers[i].category;


              var html = "<div class='close'><a onclick='map.closeExtInfoWindow();' href='javascript:;'><span>X<\/span><\/a><\/div><div class='moreinfo'><h3>"+name+"<\/h3><span class='clear'><\/span><p>"+address+"<br /><strong><a style=\"padding-bottom: 10px;\" href="+detailurl+">V&iacute;ce informac&iacute;...<\/a><strong><\/p><\/div><div class='zoom'><a class='zoomIn' href='javascript:zoomIn();'>Přiblížit<\/a><span class='oddelovac'>|<\/span><a class='zoomOut' href='javascript:zoomOut();'>Oddálit<\/a><span class='oddelovac'>|<\/span><a class='center' href='javascript:map.setCenter(new GLatLng(49.793785, 15.459565), 7);javascript:map.closeExtInfoWindow();'>Původni<\/a><\/div>";

//          var html = "<div style=\"height:auto;width:200px;\"><h2>"+name+"</h2><p><strong>Adresa:</strong><br />"+address+"<br /><strong><a style=\"padding-bottom: 10px;\" href="+detailurl+">V&iacute;ce informac&iacute;...</a><strong></p></div>";

          var marker = createMarker(point, name, html, category );
          map.addOverlay(marker);
        }
        show("hriste");
      }        
	
	  if(location.hostname != 'iportal.cezdata.corp')  {
        GDownloadUrl("/edee/content/sysutf/nd2/js/projects-data.json", process_it);
	  } else {
        GDownloadUrl("/edee/content/sysutf/nd2/js/projects-data.json", process_it);
	  };

          // povoleni max/min zoomu
          G_PHYSICAL_MAP.getMinimumResolution = function () { return 7 };
          G_NORMAL_MAP.getMinimumResolution = function () { return 7 };
          G_SATELLITE_MAP.getMinimumResolution = function () { return 7 };
          G_HYBRID_MAP.getMinimumResolution = function () { return 7 };

          G_PHYSICAL_MAP.getMaximumResolution = function () { return 13 };
          G_NORMAL_MAP.getMaximumResolution = function () { return 13 };
          G_SATELLITE_MAP.getMaximumResolution = function () { return 13 };
          G_HYBRID_MAP.getMaximumResolution = function () { return 13 };  


/* *********** Fce z info okna *********** */
            
      function zoomIn() {	            /* funkce pro zoomovani a defaultni zobrazeni */
        map.setCenter();
        map.zoomIn();
          jQuery("div[id='simple_example_window_contents']").css("margin-top","36px");
      }
      function zoomOut() {
        map.setCenter();
        map.zoomOut();
          jQuery("div[id='simple_example_window_contents']").css("margin-top","36px");
      }
