function _entity_replace(s){switch(s){case'&':return'&amp;';break;case'<':return'&lt;';break;case'>':return'&gt;';break;case'"':return'&quot;';break;case"'":return'&#39;';break;default:return s;break;}}
function entity(s){return s.replace(/[&<>"']/g,_entity_replace);}
function ajax_error(httpRequest,textStatus,errorThrown){alert('Ajax request '+textStatus+': '+httpRequest.status+' '+httpRequest.statusText);}
var map_offset;var cookie_accept=true;var fixed_zoom=false;function window_resize(){var _win=$(window);var _win_height=_win.height()-12;if(jQuery.browser.msie){_win_height-=4;$('body').height(_win.height());}
var _win_width=_win.width()-20;var height=_win_height-map_offset.top;var side_height=height-20;$('#left').height(height).width(_win_width-320);$('#right').height(side_height);if(jQuery.browser.safari){$('#map_canvas').height(height);$('#sidewrapper').height(side_height);}
if(map){map.checkResize();}}
function window_init(){var _win=$(window);var map=$('#map_canvas');map_offset=map.offset();_win.resize(window_resize);window_resize();}
var map;var directions;var geocoder;function init_geocoder(){if(GBrowserIsCompatible()){geocoder=new GClientGeocoder();geocoder.setBaseCountryCode('ja');}}
function centering_at_location(zoom){var lat=35.680964;var lng=139.766688;if(google&&google.loader&&google.loader.ClientLocation){lat=google.loader.ClientLocation.latitude;lng=google.loader.ClientLocation.longitude;}
if(zoom){map.setCenter(new GLatLng(lat,lng),zoom);}else{map.setCenter(new GLatLng(lat,lng));}}
function zoom_cookie(zoom){var d=new Date();d.setDate(d.getDate()+7);document.cookie='mapzoom='+encodeURIComponent(zoom)+'; path=/'+'; expires='+d.toGMTString();}
function on_zoomend(){if(cookie_accept){zoom_cookie(map.getZoom());}}
function map_init(callback){$(window).unload(GUnload);if(GBrowserIsCompatible()){map=new GMap2(document.getElementById("map_canvas"));if(callback){GEvent.addListener(map,"load",callback);}
map.addControl(new GLargeMapControl());map.addControl(new GMapTypeControl());map.addControl(new GScaleControl());map.addControl(new GOverviewMapControl());var zoom=13;if(fixed_zoom){cookie_accept=false;zoom=fixed_zoom;}else{var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;++i){var matches=cookies[i].match(/mapzoom=(\d*)/);if(matches!=null){zoom=parseInt(matches[1]);if(cookie_accept){zoom_cookie(zoom);}}}}
centering_at_location(zoom);GEvent.addListener(map,"zoomend",on_zoomend);var textual_div=document.getElementById('my_textual_div');if(textual_div){directions=new GDirections(map,textual_div);}}}
function init(){window_init();map_init();}
var icon_cache={};function create_image_icon(url){var icon;if(icon_cache[url]){icon=new GIcon(icon_cache[url]);}else{icon=new GIcon(G_DEFAULT_ICON);icon.image=url;icon.shadow=null;icon.iconSize=new GSize(31,31);icon.iconAnchor=new GPoint(15,31);icon.infoWindowAnchor=new GPoint(15,31);icon.imageMap=[0,0,31,0,31,31,0,31];icon_cache[url]=icon;}
return icon;}
function encode_latlng(lat,lng){return encodeURIComponent(lat)+','+encodeURIComponent(lng);}
function goog_link(route){switch(route.length){case 0:return null;break;case 1:var last=route[route.length-1];return'http://maps.google.co.jp/maps?hl=ja&q='+
encodeURIComponent(last.address);break;}
var first=route[0];var last=route[route.length-1];var now=new Date();var url='http://maps.google.co.jp/maps?hl=ja&ie=UTF8&date='+
now.getFullYear()+'/'+now.getMonth()+'/'+
now.getDate()+'&time='+now.getHours()+':'+now.getMinutes()+'&sort=time&saddr='+encodeURIComponent(first.address);switch(route.length){case 2:url+='&daddr='+encodeURIComponent(last.address);break;default:url+='&dirflg=d&daddr=';for(var i=1;i<route.length-1;++i){url+=encodeURIComponent(route[i].address)+'+';}
url+='to:'+encodeURIComponent(last.address);}
return url;}
function display_goog_link(route){var link=goog_link(route);if(link){document.write('<a href="'+goog_link(route)+'">Google\u30de\u30c3\u30d7</a>');}}
function goog_q_link(route,q){if(route.length==0){return null;}
var last=route[route.length-1];var sspn=map.getBounds().toSpan().toUrlValue();var hq=encodeURIComponent(q);return'http://map.google.co.jp/maps?hl=ja&ie=UTF8&geocode=&hnear=&z=12&sll='+last.lat+','+last.lng+'&sspn='+encodeURIComponent(sspn)+'&q='+hq+'&hq='+hq;}
function display_goog_q_link(route,q){var link=goog_q_link(route,q);if(link){document.write('<a href="'+goog_link(route)+'">'+entity(q)+'</a>');}}
function gurunavi_link(route){if(route.length==0){return null;}
var last=route[route.length-1];return'http://map.gnavi.co.jp/search.php?nl='+last.lat+'&el='+last.lng;}
function create_fukidasi(datum){var table=document.createElement('table');table.className='fukidasi';var tbody=document.createElement('tbody');var tr=document.createElement('tr');var left=document.createElement('td');left.className='message_left';var user_link=document.createElement('a');user_link.href=datum.user_link;var image=document.createElement('img');image.src=datum.profile_image_url;image.width=31;image.height=31;user_link.appendChild(image);left.appendChild(user_link);tr.appendChild(left);var right=document.createElement('td');right.className='message_right';var status=document.createElement('div');status.className='status';var user_link2=user_link.cloneNode(false);user_link2.appendChild(document.createTextNode(datum.screen_name));user_link2.className='screen_name';status.appendChild(user_link2);status.appendChild(document.createTextNode(' '));status.innerHTML+=datum.status;right.appendChild(status);var created=document.createElement('div');created.className='created';if(datum.created){created.appendChild(document.createTextNode(datum.created));}
if(datum.mapurl){created.appendChild(document.createTextNode(' '));var mapurl=document.createElement('a');mapurl.href=datum.mapurl;mapurl.appendChild(document.createTextNode('\u8a73\u7d30'));created.appendChild(mapurl);}
created.appendChild(document.createElement('br'));if(datum.status_id){var twitter_link=document.createElement('a');twitter_link.target='_blank';twitter_link.href='http://twitter.com/'+encodeURIComponent(datum.screen_name)+'/status/'+encodeURIComponent(datum.status_id);twitter_link.appendChild(document.createTextNode('Twitter'));created.appendChild(twitter_link);}
if(datum.route.length>0){created.appendChild(document.createTextNode(' '));var a=document.createElement('a');a.href=goog_link(datum.route);a.target='_blank';a.innerHTML='Google\u30de\u30c3\u30d7';created.appendChild(a);created.appendChild(document.createTextNode(' ('));var last=datum.route[datum.route.length-1];var a=document.createElement('a');a.href=goog_q_link(datum.route,'\u30db\u30c6\u30eb \u65c5\u9928');a.target='_blank';a.innerHTML='\u30db\u30c6\u30eb\u30fb\u65c5\u9928';created.appendChild(a);created.appendChild(document.createTextNode(', '));var last=datum.route[datum.route.length-1];var a=document.createElement('a');a.href=goog_q_link(datum.route,'\u30ec\u30b9\u30c8\u30e9\u30f3');a.target='_blank';a.innerHTML='\u30ec\u30b9\u30c8\u30e9\u30f3';created.appendChild(a);created.appendChild(document.createTextNode(')'));}
right.appendChild(created);tr.appendChild(right);tbody.appendChild(tr);table.appendChild(tbody);return table;}
var map_center=null;var next_id=null;var selected_id=null;var handler_cache={};var icon_cache={};var initialized=false;var listener=null;fixed_zoom=5;function enable_centering(){if(!listener){listener=GEvent.addListener(map,"moveend",update_map_center);}}
function disable_centering(){if(listener){GEvent.removeListener(listener);listener=null;}}
function create_popup_handler(datum,latlng){return function(){$('#timeline .selected').removeClass('selected');map.openInfoWindow(latlng,create_fukidasi(datum));selected_id='#status_'+datum.id;$(selected_id).addClass('selected');};}
function push_status(wrapper,datum){var table=document.createElement('table');var tbody=document.createElement('tbody');var tr=document.createElement('tr');var td=document.createElement('td');td.className='message_left';var a=document.createElement('a');a.href=datum.user_link;var img=document.createElement('img');img.src=datum.profile_image_url;img.width=31;img.height=31;a.appendChild(img);td.appendChild(a);tr.appendChild(td);td=document.createElement('td');td.className='message_right';var st=document.createElement('div');st.className='status';var sr=document.createElement('a');sr.href=datum.user_link;sr.className='screen_name';sr.appendChild(document.createTextNode(datum.screen_name));st.appendChild(sr);st.innerHTML+=' '+datum.status;td.appendChild(st);var cr=document.createElement('div');cr.className='created';if(datum.route.length>0){var ptr1=document.createElement('a');ptr1.className='pointer marker';ptr1.appendChild(document.createTextNode(datum.created));cr.appendChild(ptr1);var handler;var last=datum.route[datum.route.length-1];var latlng=new GLatLng(last.lat,last.lng);if(handler_cache[datum.id]){handler=handler_cache[datum.id];}else{var marker=new GMarker(latlng,{icon:create_image_icon(datum.profile_image_url)});handler=create_popup_handler(datum,latlng);GEvent.addListener(marker,'click',handler);map.addOverlay(marker);handler_cache[datum.id]=handler;}
if(!initialized){disable_centering();handler();map.setCenter(latlng);initialized=true;enable_centering();}
ptr1.onclick=handler;}else{cr.appendChild(document.createTextNode(datum.created));}
cr.appendChild(document.createTextNode(' '));var ptr2=document.createElement('a');ptr2.className='pointer';ptr2.href=datum.mapurl;ptr2.appendChild(document.createTextNode('\u8a73\u7d30'));cr.appendChild(ptr2);td.appendChild(cr);tr.appendChild(td);tbody.appendChild(tr);table.appendChild(tbody);wrapper.appendChild(table);}
function add_map_data(json,className){var user_status=document.getElementById('timeline');for(var i=0;i<json.data.length;++i){var li=document.createElement('li');li.id='status_'+json.data[i].id;if(className){li.className='status_wrapper '+className;}else{li.className='status_wrapper';}
push_status(li,json.data[i]);user_status.appendChild(li);}
next_id=json.next_id;if(next_id){$('#more').fadeIn();}}
function map_no_data(){$('#timeline').append('<li class="no_data">\u3053\u306e\u4ed8\u8fd1\u3067\u306e\u6295\u7a3f\u306f\u307e\u3060\u7121\u3044\u3088\u3046\u3067\u3059\u3002</li>');}
function readmore(){if(next_id){var bounds=map.getBounds();var northEast=bounds.getNorthEast();var southWest=bounds.getSouthWest();$('#more_spinner').css('display','inline');$.ajax({type:'GET',url:readmore_url(northEast.lat(),northEast.lng(),southWest.lat(),southWest.lng(),next_id),dataType:'json',success:function(json){$('#more_spinner').css('display','none');if(!json.next_id){$('#more').fadeOut();}
if(json.data.length>0){add_map_data(json,'hide');$('.hide').fadeIn('slow');}},error:ajax_error});}
return false;}
function update_map_center(){var bounds=map.getBounds();var northEast=bounds.getNorthEast();var southWest=bounds.getSouthWest();$.ajax({type:'GET',url:readmore_url(northEast.lat(),northEast.lng(),southWest.lat(),southWest.lng()),dataType:'json',success:function(json){$('#timeline li').remove();if(json.data.length>0){add_map_data(json);if(selected_id){$(selected_id).addClass('selected');}}else{map_no_data();}},error:ajax_error});}
$(function(){init();if(map_center!=null){map.setCenter(map_center);}
update_map_center();enable_centering();var _win=$(window);_win.resize(function(){window_resize();update_map_center();});$("#readmore_link").click(readmore);});