var maps = {
    immoIcon: null,
    immoIconSel: null,
    
    load: function () {
        if (GBrowserIsCompatible()) {
            var cities = [
                ['Wiesbaden', new GLatLng(50.0840697, 8.2383811), 'wiesbaden'],
                ['Oestrich-Winkel', new GLatLng(50.0026010, 8.0184690), 'oestrich-winkel'],
                ['Lorch', new GLatLng(50.045186, 7.803887), 'lorch'],
                ['Geisenheim', new GLatLng(49.9839670, 7.9665900), 'geisenheim'],
                ['Rüdesheim', new GLatLng(49.9789962, 7.9263657), 'ruedesheim'],
                ['Walluf', new GLatLng(50.0364940, 8.1560550), 'walluf'],
                ['Kiedrich', new GLatLng(50.0407560, 8.0848480), 'kiedrich'],
                ['Eltville', new GLatLng(50.0250530, 8.1177780), 'eltville']
            ];
            
            var map = new GMap2($('map'), { size: GSize(550, 250) });
            
            maps.immoIcon = maps.createImmoIcon();
            maps.immoIconSel = maps.createImmoIcon(true);
            
            map.setCenter(new GLatLng(50.04, 8.0), 10);

            var mapControl = new GSmallMapControl();
            map.addControl(mapControl);
            
            cities.each(function (city) {
                var icon = location.href.split('/').pop() == city[2] ?
                                            maps.immoIconSel : maps.immoIcon;
                var marker = new GMarker(city[1], icon);
                GEvent.addListener(marker, "click", function () {
                    location.href = "/orte/" + city[2];
                });
                map.addOverlay(marker);
            });
        }
    },
    
    createImmoIcon: function (sel) {
        var icon = new GIcon();
        icon.shadow = "/bild/maps/haus-schatten.png";
        icon.iconSize = new GSize(24, 24);
        icon.shadowSize = new GSize(33, 24);
        icon.iconAnchor = new GPoint(12, 24);
        icon.infoWindowAnchor = new GPoint(9, 2);
        icon.infoShadowAnchor = new GPoint(18, 25);
        
        icon.image = sel ? "/bild/maps/haus-sel.png" : "/bild/maps/haus.png";
        return icon;
    },
    
    unload: function () {
        try {
            GUnload();
        }
        catch (e) {
        }
    }
};

