/** 
 * cSimpleMap - Versimpelde Google Maps
 *
 * @author Jeroen van der Geer jeroen@swis.nl
 * @version 0.001b ;-)
 * 
**/

function cSimpleMap(oMap){

    /**
    *   @desc Initialisatie van de class.
    *   @param oMap Id van de map div
    **/
    this.initialize = function(oMap){    
        this.map = new GMap2(document.getElementById(oMap));        
        this.geocoder = new GClientGeocoder();
        this._powered_by_geostart = function(oMap){ this.oMap = oMap; };
        this._infoWindowWidth = 0;

    }
    
    /**
    *   @desc Zet het map type. 
    *   @param oMapType (G_NORMAL_MAP, G_NORMAL_MAP, G_HYBRID_MAP)
    **/
    this.setMapType = function(oMapType){       
        this.map.setMapType(oMapType);
    }
    
    /**
    *   @desc de 'private' function die daadwerkelijk de kaart centreerd op basis van een GLatLng.
    *   @param point GLatLng van de locatie
    *   @param iZoom Zoomniveau
    **/
    this._setCenterMap = function(point, iZoom){
        this.map.setCenter(point, iZoom);
    };
    
    /**
    *   @desc de 'public' function die lat + long omzet in een GLatLng en daarna de map hier op laat centreren.
    *   @param aLatLng Array met Lat en Long
    *   @param iZoom Zoomniveau
    **/
    this.setCenter = function(aLatLng, iZoom){
        var point = new GLatLng(aLatLng[0],aLatLng[1]);
        this._setCenterMap(point, iZoom);
    };    

    
    /**
    *   @desc de 'public' function die een adres omzet in een GLatLng en daarna de map hier op laat centreren.
    *   @param sAddress string met adres
    *   @param iZoom Zoomniveau
    **/
    this.setCenterByAddress = function(sAddress, iZoom){
        var self = this;
            this.geocoder.getLatLng(
                sAddress,
                function(point) {
                  if (!point) {
                    alert(sAddress + " kon niet worden gevonden");
                  } else {
                        self._setCenterMap(point, iZoom);
                  }
                }
              );
      }; 
   
    /**
    *   @desc voeg een control toe aan de kaart
    *   @param oControl het control wat toegevoegd moet worden aan de kaart. (Bijv. GSmallMapControl)
    **/
    this.addControl = function(oControl){
        this.map.addControl(new oControl());
    };
    
    /**
    *   @desc voeg het PoweredByGeostart logo toe aan de kaart
    **/
    this.addPoweredByGeostart = function(){
    
/*        this._powered_by_geostart.prototype = new GControl(true, false);
        this._powered_by_geostart.prototype.initialize = function () {
            var oContainer = document.createElement("div");
            oContainer.innerHTML    = "<a target='_blank' href='http://www.geostart.nl' style='display:block;height:29px;width:90px;'>TEST<img class='png' style='border:0;' src='"+sBaseUrl+"GeoStart/images/geostart_logo.png'></a>";
                    
            oContainer.id           = "powered_by_geostart";
            oContainer.style.cssText= "width:89px;text-decoration:none;border:none;height:29px;cursor:pointer;padding-bottom:2px;_padding-bottom:0px;";

            this.oMap.getContainer().appendChild(oContainer);
                    
            return oContainer;
        }

        this._powered_by_geostart.prototype.getDefaultPosition = function () {
                return new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(67,3));
        };
        
        this.map.addControl(new this._powered_by_geostart(this.map));          */
        
        this._MyPane = function() {}
        MyPane.prototype = new GControl;
        MyPane.prototype.initialize = function(map) {
          var me = this;
          me.panel = document.createElement("div");
          me.panel.style.width = "150px";
          me.panel.style.height = "100px";
          me.panel.style.border = "1px solid gray";
          me.panel.style.background = "white";
          me.panel.innerHTML = "Hello World!";
          map.getContainer().appendChild(me.panel);
          return me.panel;
        };

        MyPane.prototype.getDefaultPosition = function() {
          return new GControlPosition(
              G_ANCHOR_TOP_RIGHT, new GSize(10, 50));
              //Should be _ and not &#95;
        };

        MyPane.prototype.getPanel = function() {
          return me.panel;
        }
        this.map.addControl(new this._MyPane());

        
        
    };
    
   
   /**
    *   @desc Bepaal de breedte van het infowindowtje
    *   @param iWidth De breedte van de infowindow in pixels
    **/ 
   this.setInfoWindowWidth = function(iWidth){
        this._infoWindowWidth = iWidth;
   }
   
   /**
    *   @desc Start de initialisatie
    **/ 
   this.initialize(oMap);

}    


/** 
 * cSimpleMarker - Extensie op cSimpleMap
 *
 * @author Jeroen van der Geer jeroen@swis.nl
 * @version 0.001b ;-)
 * 
**/
function cSimpleMarker(oMap){

        /**
        *   @desc Initialisatie van de class.
        *   @param oMap map object waarop het extend
        **/
        this.initialize = function(oMap){        
            this.geocoder = new GClientGeocoder();             
            this._markerContainer = new Array; 

            this.marker = new Object;
            this._markerSize = new GSize(14, 14);
            this._markerShadowSize = new GSize(0,0);
            this._markerAnchor = new GPoint(7, 7);
            this._markerImage = "/images/marker.png";
            this._markerShadowImage = "";      
        }
        
        /**
        *   @desc Zet de grootte van de marker
        *   @param iWidth breedte in pixels
        *   @param iHeight hoogte in pixels
        **/
        this.setMarkerSize = function(iWidth, iHeight){
            this._markerSize = new GSize(iWidth, iHeight);
            this._iconAnchor = new GPoint(iWidth/2, iHeight/2);
        };        
        
        
        /**
        *   @desc Zet de grootte van de marker schaduw
        *   @param iWidth breedte in pixels
        *   @param iHeight hoogte in pixels
        **/
        this.setMarkerShadowSize = function(iWidth, iHeight){
            this._markerShadowSize = new GSize(iWidth, iHeight);
        };
        
        /**
        *   @desc Zet het plaatje voor de marker
        *   @param sImage URL van het plaatje (mag relatief)
        **/
        this.setMarkerImage = function(sImage){
            this._markerImage = sImage;
        };

        /**
        *   @desc Zet de schaduw voor de marker
        *   @param iWidth breedte in pixels
        *   @param iHeight hoogte in pixels
        **/
        this.setMarkerShadowImage = function(sImage){
            this._markerShadowImage = sImage;
        };
       
       /**
        *   @desc Marker op de kaart zetten op basis van Lat Long
        *   @param sLat Latitude voor de marker
        *   @param sLong Longitude voor de marker
        *   @param sInfoWindow De tekst voor de InfoWindow (HTML mag!)
        *   @param bOpenOnLoad Of de InfoWindow onload geopent moet worden (true / false). Standaard false.
        **/ 
        this.addMarker = function(sLat, sLong, sInfoWindow, bOpenOnLoad){
            var point = new GLatLng(sLat,sLong);
            var oMarker = this._addMarkerToMap(point);

            if(typeof(sInfoWindow) != "undefined"){
                oMarker.html = sInfoWindow;      
                this._addInfoWindowToMarker(oMarker, bOpenOnLoad);
            }
        };
        

        /**
        *   @desc Marker op de kaart zetten op basis van een adres
        *   @param oMap map object waarop het extend
        **/
        this.addMarkerByAddress = function(sAddress, sInfoWindow, bOpenOnLoad){
            var self = this;
            this.geocoder.getLatLng(
                    sAddress,
                    function(point) {
                      if (!point) {
                        alert(sAddress + " kon niet worden gevonden");
                      } else {
                            var oMarker = self._addMarkerToMap(point);
                            if(sInfoWindow != ""){
                                oMarker.html = sInfoWindow;
                                this._addInfoWindowToMarker(oMarker, bOpenOnLoad);
                            }
                      }
                    }
                  );
        };
        
        /**
        *   @desc 'Private' function die de infowindow aan de marker toevoegd
        *   @param oMarker marker object waar de infowindow aan toegevoegd moet worden
        *   @param bOpenOnload Of de infowindow onload geopent moet worden
        **/
        this._addInfoWindowToMarker = function(oMarker, bOpenOnLoad){
                GEvent.addListener(oMarker, "click", function(){
                    oMarker.openInfoWindowHtml(oMarker.html);
                });
                
                if(bOpenOnLoad === true){
                    oMarker.openInfoWindowHtml(oMarker.html);
                }
        };
        
        /**
        *   @desc 'Private' function die daadwerkelijk de marker op de kaart zet 
        *   @param point de GLatLng waar de marker moet worden geplaatst.
        **/    
        this._addMarkerToMap = function(point){
            var icon = G_DEFAULT_ICON;
            icon.image = this._markerImage;
            icon.shadow = this._markerShadowImage;
            icon.iconSize = this._markerSize;
            icon.shadowSize = this._markerShadowSize;
            icon.iconAnchor = this._markerAnchor;  
            
            var marker = new GMarker(point, {icon:icon});
            oMap.map.addOverlay(marker);
            this._markerContainer.push(marker);
  
            return marker;
        };

        /**
        *   @desc Verwijder 1 of meer markers van de kaart
        *   @param aMarkers array met marker ID's
        **/
        this.removeMarkers = function(aMarkers){            
            if (aMarkers.constructor.toString().indexOf("Array") == -1){
              for(i in this._markerContainer){
                    oMap.map.removeOverlay(this._markerContainer[i]);
              }
            }             
        };
        
        /**
        *   @desc Initialisatie starten
        **/
        this.initialize(oMap);
}


