var map,marker,geocoder,geoResult,gtURL="http://www.geotruc.net/gt.php?sid=",c0=/^([-]?[0-9]{1,2}[\.]?[0-9]*)[,; ]*([-]?[0-1]?[0-9]{1,2}[\.]?[0-9]*)$/,c1=/^([N|n|S|s])[ ]?(\d{1,2})[\°][ ]?(\d{1,2})[\u2032\'][ ]?(\d{1,2})[\u2033\"\']{1,2}[,; ]*([E|e|W|w])[ ]?(\d{1,3})[\°][ ]?(\d{1,2})[\u2032\'][ ]?(\d{1,2})[\u2033\"\']{1,2}$/,c2=/^(\d{1,2})[\°]?[ ]?(\d{1,2})[\u2032\']?[ ]?(\d{1,2})[\u2033\"\']{0,2}[ ]?([N|n|S|s])[,; ]*(\d{1,3})[\°]?[ ]?(\d{1,2})[\u2032\']?[ ]?(\d{1,2})[\u2033\"\']{0,2}[ ]?([E|e|W|w])$/,
c3=/^([N|n|S|s])[ ]?(\d{1,2})[\°][ ]?(\d{1,2})[\u2032\'][,; ]*([E|e|W|w])[ ]?(\d{1,3})[\°][ ]?(\d{1,2})[\u2032\']$/,c4=/^(\d{1,2})[\°][ ]?(\d{1,2})[\u2032\'][ ]?([N|n|S|s])[,; ]*(\d{1,3})[\°][ ]?(\d{1,2})[\u2032\'][ ]?([E|e|W|w])$/;with(google.maps.MapTypeId)var mapTypes=[ROADMAP,SATELLITE,HYBRID,TERRAIN];
function toolbar(){var a,b,c=['<input id="minimap-url" type="hidden" value="" />','<select id="gt-menu">'],e=0,d;d=[{"-1":"Code :"},{"6":"Geo (microformat)"},{"13":"GeoCoordinates (microdata)"},{"8":"GeoJSON"},{"2":"GeoRSS (GML)"},{"3":"GeoRSS (simple)"},{"11":"Google Maps (static)"},{"12":"Google Maps"},{"9":"GPX"},{"4":"HTML"},{"5":"KML"},{"1":"Machine tags"},{"10":"Nanoformat"},{"7":"W3C geo"}];var f={lnk:{title:"Add to your favorites",href:"http://www.geotruc.net/",style:"0px -29px;"},bm:{title:"Add to Blogmarks.net",
href:"http://www.blogmarks.net/my/new.php?mini=1&amp;simple=1&amp;url=http%3A%2F%2Fwww.geotruc.net%2F&amp;title=geo%3Atruc",style:"-16px -29px;"},dlc:{title:"Add to del.icio.us",href:"http://del.icio.us/post?url=http%3A%2F%2Fwww.geotruc.net%2F&amp;title=geo%3Atruc",style:"-32px -29px;"},fb:{title:"Share on Facebook",href:"http://www.facebook.com/sharer.php?u=http%3A%2F%2Fwww.geotruc.net%2F&amp;t=geo%3Atruc",style:"-48px -29px;"},ff:{title:"Share on Friendfeed",href:"http://friendfeed.com/share?url=http%3A%2F%2Fwww.geotruc.net%2F&amp;title=geo%3Atruc",
style:"-64px -29px;"},ggl:{title:"Add to Google Bookmarks ",href:"http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http%3A%2F%2Fwww.geotruc.net%2F&amp;title=geo%3Atruc",style:"-80px -29px;"},bzz:{title:"Share on Google Buzz",style:"-144px -29px; cursor:pointer"},ica:{title:"Share on Identi.ca",href:"http://identi.ca/?action=newnotice&amp;status_textarea=geo%3Atruc: http%3A%2F%2Fwww.geotruc.net%2F",style:"-96px -29px;"},twr:{title:"Share on Twitter",href:"http://twitter.com/intent/tweet?url=http%3A%2F%2Fwww.geotruc.net%2F&amp;text=geo%3Atruc&amp;related=geotruc",
style:"-128px -29px;"},yho:{title:"Add to Yahoo! MyWeb",href:"http://bookmarks.yahoo.com/myresults/bookmarklet?u=http%3A%2F%2Fwww.geotruc.net%2F&amp;t=geo%3Atruc",style:"-160px -29px"}};for(a in d)for(b in d[a])c.push(d[a][b].opt(b));c.push('</select><ul id="gt-social">');for(a in f){d={id:a+"_a"};for(b in f[a])b!="style"&&(d[b]=f[a][b]),b=="href"&&(d.target="_blank");c.push(f[a].title.span().a(!1,d).li({id:a,"class":"gt-socials gt-sprite",style:"left:"+e+"px;px;background-position:"+f[a].style}));
e+=19}c.push("</ul>");$("#gt-toolbar").append($(c.join("")));a=$("#gt-menu");a.change(function(a,b){a=marker.getPosition();b=this.options[this.selectedIndex];a!=null&&b.value>0&&(AJAXcode(b.value,rond(a.lat()),rond(a.lng()),$("#gt-result-address").text()),showCodeDialog(b.text))});a.attr("disabled","disabled");$("#bzz_a").bind("click",function(){window.open("http://www.google.com/buzz/post?message=geo%3Atruc&amp;url=http%3A%2F%2Fwww.geotruc.net%2F&amp;imageurl=http://maps.google.com/maps/api/staticmap?zoom=1&size=150x150&maptype=terrain&center=20,0&sensor=false",
window.title,"width=710,height=480")})}
function showCodeDialog(a){$('<div id="gt-dialog" title="Code"><h3>'+a+'</h3><textarea id="gt-code" class="code" cols="44" rows="13" readonly="readonly" title="Click to select" onclick="this.select()"></textarea></div>').modal({containerCss:{width:"400px",height:"320px"},onOpen:function(a){a.overlay.fadeIn("fast",function(){a.container.slideDown("fast",function(){a.data.fadeIn("fast")})})},onClose:function(a){a.data.fadeOut("fast",function(){a.container.slideUp("fast",function(){a.overlay.fadeOut("fast",
function(){$.modal.close()})})})},onShow:function(a){$("#gt-code",a.data).click(function(){this.select()})}});return!1}function wsURL(a,b,c,e,d){d=[gtURL,Math.random(),"&t=",a,"&hl=","en_US","&y=",c,"&x=",b,"&z=",map.getZoom(),"&mt=",$.inArray(map.getMapTypeId(),mapTypes)];e&&d.push("&title="+encodeURI(e));return d.join("")}
function showResults(a){var b=marker.getPosition(),c=b.lat(),b=b.lng(),e=rond(c)+", "+rond(b),d=latDMS(c)+", "+lngDMS(b),a=a?a:e;$("title").text(a+" - geo:truc");if(!$("#gt-result-address").length){var f="".span({style:"font-weight:bold"}),g=$("#gt-result");g.html($(f).attr("id","gt-result-address"));g.append($('<table><tbody><tr><td id="gt-coordinates"></td><td><input/></td></tr><tr><td>&nbsp;</td><td><input/></td></tr></tbody></table>'));$("#gt-coordinates").append($(f).text("Coordinates : "));
$("#gt-result input").attr({"class":"gt-coords",size:"23",readonly:"readonly",title:"Click to select"}).click(function(){this.select()});$("#gt-menu").removeAttr("disabled")}AJAXlinks(c,b,a);$("#gt-result-address").text(a);$("#gt-result :input:first").val(d);$("#gt-result :input:last").val(e)}
function showHelp(){var a=['<div id="gt-dialog" title="Code"><h3>Help</h3><div>',"How to get the coordinates/geotag of a location ?".p(),"<ul>","Browse the map until you find the location you want, and click to set a marker".li(),"Or write an address in the search field".li(),"Or write coordinates (latitude THEN longitude) in the search field".li(),"</ul>","Click on a marker to remove it.".p(),"</div></div>"].join("");$(a).modal({containerCss:{width:"400px",height:"230px"},onOpen:function(a){a.overlay.fadeIn("fast",
function(){a.container.slideDown("fast",function(){a.data.fadeIn("fast")})})},onClose:function(a){a.data.fadeOut("fast",function(){a.container.slideUp("fast",function(){a.overlay.fadeOut("fast",function(){$.modal.close()})})})},onShow:function(a){$("#gt-code",a.data).click(function(){this.select()})}});return!1}
function init(){toolbar();var a,b=new Boolean;a=$("#gt-latLng");var c=$("#gt-mapType"),e=$("#gt-startZoom"),d=$("#gt-search"),f=d.val(),c=mapTypes[c.length?Number(c.val()):3],e=e.length?Number(e.val()):2;a.length?(b=a.val().split(","),a=new google.maps.LatLng(b[0],b[1]),b=!0):a=new google.maps.LatLng(20,0);$("#minimap-url").val(["http://maps.google.com/maps/api/staticmap?zoom=",e,"&size=150x150&maptype=",c,"&markers=",a.lat(),",",a.lng(),"&sensor=false"].join(""));geocoder=new google.maps.Geocoder;
map=new google.maps.Map(document.getElementById("gt-map"),{zoom:e,center:a,mapTypeId:c,streetViewControl:!1,scaleControl:!0,overviewMapControl:!0});marker=new google.maps.Marker({map:map,draggable:!0,visible:!1});b==!0&&(placeMarker(a),showResults());d.live("keypress",function(a){if(a.keyCode==13)return findAddress(),!1});$("#gt-search-btn").click(function(){findAddress()});$("#gt-help").click(function(){showHelp()});google.maps.event.addListener(map,"click",function(a){placeMarker(a.latLng);showResults()});
google.maps.event.addListener(map,"zoom_changed",function(){var a=$("#gt-result-address");if(a.length){var b=$("#gt-result :input:last").val().split(", ");AJAXlinks(Number(b[0]),Number(b[1]),a.text())}});google.maps.event.addListener(map,"maptypeid_changed",function(){var a=$("#gt-result-address");if(a.length){var b=$("#gt-result :input:last").val().split(", ");AJAXlinks(Number(b[0]),Number(b[1]),a.text())}});google.maps.event.addListener(marker,"dragend",function(a){placeMarker(a.latLng);showResults()});
google.maps.event.addListener(marker,"click",function(){marker.setVisible(!1)});f.length>0&&findAddress()}function AJAXlinks(a,b,c){$.getJSON(wsURL(0,b,a,c),function(a){$.each(a,function(a,b){a=="map"?$("#minimap-url").val(b):a=="bzz"?$("#bzz_a").unbind("click").bind("click",function(){window.open(b,c,"width=710,height=480")}):$("#"+a+"_a").attr("href",b)})})}
function AJAXcode(a,b,c,e,d,f){d=wsURL(a,c,b);if(geoResult){d+="&ad="+encodeURI(geoResult.formatted_address);try{for(var g in geoResult.address_components)f=encodeURI(g.short_name),g.types[0]=="country"&&(d+="&reg="+f),g.types[0]=="administrative_area_level_1"&&(d+="&ar="+f)}catch(h){}}$.get(d,function(a){$("#gt-code").html(a)})}function placeMarker(a,b){marker.setPosition(a);marker.setVisible(!0);map.panTo(a);b&&map.setZoom(b)}
function findAddress(){var a=$("#gt-search").val(),b=map.getZoom(),c=a.match(c0),e=a.match(c1),d=a.match(c2),f=a.match(c3),g=a.match(c4),h,i;b<13&&(b=13);c?(h=latBnd(c[1]),i=lngBnd(c[2])):e?(h=decDeg(e[1],latBnd(e[2]),e[3],e[4]),i=decDeg(e[5],lngBnd(e[6]),e[7],e[8])):d?(h=decDeg(d[4],latBnd(d[1]),d[2],d[3]),i=decDeg(d[8],lngBnd(d[5]),d[6],d[7])):f?(h=decDeg(f[1],latBnd(f[2]),f[3],0),i=decDeg(f[4],lngBnd(f[5]),f[6],0)):g?(h=decDeg(g[3],latBnd(g[1]),g[2],0),i=decDeg(g[6],lngBnd(g[4]),g[5],0)):geocoder&&
geocoder.geocode({address:a},function(a,c){c==google.maps.GeocoderStatus.OK?(geoResult=a[0],placeMarker(a[0].geometry.location,b),showResults(a[0].formatted_address)):alert("Geocoding error: "+c)});h!==void 0&&i!==void 0&&(placeMarker(new google.maps.LatLng(h,i),b),showResults(rond(h)+","+rond(i)))}function decDeg(a,b,c,e){b=Number(b);c=Number(c);e=Number(e);c>59&&(c=59);e>59&&(e=59);return(a.match(/[EeNn]/)?1:-1)*(b*3600+c*60+e)/3600}
function toDMS(a,b,c,e,d){b=Math.abs(a).toString().split(".");c=b[0];if(!b[1])return c+"° 0' 0'' ";b=(("."+b[1])*60).toString().split(".");e=b[0];if(!b[1])return c+"° "+e+"' 0'' ";d=rond(Math.round(("."+b[1])*60));return c+"° "+e+"' "+d+"'' "}function latDMS(a){return toDMS(a)+(a<0?"S":"N")}function lngDMS(a){return toDMS(a)+(a<0?"W":"E")}function rond(a){return Math.round(a*1E6)/1E6}function chkBnd(a,b,c){c=-1*b;a<c&&(a=c);a>b&&(a=b);return a}
function latBnd(a){return chkBnd(a,90)}function lngBnd(a){return chkBnd(a,180)}var t=function(a,b,c,e,d){e="";if(c)for(d in c)e+=" "+d+"='"+c[d]+"'";return"<"+a+e+">"+b+"</"+a+">"};Bin=String.prototype;Bin.a=function(a,b){b=b||{};a&&(b.href=a);return t("a",this,b)};Bin.li=function(a){return t("li",this,a)};Bin.opt=function(a,b){b=b||{};b.value=a;return t("option",this,b)};Bin.p=function(a){return t("p",this,a)};Bin.span=function(a){return t("span",this,a)};

