function Shops() {
  this.init.apply(this, arguments);
}

Shops.prototype = {
  init: function() {
    if (!GBrowserIsCompatible()) {
      return;
    }

    this.i       = 0;
    this.markers = new Array();
    this.shops   = new Array();
    this.isIE    = (document.documentElement.getAttribute('style') == document.documentElement.style);

    var map = new GMap2(document.getElementById('map'));
    map.addControl(new GLargeMapControl3D());
    map.addControl(new GScaleControl());
//  map.addControl(new GMapTypeControl());
    map.setCenter(new GLatLng(34.488448, 132.648926), 7, G_NORMAL_MAP);
    this.map = map;

    var copy = this;

    GDownloadUrl('gmap2/data.json', function(data, responseCode) {
      copy.shops = eval('('+data+')').shops;
      copy.draw_marker();
    });
  },

  draw_marker: function() {
    if (this.shops.length == this.i) {
      return;
    }

    var i      = this.i++;
    var shop   = this.shops[i];
    var point  = new GLatLng(parseFloat(shop.lat),parseFloat(shop.lng));
    var marker = new GMarker(point, {'title':shop.name});

    this.map.addOverlay(marker);

    GEvent.addListener(marker, 'click', function() {
      var em = document.createElement('em');
      em.appendChild(document.createTextNode(shop.name));

      var dl = document.createElement('dl');
      dl.setAttribute('id', 'infowindow');

      var dt = document.createElement('dt');
      dt.appendChild(document.createTextNode(shop.pref + ' '));
      dt.appendChild(em);
      dl.appendChild(dt);

      var dd1 = document.createElement('dd');
      dd1.appendChild(document.createTextNode('住所: ' + shop.address));
      dl.appendChild(dd1);

      var dd2 = document.createElement('dd');
      dd2.appendChild(document.createTextNode('TEL: ' + shop.phone));
      dl.appendChild(dd2);

      if (shop.open) {
        var dd3 = document.createElement('dd');
        dd3.appendChild(document.createTextNode('営業時間: ' + shop.open));
        dl.appendChild(dd3);
      }

      if (shop.car) {
        var dd4 = document.createElement('dd');
        dd4.appendChild(document.createTextNode('駐車場: ' + shop.car));
        dl.appendChild(dd4);
      }

      this.openInfoWindow(dl);
    });

    this.markers[i] = marker;

    return this.draw_next();
  },

  draw_next: function() {
    var copy = this;
    var next = function() { copy.draw_marker(); };

    setTimeout(next, 100);
  }
};

