function mapp(a) {
    if (a.pois) {
        this.pois = a.pois
    } else {
        this.pois = new Array
    }
    this.editable = a.editable;
    this.size = a.size;
    this.width = parseInt(a.width);
    this.height = parseInt(a.height);
    this.zoom = parseInt(a.zoom);
    this.center = new GLatLng(parseFloat(a.centerLat), parseFloat(a.centerLng));
    this.addressFormat = a.addressFormat;
    this.defaultIcon = a.defaultIcon;
    this.mapname = a.mapname;
    this.mapDiv = document.getElementById(a.mapname);
    this.mapType = a.mapType;
    this.googlebar = a.googlebar;
    this.mapTypes = a.mapTypes;
    this.bigZoom = a.bigZoom;
    this.scrollWheelZoom = a.scrollWheelZoom;
    this.autoCenter = a.autoCenter;
    this.ui = new GMapUIOptions(new GSize(this.width, this.height));
    this.map;
    this.mapOptions = {};
    var b = this;
    if (document.all && window.attachEvent) {
        window.attachEvent("onload", function () {
            b.display();
            b.init()
        });
        window.attachEvent("onunload", GUnload)
    } else {
        if (window.addEventListener) {
            window.addEventListener("load", function () {
                b.display();
                b.init()
            }, false);
            window.addEventListener("unload", GUnload, false)
        }
    }
}
mapp.prototype = {
    display: function () {
        if (!GBrowserIsCompatible() || typeof(GMap2) == "undefined") {
            return
        }
        if (this.size && this.size != "CUSTOM") {
            this.width = mapSizes[this.size].width;
            this.height = mapSizes[this.size].height
        }
        this.mapOptions.size = new GSize(this.width, this.height);
        this.map = new GMap2(this.mapDiv, this.mapOptions);
        this.map.setCenter(new GLatLng(0, 0), 0);
        this.ui.controls.maptypecontrol = false;
        if (this.mapTypes == true) {
            this.ui.controls.menumaptypecontrol = true
        } else {
            this.ui.controls.menumaptypecontrol = false
        }
        if (this.bigZoom == true) {
            this.ui.controls.largemapcontrol3d = true;
            this.ui.controls.smallzoomcontrol3d = false
        } else {
            this.ui.controls.largemapcontrol3d = false;
            this.ui.controls.smallzoomcontrol3d = true
        }
        if (this.scrollWheelZoom == true) {
            this.ui.zoom.scrollwheel = true
        } else {
            this.ui.zoom.scrollwheel = false
        }
        this.map.setUI(this.ui);
        switch (this.mapType.toLowerCase()) {
        case "map":
            this.map.setMapType(G_NORMAL_MAP);
            break;
        case "satellite":
            this.map.setMapType(G_SATELLITE_MAP);
            break;
        case "hybrid":
            this.map.setMapType(G_HYBRID_MAP);
            break;
        case "terrain":
            this.map.setMapType(G_PHYSICAL_MAP);
            break
        }
        len = this.pois.length;
        for (var a = 0; a < len; a++) {
            this.addMarker(a)
        }
    },
    automaticCenter: function () {
        if (this.autoCenter == true || !this.center.lat() || !this.center.lng() || !this.zoom || this.pois.length == 0) {
            this.reCenter(null, true)
        } else {
            this.map.setCenter(this.center);
            this.map.setZoom(this.zoom)
        }
    },
    addMarker: function (d) {
        var c = {};
        if (this.pois[d].icon !== undefined && this.pois[d].icon != "") {
            c = {
                icon: mappIcons[this.pois[d].icon]
            }
        } else {
            if (this.defaultIcon !== undefined && this.defaultIcon != "") {
                c.icon = mappIcons[this.defaultIcon]
            }
        }
        if (this.editable) {
            c.draggable = true
        }
        var a = new GLatLng(this.pois[d].lat, this.pois[d].lng);
        var b = new GMarker(a, c);
        this.pois[d].marker = b;
        this.map.addOverlay(b);
        this.addMarkerEvents(d)
    },
    addMarkerEvents: function (b) {
        var c = this;
        var a = this.pois[b].marker;
        GEvent.clearListeners(a, "click");
        GEvent.addListener(a, "click", function () {
            c.renderMarker(b)
        });
        if (this.editable) {
            GEvent.addListener(a, "dragstart", function () {
                c.map.closeInfoWindow()
            });
            GEvent.addListener(a, "dragend", function (d) {
                c.pois[b].lat = d.lat();
                c.pois[b].lng = d.lng();
                c.renderMarker(b);
                c.listMarkers()
            })
        }
    },
    renderMarker: function (e, b) {
        var d;
        var a;
        if (this.pois[e].body == "undefined" || this.pois[e].body === undefined) {
            a = this.pois[e].address
        } else {
            a = this.pois[e].body
        }
        d = '<div class="mapp-overlay-div"><div class="mapp-overlay-title">' + this.pois[e].caption + '</div><div class="mapp-overlay-body">' + a + "</div>";
        if (this.editable == true) {
            var c = "<a href='#' onclick=\"editMap.editMarker('" + e + "'); return false;\" alt='" + mappressl10n.edit + "'>" + mappressl10n.edit + "</a> | <a href='#' onclick=\"editMap.deleteMarker('" + e + "'); return false;\">" + mappressl10n.del + "</a>";
            d += '<div class="mapp-overlay-edit">' + c + "</div>"
        }
        if (this.directions == true) {
            var f;
            switch (b) {
            case "to":
                f = mappressl10n.directions + ": <b>" + mappressl10n.to_here + '</b> - <a href="#" onclick="' + this.mapname + ".renderMarker(" + e + ", 'from'); return false;\" >" + mappressl10n.from_here + '</a><form onSubmit="return false"><input type="text" id="saddr" value="" /><input type="hidden" id="daddr" value="' + this.pois[e].corrected_address + '"/><input type="submit" onclick="' + this.mapname + '.directionsShow(form)" value="' + mappressl10n.go + '" /></form>';
                break;
            case "from":
                f = mappressl10n.directions + ': <a href="#" onclick="' + this.mapname + ".renderMarker(" + e + ", 'to'); return false\" >" + mappressl10n.to_here + "</a> - <b>" + mappressl10n.from_here + '</b><form onSubmit="return false"><input type="text" id="daddr" value="" /><input type="hidden" id="saddr" value="' + this.pois[e].corrected_address + '"/><input type="button" onclick="' + this.mapname + '.directionsShow(form)" value="' + mappressl10n.go + '" /></form>';
                break;
            default:
                f = '<a href="#" onclick="' + this.mapname + ".renderMarker(" + e + ", 'to'); return false;\" >" + mappressl10n.directions + "</a>"; + '<form onSubmit="return false"><input type="text" id="daddr" value="" /><input type="hidden" id="saddr" value="' + this.pois[e].corrected_address + '"/><input type="button" onclick="' + this.mapname + '.directionsShow(form)" value="' + mappressl10n.go + '" /></form>';
                break
            }
            d += '<div class="mapp-overlay-directions">' + f + "</div>"
        }
        if (this.streetview == true) {
            d += '<a href="#" onclick="' + this.mapname + ".streetviewShow(" + e + '); return false">' + mappressl10n.street_view + "</a>"
        }
        d += "</div>";
        this.pois[e].marker.openInfoWindowHtml(d)
    },
    formatAddress: function (c) {
        var a = this.pois[c].address;
        var b = this.pois[c].corrected_address;
        switch (this.addressFormat) {
        case "ENTERED":
            return a;
            break;
        case "CORRECTED":
            if (b.lastIndexOf(", USA") > 0) {
                b = b.slice(0, b.lastIndexOf(", USA"))
            }
            var d = b.indexOf(",");
            if (d > 0) {
                return b.slice(0, d) + "<br/>" + b.slice(d + 2, b.length)
            } else {
                return b
            }
            break;
        default:
            return a;
            break
        }
    },
    reCenter: function (e, c) {
        var b;
        var d;
        var f = new GLatLngBounds();
        this.map.closeInfoWindow();
        if (this.pois.length == 1) {
            e = 0
        }
        if (e != null) {
            b = this.pois[e].marker.getLatLng();
            f.extend(b);
            if (this.pois[e].boundsbox != undefined) {
                var a = this.pois[e].boundsbox;
                if (a.north != 0 && a.south != 0 && a.west != 0 && a.east != 0) {
                    f = new GLatLngBounds(new GLatLng(a.south, a.west), new GLatLng(a.north, a.east))
                }
            }
            d = this.map.getBoundsZoomLevel(f)
        } else {
            for (j = 0; j < this.pois.length; j++) {
                f.extend(this.pois[j].marker.getLatLng())
            }
            b = f.getCenter();
            d = this.map.getBoundsZoomLevel(f)
        }
        this.map.setCenter(b);
        if (c) {
            if (d > 15) {
                d = 15
            }
            this.map.setZoom(d)
        }
    }
};

function mappEdit(a) {
    mapp.call(this, a)
}
extendObject(mappEdit.prototype, mapp.prototype);
extendObject(mappEdit.prototype, {
    init: function () {
        var a = this;
        GEvent.addListener(this.map, "moveend", function () {
            a.center = a.map.getCenter();
            jQuery("#mapp_center_lat").val(a.center.lat());
            jQuery("#mapp_center_lng").val(a.center.lng())
        });
        GEvent.addListener(this.map, "zoomend", function () {
            a.zoom = a.map.getZoom();
            jQuery("#mapp_zoom").val(a.zoom)
        });
        GEvent.addListener(this.map, "maptypechanged", function () {
            a.mapType = a.map.getCurrentMapType().getName();
            jQuery("#mapp_maptype").val(a.mapType)
        });
        this.automaticCenter();
        if (this.editable == true) {
            this.listMarkers()
        }
    },
    addPOI: function (b) {
        this.pois.push(b);
        var a = this.pois.length - 1;
        this.pois[a].caption = "";
        this.pois[a].body = this.formatAddress(a);
        this.addMarker(a);
        editMap.listMarkers();
        this.reCenter(a, true);
        this.renderMarker(a);
        return a
    },
    editMarker: function (b) {
        var c = this.map.getSize().width * 0.8;
        var a = '<div style="text-align: left; width: ' + c + 'px">' + mappressl10n.title + ': <input type="text" id="markerCaption" rows="2" style="width: 90%" value="' + this.escapeQuotes(this.pois[b].caption) + '" /><br/><textarea id="markerBody" rows="5" cols="120" style="max-width:100%">' + this.pois[b].body + '</textarea><br/><input type="button" name="saveEditMarker" value="' + mappressl10n.save + '" onclick="editMap.saveEditMarker(\'' + b + '\')" /><input type="button" name="cancelEditMarker" value="' + mappressl10n.cancel + '" onclick="editMap.cancelEditMarker(\'' + b + "')\" /></div>";
        this.pois[b].marker.openInfoWindowHtml(a)
    },
    saveEditMarker: function (c) {
        var b = jQuery("#markerCaption").val();
        var a = jQuery("#markerBody").val();
        this.pois[c].caption = b;
        this.pois[c].body = a;
        this.addMarkerEvents(c);
        this.renderMarker(c);
        this.listMarkers()
    },
    cancelEditMarker: function (a) {
        this.renderMarker(a)
    },
    listMarkers: function () {
        var c, a;
        c = '<table id="mapp_poi_table" style="width: 100%;"> \r\n<tbody>';
        for (var b = 0; b < this.pois.length; b++) {
            c += '<tr style="padding: 0 0 0 0"><td style="width: 80%"><a id="mapp_poi_label" name="mapp_poi_label" style="width:90%; margin 0 0 0 0;" href="#" onclick="editMap.renderMarker(' + b + '); return false;">';
            if (this.pois[b].caption != "") {
                c += this.pois[b].caption + ": " + this.pois[b].corrected_address
            } else {
                c += this.pois[b].corrected_address
            }
            c += "</a>";
            if (!this.pois[b].boundsbox) {
                this.pois[b].boundsbox = {
                    north: 0,
                    south: 0,
                    west: 0,
                    east: 0
                }
            }
            c += '<input type="hidden" name="mapp_poi_address[]" value="' + this.pois[b].address + '"/>';
            c += '<input type="hidden" name="mapp_poi_caption[]" value="' + this.escapeQuotes(this.pois[b].caption) + '"/>';
            c += '<textarea style="display:none" name="mapp_poi_body[]">' + this.pois[b].body + "</textarea>";
            c += '<input type="hidden" name="mapp_poi_corrected_address[]" value="' + this.pois[b].corrected_address + '"/>';
            c += '<input type="hidden" name="mapp_poi_lat[]" size="15" value="' + this.pois[b].lat + '"/>';
            c += '<input type="hidden" name="mapp_poi_lng[]" size="15" value="' + this.pois[b].lng + '"/>';
            c += '<input type="hidden" name="mapp_poi_boundsbox_north[]" size="15" value="' + this.pois[b].boundsbox.north + '"/>';
            c += '<input type="hidden" name="mapp_poi_boundsbox_south[]" size="15" value="' + this.pois[b].boundsbox.south + '"/>';
            c += '<input type="hidden" name="mapp_poi_boundsbox_east[]" size="15" value="' + this.pois[b].boundsbox.east + '"/>';
            c += '<input type="hidden" name="mapp_poi_boundsbox_west[]" size="15" value="' + this.pois[b].boundsbox.west + '"/>';
            c += "</td></tr>"
        }
        c += "</tbody></table>";
        jQuery("#admin_poi_div").html(c)
    },
    escapeQuotes: function (a) {
        return a.replace(/"/g, "&quot;");
        return a.replace(/'/g, "&apos;")
    },
    deleteMarker: function (b) {
        var a = confirm(mappressl10n.delete_this_marker);
        if (!a) {
            return
        }
        this.map.closeInfoWindow();
        this.map.removeOverlay(this.pois[b].marker);
        this.pois.splice(b, 1);
        this.listMarkers();
        for (var b = 0; b < this.pois.length; b++) {
            this.addMarkerEvents(b)
        }
    },
    reSize: function (b, c, a) {
        if (b && b != "CUSTOM") {
            c = mapSizes[b].width;
            a = mapSizes[b].height
        }
        this.mapDiv.style.width = c;
        this.mapDiv.style.height = a;
        if (this.map) {
            this.map.checkResize()
        }
        this.size = b;
        this.width = c;
        this.height = a;
        this.reCenter(null, true)
    }
});

function mappDisplay(a) {
    this.initialOpenInfo = a.initialOpenInfo;
    this.directions = a.directions;
    this.traffic = 0;
    this.streetview = 0;
    if (this.googlebar == true) {
        this.mapOptions = {
            googleBarOptions: {
                style: "new",
                adsOptions: {
                    client: "partner-pub-4213977717412159",
                    channel: "mappress",
                    adsafe: "high"
                }
            }
        }
    }
    mapp.call(this, a)
}
extendObject(mappDisplay.prototype, mapp.prototype);
extendObject(mappDisplay.prototype, {
    init: function () {
        this.automaticCenter();
        if (this.streetview) {
            this.streetDiv = document.getElementById(this.mapname + "_street_div");
            this.streetOuterDiv = document.getElementById(this.mapname + "_street_outer_div");
            this.streetviewPanorama
        }
        if (this.directions) {
            this.directionsDiv = document.getElementById(this.mapname + "_directions_div");
            this.directionsOuterDiv = document.getElementById(this.mapname + "_directions_outer_div");
            this.saddr = document.getElementById(this.mapname + "_saddr");
            this.daddr = document.getElementById(this.mapname + "_daddr");
            this.saddrCorrected = document.getElementById(this.mapname + "_saddr_corrected");
            this.daddrCorrected = document.getElementById(this.mapname + "_daddr_corrected");
            this.GDirections = new GDirections(this.map, this.directionsDiv);
            GEvent.addListener(this.GDirections, "error", function () {
                switch (this.getStatus().code) {
                case 400:
                    alert(mappressl10n.dir_400);
                    break;
                case 500:
                    alert(mappressl10n.dir_500);
                    break;
                case 601:
                    alert(mappressl10n.dir_601);
                    break;
                case 602:
                    alert(mappressl10n.dir_602);
                    break;
                case 603:
                    alert(mappressl10n.dir_603);
                    break;
                case 604:
                    alert(mappressl10n.dir_604);
                    break;
                case 610:
                    alert(mappressl10n.dir_610);
                    break;
                case 620:
                    alert(mappressl10n.dir_620);
                    break;
                default:
                    alert(mappressl10n.dir_default) + getStatus().code;
                    break
                }
            })
        }
        if (this.googlebar == true) {
            this.map.enableGoogleBar()
        }
        if (this.traffic == true) {
            if (this.mapTypes == true) {
                this.map.addControl(new ExtMapTypeControl({
                    showMapTypes: false,
                    posRight: 100,
                    showTraffic: true,
                    showTrafficKey: true,
                    showMore: false
                }))
            } else {
                this.map.addControl(new ExtMapTypeControl({
                    showMapTypes: false,
                    posRight: 10,
                    showTraffic: true,
                    showTrafficKey: true,
                    showMore: false
                }))
            }
        }
        if (this.initialOpenInfo == true) {
            GEvent.trigger(this.pois[0].marker, "click")
        }
    },
    directionsShow: function (b) {
        this.streetviewClose();
        this.directionsClose();
        this.map.closeInfoWindow();
        for (var a = 0; a < this.pois.length; a++) {
            this.pois[a].marker.hide()
        }
        this.saddr.value = b.saddr.value;
        this.daddr.value = b.daddr.value;
        this.directionsOuterDiv.style.display = "block";
        this.directionsGet()
    },
    directionsGet: function () {
        this.saddr.className = "mapp-address";
        this.daddr.className = "mapp-address";
        if (!this.saddr.value || this.saddr.value == "") {
            this.saddr.className = "mapp-address-error";
            this.saddrCorrected.innerHTML = mappressl10n.enter_address;
            return
        }
        if (!this.daddr.value || this.daddr.value == "") {
            this.daddr.className = "mapp-address-error";
            this.daddrCorrected.innerHTML = mappressl10n.enter_address;
            return
        }
        var a = this;
        mappGeocoder.getLocations(this.saddr.value, function (b) {
            a.addressCheck(b, a.saddr, a.saddrCorrected, "saddr");
            mappGeocoder.getLocations(a.daddr.value, function (c) {
                a.addressCheck(c, a.daddr, a.daddrCorrected, "daddr");
                a.GDirections.load("from: " + a.saddr.value + " to: " + a.daddr.value)
            })
        })
    },
    addressCheck: function (a, e, d, c) {
        if (a == null || a.Placemark == null || a.Status.code != 200) {
            e.className = "mapp-address-error";
            d.innerHTML = mappressl10n.no_address;
            return false
        }
        if (a.Placemark.length > 1) {
            var b = a.Placemark[0].address;
            d.innerHTML = mappressl10n.did_you_mean + "<a href='#' onclick='" + this.mapname + '.addressAccept("' + c + '", "' + b + "\"); return false;'>" + b + "</a>";
            e.className = "mapp-address-error";
            return false
        }
        e.value = a.Placemark[0].address;
        d.innerHTML = "";
        d.className = "mapp-address";
        return true
    },
    addressAccept: function (b, a) {
        if (b == "saddr") {
            this.saddr.value = a;
            this.saddrCorrected.innerHTML = "";
            this.saddr.className = "mapp-address"
        } else {
            this.daddr.value = a;
            this.daddrCorrected.innerHTML = "";
            this.daddr.className = "mapp-address"
        }
        this.directionsGet()
    },
    directionsPrint: function () {
        var c = document.getElementById(this.mapname + "_saddr");
        var b = document.getElementById(this.mapname + "_daddr");
        var a = "http://maps.google.com";
        a += "?daddr=" + b.value;
        a += "&saddr=" + c.value;
        a += "&pw=2";
        window.open(a)
    },
    directionsClose: function () {
        if (this.GDirections) {
            this.GDirections.clear()
        }
        this.directionsOuterDiv.style.display = "none";
        for (var a = 0; a < this.pois.length; a++) {
            this.pois[a].marker.show()
        }
        this.reCenter(null, true)
    },
    streetviewShow: function (b) {
        this.streetviewClose();
        this.GDirectionsClose();
        var a = {
            latlng: this.pois[b].marker.getLatLng()
        };
        this.streetviewPanorama = new GStreetviewPanorama(this.streetDiv, a);
        GEvent.addListener(this.streetviewPanorama, "error", this.streetviewError);
        this.streetOuterDiv.style.display = "block"
    },
    streetviewClose: function () {
        if (this.streetviewPanorama) {
            this.streetviewPanorama.remove()
        }
        if (this.streetOutderDiv) {
            this.streetOuterDiv.style.display = "none"
        }
    },
    streetviewError: function (a) {
        switch (a) {
        case 603:
            alert(mappressl10n.street_603);
            break;
        case 600:
            alert(mappressl10n.street_600);
            break;
        default:
            alert(mappressl10n.street_default);
            break
        }
    }
});

function extendObject(a, c) {
    for (var b in c) {
        a[b] = c[b]
    }
    return a
};