/*
bar maps for googlemaps
*/
var infowindow;
var disp_html = null;
var geocoder;
var map;



function setBarMaps(first_lat, first_lng) {
  var myOptions = {
      zoom: 17,
      mapTypeId: google.maps.MapTypeId.ROADMAP
  };


  //緯度経度がない場合、銀座を表示する
  if (first_lat == 0 && first_lng == 0) {
    first_lat = 35.671989;
    first_lng = 139.76396499999998;
  }

  geocoder = new google.maps.Geocoder();
  map = new google.maps.Map($("bar_map"), myOptions);
  //地図の初期表示
  codeLatLng(new google.maps.LatLng(first_lat, first_lng), "base", null);
}




function codeLatLng(latLng, type, html) {
  geocoder.geocode({latLng: latLng}, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
      //地図の初期表示
      if (type == "base") {
        map.setCenter(results[0].geometry.location);
      }

      //マーカーの表示
      if (type == "marker") {
        var marker = new google.maps.Marker({
          map: map,
          position: results[0].geometry.location
        });

        google.maps.event.addListener(marker, "click", function() {
          fukidashi(results[0].geometry.location, html);
        });
      }
    }
  });
}


/*
function setBarMaps2() {

    var codeAddress = function(areaname) {
        if (geocoder) {
            geocoder.geocode({'address': areaname}, function(results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    map.setCenter(results[0].geometry.location);
                    marker = new google.maps.Marker({
                        map: map,
                        position: results[0].geometry.location
                    });

                    var htmlstr = "<div style='float:left;'>店舗名:" + areaname + "<br/>";
                        htmlstr += "住所:銀座4丁目<br/>";
                        htmlstr += "URL:http://ginza.com<br/>";
                        htmlstr += "TEL:03-1111-2222</div>";
                        htmlstr += "<div style='float:right;'><img src='http://www.logo1.biz/oa51.jpg' width='30'></div>";
                    var infowindow = new google.maps.InfoWindow({
                        content: htmlstr
                    });
                    infowindow.open(map,marker); 
                 
                        alert(results[0].geometry.location);

                } else {
                    alert("Geocode was not successfull for the following reason: " + status);
                }
            });
        }
    }

    var codeLatLng = function(latLng, type, html) {
      if (geocoder) {
        geocoder.geocode({latLng: latLng}, function(results, status) {
          if (status == google.maps.GeocoderStatus.OK) {
            //地図の初期表示
            if (type == "base") {
              map.setCenter(results[0].geometry.location);
            }

            //マーカーの表示
            if (type == "marker") {
              marker = new google.maps.Marker({
                map: map,
                position: results[0].geometry.location
              });

              google.maps.event.addListener(marker, "click", function() {
                fukidashi(results[0].geometry.location, html);
              });


            }

          }
        });
      }
    }




    var myOptions = {
        //zoom: 18,
        zoom: 15,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var marker = null;
    geocoder = new google.maps.Geocoder();
    map = new google.maps.Map($("bar_map"), myOptions);

    codeLatLng(new google.maps.LatLng(35.671989, 139.76396499999998), "base", null);

    var html = "<div style='float:left;'>築地<br/>";
    html += "中央区築地4丁目<br/>";
    html += "URL:http://tsukiji.com<br/>";
    html += "TEL:03-1111-2222</div>";
    html += "<div style='float:right;'><img src='http://www.logo1.biz/oa51.jpg' width='40'></div>";

    codeLatLng(new google.maps.LatLng(35.668115, 139.772603), "marker", html);

    var html = "<div style='float:left;'>有楽町<br/>";
    html += "有楽町3町目<br/>";
    html += "URL:http://yurakucho.com<br/>";
    html += "TEL:03-9999-8888</div>";
    html += "<div style='float:right;'><img src='http://www.logo1.biz/oe23.jpg' width='40'></div>";

    codeLatLng(new google.maps.LatLng(35.675069, 139.763328), "marker", html);


}
*/


function fukidashi(latLng, html) {
  //現在表示中と同じマーカーがクリックされた場合
  if (disp_html == html) return;

  if (infowindow) infowindow.close();
  map.setCenter(latLng);

  var marker = new google.maps.Marker({map: map, position: latLng });

  google.maps.event.addListener(marker, "click", function() { fukidashi(latLng, html); });

  infowindow = new google.maps.InfoWindow({ content: html });

  infowindow.open(map, marker);
  disp_html = html;
}

function setFukidashi(id) {
  fukidashi(latLng[id], local_fukidashi[id]);
}

