﻿//<![CDATA[
// グーグルマップ
var map = null;
var showed = false;
var isPrint = false;
var addedList = new Object();
var addedList2 = new Object();
var dataList = null;
var dataList2 = null;

var loadFlg = false;

// GMapの初期処理
function loadGMap(isPrintWindow)
{    
    isPrint = isPrintWindow;
    if (GBrowserIsCompatible())
    { 
        //alert(document.getElementById("map"));
        // ===== 基礎部分、setCenterで中心座標とズームレベルを指定 =====
        map = new GMap2(document.getElementById("map"));
        // ズームコントロール。Small で小型
        map.addControl(new GLargeMapControl());
        // 地図タイプ切り替え。Control(true)で小型 
        map.addControl(new GMapTypeControl()); 
        //  約北緯35度68分、約東経139度70分、ズームレベル10（最大は19）
        map.setCenter(new GLatLng(35.680161, 139.705395), 4); 
        // 縮尺 
        map.addControl(new GScaleControl()); 
        // ズームイベントをセットする。
        GEvent.addListener(map, "zoomend", function() { ZoomedEvent(); });
        GEvent.addListener(map, "dragend", function() { OnDragEnd(); });
        
        loadFlg = true;
        //alert(loadFlg);
    }
}

function OnDragEnd(){
    if(isPrint) return;
    dataShow(dataList);
    dataShow2(dataList2);
}

// *メソッドの名前を変更しないでください。*
// データ表示用
function dataShow(data)
{
    if(data == null || data == undefined || data.length == 0) return;
    // ズームレベルに達していないと、吹き出しを表示しない。
    // ズームレベルを変更時はここの数値を変更してください。
    if(dataList == null)
        dataList = data;
    
    if(showed == "true")
    {
        if(map.getZoom() < 10)
        {
            showed = "false";
            // オーバーレイを削除
            map.clearOverlays();
            addedList = new Object();
            return;
        }
        /*
        else
        {
            // 表示しているので、再表示をしない。
            return;
        }
        */
    }
    else
    {
        // 表示していない状態、
        // ズームレベルは10以下なら、returnする。
        if(map.getZoom() < 10) return;
    }    
    
    if (GBrowserIsCompatible())
    { 
        // ============アイコン指定=============
        /*var icon = Array();
        icon = new GIcon();
        icon.image = 'images/jtb_icon.png';
        icon.iconSize = new GSize( 16, 16 );	// 画像の大きさ
        icon.iconAnchor = new GPoint( 12, 20 );	// 画像の「基準点」
        icon.infoWindowAnchor = new GPoint( 0, 0 );	// 情報ウィンドウの基準点*/
        // ===== マーカーとフキダシ（変更不要） =====
        if(isPrint == false)
        {
            
            var bounds =  map.getBounds();
            for(i = 0; i < data.length; i++)
            {           
                var icon = makeShowIcon(data[i].Icon);               
                var point = new GLatLng(data[i].Latitude, data[i].Longitude);
                if(bounds.containsLatLng(point) && !addedList.hasOwnProperty(i)){
                    var marker = createMarker(point, data[i].Html, icon); //             
                    map.addOverlay(marker);
                    addedList[i] = true;     
                }
                //var marker = createMarker(point, data[i].Html, icon); //             
                //map.addOverlay(marker);            
            }
        }
        else
        {
            for(i = 0; i < data.length; i++)
            {           
                var icon = makeShowIcon(data[i].Icon);               
                var point = new GLatLng(data[i].Latitude, data[i].Longitude);
                var marker = createMarker2(point, data[i].Html, icon); //             
                map.addOverlay(marker);            
            }
        }
        showed = "true";        
    }    
}

function makeShowIcon(fileName)
{
    var icon = Array();
    icon = new GIcon();    
    icon.image = fileName;
    icon.iconSize = new GSize( 16, 16 );
    icon.iconAnchor = new GPoint( 12, 20 );
    icon.infoWindowAnchor = new GPoint( 0, 0 );
    
    return icon;
}

function createMarker(point, html, icon)
{
    var marker = new GMarker(point, icon);
    GEvent.addListener(marker, "click", function(){map.setCenter(point); marker.openInfoWindowHtml(html);});
    return marker;
}
// 印刷画面用
function createMarker2(point, html, icon)
{
    var marker = new GMarker(point, icon);
    return marker;
}


// 都道府県移動用メソッド
// lat: 緯度
// lon: 経度
// zoom: ズームレベル
function kenMove(lat, lon, zoom, id)
{    
    if(lat == "-1" || lon == "-1" || zoom == "-1") return;
    if (map != null)
    { 
        map.setCenter(new GLatLng(lat, lon), zoom); 
        dataShow(dataList);
        if(!isPrint) // 印刷の時は呼ばない。
            dataShow2(dataList2);
    }    
    if(id == "") return;      
    
    var linkObj = document.getElementById(id);
    var titleObj = document.getElementById("titile_blue");
    //[XXX] の検索結果
    if(linkObj != null && titleObj != null)
    {
        titleObj.innerHTML = "<span class=\"fontnormal howto white\"><a  href=\"javascript:;\" onclick=\"showMapManual('help.html')\">googleマップ使い方</a></span>" + "[" + linkObj.innerHTML + "] の検索結果";
    }
}
var cbInv = null;
function CallBackKenMove(lat, lon, zoom, id){
        
    if(map == null){    
        if(cbInv == null){            
             cbInv = setInterval(function(){CallBackKenMove(lat, lon, zoom, id);}, 100);
        }
    } else {
         
        if(loadFlg == true)
        {
            if(cbInv != null){           
                clearInterval(cbInv);
                cbInv = null;
                kenMove(lat, lon, zoom, id);
            }
            
        }
        
        return;
    }
}

// 印刷画面へ遷移するメソッド
// /*パラメータを変えないでください。*/
function myMiniwin(url, id, lat, lng){    
    url = url + "?shopid=" + id + "&lat=" + lat + "&lng=" + lng + "&zoom=" + map.getZoom() + "&from=fromIndex" + "&title=" + escape(document.getElementById("titile_blue").innerHTML);
    var subwin=window.open(url,"window1","width=750,height=600,toolbar=0,location=0,directories=0,status=1,scrollbars=1,resizable=1,menubar=0");
}
function SetPrefCode(code){
    var f = document.getElementById("form1");
    var a = f.action;
    a = a.replace(/\?.*/,"");
    f.action = a + "?Pref=" + code;
}


//]]>