var PPDLMap = Class.create();
PPDLMap.prototype = {
    initialize: function(container) {
        this.isCompatible = GBrowserIsCompatible();
        if ( this.isCompatible )
        {
            this.name = "MedCongresGMap";
	        this.map = new GMap2( $(container) );
			this.map.addControl( new GSmallMapControl() );
			//this.map.addControl( new GMapTypeControl() );
			this.locations = new Array();
			//this.map.setCenter( new GLatLng(48.856578, 2.351828), 8 );
		}
    },
    
    setView: function(view, location) {
        switch(view)
        {
            case "region":
                this.altitude = 7;
                break;
            case "departement":
				this.altitude = 8;
                break;
			case "ville":
				this.altitude = 10;
			    break;
			default:
			    this.altitude = view;
			    break;
        }
        var geocoder = new GClientGeocoder();
	    geocoder.getLocations(location, this.center.bind(this));
    },
    
    center: function(response) {
	    if (!response || response.Status.code != 200) {}
		else
	        this.map.setCenter( new GLatLng(response.Placemark[0].Point.coordinates[1], response.Placemark[0].Point.coordinates[0]), this.altitude );
    },

	createMarker: function(point, html) {
        if ( this.isCompatible )
        {
			var marker = new GMarker(point);
			GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml(html, {maxWidth: '100'});
			});

			// The new marker "mouseover" listener
			GEvent.addListener(marker, "mouseover", function() {
			marker.openInfoWindowHtml(html, {maxWidth: '100'});
			});

			return marker;
		}
	},
    
    addPoint: function(lat, lng, text) {
        if ( this.isCompatible )
        {
		    var point = new GLatLng(lat, lng);
			var marker = this.createMarker(point, text);
			this.map.addOverlay(marker);
		}
	},
	
	addressToPoint: function() {
		response = arguments[1];
		text = arguments[0];
	    if (!response || response.Status.code != 200) {}
		else
			this.addPoint( response.Placemark[0].Point.coordinates[1], response.Placemark[0].Point.coordinates[0], text );
	},
	
	isPresent: function(location) {
	    for(i=0; i<this.locations.length; i++)
	    {
	        if ( this.locations[i] == location)
	            return true;
	    }
	    this.locations.push(location);
	    return false;
	},
	
	addLocation: function(location, text) {
	    if ( this.isPresent(location) )
	        return false;
	    var geocoder = new GClientGeocoder();
	    geocoder.getLocations(location, this.addressToPoint.bind(this, text));
	}
};
/*
var ammap = new AMMap("map");

ammap.addLocation("6 rue de Verdun, Boulogne Billancourt, France", "paris");

ammap.addLocation("Louvres, Paris, France", "paris");

ammap.addLocation("Tour Eiffel", "paris");
*/


