var currentMarkers = [];
var geocoder;
var map2;

function initialize() {
    if (GBrowserIsCompatible()) {
        map2 = new GMap2(document.getElementById("map_canvas"));
        map2.setCenter(new GLatLng(52.025459,19.204102), 5);
        var opts = map2.getDefaultUI();
        opts['maptypes']['normal'] = true;
        opts['maptypes']['satellite'] = false;
        opts['maptypes']['hybrid'] = false;
        opts['maptypes']['physical'] = false;
        opts['zoom']['scrollwheel'] = true;
        opts['zoom']['doubleclick'] = true;
        opts['controls']['scalecontrol'] = false;
        opts['controls']['menumaptypecontrol'] = false;
        
        map2.setUI(opts);

        geocoder = new GClientGeocoder();
        geocoder.setBaseCountryCode("pl");



        jQuery("p.company").click( function (){
                        map2.setCenter(new GLatLng(jQuery(this).children("span.lat").text(),jQuery(this).children("span.lng").text()), 14);
        });

    }
}

jQuery().ready(function(){
    current = "";
    jQuery("a.divletter").click(function(event){
        if(current) current.hide();
        current = jQuery("#"+this.title);
        jQuery("#"+this.title).show();
        for(var n in currentMarkers){
            map2.removeOverlay(currentMarkers[n]);
        }
        currentMarkers = [];

        jQuery("#"+this.title).children("p.company").each(function(){
            var txt = jQuery(this).html();
                        var marker = new GMarker(new GLatLng(jQuery(this).children("span.lat").text(),jQuery(this).children("span.lng").text()));
                        currentMarkers.push(marker);
                        map2.addOverlay(marker);
                        marker.bindInfoWindowHtml(txt);
        });
        map2.setCenter(new GLatLng(52.025459,19.204102), 5);
    });

    initialize();

    jQuery("p.company").each(function(){
        var txt = jQuery(this).html();
                    var marker = new GMarker(new GLatLng(jQuery(this).children("span.lat").text(),jQuery(this).children("span.lng").text()));
                    currentMarkers.push(marker);
                    map2.addOverlay(marker);
                    marker.bindInfoWindowHtml(txt);
    });
});

