var map;
if (GBrowserIsCompatible()) {
    map = new GMap2(document.getElementById("global_map"));
}

var nowLoadingFlag = true;

function loadingImage() {
    if (!nowLoadingFlag) {
        hiddenLoadingImage();
    } else {
        visibleLoadingImage();
    }
}

function map_load(drag_disable){

    if (GBrowserIsCompatible()) {

    nowLoadingFlag = true;
        visibleLoadingImage();
    setInterval("loadingImage()", 500);

        lat = document.form1.LATITUDE.value * 1;
        lng = document.form1.LONGITUDE.value * 1;
        zoom = document.form1.ZOOM.value * 1;

        if (drag_disable != '1') {
            GEvent.addListener(map, 'moveend', function() {
              var center = map.getCenter();
              document.form1.LATITUDE.value  = center.lat();
              document.form1.LONGITUDE.value = center.lng();
              document.form1.ZOOM.value = map.getZoom();
              lat  = center.lat();
              lng  = center.lng();
              zoom = map.getZoom();
              document.form1.bounds.value = map.getBounds();
            });
            map.addControl(new GLargeMapControl());
            map.addControl(new GMapTypeControl());
        }
        
        map.setCenter(new GLatLng(lat, lng), zoom);
        
        if (typeof set_marker2 == "function") {
                set_marker2();
        }
//        if (typeof shopSearch == "function") {
//            shopSearch();
//        }

 
        // 20081215 ADD "zoom in/out function add with the mouse wheel." by S.Hojo // start 
        map.enableContinuousZoom();
        map.enableScrollWheelZoom();
        GEvent.addDomListener(map, "DOMMouseScroll", zoomByMousewheel);
        // 20081215 ADD "zoom in/out function add with the mouse wheel." by S.Hojo // end
    }
}

function set_marker(map_data) {
    var cnt = map_data.length;
    var icon = new Array(cnt);
    var latlng = new Array(cnt);
    var marker = new Array(cnt);
    var html_str;
    var caption;

    map.clearOverlays();
    for (i=0; i < cnt; i++) {
        icon[i] = new GIcon();
        icon[i].image  = "/images/common/pin_ctg" + map_data[i].category_id + "_" + (i+1) + ".gif";
        icon[i].shadow = "/images/common/pin_ctg" + map_data[i].category_id + "_" + (i+1) + ".gif";
        icon[i].iconSize   = new GSize(25, 32);
        icon[i].shadowSize = new GSize(25, 32);
        icon[i].iconAnchor = new GLatLng(32, 8);
        icon[i].infoWindowAnchor = new GLatLng(0, 12);
        latlng[i]  = new GLatLng(map_data[i].latitude, map_data[i].longitude);
        
        marker[i] = new GMarker(latlng[i],{
            icon: icon[i]
        });
        map.addOverlay(marker[i]);
        caption = document.getElementById("shop_info" + (i+1));
        marker_event(marker[i],caption);
    }
}

function marker_event(marker, caption) {
    GEvent.addListener(marker, "click", function() {
            marker.openInfoWindow(caption);
    });
}

function map_disp() {
    if (GBrowserIsCompatible()) {
        lat = document.form1.LATITUDE.value * 1;
        lng = document.form1.LONGITUDE.value * 1;
        zoom = document.form1.ZOOM.value * 1;
        map.setCenter(new GLatLng(lat, lng), zoom);
    }
}

// 20081215 ADD "zoom in/out function add with the mouse wheel." by S.Hojo // start 
function zoomByMousewheel(event) {

    if (window.event) {
        event.returnValue = false;
    }
    if (event.cancelable) {
        event.preventDefault();
    }

    if ((event.detail || -event.wheelDelta) < 0) {
        map.zoomIn();
    } else {
        map.zoomOut();
    }

    return false;
}
// 20081215 ADD "zoom in/out function add with the mouse wheel." by S.Hojo // end

