function Blue2MapModel() {
    this.items = new Hash();
    this.changed = false;
    this.deferChangeNotification = false;
    this.selectedItem = null;
}

Blue2MapModel.prototype.addItem = function (itemId, data) {
    this.items.set(itemId, { data: data, id: itemId, highlighted: false });
};

Blue2MapModel.prototype.beginUpdate = function () {
    this.deferChangeNotification = true;
};

Blue2MapModel.prototype.endUpdate = function () {
    this.deferChangeNotification = false;
    this.notifyChanged();
};

Blue2MapModel.prototype.setSelected = function (itemId) {
    if (!this.selectedItem || this.selectedItem.id !== itemId) {
        this.selectedItem = this.items.get(itemId);
        this.setChanged();
    }
};

Blue2MapModel.prototype.clearSelected = function (itemId) {
    if (this.selectedItem) {
        if (!itemId || this.selectedItem.id === itemId) {
            this.selectedItem = null;
            this.setChanged();
        }
    }
};

Blue2MapModel.prototype.setHighlighted = function (itemId) {
    var item = this.items.get(itemId);
    if (!item.highlighted) {
        item.highlighted = true;
        this.setChanged();
    }
};

Blue2MapModel.prototype.clearHighlighted = function () {
    this.items.each(function (pair) {
        pair.value.highlighted = false;
    });
    this.setChanged();
};

Blue2MapModel.prototype.setChanged = function () {
    this.changed = true;
    this.notifyChanged();
};

Blue2MapModel.prototype.notifyChanged = function () {
    if (!this.deferChangeNotification && this.changed) {
        GEvent.trigger(this, 'changed');
        this.changed = false;
    }
};


function Blue2Map() {
    this.map = new GMap2(document.getElementById("map"));
    this.map.setCenter(new GLatLng(0, 0));
    this.map.addControl(new GSmallMapControl());
    this.map.addControl(new GMapTypeControl());

    this.tooltip = new Element('div', { 'class': 'tooltip', 'style': 'display:none' });
    $('map').appendChild(this.tooltip);

    this.markers = [];
    this.clusterMarkers = [];
    this.visibleMarkers = new Hash();
    this.bounds = new GLatLngBounds();
    this.intersectPadding = -2;

    GEvent.bind(this.map, 'zoomend', this, this.onMapZoomEnd);
}

(function () {
    var path = "../App_Themes/Red2/images/";
    var baseIcon = new GIcon();
    baseIcon.image = path + "round_marker_1.png";
    //baseIcon.shadow = "/content/images/system/map/single_shadow.png";
    baseIcon.iconSize = new GSize(47, 62);
    baseIcon.shadowSize = new GSize(47, 62);
    baseIcon.iconAnchor = new GPoint(23, 62);
    baseIcon.className = "png_ie";
    baseIcon.infoWindowAnchor = new GPoint(12, 1);
    Blue2Map.prototype.baseIcon = baseIcon;


    var i, icon;
    Blue2Map.prototype.letteredIcons = [];
    for (i = 0; i < 20; i++) {
        icon = new GIcon(baseIcon);
        icon.image = path + "round_marker_" + (i + 1) + ".png";
        icon.iconSize = new GSize(25, 39);
        icon.iconAnchor = new GPoint(23, 35);
        Blue2Map.prototype.letteredIcons[i] = icon;
    }

    Blue2Map.prototype.randstadLetteredIcons = [];
    for (i = 0; i < 20; i++) {
        icon = new GIcon(baseIcon);
        icon.iconSize = new GSize(25, 39);
        icon.image = path + "round_marker_" + (i + 1) + ".png";
        icon.iconAnchor = new GPoint(23, 35);
        Blue2Map.prototype.randstadLetteredIcons[i] = icon;
    }

    Blue2Map.prototype.highlightLetteredIcons = [];
    for (i = 0; i < 20; i++) {
        icon = new GIcon(baseIcon);
        icon.image = path + "round_marker_m_" + (i + 1) + ".png";
        icon.iconSize = new GSize(25, 39);
        icon.iconAnchor = new GPoint(23, 35);
        Blue2Map.prototype.highlightLetteredIcons[i] = icon;

    }

    Blue2Map.prototype.groupNumberedIcons = [];
    for (i = 0; i < 20; i++) {
        icon = new GIcon(baseIcon);
        icon.image = path + "star_marker_" + (i + 1) + ".png";
        icon.iconSize = new GSize(47, 62);
        Blue2Map.prototype.groupNumberedIcons[i] = icon;
    }

    Blue2Map.prototype.highlightGroupNumberedIcons = [];
    for (i = 0; i < 20; i++) {
        icon = new GIcon(baseIcon);
        icon.image = path + "star_marker_active_" + (i + 1) + ".png";
        icon.iconSize = new GSize(47, 62);
        Blue2Map.prototype.highlightGroupNumberedIcons[i] = icon;
    }
}
)();

Blue2Map.prototype.setModel = function (model) {
    this.model = model;
    GEvent.bind(this.model, 'changed', this, this.updateView);
    var othis = this;
    this.model.items.each(function (pair) {
        othis.addLocation(pair.value.data);
    });

    var zoomLevel = Math.min(10, this.getInitialZoomLevel());
    this.map.setCenter(this.bounds.getCenter(), zoomLevel);
    this.refreshMarkers();
};

Blue2Map.prototype.onMapZoomEnd = function (oldLevel, newLevel) {
    this.refreshMarkers();
    this.updateView();
};

Blue2Map.prototype.addLocation = function (loc) {
    var marker = this.createMarker(loc, this.markers.length);
    this.markers.push(marker);
    this.map.addOverlay(marker);

    var model = this.model;
    GEvent.addListener(marker, 'mouseover', GEvent.callbackArgs(model, model.setHighlighted, marker.locationId));
    GEvent.bind(marker, 'mouseout', model, model.clearHighlighted);
    GEvent.addListener(marker, 'click', GEvent.callbackArgs(model, model.setSelected, marker.locationId));
    GEvent.bind(marker, 'infowindowclose', this, this.onInfoWindowClose);

    this.bounds.extend(marker.getPoint());
};

Blue2Map.prototype.refreshMarkers = function () {
    this.model.beginUpdate();

    // Remember the currently selected location. We are going to hide and remove markers which can
    // cause closing an info window and deselecting the currently selected location. At the end of the method
    // we select this location again.
    var selectedItem = this.model.selectedItem;

    this.clearClusterMarkers();
    var clusters = this.calculateClusters();
    for (var i = 0; i < clusters.length; ++i) {
        var cluster = clusters[i];
        if (cluster.length === 1) {
            var marker = cluster[0];
            marker.show();
            this.visibleMarkers.set(marker.locationId, marker);
        } else {
            var clusterMarker = this.createClusterMarker(cluster);
            for (var j = 0; j < cluster.length; ++j) {
                var clusteredMarker = cluster[j];
                if (!this.map.getInfoWindow().isHidden() && clusteredMarker.locationId === this.infoWindowLocationId) {
                    clusteredMarker.closeInfoWindow();
                }
                clusteredMarker.hide();
                if (clusteredMarker === this.highlightedMarker) {
                    this.highlightedMarker = null;
                }
                this.visibleMarkers.set(clusteredMarker.locationId, clusterMarker);
            }
            this.clusterMarkers.push(clusterMarker);
            this.map.addOverlay(clusterMarker);

            GEvent.addListener(clusterMarker, 'mouseover', GEvent.callbackArgs(this, this.onClusterMarkerMouseOver, clusterMarker));
            GEvent.bind(clusterMarker, 'mouseout', this.model, this.model.clearHighlighted);
            GEvent.addListener(clusterMarker, 'click', GEvent.callbackArgs(this, this.onClusterMarkerClick, clusterMarker));
            GEvent.bind(clusterMarker, 'infowindowclose', this, this.onInfoWindowClose);
        }
    }

    if (selectedItem) {
        this.model.setSelected(selectedItem.id);
    }

    this.model.endUpdate();
};

Blue2Map.prototype.createMarker = function (location, markerIndex) {
    var marker = new GMarker(new GLatLng(location.get('lat'), location.get('lng')), {
        icon: this.randstadLetteredIcons[markerIndex]
    });
    marker.locationId = location.get('id');
    marker.id = marker.locationId;
    marker.locationlocationlocationlocation = this.highlightLetteredIcons[markerIndex];
    marker.highlightIcon = this.highlightLetteredIcons[markerIndex];
    marker.tooltip = this.getTooltip(location);
    return marker;
};

Blue2Map.prototype.createClusterMarker = function (cluster) {
    var clusterBounds = new GLatLngBounds();
    for (var i = 0; i < cluster.length; ++i) {
        clusterBounds.extend(cluster[i].getPoint());
    }
    var marker = new GMarker(clusterBounds.getCenter(), { icon: this.groupNumberedIcons[cluster.length - 1] });
    marker.cluster = cluster;
    marker.locationId = cluster[0].locationId;
    marker.id = 'cluster_' + marker.locationId;
    marker.highlightIcon = this.highlightGroupNumberedIcons[cluster.length - 1];
    marker.tooltip = this.clusterTooltipTemplate.evaluate({ count: cluster.length });


    return marker;
};

Blue2Map.prototype.clearClusterMarkers = function () {
    var map = this.map;
    var othis = this;
    this.clusterMarkers.each(function (marker) {
        GEvent.clearInstanceListeners(marker);
        map.removeOverlay(marker);
        if (marker === othis.highlightedMarker) {
            othis.highlightedMarker = null;
        }
    });
    this.clusterMarkers.clear();
};

Blue2Map.prototype.onClusterMarkerMouseOver = function (marker) {
    var cluster = marker.cluster;
    this.model.beginUpdate();
    for (var i = 0; i < cluster.length; ++i) {
        this.model.setHighlighted(cluster[i].id, true);
    }
    this.model.endUpdate();
};

Blue2Map.prototype.onClusterMarkerClick = function (marker) {
    var selectedMarker = this.findVisibleMarker(this.selectedLocationId);
    if (selectedMarker !== marker) {
        this.model.setSelected(marker.cluster[0].locationId);
    }
};

Blue2Map.prototype.onInfoWindowClose = function () {
    // The check below is necessary to make sure that we don't clear the selection if 
    // the window was closed as the result of a newly opened info window.
    if (this.model.selectedItem && this.model.selectedItem.id === this.infoWindowLocationId) {
        this.model.clearSelected();
    }
};

Blue2Map.prototype.showTooltip = function (marker) {
    var viewport = this.map.getBounds();
    if (!viewport.containsLatLng(marker.getPoint())) {
        // Do not show the tooltip if the marker is not visible.
        return;
    }

    this.tooltip.update(marker.tooltip);
    new GControlPosition(G_ANCHOR_TOP_LEFT, this.getTooltipPosition(marker)).apply(this.tooltip);
    this.tooltip.show();
};

Blue2Map.prototype.getTooltipPosition = function (marker) {
    var offset = this.map.fromLatLngToContainerPixel(marker.getPoint());
    var iconAnchor = marker.getIcon().iconAnchor;
    var iconSize = marker.getIcon().iconSize;

    var iconX = offset.x - iconAnchor.x;
    var iconY = offset.y - iconAnchor.y;

    var tooltipDimensions = this.tooltip.getDimensions();
    // Add some extra padding to compensate for the tooltip borders.
    tooltipDimensions.width += 5;
    tooltipDimensions.height += 5;

    var tooltipX = iconX + iconSize.width;
    var rightOvershoot = tooltipX + tooltipDimensions.width - this.map.getSize().width;
    if (rightOvershoot > 0) {
        tooltipX = Math.max(0, tooltipX - rightOvershoot);
    }

    var tooltipY;
    if (iconY - tooltipDimensions.height >= 0) {
        tooltipY = iconY - tooltipDimensions.height;
    } else {
        tooltipY = iconY + iconSize.height;
    }

    return new GSize(tooltipX, tooltipY);
};

Blue2Map.prototype.updateView = function () {
    this.updateHighlightedMarker();
    this.updateTooltip();
    this.updateInfoWindow();
};

Blue2Map.prototype.updateHighlightedMarker = function () {
    var newHighlightedMarker = null;
    var selectedItem = this.model.selectedItem;
    var othis = this;
    this.model.items.each(function (pair) {
        var itemId = pair.key;
        var item = pair.value;
        var marker = othis.findVisibleMarker(itemId);
        if ((item.highlighted && !selectedItem) || item === selectedItem) {
            newHighlightedMarker = marker;
        }
    });

    if (newHighlightedMarker !== this.highlightedMarker) {
        if (this.highlightedMarker) {
            othis.unhighlightMarker(this.highlightedMarker);
        }
        if (newHighlightedMarker) {
            othis.highlightMarker(newHighlightedMarker);
        }
        this.highlightedMarker = newHighlightedMarker;
    }
};

Blue2Map.prototype.updateInfoWindow = function () {
    var selectedItem = this.model.selectedItem;
    if (selectedItem) {
        if (this.map.getInfoWindow().isHidden()) {
            this.openInfoWindow();
        } else {
            var marker = this.findVisibleMarker(selectedItem.id);
            if (marker === this.findVisibleMarker(this.infoWindowLocationId)) {
                this.updateTabbedInfoWindow();
            } else {
                this.openInfoWindow();
            }
        }
    } else {
        this.map.closeInfoWindow();
    }
};

Blue2Map.prototype.updateTooltip = function () {
    if (this.highlightedMarker && !this.model.selectedItem) {
        this.showTooltip(this.highlightedMarker);
    } else {
        this.tooltip.hide();
    }
};

Blue2Map.prototype.highlightMarker = function (marker) {
    this.bringMarkerToFront(marker);
    marker.originalImage = marker.getIcon().image;
    marker.setImage(marker.highlightIcon.image);
};

Blue2Map.prototype.unhighlightMarker = function (marker) {
    this.sendMarkerToBack(marker);
    marker.setImage(marker.originalImage);
};

Blue2Map.prototype.openInfoWindow = function () {
    var selectedItemId = this.model.selectedItem.id;
    var marker = this.findVisibleMarker(selectedItemId);
    var content;
    if (marker.cluster) {
        content = this.getTabbedInfoWindowContent(marker, selectedItemId);
        marker.openInfoWindowTabs([new GInfoWindowTab('', content)], { maxWidth: 365 });
    } else {
        content = this.getInfoWindowContent(selectedItemId);
        marker.openInfoWindow(content, { maxWidth: 365 });
    }
    this.infoWindowLocationId = selectedItemId;
};

Blue2Map.prototype.updateTabbedInfoWindow = function () {
    var selectedItemId = this.model.selectedItem.id;
    var marker = this.findVisibleMarker(selectedItemId);
    if (marker.cluster && selectedItemId !== this.infoWindowLocationId) {
        this.map.updateInfoWindow([new GInfoWindowTab('', this.getTabbedInfoWindowContent(marker, selectedItemId))]);
        this.infoWindowLocationId = selectedItemId;
    }
};

Blue2Map.prototype.getInfoWindowContent = function (locationId) {
    var content = $(this.getInfoWindowContentId(locationId)).cloneNode(true);
    if (content.id) {
        content.id = "gm_" + content.id;
    }
    content.addClassName('search-result-map');
    $(content).select('*[id]').each(function (el) { el.id = "gm_" + el.id; });

    // event are not cloned (except in IE); bind events on cloned nodes
    $(content).select("a[rel=facebox]").each(function (sendLink) {
        Facebox.facebox(sendLink);
    });

    return content;
};

Blue2Map.prototype.getTabbedInfoWindowContent = function (clusterMarker, selectedLocationId) {
    function tabClickHandler(othis, locationId) {
        return function (event) {
            event.stop();
            othis.model.setSelected(locationId);
        };
    }

    if (!selectedLocationId) {
        selectedLocationId = clusterMarker.cluster[0].locationId;
    }

    var content = new Element('div', { 'style': 'display: block;' });
    var ul = new Element('ul', { 'id': 'tabbed-info-window-header', 'style': 'display: inline-block;' });
    content.insert(ul);
    content.insert(this.getInfoWindowContent(selectedLocationId));

    var cluster = clusterMarker.cluster;

    for (var i = 0; i < cluster.length; ++i) {
        var locationId = cluster[i].locationId;
        var li, img, imgSrc;
        var markerDiv = new Element('div');
        markerDiv.style.width = "25px";
        markerDiv.style.height = "37px";
        img = new Element('img');
        if (locationId === selectedLocationId) {

            //            if (Prototype.Browser.IE && getIEVersionNumber() < 8) {

            //                li = new Element('li', { 'class': 'selected', 'style': 'display: inline;float:right' });
            //            }
            //            else {
            //                
            //            }
            li = new Element('li', { 'class': 'selected', 'style': 'float: left;' });
            ul.insert(li);
            imgSrc = this.findMarker(locationId).highlightIcon.image;
            if (Prototype.Browser.IE) {
                markerDiv.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=crop,src="' + imgSrc + '")';
            } else {
                markerDiv.style.backgroundImage = "url('" + imgSrc + "')";
            }
            li.insert(markerDiv);
        } else {

            //            if (Prototype.Browser.IE && getIEVersionNumber() < 8) {

            //                li = new Element('li', { 'style': 'display: inline;float:right;' });
            //            }
            //            else {
            //               
            //            }
            li = new Element('li', { 'style': 'float: left;' });

            ul.insert(li);
            var a = new Element('a', { 'href': '#' });
            imgSrc = this.findMarker(locationId).getIcon().image;
            if (Prototype.Browser.IE) {
                markerDiv.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=crop,src="' + imgSrc + '")';
            } else {
                markerDiv.style.backgroundImage = "url('" + imgSrc + "')";
            }
            markerDiv.style.cursor = 'pointer';
            //img = new Element('img', {'src': imgSrc, 'style': 'cursor: pointer'});
            markerDiv.observe('click', tabClickHandler(this, locationId));
            li.insert(markerDiv);
        }
    }
    var br = new Element('br');
    content.insert(br);
    return content;
};

function getIEVersionNumber() {
    var ua = navigator.userAgent;
    var MSIEOffset = ua.indexOf("MSIE ");

    if (MSIEOffset == -1) {
        return 0;
    } else {
        return parseFloat(ua.substring(MSIEOffset + 5, ua.indexOf(";", MSIEOffset)));
    }
}


Blue2Map.prototype.bringMarkerToFront = function (marker) {
    if (!marker.originalZIndex) {
        var imgElement = $("mtgt_" + marker.id);

        marker.originalZIndex = imgElement.style.zIndex;
        imgElement.style.zIndex = "1";
    }
};

Blue2Map.prototype.sendMarkerToBack = function (marker) {
    if (marker.originalZIndex) {
        var imgElement = $("mtgt_" + marker.id);

        imgElement.style.zIndex = marker.originalZIndex;
        marker.originalZIndex = null;
    }
};

Blue2Map.prototype.findMarker = function (locationId) {
    return this.markers.find(function (e) {
        return e.locationId === locationId;
    });
};

Blue2Map.prototype.findVisibleMarker = function (locationId) {
    return this.visibleMarkers.get(locationId);
};

/**
* calculateClusters returns a partition of the set of map markers according to the distance between each other 
* such that overlapping markers are grouped in the same part or cluster. Whether two markers overlap is dependent
* on the current zoom level. 
* 
* If there are for example five markers on the map: m1, m2, m3, m4, m5, of which the pairs (m2, m5) and (m3, m4) overlap
* the result is the array [[m1], [m2,m5], [m3, m4]].
*/
Blue2Map.prototype.calculateClusters = function () {
    var projection = this.map.getCurrentMapType().getProjection();
    var iconBounds = [];
    var i;

    for (i = 0; i < this.markers.length; ++i) {
        iconBounds[i] = this.getIconLatLngBounds(this.markers[i]);
    }

    // Tracks which markers are already added to a cluster.
    var clustered = [];
    for (i = 0; i < this.markers.length; ++i) {
        clustered[i] = false;
    }

    var clusters = [];
    for (i = 0; i < this.markers.length; ++i) {
        if (!clustered[i]) {
            var cluster = [];
            cluster.push(this.markers[i]);
            for (var j = i + 1; j < this.markers.length; ++j) {
                if (!clustered[j] && iconBounds[i].intersects(iconBounds[j])) {
                    cluster.push(this.markers[j]);
                    clustered[j] = true;
                }
            }
            clusters.push(cluster);
        }
    }

    return clusters;
};

Blue2Map.prototype.getIconLatLngBounds = function (marker) {
    var iconSize = marker.getIcon().iconSize;
    var iconAnchorPoint = this.map.fromLatLngToContainerPixel(marker.getLatLng());
    var iconAnchorPointOffset = marker.getIcon().iconAnchor;
    var iconBoundsPointSw = new GPoint(iconAnchorPoint.x - iconAnchorPointOffset.x - this.intersectPadding, iconAnchorPoint.y - iconAnchorPointOffset.y + iconSize.height + this.intersectPadding);
    var iconBoundsPointNe = new GPoint(iconAnchorPoint.x - iconAnchorPointOffset.x + iconSize.width + this.intersectPadding, iconAnchorPoint.y - iconAnchorPointOffset.y - this.intersectPadding);
    var iconBoundsLatLngSw = this.map.fromContainerPixelToLatLng(iconBoundsPointSw);
    var iconBoundsLatLngNe = this.map.fromContainerPixelToLatLng(iconBoundsPointNe);
    return new GLatLngBounds(iconBoundsLatLngSw, iconBoundsLatLngNe);
};

/**
* Returns the initial zoom level. This method is used instead of GMap2.getBoundsZoomLevel(bounds:GLatLngBounds) to 
* make sure that markers near the border of the viewport which might otherwise be partially hidden are completely shown.
*/
Blue2Map.prototype.getInitialZoomLevel = function () {
    var viewSize = new GSize(this.map.getSize().width, this.map.getSize().height);
    viewSize.height = viewSize.height - this.baseIcon.iconSize.height;
    viewSize.width = viewSize.width - this.baseIcon.iconSize.width;
    return this.map.getCurrentMapType().getSpanZoomLevel(this.bounds.getCenter(), this.bounds.toSpan(), viewSize);
};

Blue2Map.prototype.getInfoWindowContentId = function (id) {
    return this.infoWindowContentIdPrefix + id;
};

Blue2Map.prototype.infoWindowContentIdPrefix = undefined; // abstract

Blue2Map.prototype.getTooltip = function (location) {
    // abstract
};


function ItemList() {
}

ItemList.prototype.setModel = function (model) {
    this.model = model;
    GEvent.bind(this.model, 'changed', this, this.updateView);
    var othis = this;
    this.model.items.each(function (pair) {
        othis.addItem(pair.key);
    });
};

ItemList.prototype.addItem = function (itemId) {
    var model = this.model;
    var listItem = $(this.getListItemId(itemId));
    listItem.down('a').observe('click', function (event) { model.setSelected(itemId); event.stop(); });
    listItem.observe('mouseover', function (event) { model.setHighlighted(itemId, true); });
    listItem.observe('mouseout', function (event) { model.clearHighlighted(); });
};

ItemList.prototype.updateView = function () {
    var selectedItem = this.model.selectedItem;
    var othis = this;
    this.model.items.each(function (pair) {
        var itemId = pair.key;
        var item = pair.value;
        // Do not show items highlighted if there are other selected items.
        if ((item.highlighted && !selectedItem) || item === selectedItem) {
            othis.highlightListItem(itemId);
        } else {
            othis.unhighlightListItem(itemId);
        }
    });
};

ItemList.prototype.highlightListItem = function (itemId) {
    $(this.getListItemId(itemId)).addClassName('SelectedJob');
};

ItemList.prototype.unhighlightListItem = function (itemId) {
    $(this.getListItemId(itemId)).removeClassName('SelectedJob');
};

ItemList.prototype.getListItemId = function (itemId) {
    return this.listItemIdPrefix + itemId;
};

ItemList.prototype.listItemIdPrefix = undefined; // abstract


/**
* Blue2MapView combines a Blue2Map and an ItemList with a Blue2MapModel. The map
* and list are kept in sync through the model.
*/
function Blue2MapView() {
    this.model = new Blue2MapModel();
    this.map = new Blue2Map();
    this.locationList = new ItemList();
}

Blue2MapView.prototype.addLocation = function (loc) {
    loc = $H(loc);
    this.model.addItem(loc.get('id'), loc);
};

Blue2MapView.prototype.show = function () {
    this.map.setModel(this.model);
    this.locationList.setModel(this.model);
};

Blue2MapView.createJobMapView = function () {
    var view = new Blue2MapView();

    var map = view.map;
    map.tooltipTemplate = new Template('<div class="toolTipBox"><strong>#{title}</strong><br/><span>published: #{date}</span></div>');
    map.clusterTooltipTemplate = new Template('There are #{count} jobs in this marker');
    map.infoWindowContentIdPrefix = 'result_';
    map.getTooltip = function (location) {
        /* Fixed a small bug that shows 'en' when there is no companyname to display (#51595) */
        var tooltipAt = location.get('name') === undefined ? "" : "teste "; // +L("at") + " ";
        location.set('at', tooltipAt);
        return this.tooltipTemplate.evaluate(location);
    };

    view.locationList.listItemIdPrefix = 'job_';

    return view;
};

Blue2MapView.createUnitMapView = function () {
    var view = new Blue2MapView();

    var map = view.map;
    map.tooltipTemplate = new Template('<h3>#{title}</h3><div>#{city}, #{street} #{number} #{numberExtension}</div>');
    map.clusterTooltipTemplate = new Template('#{count} units');
    map.infoWindowContentIdPrefix = 'unit_result_';
    map.getTooltip = function (location) {
        return this.tooltipTemplate.evaluate(location);
    };

    view.locationList.listItemIdPrefix = 'unit_';

    return view;
};

Blue2MapView.prototype.setClusterTooltip = function (template) {
    this.map.clusterTooltipTemplate = new Template(template);
};

Blue2MapView.prototype.setTooltip = function (template) {
    this.map.tooltipTemplate = new Template(template);
};

