jQuery.fn.yellowFade=function(){return this.css({backgroundColor:"yellow"}).animate({backgroundColor:"white"},1500)};google.load("maps","2",{other_params:"sensor=false"});if(typeof INITIAL_LAT=="undefined")var INITIAL_LAT=43.834526782236814;if(typeof INITIAL_LON=="undefined")var INITIAL_LON=-37.265625;if(typeof INITIAL_ZOOM=="undefined")var INITIAL_ZOOM=3;function __zoom_in(a){a||(a=0);gmap.setZoom(gmap.getZoom()+2+a)}function __zoom_out(a){a||(a=0);gmap.setZoom(gmap.getZoom()-2-a)}
function __reversed_geocode(a,c,b,d){if($("#id_location_description").val()!=a){$("#id_location_description").val(a);$("#id_location_description").parent().yellowFade();if(marker){marker_html=a+"<br>"+c+"<br>";if(LOCATION_BY_IP)marker_html+='(<font size="-1"><strong>note:</strong> you can correct this in your profile afterwards)</font><br>';marker_html+='<br><font size="-1">zoom ';if(gmap.getZoom()<14)marker_html+='<a href="#" onclick="__zoom_in();return false">in</a> ';if(gmap.getZoom()>2)marker_html+=
'<a href="#" onclick="__zoom_out();return false">out</a>';marker_html+="</font>";marker.openInfoWindowHtml(marker_html);gmap.getZoom()>=2&&gmap.setCenter(marker.getLatLng(),gmap.getZoom()+3);$("#id_club_url").val()&&$("#id_club_name").val()||__suggest_club_by_location()}}$("#id_country").val(b).change();d&&$("#id_region").val("")}
function reverseGeocode(){var a=$("#id_longitude").val(),c=$("#id_latitude").val();if(!(!a||!c||Math.abs(c-INITIAL_LAT)<0.01&&Math.abs(a-INITIAL_LON)<0.01)){var b="http://ws.geonames.org/findNearbyPlaceNameJSON?";b+="lat="+c+"&lng="+a+"&callback=?";jQuery.getJSON(b,function(d){if(typeof d.geonames!="undefined"&&d.geonames.length>0){d=d.geonames[0];var e=d.countryCode,h=d.countryName,f=d.adminName1,g=d.name;if(f&&f.toLowerCase()!=g.toLowerCase())g+=", "+f;f="";if(hasRegions(h)&&d.adminCode1)f=d.adminCode1;
__reversed_geocode(g,h,e,f);$("#content-box:hidden").show()}});return true}}var _club_suggestions={};function suggest_club(a){if(a){$("#club-suggestions-tip:visible").hide();$("#id_club_name").val(_club_suggestions[a][0]);$("#id_club_url").val(_club_suggestions[a][1])}$("#id_club_name").qtip("destroy")}
function __suggest_club_by_location(){var a={latitude:$("#id_latitude").val(),longitude:$("#id_longitude").val(),country:$("#id_country").val(),location_description:$("#id_location_description").val()};$.getJSON("/find-clubs-by-location.json",a,function(c){if(c.error)alert(c.error);else if(c.length){var b='<p id="club-suggestions-tip"><strong>Let me guess! Is it';b+=c.length==1?"...:":" one of these:";b+="</strong><br/>";$.each(c,function(d,e){b+=e.name;b+="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";_club_suggestions[e.id]=
[e.name,e.url];b+=' <a href="#" onclick="suggest_club('+e.id+'); return false">yes</a>';b+=' <a href="#" onclick="suggest_club(false); return false">no</a>';b+="<br/>"});b+="</p>";$("#id_club_name").data("qtip")&&$("#id_club_name").qtip("destroy");$("#id_club_name").qtip({content:b,position:{corner:{tooltip:"bottomLeft",target:"topRight"}},style:{border:{width:3,radius:10},padding:8,tip:true,name:"cream"},show:{when:false,ready:true},hide:false})}})}
function hasRegions(a){return $('select#id_region optgroup[label="'+a+'"]').length}
function __on_dragend(a){point=marker.getLatLng();var c=point.lat(),b=point.lng();$("#id_latitude").val(c);$("#id_longitude").val(b);if(!b||!c||Math.abs(c-INITIAL_LAT)<0.01&&Math.abs(b-INITIAL_LON)<0.01)marker.openInfoWindowHtml(marker_html);else{marker_html='<img src="/static/img/loading.gif" width="16" height="16" alt="Please wait..."> Please wait...<br>Fetching location name';marker.openInfoWindowHtml(marker_html);if(a){lookupTimer&&clearTimeout(lookupTimer);lookupTimer=setTimeout(reverseGeocode,
a*1E3)}else reverseGeocode()}}function __create_marker(a){marker=new GMarker(a,{draggable:true});GEvent.addListener(marker,"dragstart",function(){gmap.closeInfoWindow()});GEvent.addListener(marker,"dragend",function(){__on_dragend(1)});gmap.addOverlay(marker)}var zoom_level,point,marker,marker_html,gmap,lookupTimer=false;function __iso_code_to_country_name(a){var c=a;$("option","#id_country").each(function(b,d){if(d.value==a)c=$(d).text()});return c}
google.setOnLoadCallback(function(){$("#content-box:hidden").show();$("select#id_country").change(function(){$(this).parent().find("span.flag").remove();var a=$(this).val().toLowerCase();a&&$('<span class="flag iso-'+a+'"></span>').insertAfter(this)}).change();$("select#id_country").change(function(){var a=$('select#id_country option[value="'+$(this).val()+'"]').text();if(hasRegions(a))$("select#id_region").parent().show();else{$("select#id_region").parent().hide();$("#id_region").val("")}}).change();
$("select#id_region").parent().hide();$("input#id_latitude").parent().hide();$("input#id_longitude").parent().hide();gmap=new google.maps.Map2(document.getElementById("gmap"));gmap.addControl(new google.maps.LargeMapControl3D);gmap.addControl(new google.maps.MapTypeControl);if($("#id_latitude").val()&&$("#id_longitude").val()){point=new google.maps.LatLng($("#id_latitude").val(),$("#id_longitude").val());__create_marker(point);if(LOCATION_BY_IP){zoom_level=5;marker_html="<strong>Drag the marker to where you train</strong><br>";
marker_html+="Currently at: "+$("#id_location_description").val();marker_html+="<br>"+__iso_code_to_country_name($("#id_country").val());marker_html+='<br><br><font size="-1">zoom ';marker_html+='<a href="#" onclick="__zoom_in(3);return false">in</a> ';marker_html+='<a href="#" onclick="__zoom_out();return false">out</a>';marker_html+="</font>";marker.openInfoWindowHtml(marker_html)}else zoom_level=8}else{$("#content-box:visible").hide();point=new google.maps.LatLng(INITIAL_LAT,INITIAL_LON);zoom_level=
INITIAL_ZOOM}gmap.setCenter(point,zoom_level);if(!marker){$("html,body").animate({scrollTop:$("#gmap").offset().top},500);point||(point=gmap.getCenter());__create_marker(point);marker_html="Drag the marker to where you train";marker.openInfoWindowHtml(marker_html)}});
