function CGoogleMap(DivId)
{
  this.ObjGMap = new GMap2(document.getElementById(DivId));
  this.ObjGMarkerManager = new GMarkerManager(this.ObjGMap);
  this.BoundsMap = new GLatLngBounds();
  this.Markers = [];
}

CGoogleMap.prototype.SetLargeMapControls = function ()
{  
  this.ObjGMap.addMapType(G_PHYSICAL_MAP);                  
  var mapControl = new GHierarchicalMapTypeControl();

  mapControl.clearRelationships();
  mapControl.addRelationship(G_SATELLITE_MAP, G_HYBRID_MAP, "Labels", false);
  this.ObjGMap.addControl(mapControl);
  
  this.ObjGMap.addControl(new GLargeMapControl());
  this.ObjGMap.addControl(new GScaleControl());

  this.ObjGMap.setMapType(G_PHYSICAL_MAP);   
}

CGoogleMap.prototype.SetSmallMapControls = function ()
{
  this.ObjGMap.addMapType(G_PHYSICAL_MAP);                  
  var mapControl = new GHierarchicalMapTypeControl();

  mapControl.clearRelationships();
  mapControl.addRelationship(G_SATELLITE_MAP, G_HYBRID_MAP, "Labels", false);
  this.ObjGMap.addControl(mapControl);
  
  this.ObjGMap.addControl(new GLargeMapControl3D());
  this.ObjGMap.setMapType(G_PHYSICAL_MAP);
}

CGoogleMap.prototype.AddMarker = function(Description, MarkImgUrl, Lat, Lng, InfoHtml, DetailUrl, Id, Type)
{
  var LatLng = new GLatLng(Lat, Lng);
  var Icon = new GIcon();
  Icon.image = MarkImgUrl;
  Icon.iconAnchor = new GPoint(0, 0);
  Icon.infoWindowAnchor = new GPoint(10, 0);
  
  var Marker = new GMarker(LatLng, {icon:Icon, title:Description});
  Marker.id = Id;
  this.Markers.push(Marker);
  
  this.ObjGMarkerManager.addMarker(Marker, 1);
  
  GEvent.addListener(Marker, "mouseover", function() { Marker.openInfoWindowHtml( InfoHtml,{suppressMapPan:true}); })
  GEvent.addListener(Marker, "mouseout", function() { Marker.closeInfoWindow(); })
  GEvent.addListener(Marker, "click", function() { return GoogleMap.ShowSingleMarker(Id, DetailUrl, Type); })
  this.BoundsMap.extend(LatLng);
}

/**
* There's a bug in the Google show/hide api in which zooming automatically displays all the markers again instead of ony the visible one...
* Overloading of the Google API functions necessary, see below for the overloading
*/
CGoogleMap.prototype.ShowSingleMarker = function(Id, element, type)
{
  for(var i=0;i<this.Markers.length;i++) {
      if(this.Markers[i].id == Id) {
        this.Markers[i].show();
        this.CenterMapToMarker(this.Markers[i].getPoint().lat(), this.Markers[i].getPoint().lng());
      } else {
        this.Markers[i].hide();  
      }
  }

  if(type == "employer"){
  	return callEmployer(element);     
  }
  return callVacancy(element);
}

CGoogleMap.prototype.ShowMarker = function(Id)
{
  for(var i=0;i<this.Markers.length;i++) {
    if(this.Markers[i].id == Id) {
      this.Markers[i].show();
    }
  }
}

CGoogleMap.prototype.ShowAllMarkers = function()
{
  for(var i=0;i<this.Markers.length;i++) {
        this.Markers[i].show();
  }
  return false;
}

CGoogleMap.prototype.HideAllMarkers = function()
{
  for(var i=0;i<this.Markers.length;i++) {
        this.Markers[i].hide();
  }
}

CGoogleMap.prototype.FitMapToMarkers = function() {
  this.ObjGMap.checkResize();
  this.ObjGMap.setCenter(this.BoundsMap.getCenter(), this.ObjGMap.getBoundsZoomLevel(this.BoundsMap))
}

CGoogleMap.prototype.CenterMapToMarker = function(lat, lng) {
    this.ObjGMap.setCenter(new GLatLng(lat, lng),8);
}

/* Prototyping the show/hide/isHidden methods of GMarker */
                
                
// the hide() method saves the markers current position and then 
// positions the marker outside the map
GMarker.prototype.hide = function() {  
    if (this.getPoint().lat() < 90) {  
        try {  
            this.savePoint = this.getPoint();  
            this.setPoint(new GLatLng(90, 0));  
        } catch (e) { }  
    }  
}  
// the show() method puts the marker back in the original position
GMarker.prototype.show = function() {  
    if (this.getPoint().lat() == 90) {  
        if (this.savePoint) {  
            try {  
                this.setPoint(this.savePoint);  
                this.savePoint = null;  
            } catch (e) { }  
        }  
    }  
} 

// the isHidden() method checks if the marker is put outside the map and if it does
// returns true
GMarker.prototype.isHidden = function() {  
     if (this.getPoint().lat() == 90) {  
        return true;  
    } else {  
        return false;  
    }  
} 
