function Route() {
  this.initialize.apply(this, arguments);
}

$.extend(Route.prototype, Basic, {

  name: "Route",
  content: '<div class="window"><dl><!--% if (data.route_category) { %--><dt><!--%= data.route_category %--> <!--%= data.route_name %--><br /><!--%= data.name %-->（<!--%= data.kana %-->）</dt><!--% } else { %--><dt><!--%= data.category %--> <!--%= data.name %--></dt><!--% } %--><dd><p><!--%= data.summary %--></p><!--% if (data.route_category) { %--><ul><li><a class="zoom" title="詳細／広域" href="#zoom" rel="zoom">詳細／広域</a>｜</li><li><a class="prev" title="前へ" href="#prev" rel="prev">前へ</a>｜</li><li><a class="next" title="次へ" href="#next" rel="next">次へ</a></li></ul><!--% } %--></dd></dl></div>',

  _create: function(data) {
    $.each(data, $.scope(this, function(index, route) {
      var markers = this._markers(route);
      var polyline = new google.maps.Polyline(
        $.map(markers, function(marker) { return marker.getLatLng(); }),
        route.color,
        route.weight,
        route.opacity,
        route.options
      );
      this.maps.addOverlay(polyline);
      this.getPolylines().push(polyline);
      polyline.markers = markers;
      google.maps.Event.addListener(polyline, "click", $.scope(this, function(point) {
        this.maps.openInfoWindow(point, $(this.content).evaluate(route).get(0), {
          maxWidth: 400
        });
      }));
    }));
  },

  _markers: function(route) {
    var markers = [];
    $.each(route.stations, $.scope(this, function(index, station) {
      var marker = new google.maps.Marker(new google.maps.LatLng(station.lat, station.lng), {
        icon: new google.maps.Icon({
          iconAnchor: new google.maps.Point(10, 10),
          iconSize: new google.maps.Size(20, 20),
          image: route.icon,
          infoWindowAnchor: new google.maps.Point(10, 0),
          mozPrintImage: route.icon.replace(/\.png$/i, "_print.gif"),
          printImage: route.icon.replace(/\.png$/i, "_print.gif")
        }),
        title: station.name
      });
      this.maps.addOverlay(marker);
      this.getMarkers().push(marker);
      markers.push(marker);
      if (!station.name) { marker.hide(); marker.show = function() {}; return; }

      var content = $(this.content).evaluate($.extend(station, {
        route_category: route.category,
        route_name: route.name
      }));
      if (!index || index >= route.stations.length - 1)
        content.find(index ? "a[rel=next]" : "a[rel=prev]").attr("rel", "disabled").addClass("disabled");
      content.find("a[rel]").click(this._events(markers, index));
      marker.window = new google.maps.InfoWindowTab(route.name, content.get(0));

      var equals = $.grep(this.getMarkers(), function(value) {
        return value.window && value.getLatLng().equals(marker.getLatLng());
      });
      $.each(equals, function(index, equal) {
        equal.bindInfoWindowTabs($.map(equals, function(equal) { return equal.window; }), {
          maxWidth: 400,
          selectedTab: index
        });
      });
      if (equals.length > 1) { marker.hide(); marker.show = function() {}; }
    }));
    return markers;
  },

  getAnchors: function() {
    return $.map(this.getPolylines(), $.scope(this, function(polyline, index) {
      var anchor = $('<a title="" href="#"><!--%= data.category %--> <!--%= data.name %--></a>').evaluate(this.data[index]);
      anchor.click(function() {
        google.maps.Event.trigger(polyline.markers[0], "click");
        return false;
      });
      anchor.css("display", "inline");
      return anchor;
    }));
  }

});