google.load("maps","3",{other_params:"sensor=true"});google.load("jquery","1.3.2");var map,map_wide,MAP_MAX_ZOOM=16,MAP_MIN_ZOOM=14,MAP_BACKGROUND_COLOR="#F2EFE9",requested_bounds=[],requested_zoom=[],markers=[],infowindows=[],spaceratio=[];spaceratio[11]=0.15;spaceratio[12]=0.2;spaceratio[13]=0.3;spaceratio[14]=0.3;spaceratio[15]=0.6;spaceratio[16]=0.8;spaceratio[17]=0.8;spaceratio[18]=0.8;var oshirase_guide_max_markers=[];oshirase_guide_max_markers[11]=40;oshirase_guide_max_markers[12]=25;
oshirase_guide_max_markers[13]=15;oshirase_guide_max_markers[14]=10;oshirase_guide_max_markers[15]=8;oshirase_guide_max_markers[16]=2;oshirase_guide_max_markers[17]=1;oshirase_guide_max_markers[18]=1;var iconsize=[];iconsize[11]=24;iconsize[12]=28;iconsize[13]=28;iconsize[14]=32;iconsize[15]=32;iconsize[16]=36;iconsize[17]=36;iconsize[18]=36;var oshirase_range=1200,oshirase_map_circle=null,params=getJsParam("map.js");params.lat-=0;params.lng-=0;params.zoom-=0;params.range-=0;
function initialize(){if(params.target!=undefined){if(params.oshirase=="true")MAP_MAX_ZOOM=14;if(params.station_id>0)params.lat+=0.0010;var a={backgroundColor:MAP_BACKGROUND_COLOR,center:new google.maps.LatLng(params.lat,params.lng),zoom:params.zoom,mapTypeId:google.maps.MapTypeId.ROADMAP,disableDefaultUI:true,scaleControl:true,disableDoubleClickZoom:true,scrollwheel:false,draggable:true};map=new google.maps.Map(document.getElementById(params.target),a);markers[map.getDiv().id]=[];infowindows[map.getDiv().id]=
[];if(document.getElementById("map_canvas_wide")!=null){a={backgroundColor:MAP_BACKGROUND_COLOR,center:new google.maps.LatLng(params.lat,params.lng),zoom:13,mapTypeId:google.maps.MapTypeId.ROADMAP,disableDefaultUI:true,disableDoubleClickZoom:true,scrollwheel:false,draggable:false};map_wide=new google.maps.Map(document.getElementById("map_canvas_wide"),a);markers[map_wide.getDiv().id]=[];infowindows[map_wide.getDiv().id]=[]}google.maps.event.addListener(map,"idle",function(){update_marker(map);updateHtmlZoomUI();
if(document.getElementById("map_canvas_wide")!=null){map_wide.setCenter(map.getCenter());update_marker(map_wide)}updateHtmlOshiraseGuide()});google.maps.event.addListener(map,"dblclick",function(){if(map.getZoom()<MAP_MAX_ZOOM){clear_all_marker();map_zoom_in()}});google.maps.event.addListener(map,"zoom_changed",function(){clear_all_marker()});google.maps.event.addListener(map,"dragstart",function(){close_all_infowindow()});google.maps.event.addListener(map,"click",function(){close_all_infowindow()});
params.station_id!=undefined&&params.admin!="true"&&log_stationpage_view(params.station_id,params.tab);params.production=="true"&&google.maps.event.addListener(map,"drag",function(){document.getElementById("map_forDev").innerHTML=map.getCenter()+map.getZoom()});params.admin=="true"&&admin_load();if(params.oshirase=="true"){oshirase_load();markers.oshirase=new google.maps.Marker({map:map,position:map.getCenter(),icon:"/img/map/marker/oshirase/marker.gif",zIndex:99999,draggable:true});if(params.oshirase_range!=
undefined)oshirase_range=params.oshirase_range;updateOshiraseMapCircle(map,markers.oshirase.getPosition(),oshirase_range);google.maps.event.addListener(markers.oshirase,"drag",function(){updateOshiraseMapCircle(map,markers.oshirase.getPosition(),oshirase_range)});google.maps.event.addListener(markers.oshirase,"position_changed",function(){updateOshiraseMapCircle(map,markers.oshirase.getPosition(),oshirase_range)});google.maps.event.addListener(markers.oshirase,"dragend",function(){updateHtmlOshiraseForm();
blinkOshiraseConfirmBotton()});updateHtmlOshiraseForm()}params.display_scalecontrol=="true"&&map.setOptions({navigationControl:true,scaleControl:true})}}
function update_marker(a){var d=a.getBounds(),b=d.getSouthWest().lat(),f=d.getNorthEast().lat(),e=d.getSouthWest().lng(),h=d.getNorthEast().lng(),g=f-b,k=h-e;$request_spaceratio=requested_bounds[a.getDiv().id]==undefined?0.05:spaceratio[a.getZoom()];b=b-g*$request_spaceratio;f=f+g*$request_spaceratio;e=e-k*$request_spaceratio;h=h+k*$request_spaceratio;k="/api/station?n="+b.toFixed(4)+"&s="+f.toFixed(4)+"&e="+e.toFixed(4)+"&w="+h.toFixed(4)+"&c="+params.company+"&a="+params.area;if(requested_bounds[a.getDiv().id]==
undefined||!requested_bounds[a.getDiv().id].contains(d.getNorthEast())||!requested_bounds[a.getDiv().id].contains(d.getSouthWest())||requested_zoom[a.getDiv().id]!=a.getZoom()){if(params.production=="true")document.getElementById("map_forDev").innerHTML="Requesting station data.";if(document.getElementById("map_updating")!=null)document.getElementById("map_updating").style.display="block";jQuery.ajax({type:"GET",url:k,dataType:"xml",timeout:15E3,success:function(l,j){parse_xml(l,j,a)},error:function(){if(document.getElementById("map_updating")!=
null)document.getElementById("map_updating").style.display="none";if(params.production=="true")document.getElementById("map_forDev").innerHTML="Can't recieve data."}});requested_bounds[a.getDiv().id]=new google.maps.LatLngBounds(new google.maps.LatLng(b,e),new google.maps.LatLng(f,h));requested_zoom[a.getDiv().id]=a.getZoom()}}
function parse_xml(a,d,b){if(params.production=="true")document.getElementById("map_forDev").innerHTML="Station data recieved.";var f=[],e=0,h=0;jQuery(a).find("st").each(function(){var g=$(this).find("i").text(),k=$(this).find("n").text(),l=$(this).find("t").text(),j=$(this).find("g").text();j=new google.maps.LatLng(l,j);l=$(this).find("s").text();var m=$(this).find("o").text();if(!(g in markers[b.getDiv().id])){if(b.getDiv().id!="map_canvas_wide"){if(g==params.station_id){m="/img/map/marker/yellow/"+
iconsize[b.getZoom()]+".png";markers[b.getDiv().id][g]=new google.maps.Marker({name:g,map:b,position:j,icon:m,title:k});j="";j+='<div class="mW-stationName">'+k+"</div>";j=j+'<div class="mW-box"><div class="mW-serviceName"><strong>'+l+"</strong>\u306e\u30ab\u30fc\u30b7\u30a7\u30a2\u30fb\u30b9\u30c6\u30fc\u30b7\u30e7\u30f3\u3067\u3059</div></div>"}else{m=m=="0"?"/img/map/marker/orange/"+iconsize[b.getZoom()]+".png":"/img/map/marker/orange/"+iconsize[b.getZoom()]+"_new.png";markers[b.getDiv().id][g]=
new google.maps.Marker({name:g,map:b,position:j,icon:m,title:k+"\n\uff08\u30af\u30ea\u30c3\u30af\u3059\u308b\u3068\u8a73\u7d30\u60c5\u5831\u3092\u3054\u78ba\u8a8d\u3044\u305f\u3060\u3051\u307e\u3059\uff09"});j="";j+='<div class="mW-stationName">'+k+"</div>";j=j+'<div class="mW-box"><div class="mW-serviceName"><strong>'+l+'</strong>\u306e\u30ab\u30fc\u30b7\u30a7\u30a2\u30fb\u30b9\u30c6\u30fc\u30b7\u30e7\u30f3\u3067\u3059</div><div class="mW-linkWrap"><a href ="/'+params.area+"/station/"+g+'" class="mW-more"></a></div></div><div class="mW-footnote">\u203b\u5468\u8fba\u306e\u8a73\u7d30\u5730\u56f3\u3068\u5951\u7d04\u30d7\u30e9\u30f3\u7b49\u3092\u3054\u78ba\u8a8d\u3044\u305f\u3060\u3051\u307e\u3059</div>'}infowindows[b.getDiv().id][g]=
new google.maps.InfoWindow({content:j,maxWidth:300});g==params.station_id&&infowindows[b.getDiv().id][g].open(b,markers[b.getDiv().id][g]);google.maps.event.addListener(markers[b.getDiv().id][g],"click",function(){close_all_infowindow();infowindows[b.getDiv().id][g].open(b,markers[b.getDiv().id][g]);log_infowindow_action(g,"open")});google.maps.event.addListener(infowindows[b.getDiv().id][g],"closeclick",function(){log_infowindow_action(g,"close")})}else if(g==params.station_id)markers[b.getDiv().id][g]=
new google.maps.Marker({name:g,map:b,position:j,icon:"/img/map/marker/yellow/24.png"});else markers[b.getDiv().id][g]=new google.maps.Marker({name:g,map:b,position:j,icon:"/img/map/marker/orange/20.png"});e++}f[g]=name;b.getDiv().id=="map_canvas"&&b.getBounds().contains(markers[b.getDiv().id][g].getPosition())==true&&h++});document.getElementById("map_oshirase_guide")!=null&&h<oshirase_guide_max_markers[b.getZoom()]&&blinkOshiraseGuideBotton();a=0;for(search_id in markers[b.getDiv().id])if(!(search_id in
f)){markers[b.getDiv().id][search_id].setMap(null);delete markers[b.getDiv().id][search_id];delete infowindows[b.getDiv().id][search_id];a++}if(document.getElementById("map_updating")!=null)document.getElementById("map_updating").style.display="none";if(params.production=="true")document.getElementById("map_forDev").innerHTML=b.getDiv().id+": "+e+" added. "+a+"deleted.";b.getDiv().id!="map_canvas_wide"&&b.getCenter().lat()!=params.lat&&b.getCenter().lng()!=params.lng&&log_current_position()}
function clear_all_marker(){for(keys in markers[map.getDiv().id]){markers[map.getDiv().id][keys].setMap(null);delete markers[map.getDiv().id][keys]}}function close_all_infowindow(){for(keys in infowindows[map.getDiv().id])infowindows[map.getDiv().id][keys].close()}
function moveTo(a,d,b,f,e){if(params.oshirase=="true"){markers.oshirase.setPosition(new google.maps.LatLng(d,b));updateHtmlOshiraseForm();f=14}close_all_infowindow();if(f!=map.getZoom()){map.setCenter(new google.maps.LatLng(d,b));map.setZoom(f)}else map.panTo(new google.maps.LatLng(d,b));if(e==undefined)e="";log_moveto(a,e)}
function searchByStationName(a,d){var b=document.getElementById("searchText").value;if(!b||!a||!d)quit();var f=a+" + "+b+" + \u99c5",e=new google.maps.Geocoder;e&&e.geocode({address:f,language:"japanese",region:"jp",latLng:map.getCenter()},function(h,g){if(g==google.maps.GeocoderStatus.OK)if(h[0].formatted_address.indexOf("\u99c5")!=-1&&h[0].formatted_address.indexOf(a)!=-1){moveTo(b,h[0].geometry.location.lat(),h[0].geometry.location.lng(),14,"search_by_railstationname");return}alert(d+"\u5185\u3067\u300c"+
b+"\u99c5\u300d\u3092\u898b\u3064\u3051\u3089\u308c\u307e\u305b\u3093\u3067\u3057\u305f\u3002\n\u4ed6\u306e\u304a\u8fd1\u304f\u306e\u99c5\u540d\u3067\u306e\u691c\u7d22\u3092\u304a\u9858\u3044\u3044\u305f\u3057\u307e\u3059\u3002\n\u30ab\u30fc\u30b7\u30a7\u30a2\u30fb\u30de\u30c3\u30d7");clicky.log("/"+params.area+"/#search_by_railstationname_failed","Search failed: "+b)})}
function mapUI(a){var d=map.getBounds(),b=d.getNorthEast().lat()-d.getSouthWest().lat();d=d.getNorthEast().lng()-d.getSouthWest().lng();b=b*0.25;d=d*0.25*0.75;if(a=="up"){map.setCenter(new google.maps.LatLng(map.getCenter().lat()+b,map.getCenter().lng()));var f="/"+params.area+"/#panto-up"}if(a=="down"){map.setCenter(new google.maps.LatLng(map.getCenter().lat()-b,map.getCenter().lng()));f="/"+params.area+"/#panto-down"}if(a=="left"){map.setCenter(new google.maps.LatLng(map.getCenter().lat(),map.getCenter().lng()-
d));f="/"+params.area+"/#panto-left"}if(a=="right"){map.setCenter(new google.maps.LatLng(map.getCenter().lat(),map.getCenter().lng()+d));f="/"+params.area+"/#panto-right"}if(a=="zoomin"){map_zoom_in();f="/"+params.area+"/#zoom-in"}if(a=="zoomout"){map_zoom_out();f="/"+params.area+"/#zoom-out"}clicky.log(f,"Map UI")}function map_zoom_in(){clear_all_marker();close_all_infowindow();map.setZoom(map.getZoom()+1)}
function map_zoom_out(){clear_all_marker();close_all_infowindow();map.setZoom(map.getZoom()-1)}
function updateHtmlZoomUI(){if(document.getElementById("mapZoom-in")!=null)if(map.getZoom()>=MAP_MAX_ZOOM)document.getElementById("mapZoom-in").style.display="none";else document.getElementById("mapZoom-in").style.display="block";if(document.getElementById("mapZoom-out")!=null)if(map.getZoom()<=MAP_MIN_ZOOM)document.getElementById("mapZoom-out").style.display="none";else document.getElementById("mapZoom-out").style.display="block"}
function log_moveto(a,d){if(d==undefined)d="";clicky.log("/"+params.area+"/#"+d,"Map move to: "+a)}
function log_current_position(){var a={lat:map.getCenter().lat().toFixed(4),lng:map.getCenter().lng().toFixed(4),zoom:map.getZoom()};log_send("position",a);a="/";if(params.area!="tokyo")a+=params.area+"/";if(params.company!="all")a+="company/"+params.company+"/";a+="?lat="+map.getCenter().lat().toFixed(4)+"&lng="+map.getCenter().lng().toFixed(4)+"&zoom="+map.getZoom();clicky.log(a,"Map position changed")}
function log_infowindow_action(a,d){d=="open"&&log_send("infowindow",{station_id:a,action:d});d="/"+params.area+"/#infowindow-"+a+"-"+d;a="Map UI: "+markers[map.getDiv().id][a].getTitle();clicky.log(d,a)}function log_stationpage_view(a,d){log_send("stationpage",{station_id:a,tab:d})}
function log_send(a,d){a="/api/maplog?mode="+a;for(var b in d)a+="&"+b+"="+d[b];return jQuery.ajax({type:"GET",url:a,dataType:"text",timeout:15E3,success:function(){return true},error:function(){return false}})?true:false}
function updateOshiraseMapCircle(a,d,b){radius=b/1E3/1.6;a=d.lat();d=d.lng();b=radius/3963*(180/Math.PI);for(var f=b/Math.cos(a*(Math.PI/180)),e=[],h=0;h<40;h++){var g=Math.PI*(h/20);Cx=d+f*Math.cos(g);Cy=a+b*Math.sin(g);e.push(new google.maps.LatLng(Cy,Cx))}if(oshirase_map_circle==null){oshirase_map_circle=new google.maps.Polygon({paths:e,strokeColor:"#000000",strokeOpacity:0,strokeWeight:1,fillColor:"#F26620",fillOpacity:0.4});oshirase_map_circle.setMap(map)}else oshirase_map_circle.setOptions({paths:e})}
function updateHtmlOshiraseForm(){if(params.oshirase=="true"){document.getElementById("oshiraseForm").action="/"+params.area+"/oshirase_confirm?lat="+markers.oshirase.getPosition().lat().toFixed(5)+"&lng="+markers.oshirase.getPosition().lng().toFixed(5)+"&zoom="+map.getZoom();document.getElementById("OshirasePointLat").value=markers.oshirase.getPosition().lat().toFixed(5);document.getElementById("OshirasePointLng").value=markers.oshirase.getPosition().lng().toFixed(5);document.getElementById("OshirasePointRange").value=
oshirase_range;getGeodataByLatlng(markers.oshirase.getPosition())}}function getGeodataByLatlng(a){var d=new google.maps.Geocoder;d&&d.geocode({latLng:a},function(b,f){if(f==google.maps.GeocoderStatus.OK){for(f=0;f<=b.length-1;f++)if(b[f].types[0]=="sublocality"&&b[f].types[1]=="political"){var e=b[f];break}if(e!=undefined){parse_geodata(e);return}}setTimeout(function(){getGeodataByLatlng(new google.maps.LatLng(a.lat()-0.0010,a.lng()-0.0010))},1E3)})}
function parse_geodata(a){var d=[];d.areaname="";if(a.formatted_address!=undefined){for(var b=1,f=1,e=a.address_components.length-1;e>=0;e--){a.address_components[e].long_name=convertToHankakuNum(a.address_components[e].long_name);if(a.address_components[e].types[0]=="administrative_area_level_1"){d.prefecture_name=a.address_components[e].long_name;d.areaname+=a.address_components[e].long_name}if(a.address_components[e].types[0]=="locality"){if(b==1)d.city_name=a.address_components[e].long_name;if(b==
2)d.ward_name=a.address_components[e].long_name;d.areaname+=a.address_components[e].long_name;b++}if(a.address_components[e].types[0]=="sublocality"){if(a.address_components[e].long_name.length>=2&&f<=2){if(!isNaN(a.address_components[e].long_name+0))break;d.areaname+=a.address_components[e].long_name}f++}}d.areaname+="\u5468\u8fba"}if(document.getElementById("OshirasePointName")!=null)document.getElementById("OshirasePointName").value=d.areaname;if(document.getElementById("OshirasePointName_display")!=
null)document.getElementById("OshirasePointName_display").innerHTML=d.areaname}function updateHtmlOshiraseGuide(){if(document.getElementById("map_oshirase_guide")!=null)document.getElementById("map_oshirase_guide").href="/"+params.area+"/oshirase?lat="+map.getCenter().lat().toFixed(5)+"&lng="+map.getCenter().lng().toFixed(5)+"&zoom=14"}
function blinkOshiraseGuideBotton(){setTimeout(function(){document.getElementById("map_oshirase_guide").style.backgroundPosition="center bottom"},1E3);setTimeout(function(){document.getElementById("map_oshirase_guide").style.backgroundPosition="center top"},1400);setTimeout(function(){document.getElementById("map_oshirase_guide").style.backgroundPosition="center bottom"},1800);setTimeout(function(){document.getElementById("map_oshirase_guide").style.backgroundPosition="center top"},2200)}
function clicky_initialize(){params.clicky!=undefined&&clicky.init(params.clicky)}function getJsParam(a){for(var d=document.getElementsByTagName("script"),b,f={},e=0;e<d.length;e++){var h=d.item(e);if(h.src.indexOf(a)!=-1){b=h;break}}if(b){b.src.match(/(.*)(\?)(.*)/);if(RegExp.$3)if(a=RegExp.$3.split("&"))for(d=0;d<a.length;d++){b=a[d].split("=");if(b[0])f[b[0]]=b[1]}else return false;else return false}else return false;return f}
function convertToHankakuNum(a){var d="";for(i=0;i<a.length;i++){c=a.charAt(i);n="\uff10\uff11\uff12\uff13\uff14\uff15\uff16\uff17\uff18\uff19".indexOf(c,0);d+=n>=0?"0123456789".charAt(n):c}return d}google.setOnLoadCallback(initialize);google.setOnLoadCallback(clicky_initialize);