	
var googleMap = Class.create({
	map : null,
	markersArr : [], 
	showMarkersArr : [],
	mapBoundsExtend : true,
	mapCenterAdjust : true,
	
    initialize: function(divID, options) 
	{
		this.map = new GMap2(document.getElementById(divID));	
		
		this.map.setCenter(new GLatLng(51.771000,5.000000), 11);

		this.map.bounds = new GLatLngBounds();

		this.map.initialized = true;
	},
	getBounds: function() 
	{
		return this.map.getBounds();
	},
	addControl: function(control) 
	{
		this.map.addControl(control);
	},
	enableScrollZoom: function()
	{
		this.map.enableScrollWheelZoom();
	},
	setMapType: function(type) 
	{
        this.map.setMapType(type); 
    },
	setCenter: function(center) 
	{
        this.map.setCenter(center); 
    },
	setZoom: function(zoom) 
	{
		this.map.setZoom(zoom);
	},		
	setIcon: function(file) 
	{
		var smallIcon = new GIcon(G_DEFAULT_ICON);
		smallIcon.image = file;
		
		this.markerOptions = { icon:smallIcon };
       	this.uniqueIcon = { icon:smallIcon };		
	},

	setMapBoundsExtend: function() 
	{
		this.mapBoundsExtend = true;
	},		
	resetMapBoundsExtend: function() 
	{
		this.mapBoundsExtend = false;
	},		
	setMapCenterAdjust: function() 
	{
		this.mapCenterAdjust = true;
	},		
	resetMapCenterAdjust: function() 
	{
		this.mapCenterAdjust = false;
	},		

	setShowMarker4Polygon: function() 
	{
		this.showMarker4Polygon = true;
	},		
	resetShowMarker4Polygon: function() 
	{
		this.showMarker4Polygon = false;
	},		
	setPolygonMarkerAtCenter: function() 
	{
		this.polygonMarkerAtCenter = true;
	},		
	resetPolygonMarkerAtCenter: function() 
	{
		this.polygonMarkerAtCenter = false;
	},		
	setPolyTransparency: function(value) 
	{
		if(value >= 0 && value <= 1)
		{
			this.polyTransparency = value;
		}
	},
	isArray: function(obj) 
	{
		return obj.constructor == Array;
	},		
	addMarkerToGroup: function (marker, iGroup)
	{
    	if(!this.markersArr[iGroup])
        {
    		this.markersArr[iGroup] = [];
        }

    	this.markersArr[iGroup].push(marker);
    },
	addMarker: function(longitude, latitude, textToShow, iGroup)
	{

		var point = new GLatLng(latitude, longitude);	
		
		if(this.mapBoundsExtend)
		{
    		//extend our this.map
    		this.map.bounds.extend(point);
        }

		if(this.mapCenterAdjust)
		{
            //set center of the this.map
            this.map.setCenter(this.map.bounds.getCenter());
        }

        var marker;
        
        if(this.isArray(this.markerOptions))
        {
        	marker = new GMarker(point, this.markerOptions[iGroup]);
        }
        else if(this.markerOptions)
        {
        	marker = new GMarker(point, this.markerOptions);
        }
        else
        {
        	marker = new GMarker(point, this.map.icon);
        }
        
        if(textToShow)
        {
        	GEvent.addListener(marker, "mouseover", function() { marker.openInfoWindowHtml(textToShow) });
        }

        if(iGroup != null)
        {	
			this.addMarkerToGroup(marker, iGroup);
        }
        else
        {
        	this.map.addOverlay(marker);
        }
	},
	toggleMarkers: function (iGroup) 
	{		
		if(this.showMarkersArr[iGroup])
		{
			this.removeMarkers(iGroup);
			this.showMarkersArr[iGroup] = false;
		}
		else
		{
			this.showMarkers(iGroup);
			this.showMarkersArr[iGroup] = true;
		}
    },
	showMarkers: function (iGroup)
	{				
		if(this.markersArr[iGroup])
		{
			var oObject = this.map;
			this.markersArr[iGroup].each(
				function(oMarker){
					oObject.addOverlay(oMarker);
				}
			);
		}
	},
	removeMarkers: function (iGroup)
	{
		if(this.markersArr[iGroup])
		{
			var oObject = this.map;
			this.markersArr[iGroup].each(
				function(oMarker){
					oObject.removeOverlay(oMarker);
				}
			);
		}

	},
	removeAllMarkers: function ()
	{
		this.map.closeInfoWindow();
		
		var oClone = this;
		this.markersArr.each(
			function(oGroup, iKey){
				oClone.removeMarkers(iKey);
			}
		);

	},
	showAllMarkers: function ()
	{
		this.map.closeInfoWindow();
		
		var oClone = this;
		this.markersArr.each(
			function(oGroup, iKey){
				oClone.showMarkers(iKey);
			}
		);

	},
	
	getMap: function()
	{
		return this.map;
	}
	
});

