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

      var myicon1 = new Image(26, 43);
      myicon1 = '/edee/content/sysutf/rg2/img/markers/projekt1.gif';
      
      var myicon2 = new Image(26, 43);
      myicon2 = '/edee/content/sysutf/rg2/img/markers/projekt2.gif';                  

      var myicon3 = new Image(26, 43);
      myicon3 = '/edee/content/sysutf/rg2/img/markers/projekt3.gif';
      
      var myicon4 = new Image(26, 43);
      myicon4 = '/edee/content/sysutf/rg2/img/markers/projekt4.gif';

      var myicon5 = new Image(26, 43);
      myicon5 = '/edee/content/sysutf/rg2/img/markers/projekt5.gif';

      var myicon6 = new Image(26, 43);
      myicon6 = '/edee/content/sysutf/rg2/img/markers/projekt6.gif';

      var myicon7 = new Image(26, 43);
      myicon7 = '/edee/content/sysutf/rg2/img/markers/projekt7.gif';

      var myicon8 = new Image(26, 43);
      myicon8 = '/edee/content/sysutf/rg2/img/markers/projekt8.gif';


// jQuery(document).ready( /* jQuery no conflict block */
//	function($) {

      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);
      gicons["kultura"] = new GIcon(G_DEFAULT_ICON,myicon5);
      gicons["vzdelani"] = new GIcon(G_DEFAULT_ICON,myicon6);
      gicons["pomoc"] = new GIcon(G_DEFAULT_ICON,myicon7);
      gicons["podpora"] = new GIcon(G_DEFAULT_ICON,myicon8);

      // 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() {
          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();
      }     

      jQuery(".nonclicked").click( function() {

        jQuery("#apimap").removeClass("nonclicked");
       loadingMap();  

        }
      );

function showCheckbox() {
     jQuery(".in").animate({"height": "toggle"}, { duration: 10 });
     jQuery(".clickMap").hide();
     jQuery('#apimap').removeAttr('onclick');
     jQuery("#kalendar-shp").css("margin-top","90px");
       loadingMap();  
}






      function loadingMap() { 
      // == 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.894634, 15.468750), 7);                // Parametry vycentrovani a prvotniho zazoomovani

      // Read the data
      // === Define the function thats going to process the JSON file ===
      function process_it(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 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);
        }

		var catParam = getParameter("cat");
		var categoryNames = ['hriste', 'nemocnice', 'kultura', 'pomoc', 'cyklostezka', 'energie', 'vzdelani', 'podpora'];
		if (typeof catParam == "undefined") {
       for (i=0;i<categoryNames.length; i++) {
 				 GOOGLEMAP_Controls.toggleCategory($("#GM"+categoryNames[i]));

	    jQuery(".oranzova-hriste").addClass("activated"); 
	    jQuery(".nemocnice").addClass("activated"); 
 	    jQuery(".kultura").addClass("activated"); 
	    jQuery(".zelena-energie").addClass("activated");
	    jQuery(".pomoc-potrebnym").addClass("activated"); 
	    jQuery(".cyklostezky").addClass("activated"); 
 	    jQuery(".vzdelani").addClass("activated"); 
	    jQuery(".podpora-regionum").addClass("activated"); 

 			 }

		} else {

        jQuery(".clickMap").hide();
        jQuery(".in").css("display","block");
        jQuery('#apimap').removeAttr('onclick');

 	    jQuery(".oranzova-hriste").removeClass("activated"); 
 	    jQuery(".nemocnice").removeClass("activated"); 
 	    jQuery(".kultura").removeClass("activated"); 
 	    jQuery(".zelena-energie").removeClass("activated");
	    jQuery(".pomoc-potrebnym").removeClass("activated"); 
	    jQuery(".cyklostezky").removeClass("activated"); 
	    jQuery(".vzdelani").removeClass("activated"); 
	    jQuery(".podpora-regionum").removeClass("activated"); 

		   for (i=0;i<categoryNames.length; i++) {
		       var category = categoryNames[i];
		       if (catParam == category) {
 		          GOOGLEMAP_Controls.toggleCategory($("#GM"+category));
           }
       }
    }

      }        

      GDownloadUrl("/edee/content/pubutf/rg2/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 };

 jQuery('#apimap').unbind('click');
}
