var PFCMap = function(canvas,markers,center,zoom) {
    //this.latlng = new GLatLng(latlng[0],latlng[1]);
    
    var pfcmap = this;
    this.gmap;
    
    this.canvas = canvas;
    this.center = new GLatLng(25.3241665257384,-5.9765625);
    this.zoom = 2;
        
    this.parseLatLng = function(string) {
        var ll = string.split(',');
        return new GLatLng(ll[0],ll[1]);
    };
    
    this.placeMarker = function(latlng,uri,type,title) {
        
        var iconTarget = new GIcon(G_DEFAULT_ICON);
        
        var isClickable = true;
        
        if(type == 'home') {
            iconTarget.image = "/img/locations/target-home.png";
            iconTarget.shadow = null;
            iconTarget.iconSize = new GSize(32, 39);
            iconTarget.iconAnchor = new GPoint(16, 39);
            isClickable = false;
        } else if(type == 'selected') {
            iconTarget.image = "/img/locations/target-selected.png";
            iconTarget.shadow = null;
            iconTarget.iconSize = new GSize(32, 39);
            iconTarget.iconAnchor = new GPoint(16, 39);
        } else {
            iconTarget.image = "/img/locations/target.png";
            iconTarget.shadow = null;
            iconTarget.iconSize = new GSize(20, 25);
            iconTarget.iconAnchor = new GPoint(10, 25);
        }
        
        var marker = new GMarker(latlng,{"icon":iconTarget,"title":title,"clickable":isClickable});
        if(uri) { GEvent.addListener(marker, "click", function() { window.location = uri; }); }
        pfcmap.gmap.addOverlay(marker);
    };
    
    if(center) {
        this.center = this.parseLatLng(center);
    } else {
        if(markers.length == 1) {
            this.center = pfcmap.parseLatLng(markers[0].latlng);
        }
    }
    
    
    if(zoom) { this.zoom = zoom; }
    
    if (GBrowserIsCompatible()) {
        
        var gmap = new GMap2(this.canvas.get(0));
        this.gmap = gmap;
        
        var center = pfcmap.center;
        var zoom = pfcmap.zoom;
        gmap.setCenter(center, zoom);
        gmap.addControl(new GSmallMapControl());
        gmap.enableDoubleClickZoom();
        
        if(markers) {
            jQuery.each(markers,function(num,marker){
                var latlng = pfcmap.parseLatLng(marker.latlng);
                pfcmap.placeMarker(latlng,marker.uri,marker.type,marker.title);
            });
        }
    }
}
