function map(d) {
    (function (e) {
        e.fn.template = function (f) {
            return this.clone().each(function () {
                for (var h in f) {
                    if (typeof f[h] === "string") {
                        e(this).find(h).html(f[h])
                    } else {
                        if (typeof f[h] === "object") {
                            for (var g in f[h]) {
                                if (g === "val" || g === "css" || g === "html" || g === "text" || g === "data" || g === "width" || g === "height" || g === "offset") {
                                    e(this).find(h)[g](f[h][g])
                                } else {
                                    if (typeof f[h][g] === "function") {
                                        e(this).find(h).bind(g, f[h][g])
                                    } else {
                                        e(this).find(h).attr(g, f[h][g])
                                    }
                                }
                            }
                        }
                    }
                }
            })
        }
    })(jQuery);
    var b = function () {
            return new google.maps.Map(document.getElementById("map-display"), {
                zoom: 3,
                mapTypeId: google.maps.MapTypeId.ROADMAP,
                center: new google.maps.LatLng(39.3683, -98.0859),
                draggable: true,
                disableDefaultUI: true,
                disableDoubleClickZoom: false,
                navigationControl: true,
                navigationControlOptions: {
                    style: google.maps.NavigationControlStyle.SMALL,
                    position: google.maps.ControlPosition.TOP_LEFT
                },
                scaleControl: false,
                scrollwheel: true
            })
        }(),
        a = function (h, g, e) {
            var i = [];
            jQuery("#map-results").html("");
            for (m = 0; m < g.length; m++) {
                var f = new google.maps.Marker({
                    position: new google.maps.LatLng(g[m].latitude, g[m].longitude),
                    map: h,
                    icon: "/wp-content/themes/bubbakeg/img/ul-marker_map.png",
                    index: m
                });
                google.maps.event.addListener(f, "click", function (k) {
                    var j = new google.maps.InfoWindow({
                        content: g[this.index].name + "<br />" + g[this.index].address + "<br />" + g[this.index].city + ", " + g[this.index].state + " " + g[this.index].zipcode
                    });
                    j.open(h, f)
                });
                i.push(f);
                jQuery("#li_template").template({
                    ".distance": c(e, new google.maps.LatLng(g[m].latitude, g[m].longitude)) + " Miles",
                    ".name": g[m].name + ": ",
                    ".address": g[m].address + " " + g[m].city + " " + g[m].state + ", " + g[m].zipcode,
                    ".directions": {
                        href: "http://maps.google.com/maps?f=d&daddr=" + g[m].address + " " + g[m].city + " " + g[m].state + ", " + g[m].zipcode
                    }
                }).appendTo("#map-results")
            }
            return i
        },
        c = function (q, p) {
            var g = q.lat();
            var j = q.lng();
            var f = p.lat();
            var i = p.lng();
            var h = 3959;
            var l = (f - g) * Math.PI / 180;
            var e = (i - j) * Math.PI / 180;
            var o = Math.sin(l / 2) * Math.sin(l / 2) + Math.cos(g * Math.PI / 180) * Math.cos(f * Math.PI / 180) * Math.sin(e / 2) * Math.sin(e / 2);
            var n = 2 * Math.atan2(Math.sqrt(o), Math.sqrt(1 - o));
            var k = h * n;
            return Math.round(k * 10) / 10
        };
    jQuery("#mapform").submit(function (g) {
        g.preventDefault();
        var h = jQuery("#city").val(),
            f = jQuery("#state").val();
        zipcode = jQuery("#zipcode").val(), rdist = jQuery('input[name="radius"]:checked', "#mapform").val();
        success = function (j) {
            var i = [],
                k = new google.maps.LatLngBounds(),
                e = new google.maps.LatLng(j.origin.latitude, j.origin.longitude);
            for (store in j.stores) {
                i.push({
                    name: j.stores[store].title,
                    address: j.stores[store].street,
                    city: j.stores[store].city,
                    state: j.stores[store].state,
                    zipcode: j.stores[store].zipcode,
                    latitude: j.stores[store].latitude,
                    longitude: j.stores[store].longitude
                })
            }
            b.setCenter(e);
            b.setZoom(7);
            var l = a.apply(this, [b, i, e])
        };
        if (zipcode.length > 0 && zipcode != "Zip Code") {
            jQuery.ajax({
                url: d,
                type: "POST",
                dataType: "json",
                data: {
                    action: "genuine_store_locator_ajax_action",
                    genuine_store_locator_ajax_action: "genuine_store_locator_json_get_stores",
                    zipcode: zipcode,
                    radius: rdist
                },
                success: success
            })
        } else {
            if ((h.length > 0 && h != "City") || (f.length > 0 && f != "State")) {
                jQuery.ajax({
                    url: d,
                    type: "POST",
                    dataType: "json",
                    data: {
                        action: "genuine_store_locator_ajax_action",
                        genuine_store_locator_ajax_action: "genuine_store_locator_json_get_stores",
                        city: h,
                        state: f,
                        radius: rdist
                    },
                    success: success
                })
            }
        }
    })
};
