var map;

window.onload = function(){
    
    map = new GMap2(document.getElementById("map"));
    map.setCenter(new GLatLng(36.28350, 139.87784), 16);
    map.addControl(new GSmallMapControl());
    //map.addControl(new GSmallZoomControl());
    //map.addControl(new GMapTypeControl());
    
    infoHtml = document.getElementById("infobox");
        

    //鹿窪運動公園のマーキングと情報ウインドウの処理

    kanakubo_maker = new GMarker(new GLatLng(36.28260, 139.8787));
    map.addOverlay(kanakubo_maker);
    openIWindow();



    //施設のエリアマーキング
    
    stadium_SW = new GLatLng(36.28074, 139.87615);
    stadium_NE = new GLatLng(36.28182, 139.87754);
    stadium_img = new GGroundOverlay("../img/gm_stadium.gif",new GLatLngBounds(stadium_SW,stadium_NE));
    
    tamokuteki_SW = new GLatLng(36.27886, 139.87478);
    tamokuteki_NE = new GLatLng(36.28044, 139.87640);
    tamokuteki_img = new GGroundOverlay("../img/gm_tamokuteki.gif",new GLatLngBounds(tamokuteki_SW,tamokuteki_NE));
    
    dai2_SW = new GLatLng(36.28154, 139.87752);
    dai2_NE = new GLatLng(36.28190, 139.87800);
    dai2_img = new GGroundOverlay("../img/gm_dai2.gif",new GLatLngBounds(dai2_SW,dai2_NE));

    budokan_SW = new GLatLng(36.28178, 139.87810);
    budokan_NE = new GLatLng(36.28202, 139.87855);
    budokan_img = new GGroundOverlay("../img/gm_budokan.gif",new GLatLngBounds(budokan_SW,budokan_NE));

    gate_ball_SW = new GLatLng(36.28324, 139.87835);
    gate_ball_NE = new GLatLng(36.28364, 139.87950);
    gate_ball_img = new GGroundOverlay("../img/gm_gate_ball.gif",new GLatLngBounds(gate_ball_SW,gate_ball_NE));

    tennis_SW = new GLatLng(36.28303, 139.87675);
    tennis_NE = new GLatLng(36.28359, 139.87837);
    tennis_img = new GGroundOverlay("../img/gm_tennis.gif",new GLatLngBounds(tennis_SW,tennis_NE));



//施設名のマーキング
    
    t_budokan = new GIcon();
    t_budokan.image = "../img/t_budokan.gif";
    t_budokan.iconSize = new GSize(38,12);
    t_budokan.iconAnchor = new GPoint(19,6);
    t_budokan_maker = new GMarker(new GLatLng(36.28190, 139.87831),t_budokan);

    
    t_dai2 = new GIcon();
    t_dai2.image = "../img/t_dai2.gif";
    t_dai2.iconSize = new GSize(57,12);
    t_dai2.iconAnchor = new GPoint(28,6);
    t_dai2_maker = new GMarker(new GLatLng(36.28171, 139.87776),t_dai2);
    
    t_gate_ball = new GIcon();
    t_gate_ball.image = "../img/t_gate_ball.gif";
    t_gate_ball.iconSize = new GSize(86,12);
    t_gate_ball.iconAnchor = new GPoint(43,6);
    t_gate_ball_maker = new GMarker(new GLatLng(36.28345, 139.87895),t_gate_ball);
    
    t_kodomo = new GIcon();
    t_kodomo.image = "../img/t_kodomo.gif";
    t_kodomo.iconSize = new GSize(50,13);
    t_kodomo.iconAnchor = new GPoint(25,6);
    t_kodomo_maker = new GMarker(new GLatLng(36.27988, 139.87470),t_kodomo);
    
    t_mizu = new GIcon();
    t_mizu.image = "../img/t_mizu.gif";
    t_mizu.iconSize = new GSize(97,11);
    t_mizu.iconAnchor = new GPoint(48,5);
    t_mizu_maker = new GMarker(new GLatLng(36.28149, 139.87833),t_mizu);
    
    t_new_sports = new GIcon();
    t_new_sports.image = "../img/t_new_sports.gif";
    t_new_sports.iconSize = new GSize(71,24);
    t_new_sports.iconAnchor = new GPoint(35,12);
    t_new_sports_maker = new GMarker(new GLatLng(36.28284, 139.87710),t_new_sports);
    
    t_rinkan = new GIcon();
    t_rinkan.image = "../img/t_rinkan.gif";
    t_rinkan.iconSize = new GSize(50,13);
    t_rinkan.iconAnchor = new GPoint(25,6);
    t_rinkan_maker = new GMarker(new GLatLng(36.27933, 139.87375),t_rinkan);
    
    t_stadium = new GIcon();
    t_stadium.image = "../img/t_stadium.gif";
    t_stadium.iconSize = new GSize(38,12);
    t_stadium.iconAnchor = new GPoint(19,6);
    t_stadium_maker = new GMarker(new GLatLng(36.28125, 139.87686),t_stadium);
    
    t_tamokuteki = new GIcon();
    t_tamokuteki.image = "../img/t_tamokuteki.gif";
    t_tamokuteki.iconSize = new GSize(74,13);
    t_tamokuteki.iconAnchor = new GPoint(37,6);
    t_tamokuteki_maker = new GMarker(new GLatLng(36.27968, 139.87558),t_tamokuteki);
    
    t_tennis = new GIcon();
    t_tennis.image = "../img/t_tennis.gif";
    t_tennis.iconSize = new GSize(72,11);
    t_tennis.iconAnchor = new GPoint(36,6);
    t_tennis_maker = new GMarker(new GLatLng(36.28331, 139.87755),t_tennis);
    
    
//駐車場用アイコンのセッティング
        
    customMakerObj_02 = new GIcon();
    customMakerObj_02.image = "../img/p_icon_01.gif";
    customMakerObj_02.iconSize = new GSize(64,32);
    customMakerObj_02.iconAnchor = new GPoint(16,16);

    customMakerObj_03 = new GIcon();
    customMakerObj_03.image = "../img/p_icon_02.gif";
    customMakerObj_03.iconSize = new GSize(70,32);
    customMakerObj_03.iconAnchor = new GPoint(16,16);

    customMakerObj_04 = new GIcon();
    customMakerObj_04.image = "../img/p_icon_03.gif";
    customMakerObj_04.iconSize = new GSize(64,32);
    customMakerObj_04.iconAnchor = new GPoint(16,16);

    customMakerObj_05 = new GIcon();
    customMakerObj_05.image = "../img/p_icon_04.gif";
    customMakerObj_05.iconSize = new GSize(64,32);
    customMakerObj_05.iconAnchor = new GPoint(16,16);

    customMakerObj_06 = new GIcon();
    customMakerObj_06.image = "../img/p_icon_05.gif";
    customMakerObj_06.iconSize = new GSize(64,32);
    customMakerObj_06.iconAnchor = new GPoint(16,16);

    customMakerObj_07 = new GIcon();
    customMakerObj_07.image = "../img/p_icon_06.gif";
    customMakerObj_07.iconSize = new GSize(64,32);
    customMakerObj_07.iconAnchor = new GPoint(16,16);

    customMakerObj_08 = new GIcon();
    customMakerObj_08.image = "../img/p_icon_07.gif";
    customMakerObj_08.iconSize = new GSize(64,32);
    customMakerObj_08.iconAnchor = new GPoint(16,16);



    //駐車場マーキング

    parking01_maker = new GMarker(new GLatLng(36.28225, 139.87910),customMakerObj_02);
    parking02_maker = new GMarker(new GLatLng(36.28299, 139.87910),customMakerObj_03);
    parking03_maker = new GMarker(new GLatLng(36.28359, 139.87698),customMakerObj_04);
    parking04_maker = new GMarker(new GLatLng(36.28279, 139.87639),customMakerObj_05);
    parking05_maker = new GMarker(new GLatLng(36.28168, 139.87578),customMakerObj_06);
    parking06_maker = new GMarker(new GLatLng(36.28101, 139.87529),customMakerObj_07); 
    parking07_maker = new GMarker(new GLatLng(36.28064, 139.87530),customMakerObj_08);   



    //

    GEvent.addListener(map, "click", function(kanakubo_maker){
        openIWindow();
        }
    );

        
    GEvent.addListener(map, "zoomend", function(){
        var zm = map.getZoom();
        if (zm >=17){
                        showParking();
                    }
       else {           
                        hideParking();}
            }
    );
};       



    //

function showParking() {
    map.addOverlay(parking01_maker);
    map.addOverlay(parking02_maker);
    map.addOverlay(parking03_maker);
    map.addOverlay(parking04_maker);
    map.addOverlay(parking05_maker);
    map.addOverlay(parking06_maker);
    map.addOverlay(parking07_maker);
    map.addOverlay(stadium_img);
    map.addOverlay(tamokuteki_img);
    map.addOverlay(dai2_img);
    map.addOverlay(budokan_img);
    map.addOverlay(gate_ball_img);
    map.addOverlay(tennis_img);
    map.addOverlay(t_budokan_maker);
    map.addOverlay(t_dai2_maker);
    map.addOverlay(t_gate_ball_maker);
    map.addOverlay(t_kodomo_maker);
    map.addOverlay(t_mizu_maker);
    map.addOverlay(t_new_sports_maker);
    map.addOverlay(t_rinkan_maker);
    map.addOverlay(t_stadium_maker);
    map.addOverlay(t_tamokuteki_maker);
    map.addOverlay(t_tennis_maker);
};
    
function hideParking() {
    map.removeOverlay(parking01_maker);
    map.removeOverlay(parking02_maker);
    map.removeOverlay(parking03_maker);
    map.removeOverlay(parking04_maker);
    map.removeOverlay(parking05_maker);
    map.removeOverlay(parking06_maker);
    map.removeOverlay(parking07_maker);
    map.removeOverlay(stadium_img);
    map.removeOverlay(tamokuteki_img);
    map.removeOverlay(dai2_img);
    map.removeOverlay(budokan_img);
    map.removeOverlay(gate_ball_img);
    map.removeOverlay(tennis_img);
    map.removeOverlay(t_budokan_maker);
    map.removeOverlay(t_dai2_maker);
    map.removeOverlay(t_gate_ball_maker);
    map.removeOverlay(t_kodomo_maker);
    map.removeOverlay(t_mizu_maker);
    map.removeOverlay(t_new_sports_maker);
    map.removeOverlay(t_rinkan_maker);
    map.removeOverlay(t_stadium_maker);
    map.removeOverlay(t_tamokuteki_maker);
    map.removeOverlay(t_tennis_maker);
};
    
function openIWindow(){
    kanakubo_maker.openInfoWindowHtml(infoHtml);
    setTimeout("map.closeInfoWindow()",5000);
};

function mapChange(num) {
    
    var lv0 = document.getElementById('gnavi_lv0');
    var lv1 = document.getElementById('gnavi_lv1');
    var lv2 = document.getElementById('gnavi_lv2');
    
    var moveMap = [
        function(){map.setCenter(new GLatLng(36.29181, 139.87518), 14);
                   lv0.className = 'gnaviItem nowlv';
                   lv1.className = 'gnaviItem';
                   lv2.className = 'gnaviItem';
                   },
        function(){map.setCenter(new GLatLng(36.28350, 139.87784), 16);
                   lv0.className = 'gnaviItem';
                   lv1.className = 'gnaviItem nowlv';
                   lv2.className = 'gnaviItem';
                   },
        function(){map.setCenter(new GLatLng(36.2819, 139.87757), 17);
                   lv0.className = 'gnaviItem';
                   lv1.className = 'gnaviItem';
                   lv2.className = 'gnaviItem nowlv';
                   },
        ];
    moveMap[num]();
    
    if (num < 2){openIWindow();}
    
};