var YWSID="H9tbYW9Qk7mYiNYKn0Bc9A";var map=null;var pano=null;var icon=null;function load(){map=new GMap2(document.getElementById("map"));GEvent.addListener(map,"load",function(){updateMap();});myPano=new GStreetviewPanorama(document.getElementById("pano"));GEvent.addListener(myPano,"error",handleNoFlash);map.setCenter(new GLatLng(34.0593,-118.2988),13);map.addControl(new GSmallMapControl());map.addControl(new GMapTypeControl());map.setMapType(G_HYBRID_MAP);icon=new GIcon();icon.image="images/marker_star.png";icon.shadow="images/marker_shadow.png";icon.iconSize=new GSize(20,29);icon.shadowSize=new GSize(38,29);icon.iconAnchor=new GPoint(15,29);icon.infoWindowAnchor=new GPoint(15,3);}
function constructYelpURL(){var mapBounds=map.getBounds();var URL="http://api.yelp.com/"+"business_review_search?"+"callback="+"handleResults"+"&term="+ document.getElementById("term").value+"&num_biz_requested=20"+"&location=90010"+"&radius=1.3"+"&ywsid="+ YWSID;return encodeURI(URL);}
function updateMap(){document.getElementById("spinner").style.visibility='visible';var yelpRequestURL=constructYelpURL();map.clearOverlays();var script=document.createElement('script');script.src=yelpRequestURL;script.type='text/javascript';var head=document.getElementsByTagName('head').item(0);head.appendChild(script);return false;}
function handleResults(data){document.getElementById("spinner").style.visibility='hidden';if(data.message.text=="OK"){if(data.businesses.length==0){alert("Error: No businesses were found near that location");return;}
for(var i=0;i<data.businesses.length;i++){biz=data.businesses[i];createMarker(biz,new GLatLng(biz.latitude,biz.longitude),i);}}
else{alert("Error: "+ data.message.text);}}
function generateInfoWindowHtml(biz){var text='<div style="width:205px;height:115px;overflow:auto;"><p style="font-size: 11px;">';text+='<img style="width:60px;height:60px;" align="left" class="businessimage" src="'+biz.photo_url+'"/>';text+='';text+='<a href="'+biz.url+'" target="_blank">'+biz.name+'</a><br/><br/>';text+='<img class="ratingsimage" src="'+biz.rating_img_url_small+'"/><br/>';text+=biz.review_count+'&nbsp;reviews</p><p style="font-size: 10px;"><br/>';text+=formatCategories(biz.categories);text+=biz.address1+'<br/>';if(biz.address2.length)
text+=biz.address2+'<br/>';text+=biz.city+',&nbsp;'+ biz.state+'&nbsp;'+ biz.zip+'<br/>';if(biz.phone.length)
text+=formatPhoneNumber(biz.phone);text+='<br/><a href="'+biz.url+'" target="_blank">Read the reviews &raquo;</a>';text+='</p></div>';return text;}
function formatCategories(cats){var s='Categories: ';for(var i=0;i<cats.length;i++){s+=cats[i].name;if(i!=cats.length-1)s+=', ';}
s+='<br/>';return s;}
function formatPhoneNumber(num){if(num.length!=10)return'';return'('+ num.slice(0,3)+') '+ num.slice(3,6)+'-'+ num.slice(6,10)+'<br/>';}
function createMarker(biz,point,markerNum){var infoWindowHtml=generateInfoWindowHtml(biz)
var marker=new GMarker(point,icon);map.addOverlay(marker);GEvent.addListener(marker,"click",function(){marker.openInfoWindowHtml(infoWindowHtml);myPano.setLocationAndPOV(point);});if(markerNum==0&&document.getElementById("term").value!=''){marker.openInfoWindowHtml(infoWindowHtml);}}
function handleNoFlash(errorCode){if(errorCode==FLASH_UNAVAILABLE){alert("Error: Flash doesn't appear to be supported by your browser");return;}}
