
var icon = Array();
icon[0] = new GIcon();
icon[0].image = "./img/busstop1.png";
icon[0].iconSize = new GSize(30,30);
icon[0].iconAnchor = new GLatLng(15,15);
icon[0].infoWindowAnchor = new GLatLng(15,15);

icon[1] = new GIcon();
icon[1].image = "./img/busstop2.png";
icon[1].iconSize = new GSize(30,30);
icon[1].iconAnchor = new GLatLng(15,15);
icon[1].infoWindowAnchor = new GLatLng(15,15);

icon[2] = new GIcon();
icon[2].image = "./img/busstop3.png";
icon[2].iconSize = new GSize(30,30);
icon[2].iconAnchor = new GLatLng(15,15);
icon[2].infoWindowAnchor = new GLatLng(15,15);

icon[3] = new GIcon();
icon[3].image = "./img/busstop4.png";
icon[3].iconSize = new GSize(30,30);
icon[3].iconAnchor = new GLatLng(15,15);
icon[3].infoWindowAnchor = new GLatLng(15,15);

icon[4] = new GIcon();
icon[4].image = "./img/busstop5.png";
icon[4].iconSize = new GSize(30,30);
icon[4].iconAnchor = new GLatLng(15,15);
icon[4].infoWindowAnchor = new GLatLng(15,15);

icon[5] = new GIcon();
icon[5].image = "./img/busstop6.png";
icon[5].iconSize = new GSize(30,30);
icon[5].iconAnchor = new GLatLng(15,15);
icon[5].infoWindowAnchor = new GLatLng(15,15);

icon[6] = new GIcon();
icon[6].image = "./img/busstop7.png";
icon[6].iconSize = new GSize(30,30);
icon[6].iconAnchor = new GLatLng(15,15);
icon[6].infoWindowAnchor = new GLatLng(15,15);

icon[7] = new GIcon();
icon[7].image = "./img/busstop8.png";
icon[7].iconSize = new GSize(30,30);
icon[7].iconAnchor = new GLatLng(15,15);
icon[7].infoWindowAnchor = new GLatLng(15,15);

icon[8] = new GIcon();
icon[8].image = "./img/busstop9.png";
icon[8].iconSize = new GSize(30,30);
icon[8].iconAnchor = new GLatLng(15,15);
icon[8].infoWindowAnchor = new GLatLng(15,15);


var map = new GMap2(document.getElementById("map"));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.addControl(new GScaleControl(300));
map.setCenter(new GLatLng(34.69250925878805,135.5002212524414), 14);
map.enableContinuousZoom();
map.enableDoubleClickZoom();

var opt = map.getInfoWindow();
opt.maxWidth = 200;

var busstop_html = "";
var gmarkers = [];
var htmls = [];
var i = 0;

//addRule();

function createMarker(point,name,html, n) {

	var html = html + "<p><a href='javascript:myclick("+[i-1]+");'>前へ<\/a>&nbsp;<a href='javascript:myclick("+[i+1]+");'>次へ<\/a><\/p>";

	var ii=i;
	var marker = new GMarker(point, {icon : icon[n],title:name});
	GEvent.addListener(marker, "click", function() {
		pickup2('stop'+ii);
		map.setZoom(17);
		marker.openInfoWindowHtml(html, opt);
	});
	gmarkers[i] = marker;
	htmls[i] = html;

	busstop_html += '<li id="stop'+i+'"><a href="javascript:pickup2(\'stop'+i+'\');myclick(' + i + ')">' + name + '<\/a></li>';
	i++;
	return marker;
}
function myclick(i) {
	map.setZoom(17);
	if(gmarkers[i]==null){
		alert('駅がありません');
	}else{
		pickup2('stop'+i);
		gmarkers[i].openInfoWindowHtml(htmls[i], opt);
	}
}

function readMap(url) {
	var request = GXmlHttp.create();
	request.open("GET", url, true);
	request.onreadystatechange = function() {
		if (request.readyState == 4) {
			var xmlDoc = request.responseXML;
			var markers = xmlDoc.documentElement.getElementsByTagName("marker");
			map.getInfoWindow().hide();
			map.clearOverlays();
			map.setZoom(13);
			gmarkers = [];
			busstop_html="<ol>\n";


			var cnt = xmlDoc.documentElement.getElementsByTagName("cnt");
			for (var i=0;i<cnt.length;i++) {
				var lat = parseFloat(cnt[i].getAttribute("lat"));
				var lng = parseFloat(cnt[i].getAttribute("lng"));
				var zoom = parseFloat(cnt[i].getAttribute("zoom"));
				map.setCenter(new GLatLng(lat,lng), zoom);
			}

			for (var i=0;i<markers.length;i++) {
				var lat = parseFloat(markers[i].getAttribute("lat"));
				var lng = parseFloat(markers[i].getAttribute("lng"));
				var point = new GLatLng(lat,lng);
				var html = markers[i].getAttribute("html");
				var label = markers[i].getAttribute("label");
				var n = markers[i].getAttribute("n");
				var marker = createMarker(point, label, html, n);
				map.addOverlay(marker);
			}
			busstop_html +="</ol>\n";
			document.getElementById("BusStop").innerHTML = busstop_html;

			var lines = xmlDoc.documentElement.getElementsByTagName("line");
			for (var a = 0; a < lines.length; a++) {
				var color = lines[a].getAttribute("color");
				var width  = parseFloat(lines[a].getAttribute("width"));
				var opacity  = parseFloat(lines[a].getAttribute("opacity"));
				var points = lines[a].getElementsByTagName("point");
				var pts = [];
				for (var i = 0; i < points.length; i++) {
					pts[i] = new GLatLng(parseFloat(points[i].getAttribute("lat")), parseFloat(points[i].getAttribute("lng")));
				}
				map.addOverlay(new GPolyline(pts,"#000000",6,1.0));
				map.addOverlay(new GPolyline(pts, color, width, opacity));
			}
		}
	}
    request.send(null);
}


function SchoolShow(){
//	map.getInfoWindow().hide();
//	map.clearOverlays();
	map.setCenter(new GLatLng(34.680334766637465,135.1196050643921), 17);
}
function pickup(str){
	map.closeInfoWindow();
	var routes = document.documentElement.getElementsByTagName("li");
	for (var a = 0; a < routes.length; a++) {
		var route = routes[a].getAttribute("id");
		if(route != null){
			if(route.substr(0,5) == 'route'){
				if(route == str){
					document.getElementById(route).className='RouteChk';
				}else{
					document.getElementById(route).className='';
				}
			}
		}
	}
}
function pickup2(str){
	map.closeInfoWindow();
	var stops = document.documentElement.getElementsByTagName("li");
	for (var a = 0; a < stops.length; a++) {
		var stop = stops[a].getAttribute("id");
		if(stop != null){
			if(stop.substr(0,4) == 'stop'){
				if(stop == str){
					document.getElementById(stop).className='StopChk';
				}else{
					document.getElementById(stop).className='';
				}
			}
		}
	}
}

function addRule(sheetindex, ruleindex ) {
  if( sheetindex == undefined ) sheetindex = 0;
  var sheet = document.styleSheets[ sheetindex ];
/*
  if( sheet.addRule ) { //IE
      if( ruleindex == undefined ) ruleindex = sheet.rules.length;
      sheet.addRule( "#map img", "{filter: alpha(opacity=75)}", ruleindex );
  }
  else
*/
	if( sheet.insertRule ) { //Mozilla
      if( ruleindex == undefined ) ruleindex = sheet.cssRules.length;
      sheet.insertRule( "#map div div div div.gmnoprint img" + "{-moz-opacity:0.75}", ruleindex );
  }
}


