//<![CDATA[
    var ICONS = [];
    var map = null;
    var geocoder = null;
    var center_marker = null;

    function load() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));
        center = new GLatLng(35.690921, 139.700258);
        map.setCenter(center, 13);
        map.addControl(new GLargeMapControl());
        map.addControl(new GOverviewMapControl());
        map.addControl(new GMapTypeControl());
        map.addControl(new GScaleControl());
        center_marker = createCenterMarker(center);
		map.enableDoubleClickZoom();
		map.enableContinuousZoom();
        geocoder = new GClientGeocoder();

		if( navigator.userAgent.match( "MSIE" ) ){ document.getElementById( "map" ).attachEvent( "onmousewheel" , mouseWheelZooming ); }
		if( navigator.userAgent.match( "Gecko" ) ){ document.getElementById( "map" ).addEventListener( "DOMMouseScroll" , mouseWheelZooming , false ); }
		if( navigator.userAgent.match( "Safari" ) ){ document.getElementById( "map" ).onmousewheel = mouseWheelZooming; }
      }
    }
	
	function getLatLng(address, func) {
      if (geocoder) {
		geocoder.getLatLng(address,func);
      }
    }
	
    function getIcon(type) {
    	index = 0;
    	img = "";
		if (type == "eikoh") {
			index = "0";
			img = "icon/icon_e.png";
		} else if (type == "visavis"){
			index = "1";
			img = "icon/icon_v.png";
		} else {
			index = "2";
			img = "icon/icon_n.png";
		}
    	if (!ICONS[index]) {
			var icon = new GIcon();
			icon.image = img;
			icon.iconAnchor = new GPoint(4, 26);
			icon.infoWindowAnchor = new GPoint(4, 0);
			icon.iconSize = new GSize(29, 31);
			icon.shadow = "icon/shadow.png";
			icon.shadowSize = new GSize(29, 31);
			ICONS[index] = icon;
		}
		return ICONS[index];
    }
    
    function MakeName(name, type) {
		if (type == "eikoh") {
			name = "栄光ゼミナール"+name;
		} else if (type == "visavis"){
			name = "栄光"+name;
		} else if (type == "navio"){
			name = "栄光ナビオ"+name;
		} else {
			name = "栄光"+name;
		}
		return name;
    }
    
	function createCenterMarker(point) {
		var icon = new GIcon();
		icon.image = "icon/green_arrow.png";
		icon.iconAnchor = new GPoint(11, 33);
		icon.iconSize = new GSize(39,34);
		marker = new GMarker(point, {icon: icon});
		map.addOverlay(marker);
		return marker;
	}

    function createMarker(lat, lng, name, address, phone, url, id, type) {
		var point = new GLatLng(lat, lng);
		var marker = new GMarker(point, {icon: getIcon(type), title: id});
		name = MakeName(name, type);
		var f = function() {
			r = makeInfoWindowHTML(name, address, phone, url, id);
			marker.openInfoWindowHtml(r);
		};
	  GEvent.addListener(marker, "click", f);
	  return marker;
	}
	
    function makeInfoWindowHTML(name, address, phone, url, id) {
    	r = '<table width=220 border=0><tr><td><center><b><a href="detail.php?id='+id+'">' + name + "</a></b><br>電話：" + phone + "<br>住所：" + address + '<br></center><div align="right"><a href="detail.php?id='+id+'">詳細ページへ</a></div></td></tr></table>';
    	return r;
    }

	function mouseWheelZooming( event ){
		if( navigator.userAgent.match( "MSIE" ) ){ var delta = -1*event.wheelDelta; event.returnValue = false; } //IE
		if( navigator.userAgent.match( "Gecko" ) ){ var delta = event.detail; event.preventDefault(); } //Gecko
		if( navigator.userAgent.match( "Safari" ) ){ var delta = -1*event.wheelDelta; event.returnValue = false; } //Safari
		map.setZoom( map.getZoom() + ( delta < 0 ? 1 : -1 ) );
	}
	
	function ShowMarker(id) {
		for (i = 0; i < markers.length; i++) {
			if (markers[i].getTitle() == id) {
			
				name = MakeName(infos[id]['NAME'], infos[id]['TYPE']);
		      	r = makeInfoWindowHTML(name, infos[id]['ADDRESS'], infos[id]['TEL'], '', id);
				markers[i].openInfoWindowHtml(r);
			}
		}
	}	
//]]>

