﻿jQuery(document).ready(function () {
    if (jQuery(".searchresult .searchresultcontent").html() != null) {
        var lon = jQuery(".MapLongitude").val().replace(",", ".");
        var lat = jQuery(".MapLatitude").val().replace(",", ".");
        $('#map_canvas').gmap3({
            action: 'init',
            options: {
                center: [lat, lon],
                zoom: 10
            }
        }
        //		,{
        //            action: 'addCircle',
        //            center: [lat, lon],
        //            radius: 20000,
        //			fillColor: 'transparent',
        //			strokeColor: '#FFDF18'
        //		}
		);
        jQuery("#map_canvas").show();
        jQuery(".searchresult .searchresultcontent").each(function () {
            var title = jQuery(".title h1", this).html().replace("\n", "");
            var fulladdress = jQuery(".address", this).html().replace("\n", "");
            jQuery('#map_canvas').gmap3({
                action: 'addMarker',
                address: fulladdress,
                marker: {
                    options: {
                        draggable: false
                    },
                    infowindow: {
                        options: {
                            content: "<b>" + title + "</b><br/>" + fulladdress
                        }
                    },
                    events: {
                        mouseover: function (marker, event, map) {
                            var map = jQuery(this).gmap3('get'),
                            infowindow = jQuery(this).gmap3({ action: 'get', name: 'infowindow' });
                            if (infowindow) {
                                infowindow.open(map, marker);
                                infowindow.setContent("<b>" + title + "</b><br/>" + fulladdress);
                            } else {
                                jQuery(this).gmap3({ action: 'addinfowindow', anchor: marker, options: { content: "<b>" + title + "</b><br/>" + fulladdress} });
                            }
                        },
                        mouseout: function () {
                            var infowindow = jQuery(this).gmap3({ action: 'get', name: 'infowindow' });
                            if (infowindow) {
                                infowindow.close();
                            }
                        }
                    }
                }
            });
        });
    }
});

