var sv_marker;var mt1;var overlayInstance=null;var client;var lastMarkerLocation;var panorama;var svLatlng;var sv_geocoder;var gmarkers=[];var rgeomarkers=[];var rbounds,gbounds;var titleText_;var titleTextRetryCount=0;var mapZoom;var sv_enabled=false;var guyIcon=new GIcon(G_DEFAULT_ICON);guyIcon.image="http://maps.google.com/intl/en_us/mapfiles/cb/man_arrow-0.png";guyIcon.transparent="http://maps.google.com/intl/en_us/mapfiles/cb/man-pick.png";guyIcon.imageMap=[26,13,30,14,32,28,27,28,28,36,18,35,18,27,16,26,16,20,16,14,19,13,22,8];guyIcon.iconSize=new GSize(49,52);guyIcon.iconAnchor=new GPoint(25,35);guyIcon.infoWindowAnchor=new GPoint(25,5);function showStreetView(){if(sv_enabled){stopStreetView()}else{loadStreetView()}}function setTitleText(a){var b=document.getElementById("title_text");if(b){b.innerHTML=a}else{titleText_=a;setTimeout(retryTitleText,100)}}function retryTitleText(){var a=document.getElementById("title_text");titleTextRetryCount++;if(a){a.innerHTML=titleText_}else{if(titleTextRetryCount<10){setTimeout(retryTitleText,100)}}}function loadStreetView(){client=new GStreetviewClient();sv_geocoder=new GClientGeocoder();svLatlng=gmap.getCenter();openNewPanorama();toggleOverlay();sv_enabled=true}function stopStreetView(){client=null;sv_geocoder=null;toggleOverlay();gmap.removeOverlay(sv_marker);if(mt1){mt1.disable();mt1=null}sv_enabled=false}function openNewPanorama(){if(!sv_marker){sv_marker=new GMarker(svLatlng,{icon:guyIcon,draggable:true})}mt1=new MarkerTracker(sv_marker,gmap);gmap.addOverlay(sv_marker);client.getNearestPanorama(svLatlng,onResponse);lastMarkerLocation=svLatlng;GEvent.addListener(sv_marker,"dragend",onDragEnd);GEvent.addListener(sv_marker,"click",openPanoramaBubble)}function openPanoramaBubble(){var d=document.createElement("div");d.style.textAlign="center";d.style.width="665px";d.style.height="425px";d.innerHTML="Loading panorama";var k;if(sv_marker&&sv_marker.Location&&sv_marker.Location.location&&sv_marker.Location.location.description){k=sv_marker.Location.location.description}else{k="unknown"}gmarkers[0]=sv_marker;var f=document.createElement("div");f.style.width="500px";f.style.height="350px";var l=document.createElement("table");l.setAttribute("border","0");var h=document.createElement("tbody");var j=document.createElement("tr");var a=document.createElement("th");a.setAttribute("id","title_text");var m=document.createTextNode(k);a.appendChild(m);j.appendChild(a);h.appendChild(j);l.appendChild(h);var g=document.createElement("tr");var e=document.createElement("td");var b=document.createElement("div");b.style.width="500px";b.style.height="300px";b.id="pano";e.appendChild(b);g.appendChild(e);h.appendChild(g);f.appendChild(l);var i=[];i.push(new GInfoWindowTab("streetview",f));sv_marker.tabs=i;sv_marker.openInfoWindowTabs(i,{maxContent:d,maxTitle:"Full screen"});panorama=new GStreetviewPanorama(b);panorama.setLocationAndPOV(sv_marker.getLatLng());GEvent.addListener(panorama,"initialized",onNewLocation);GEvent.addListener(panorama,"yawchanged",onYawChange);GEvent.addListener(panorama,"yawchanged",onPovYawChange);GEvent.addListener(panorama,"pitchchanged",onPovPitchChange);GEvent.addListener(panorama,"zoomchanged",onPovZoomChange);GEvent.addListener(panorama,"error",onPanoError);var c=gmap.getInfoWindow();GEvent.addListener(c,"maximizeend",function(){panorama.setContainer(d);window.setTimeout(panorama.checkResize(),5)});GEvent.addListener(gmap,"infowindowclose",function(){if(document.getElementById("panoflash1")===null){var t=document.createElement("div");t.id="panoflash1";t.style.display="none";document.getElementsByTagName("body").item(0).appendChild(t);document.getElementById("panoflash1").SetReturnValue=function(){}}if(document.getElementById("panoflash2")===null){var s=document.createElement("div");s.id="panoflash2";s.style.display="none";document.getElementsByTagName("body").item(0).appendChild(s);document.getElementById("panoflash2").SetReturnValue=function(){}}if(document.getElementById("panoflash3")===null){var r=document.createElement("div");r.id="panoflash3";r.style.display="none";document.getElementsByTagName("body").item(0).appendChild(r);document.getElementById("panoflash3").SetReturnValue=function(){}}if(document.getElementById("panoflash4")===null){var q=document.createElement("div");q.id="panoflash4";q.style.display="none";document.getElementsByTagName("body").item(0).appendChild(q);document.getElementById("panoflash4").SetReturnValue=function(){}}if(document.getElementById("panoflash5")===null){var p=document.createElement("div");p.id="panoflash5";p.style.display="none";document.getElementsByTagName("body").item(0).appendChild(p);document.getElementById("panoflash5").SetReturnValue=function(){}}if(document.getElementById("panoflash6")===null){var o=document.createElement("div");o.id="panoflash6";o.style.display="none";document.getElementsByTagName("body").item(0).appendChild(o);document.getElementById("panoflash6").SetReturnValue=function(){}}if(document.getElementById("panoflash7")===null){var n=document.createElement("div");n.id="panoflash7";n.style.display="none";document.getElementsByTagName("body").item(0).appendChild(n);document.getElementById("panoflash7").SetReturnValue=function(){}}})}function toggleOverlay(){if(!overlayInstance){overlayInstance=new GStreetviewOverlay();gmap.addOverlay(overlayInstance)}else{gmap.removeOverlay(overlayInstance);overlayInstance=null}}function onYawChange(b){var a=16;var c=360/a;if(b<0){b+=360}guyImageNum=Math.round(b/c)%a;guyImageUrl="http://maps.google.com/intl/en_us/mapfiles/cb/man_arrow-"+guyImageNum+".png";sv_marker.setImage(guyImageUrl)}var panoramaPov={};function onPovYawChange(a){panoramaPov.yaw=a}function onPovPitchChange(a){panoramaPov.pitch=a}function onPovZoomChange(a){panoramaPov.zoom=a}function onPanoError(a){alert("error:"+a)}function onNewLocation(l){var b=l.latlng;panorama.pitch=l.pov.pitch;panorama.yaw=l.pov.yaw;panorama.zoom=l.pov.zoom;var n=sv_marker.getLatLng().x;var m=sv_marker.getLatLng().y;var a=b.x;var o=b.y;var j=(a-n);var i=(o-m);var k=gmap.getCenter();var g=k.x;var e=k.y;var h=g+j;var f=e+i;var c=new GLatLng(f,h);sv_marker.setLatLng(b);var d=gmap.getInfoWindow();d.reset(l.latlng,d.getTabs(),new GSize(500,350),d.getPixelOffset());gmap.setCenter(c);panorama.focus()}function onDragEnd(){var a=sv_marker.getLatLng();if(panorama){client.getNearestPanorama(a,onResponse)}}function onResponse(a){if(a.code!=200){sv_marker.setLatLng(lastMarkerLocation)}else{var b=new GLatLng(a.location.lat,a.location.lng);sv_geocoder.getLocations(b,rgeocoder_callback);sv_marker.setLatLng(b);sv_marker.Location=a;lastMarkerLocation=b;openPanoramaBubble()}}function rgeocoder_callback(k){if(k.Status.code==G_GEO_SUCCESS){for(var c=0;c<rgeomarkers.length;c++){gmap.removeOverlay(rgeomarkers[c])}rgeomarkers=[];rbounds=new GLatLngBounds();for(var b=0;b<k.Placemark.length;b++){var a=k.Placemark[b].Point.coordinates;var h=new GLatLng(a[1],a[0]);rbounds.extend(h);html="placemark "+c;var d=createMarker2(h,null,b,html,k.Placemark[b]);rgeomarkers.push(d);if(h.distanceFrom(svLatlng)<10){var g=k.Placemark[b].address;g+="<br>address is approximate";var f=document.getElementById("title_text");if(f){f.innerHTML=g}else{setTitleText(g)}}}}else{var e="Code "+k.Status.code;if(reasons){if(reasons[k.Status.code]){e=reasons[k.Status.code]}}else{alert("street view failed: "+k.Status.code)}alert('Could not find "'+search+'" '+e)}}function setMarker(b,a){if(b=="g"){GEvent.trigger(gmarkers[a],"click")}else{if(b=="r"){GEvent.trigger(rgeomarkers[a],"click")}else{alert("bad marker array")}}}function createMarker2(b,a,c,e,d){var g=new GMarker(b,{draggable:true});g.marker_num=c;var f;if(d){f="Address: "+d.address;f+="<br>Accuracy: "+d.AddressDetails.Accuracy}else{f="Address: no address found"}GEvent.addListener(g,"click",function(){var h="<br>("+g.getLatLng().toUrlValue(6)+")";g.openInfoWindowHtml(e+"<br>"+f+h)});return g};

