var map_icon=new GIcon();map_icon.image="/wp-content/themes/tai/img/tai_icon.gif";map_icon.shadow="/wp-content/themes/tai/img/tai_icon_shadow.gif";map_icon.iconSize=new GSize(20,33);map_icon.iconAnchor=new GPoint(1,31);map_icon.shadowSize=new GSize(20,33);map_icon.infoWindowAnchor=new GPoint(6,2);var map;var geocoder;var default_address="Enter Address / Zip";jQuery(document).ready(function(a){a("form[name=locations_form]").get(0).reset();default_address=a("input[name=address]").val();a("input[name=address]").focus(function(){if(a(this).val()==default_address){a(this).val("")}});a("input[name=address]").blur(function(){if(a(this).val()==""){a(this).val(default_address)}})});function Clinic(){this.id=0;this.name="";this.neighborhood="";this.region="";this.region_url="#";this.url="#";this.address="";this.city="";this.state="";this.zip="";this.phone="";this.directions="";this.distance=0;this.longitude="";this.latitude=""}function load(){if(GBrowserIsCompatible()){geocoder=new GClientGeocoder();map=new GMap2(document.getElementById("map"));map.addControl(new GLargeMapControl());map.addControl(new GMapTypeControl());map.setCenter(new GLatLng(41.245991,-115.74121),5);if(location.pathname=="/locations"||location.pathname=="/locations/"){if(location.hash!=""){var f=location.hash.substring(1);var e=/addr\=([^\&]+)/;var a=f.match(e);var c=/radius\=([0-9]+)/;var b=f.match(c);if(a!=null&&b!=null){jQuery("input[name=address]").val(decodeURIComponent(a[1]));jQuery("select[name=radius]").val(decodeURIComponent(b[1]));searchLocations()}}}else{if(region!=""){var d="/clinic-search?region="+region+"&radius=&service=";getLocations(d,"","")}else{if(state!=""){var d="/clinic-search?state="+state+"&radius=&service=";getLocations(d,"","")}}}}}function getLocations(c,b,a){GDownloadUrl(c,function(k){var m=GXml.parse(k);var g=m.documentElement.getElementsByTagName("marker");map.clearOverlays();var d=document.getElementById("clinics");d.innerHTML="";if(g.length==0){d.innerHTML="No clinics found.";jQuery("#map_msg").text("No clinics found matching your criteria").show();return}else{var f="Found "+g.length+" clinics";var n="";if(a!=""){f+=" wthin a "+a+" mile radius"}if(b!=""){f+=" offering "+n}jQuery("#map_msg").text(f).show()}var e=new GLatLngBounds();var l=new Array();for(var j=0;j<g.length;j++){l[j]=new Clinic();l[j].id=g[j].getAttribute("clinic_id");l[j].name=g[j].getAttribute("name");l[j].neighborhood=g[j].getAttribute("neighborhood");l[j].region=g[j].getAttribute("region");l[j].region_url=g[j].getAttribute("region_url");l[j].url=g[j].getAttribute("url");l[j].address=g[j].getAttribute("address");l[j].city=g[j].getAttribute("city");l[j].state=g[j].getAttribute("state");l[j].zip=g[j].getAttribute("zip");l[j].phone=g[j].getAttribute("phone");l[j].directions=g[j].getAttribute("directions");l[j].distance=parseFloat(g[j].getAttribute("distance"));l[j].longitude=parseFloat(g[j].getAttribute("lng"));l[j].latitude=parseFloat(g[j].getAttribute("lat"));var p=new GLatLng(parseFloat(g[j].getAttribute("lat")),parseFloat(g[j].getAttribute("lng")));var h=createMarker(p,l[j]);map.addOverlay(h);var o=createSidebarEntry(h,l[j]);d.appendChild(o);e.extend(p)}map.setCenter(e.getCenter(),map.getBoundsZoomLevel(e))})}function searchLocations(){var a=jQuery("input[name=address]").val();if(a!=default_address){geocoder.getLatLng(a,function(c){if(!c){alert(a+" not found")}else{jQuery("#map_msg").text("").hide();var b=jQuery("select[name=radius]").val();if(b==""){b=25}location.hash="addr="+encodeURIComponent(a)+"&radius="+b;searchLocationsNear(c)}})}else{jQuery("#map_msg").text("Please enter a valid address or zip code").show()}}function searchLocationsNear(c){var b=jQuery("select[name=radius]").val();if(b==""){b=25;jQuery("select[name=radius]").val(b)}var a="";var d="/clinic-search?lat="+c.lat()+"&lng="+c.lng()+"&radius="+b+"&service="+a;getLocations(d,a,b)}function createMarker(a,d){var e=map.getZoom()+3;var b=new GMarker(a,map_icon);var f=(d.neighborhood!="")?d.neighborhood:d.name;var c='<b><a href="'+d.url+'" title="'+f+' Clinic Details">'+f+"</a></b><br/>";if(d.neighborhood!=""&&d.neighborhood!=d.name){c+="<i>"+d.name+"</i><br/>"}c+=d.address+"<br/>"+d.city+", "+d.state+" "+d.zip+"<br/>Phone: "+d.phone+"<br/>";c+='<a href="'+d.url+'" title="'+f+' Clinic Details">Clinic Details</a> | ';c+='<a href="http://maps.google.com/?q='+d.directions+'" title="Get Directions" target="_blank">Get Directions</a> | ';c+='<a href="javascript:map.zoomIn(new GLatLng('+d.latitude+", "+d.longitude+'), true, true)">Zoom In</a>';GEvent.addListener(b,"click",function(){b.openInfoWindowHtml(c)});return b}function createSidebarEntry(a,e){var g=(e.neighborhood!="")?e.neighborhood:e.name;var f=document.createElement("div");var h="clinic_"+e.id;var d='<h4><a href="'+e.url+'" title="'+g+' Clinic Page">'+g+"</a></h4>";if(!isNaN(e.distance)){d+='<div class="dist">Distance: '+e.distance.toFixed(1)+" mi</div>"}d+='<div class="region"><a href="'+e.region_url+'" title="'+e.region+' Region Clinics">'+e.region+"</a></div>";if(e.neighborhood!=""&&e.neighborhood!=e.name){d+='<div class="name">'+e.name+"</div>"}d+="<div>"+e.address+"</div><div>"+e.city+", "+e.state+" "+e.zip+"</div>";d+="<div>Phone: "+e.phone+"</div>";d+="<div>";d+='<a href="'+e.url+'" title="'+g+' Clinic Details">Clinic Details</a>';d+=' | <a href="javascript:void(0)" id="'+h+'" title="Locate '+g+' on map">Locate on Map</a>';d+="</div>";f.className="clinic ui-corner-all";f.title=g;f.innerHTML=d;var c=f.getElementsByTagName("a");for(var b=0;b<c.length;b++){if(c.item(b).id==h){GEvent.addDomListener(c.item(b),"click",function(){GEvent.trigger(a,"click")})}}return f};