bqc.Marker = Class.create({

    initialize: function(json, map, searchManager) {
        this.json = json;
        this.map = map;
        this.searchManager = searchManager;

        var that = this;
        this.marker = new GMarker(this.latlng = this.createLatLng(), this.setOptions({
            icon: this.getIcon(),
            draggable: false,
            bouncy: false,
            clickable: true
        }));
        this.marker.parent=this;
        GEvent.addListener(this.marker, 'click', function() { that.clickHandler(); });
        this.manageTooltip();
        map.addOverlay(this.marker);
    },

    manageTooltip: function() {
        var that = this;
        GEvent.addListener(this.marker, 'mouseover', function() { that.showTooltip(); });
        GEvent.addListener(this.marker, 'mouseout', function() { that.hideTooltip(); });
    },

    setOptions: function(options) {
        return options;
    },

    remove: function() {
        this.hideTooltip();
        this.map.removeOverlay(this.marker);
        this.marker = null;
    },

    getLatLng: function() {
        return this.latlng;
    },

    createLatLng: function() {
        return new GLatLng(this.json.lat, this.json.lon);
    },

    getIcon: function() {
        return bqc.unmarkedIcons[this.json.type];
    },

    showTooltip: function() {
        if (this.marker != null) {
            this.searchManager.tooltipManager.showTooltip(this.marker.getLatLng(), this.json);
        }
    },

    hideTooltip: function() {
        this.searchManager.tooltipManager.hideTooltip();
    },
    
    clickHandler: function() {
        if(!this.searchManager.isProximity && bqc.conf.zoomToDisableCLuster>=this.map.getZoom()) {
            this.showMiniFiche();
        } else {
            this.marker.startSpider(bqc.spider);
        }
    },

    showMiniFiche: function(){
        bqc.tooltipManager.setToProximitySearch();
        this.searchManager.stopListeningMap();
        this.searchManager.tooltipManager.openService(this);
     
        // *** Nombre total de mini-fiches affichées ventilé par  fiche :
        bqc.gaLogger.log(bqc.params.p_mode_org, bqc.GAnalyticsStrings.level2.miniFichesShowCount, this.json.name);
    }
});

bqc.createUnmarkedIcon = function(img) {
    var iconNode = new GIcon();
    iconNode.image = img;
    iconNode.shadow = '';
    iconNode.transparent='images/petit_point_trans.png';
    iconNode.imageMap=[0,0, 11,0, 11,11, 0,11];
    iconNode.iconSize = new GSize(16, 16);
    iconNode.iconAnchor = new GPoint(6, 6);
    iconNode.infoWindowAnchor = new GPoint(6, 6);
    iconNode.dragCrossSize = GSize(1, 1);
    iconNode.maxHeight = 1;
    iconNode.h=6;
    iconNode.w=6;
    iconNode.correction={x:2,y:2};
    return iconNode;
}
bqc.unmarkedIcons = [
    bqc.createUnmarkedIcon('images/petit_point_hebergement.png'),
    bqc.createUnmarkedIcon('images/petit_point_hebergement.png'),
    bqc.createUnmarkedIcon('images/petit_point_hebergement.png'),
    bqc.createUnmarkedIcon('images/petit_point_hebergement.png'),
    bqc.createUnmarkedIcon('images/petit_point_hebergement.png'),
    bqc.createUnmarkedIcon('images/petit_point_hebergement.png'),
    bqc.createUnmarkedIcon('images/petit_point_attraits.png'),
    bqc.createUnmarkedIcon('images/petit_point_attraits.png'),
    bqc.createUnmarkedIcon('images/petit_point_attraits.png'),
    bqc.createUnmarkedIcon('images/petit_point_attraits.png'),
    bqc.createUnmarkedIcon('images/petit_point_attraits.png'),
    bqc.createUnmarkedIcon('images/petit_point_informations.png'),
    bqc.createUnmarkedIcon('images/petit_point_services.png')
];
