$(document).ready(function() {
    $('.activateGuessedMap').each(function() {
        var $control_box = $('.control-box', this);
        var $map_container = $('.mapContainer', this);
        var post_code = $('.post-code', $control_box).text();
        var region = $('.region', $control_box).text();
        var address = $('.address', $control_box).text();
        var country_code = $('.country-code', $control_box).text();

        var query_parts = [];
        if (address) { query_parts.push(address) }
        if (post_code) { query_parts.push(post_code) }
        //if (region) { query_parts.push(region) }
        var geo_query = query_parts.join(', ');
        var geocoder = new GClientGeocoder();
        geocoder.setBaseCountryCode(country_code);
        geocoder.getLatLng(geo_query, function(point) {
            if (!point) {
                return; // address not found? What to do?
            }
            $map_container.each(function() {
                var map = new GMap2(this);
                map.addControl(new GSmallZoomControl3D());
                map.setCenter(point, 13);
                var marker = new GMarker(point);
                map.addOverlay(marker);
            });
        });
    });
});

