var TRAIL_DOWNLOAD=1;var TRAIL_DOWNLOADING=2;var TRAIL_CLEAR=3;var STR_UNREGISTERED_USER="Unregistered User";var STR_TRAIL_LOADING="Trail loading";var STR_HIDE_TRAIL="Hide Trail";var STR_SHOW_TRAIL="Show Trail";var STR_LAST_UPDATE="Last update:";var STR_LAST_ALTITUDE="Altitude:";var STR_METERS_SYMBOL="m";if(!window.WMPG)WMPG={};WMPG.model={downloadPublicUsers:function(){if($('show_users_radio_button').checked){return true}else{return false}},clearSearch:function(){$('search_text').value=""},infoWindowNode:function(){return $('info_window_node')}};WMPG.controller={addListeners:function(){Event.observe($('hide_trail'),'click',WMPG.trailController.clearTrail)}};WMPG.trailView={showTrailView:function(a){if(a){$('trail').style.display='block'}else{$('trail').style.display='none'}},showTrailLoading:function(a){if(a){$('trail_loading').style.display='block'}else{$('trail_loading').style.display='none'}},showHideTrail:function(a){if(a){$('hide_trail').style.display='block'}else{$('hide_trail').style.display='none'}},showTrailInfo:function(a){if(a){$('trail_info').style.visibility='visible'}else{$('trail_info').style.visibility='hidden'}},updateTrailInfo:function(a){if(a.trailArray.length>0){startDate=new Date;startDate.setTime(a.oldest().time_stamp*1000);finishDate=new Date;finishDate.setTime(a.newest().time_stamp*1000);$('trail_start').innerHTML=startDate;$('trail_finish').innerHTML=finishDate}},enablePrevious:function(a){if(a){Event.observe($('previous'),'click',WMPG.trailController.downloadPreviousTrail.bindAsEventListener(WMPG.trailController));$('previous').style.textDecoration='underline'}else{Event.stopObserving($('previous'),'click',WMPG.trailController.downloadPreviousTrail.bindAsEventListener(WMPG.trailController));$('previous').style.textDecoration='none'}},enableNext:function(a){if(a){Event.observe($('next'),'click',WMPG.trailController.downloadNextTrail.bindAsEventListener(WMPG.trailController));$('next').style.textDecoration='underline'}else{Event.stopObserving($('next'),'click',WMPG.trailController.downloadNextTrail.bindAsEventListener(WMPG.trailController));$('next').style.textDecoration='none'}}};WMPG.userView={handeUsersChanged:function(a,b){this.showSearch(a&&a.pub);this.showOtherUsers(a&&a.pri);this.clearUserNames(false);this.clearUserNames(true);if(a&&a.pub&&a.pub.length){el=$('public_users_div');this.addUserNames(a.pub,b,el)}if(a&&a.pri&&a.pri.length){el=$('private_users_div');this.addUserNames(a.pri,b,el)}},showHideSearch:function(a){if(a&&a.pub){if(!$('search_div').hasChildNodes()){$('search_div').appendChild($('search_form'))}}else{$('hidden_div').appendChild($('search_form'))}},showSearch:function(a){a=false;if(a){$('search_form').style.display='block'}else{$('search_form').style.display='none'}},showOtherUsers:function(a){a=false;if(a){$('show_others_form').style.display='block'}else{$('show_others_form').style.display='none'}},removeOutOfBounds:function(a){this.doRemoveOutOfBounds($('private_users_div'),a);this.doRemoveOutOfBounds($('public_users_div'),a)},doRemoveOutOfBounds:function(a,b){var c=a.firstChild;if(c){while(next=c.nextSibling){if(!b.containsLatLng(new GLatLng(c.user.lat,c.user.lng))){a.removeChild(c)}c=next}a.removeChild(c)}},clearUserNames:function(a){var b="";if(a){b='private_users_div'}else{b='public_users_div'}while($(b).firstChild){$(b).removeChild($(b).firstChild)};this.userElements=new Hash()},addUserNames:function(a,b,c){for(i=0;i<a.length;i++){if(a[i].lat){if(b.containsLatLng(new GLatLng(a[i].lat,a[i].lng))){var d=document.createElement('div');d.user=a[i];this.userElements.set(a[i].id.toString(),d);this.updateUserNameElement(d);c.appendChild(d)}}}},updateUserNameElement:function(b){user=b.user;userName="Unregistered User";if(user.name){userName=user.name}userNameLink="<a href=\"javascript:void(0)\">"+userName+"</a>";b.innerHTML=userNameLink;if(user.tp){Event.observe(b,'click',function(a){WMPG.trailController.downloadTrail(this.user)})}Event.observe(b,'mouseover',function(a){WMPG.userController.suppressDownloadOnMove=true;WMPG.map.openUserInfoWindow(this.user)})}};var descTrailInterator=Class.create({initialize:function(a){this.trailArray=a;this.reset()},reset:function(){this.current=0},oldest:function(){return this.trailArray[0]},newest:function(){return this.trailArray[this.trailArray.length-1]},next:function(){if(this.current<this.trailArray.length){var a=this.trailArray[this.current];this.current++;return a}else{return null}}});var ascTrailInterator=Class.create({initialize:function(a){this.trailArray=a;this.reset()},reset:function(){this.current=this.trailArray.length-1},oldest:function(){return this.trailArray[this.trailArray.length-1]},newest:function(){return this.trailArray[0]},next:function(){if(this.current>-1){var a=this.trailArray[this.current];this.current--;return a}else{return null}}});var INITAL_DOWNLOAD=1;var NEXT_DOWNLOAD=2;var PREVIOUS_DOWNLOAD=3;WMPG.trailController={downloadingTrail:false,limit:2000,initalDownload:true,setViewForDownload:function(){WMPG.trailView.showTrailView(true);WMPG.trailView.showTrailLoading(true);WMPG.trailView.showHideTrail(false);WMPG.trailView.showTrailInfo(false)},downloadTrail:function(a){this.state=INITAL_DOWNLOAD;var b={parameters:{id:a.id}};this.doDownloadTrail(b)},downloadNextTrail:function(){this.state=NEXT_DOWNLOAD;var a={parameters:{id:this.userId,after:this.trailIterator.newest().time_stamp}};this.doDownloadTrail(a)},downloadPreviousTrail:function(){this.state=PREVIOUS_DOWNLOAD;var a={parameters:{id:this.userId,before:this.trailIterator.oldest().time_stamp}};this.doDownloadTrail(a)},clearTrail:function(a){WMPG.map.clearTrailOverlay();WMPG.trailView.showTrailView(false);this.trailIterator=null;this.trailArray=null},doDownloadTrail:function(a){if(!this.downloadingTrail){this.setViewForDownload();this.downloadingTrail=true;this.userId=a.parameters.id;a.parameters.limit=this.limit;a.onSuccess=function(t){WMPG.trailController.handleTrailDownload(t)};a.onFailure=function(){WMPG.trailController.handleTransportError()};a.onlyLatestOfClass='trail';a.method='get';url="/positions/trail";new Ajax.Request(url,a)}},handleTrailDownload:function(a){this.downloadingTrail=false;WMPG.map.clearTrailOverlay();WMPG.trailView.showTrailView(true);this.trailArray=a.responseJSON.trail;if(this.trailArray.length>2&&(this.trailArray[0].time_stamp>this.trailArray[1].time_stamp)){this.trailIterator=new ascTrailInterator(this.trailArray)}else{this.trailIterator=new descTrailInterator(this.trailArray)}WMPG.map.setBoundsToArray(this.trailArray);WMPG.trailView.updateTrailInfo(this.trailIterator);WMPG.trailView.showHideTrail(true);WMPG.trailView.showTrailLoading(false);WMPG.trailView.showTrailInfo(true);var b=this.trailArray.length;if(this.state==INITAL_DOWNLOAD){WMPG.trailView.enablePrevious(this.limit==b);WMPG.trailView.enableNext(false)}else if(this.state==NEXT_DOWNLOAD){WMPG.trailView.enablePrevious(true);WMPG.trailView.enableNext(this.limit==b)}else if(this.state=PREVIOUS_DOWNLOAD){WMPG.trailView.enablePrevious(this.limit==b);WMPG.trailView.enableNext(true)}var c=this.createLatLngArrays(this.trailIterator);WMPG.map.drawTrails(c,this.trailArray.length)},createLatLngArrays:function(a){var b=[];var c=[];if(a.trailArray.length>0){var d=a.next();b.push(new GLatLng(d.lat,d.lng));while(d=a.next()){var e=new GLatLng(d.lat,d.lng);var f=true;distance=e.distanceFrom(b[b.length-1]);if(distance>100){c.push(b);b=[]}b.push(e)}if(b.length>0){c.push(b)}}return c},handleTransportError:function(){this.downloadingTrail=false}};WMPG.userController={suppressDownloadOnMove:true,setBounds:true,userReloadByBoundsOustanding:false,userReloadByNameOustanding:false,downloadingUsers:false,downloadUsers:function(){if(!this.downloadingUsers){this.downloadingUsers=true;this.setBounds=true;url="/positions/users";new Ajax.Request(url,{method:'get',onSuccess:function(t){WMPG.userController.handleUserDownload(t)},onFailure:function(){WMPG.userController.handleTransportError()},onlyLatestOfClass:'users'})}},downloadUsersByName:function(a){if(!this.downloadingUsers){this.downloadingUsers=true;this.setBounds=true;url="/positions/users";dlPublic=WMPG.model.downloadPublicUsers();new Ajax.Request(url,{parameters:{name:a,download_public:dlPublic},method:'get',onSuccess:function(t){WMPG.userController.handleUserDownloadByName(t)},onFailure:function(){WMPG.userController.handleTransportError()},onlyLatestOfClass:'users'})}else{this.userReloadByNameOustanding=a}},downloadUsersByBounds:function(a){if(!this.downloadingUsers){var b=a.getNorthEast();var c=a.getSouthWest();var d=b.lat();var e=c.lat();var f=b.lng();var g=c.lng();dlPublic=WMPG.model.downloadPublicUsers();url="/positions/users";new Ajax.Request(url,{parameters:{nlat:d,slat:e,elng:f,wlng:g,download_public:dlPublic},method:'get',onSuccess:function(t){WMPG.userController.handleUserDownloadByBounds(t)},onFailure:function(){WMPG.userController.handleTransportError()},onlyLatestOfClass:'users'});this.downloadingUsers=true}else{this.userReloadByBoundsOustanding=true}},handleUserDownloadByBounds:function(a){this.handleUserDownload(a.responseJSON);if(this.userReloadByBoundsOustanding){this.userReloadByBoundsOustanding=false;this.downloadUsersByBounds(WMPG.map.map.getBounds())}},handleUserDownloadByName:function(a){this.handleUserDownload(a.responseJSON);if(this.userReloadByNameOustanding){this.downloadUsersByName(this.userReloadByNameOustanding);this.userReloadByNameOustanding=null}},handleUserDownload:function(a){this.downloadingUsers=false;this.userArray=a;if(this.setBounds){this.suppressDownloadOnMove=true;if(this.userArray.pub&&this.userArray.pub.length){WMPG.map.setBoundsToArray(this.userArray.pub)}else if(this.userArray.pri&&this.userArray.pri.length){WMPG.map.setBoundsToArray(this.userArray.pri)}}WMPG.map.updateUserMarkers(this.userArray);WMPG.userView.handeUsersChanged(this.userArray,WMPG.map.map.getBounds());if(this.setBounds){this.setBounds=false}},handleMoveEnd:function(){if(!this.suppressDownloadOnMove){this.downloadUsersByBounds(WMPG.map.map.getBounds())}else{this.suppressDownloadOnMove=false}},handleTransportError:function(){this.suppressDownloadOnMove=false;this.setBounds=false;this.userReloadByBoundsOustanding=false;this.userReloadByNameOustanding=false;this.downloadingUsers=false}};WMPG.map={setupMap:function(){this.map=new GMap2($('map_canvas'));var h=new GLatLngBounds(new GLatLng(-90,-180),new GLatLng(90,180));var j="We are sorry, but we don't<br>have imagery at this zoom<br>level for this region.<br><br>Try zooming out for a<br>broader look.";var k=new GCopyright(1,h,0,"Map data &copy;2007 Mapabc.com");var l=new GCopyrightCollection("");l.addCopyright(k);var m=new GTileLayer(l,0,17);m.getTileUrl=function(a,b){return"http://servicetile.mapabc.com/googlechina/maptile?v=w2.66&x="+a.x+"&y="+a.y+"&zoom="+(17-b)};dituMap=new GMapType([m],new GMercatorProjection(23),"Ditu",{shortName:"Ditu",alt:"Show maps from Google China (Ditu)",errorMessage:j});var n=G_NORMAL_MAP.getTileLayers()[0];var o=new GMapType([n],new GMercatorProjection(23),"Google Map",{shortName:"GoogleMap",alt:"Show maps from Google Maps",errorMessage:j});this.map.addMapType(o);this.map.addMapType(dituMap);var p=new GCopyright(2,h,0,"&nbsp;&nbsp;&copy; 2007 NAVTEQ");var q=new GCopyright(3,h,10,"&nbsp;&nbsp;&copy; 2007 NAVTEQ&nbsp;&nbsp;&copy; 2007 AND");var r=new GCopyrightCollection("&copy; 2007 Microsoft Corporation");r.addCopyright(p);r.addCopyright(q);function getMSURL(a,b,c,d,e){var f=((a.y&1)<<1)+(a.x&1);var g="http://"+c+f+".ortho.tiles.virtualearth.net/tiles/"+c;for(var i=b-1;i>=0;i--){g+=((((a.y>>i)&1)<<1)+((a.x>>i)&1))}g+="."+d+"?g=110"+e;return g}var s=new GTileLayer(r,1,19);s.getTileUrl=function(a,b){return getMSURL(a,b,"r","png","")};var t=new GMapType([s],new GMercatorProjection(23),"MS Map",{shortName:"MS Map",alt:"Show road maps from Microsoft Live Search",errorMessage:j});this.map.addMapType(t);var u=new GCopyright(6,h,0,"&nbsp;&nbsp;&copy; 2007 MapLink");var v=new GCopyrightCollection("&copy; 2007 Microsoft Corporation");v.addCopyright(u);var w=new GTileLayer(v,1,19);w.getTileUrl=function(a,b){var c=((a.y&1)<<1)+(a.x&1)+1;var d="http://img"+c+".maplink3.com.br/MapaVE.aspx?v=r|"+c+"|r|";for(var i=b-1;i>=0;i--){d+=((((a.y>>i)&1)<<1)+((a.x>>i)&1))}d+="|png|66";return d};var x=new GMapType([w],new GMercatorProjection(23),"MS Brasil Map",{shortName:"MS Brasil Map",alt:"Show road maps from Microsoft Live Brasil",errorMessage:j});this.map.addMapType(x);var y=new GCopyright(4,h,0,"&nbsp;&nbsp;Data &copy; 2007 Navteq, TeleAtlas");var z=new GCopyrightCollection("&copy; 2007 Yahoo Inc.");z.addCopyright(y);function getYURL(a,b,c){var d=c;d+="&x="+a.x+"&y="+(((1<<b)>>1)-1-a.y)+"&z="+(18-b);return d}var A=new GTileLayer(z,1,17);A.getTileUrl=function(a,b){return getYURL(a,b,"http://png.maps.yimg.com/png?t=m&v=4.1&s=256&f=j")};var B=new GMapType([A],new GMercatorProjection(23),"Yahoo Map",{shortName:"Yahoo Map",alt:"Show road maps from Yahoo",errorMessage:j});this.map.addMapType(B);var C=new GCopyright(5,h,0,"&nbsp;&nbsp;Data &copy; 2007 CE Info Systems");var D=new GCopyrightCollection("&copy; 2007 Yahoo Inc.");D.addCopyright(C);var E=new GTileLayer(D,1,17);E.getTileUrl=function(a,b){return getYURL(a,b,"http://tile.in.maps.yahoo.com/tile?imgtype=png&v=0.96")};var F=new GMapType([E],new GMercatorProjection(23),"Yahoo India Map",{shortName:"Yahoo India Map",alt:"Show road maps from Yahoo India",errorMessage:j});this.map.addMapType(F);var G=new GCopyrightCollection("<a href=\"http://www.openstreetmap.org/\">OpenStreetMap</a>");G.addCopyright(new GCopyright(1,new GLatLngBounds(new GLatLng(-90,-180),new GLatLng(90,180)),0," "));var H=new GTileLayer(G,1,17,{tileUrlTemplate:'http://tile.openstreetmap.org/{Z}/{X}/{Y}.png'});var I=new GTileLayer(G,1,17,{tileUrlTemplate:'http://tah.openstreetmap.org/Tiles/tile.php/{Z}/{X}/{Y}.png'});var n=G_NORMAL_MAP.getTileLayers()[0];var J=new GMapType([H],G_NORMAL_MAP.getProjection(),"Mapnik");var K=new GMapType([I],G_NORMAL_MAP.getProjection(),"Osmarend");this.map.addMapType(J);this.map.addMapType(K);var L=G_HYBRID_MAP.getTileLayers()[0];var M=new GMapType([L],new GMercatorProjection(23),"Google Sat",{shortName:"GoogleSat",alt:"Show satellite imagery from Google Maps",textColor:"white",linkColor:"white",errorMessage:j});this.map.addMapType(M);var N=new GTileLayer(r,1,19);N.getTileUrl=function(a,b){return getMSURL(a,b,"a","jpeg","")};var O=new GMapType([N],new GMercatorProjection(23),"MS Sat",{shortName:"MS Sat",alt:"Show aerial imagery from Microsoft Live Search",textColor:"white",linkColor:"white",errorMessage:j});this.map.addMapType(O);var P=new GTileLayer(z,1,17);P.getTileUrl=function(a,b){return getYURL(a,b,"http://aerial.maps.yimg.com/ximg?t=a&v=1.7&s=256")};var Q=new GMapType([P],new GMercatorProjection(23),"Yahoo Sat",{shortName:"Yahoo Sat",alt:"Show aerial imagery from Yahoo Maps",textColor:"white",linkColor:"white",errorMessage:j});this.map.addMapType(Q);var R=G_HYBRID_MAP.getTileLayers()[1];var S=new GMapType([L,R],new GMercatorProjection(23),"Google Hyb",{shortName:"GoogleHyb",alt:"Show imagery with street names from Google Maps",textColor:"white",linkColor:"white",errorMessage:j});this.map.addMapType(S);var T=new GTileLayer(r,1,19);T.getTileUrl=function(a,b){return getMSURL(a,b,"h","jpeg","")};var U=new GMapType([T],new GMercatorProjection(23),"MS Hyb",{shortName:"MS Hyb",alt:"Show aerial imagery and street names from Microsoft Live Search",textColor:"white",linkColor:"white",errorMessage:j});this.map.addMapType(U);var V=new GTileLayer(z,1,17);V.getTileUrl=function(a,b){return getYURL(a,b,"http://aerial.maps.yimg.com/tile?t=p&v=2.5")};var W=new GMapType([P,V],new GMercatorProjection(23),"Yahoo Hyb",{shortName:"Yahoo Hyb",alt:"Show aerial imagery and road maps from Yahoo Maps",textColor:"white",linkColor:"white",errorMessage:j});this.map.addMapType(W);var X=new GTileLayer(D,1,17);X.getTileUrl=function(a,b){return getYURL(a,b,"http://aerial.in.maps.yahoo.com/tile?imgtype=png&v=0.93")};var Y=new GMapType([P,X],new GMercatorProjection(23),"Yahoo India Hyb",{shortName:"Yahoo India Hyb",alt:"Show aerial imagery and road maps from Yahoo India Maps",textColor:"white",linkColor:"white",errorMessage:j});this.map.addMapType(Y);this.map.addMapType(G_PHYSICAL_MAP);var Z=G_PHYSICAL_MAP.getTileLayers()[0];var ba=new GMapType([Z],new GMercatorProjection(23),"Google Terrain",{shortName:"GooglePhys",alt:"Show street map with terrain from Google Maps",errorMessage:j});this.map.addMapType(ba);var bb=new GTileLayer(r,1,19);bb.getTileUrl=function(a,b){return getMSURL(a,b,"r","png","&shading=hill")};var bc=new GMapType([bb],new GMercatorProjection(23),"MS Terrain",{shortName:"MS Terrain",alt:"Show road maps with terrain shading from Microsoft Live Search",errorMessage:j});this.map.addMapType(bc);this.map.addMapType(G_SATELLITE_3D_MAP);var bd=new GHierarchicalMapTypeControl();bd.clearRelationships();bd.addRelationship(G_NORMAL_MAP,o,"Google Maps",true);bd.addRelationship(G_NORMAL_MAP,dituMap,"Google China Maps",false);bd.addRelationship(G_NORMAL_MAP,t,"Microsoft Live Road Maps",false);bd.addRelationship(G_NORMAL_MAP,x,"Microsoft Brasil Road Maps",false);bd.addRelationship(G_NORMAL_MAP,B,"Yahoo Maps",false);bd.addRelationship(G_NORMAL_MAP,F,"Yahoo India Maps",false);bd.addRelationship(G_NORMAL_MAP,J,"OpenStreetMap Mapnik",false);bd.addRelationship(G_NORMAL_MAP,K,"OpenStreetMapnik OSM Renderer",false);bd.addRelationship(G_SATELLITE_MAP,M,"Google Satellite",true);bd.addRelationship(G_SATELLITE_MAP,O,"Microsoft Live Aerial Maps",false);bd.addRelationship(G_SATELLITE_MAP,Q,"Yahoo Satellite",false);bd.addRelationship(G_HYBRID_MAP,S,"Google Hybrid",true);bd.addRelationship(G_HYBRID_MAP,U,"Microsoft Live Hybrid Maps",false);bd.addRelationship(G_HYBRID_MAP,W,"Yahoo Hybrid",false);bd.addRelationship(G_HYBRID_MAP,Y,"Yahoo India Hybrid",false);bd.addRelationship(G_PHYSICAL_MAP,ba,"Google Terrain",true);bd.addRelationship(G_PHYSICAL_MAP,bc,"Microsoft Live Terrain",false);this.map.addControl(bd,new GControlPosition(G_ANCHOR_TOP_RIGHT,new GSize(10,25)));this.map.addControl(new GScaleControl());this.map.addControl(new GLargeMapControl(),new GControlPosition(G_ANCHOR_TOP_RIGHT,new GSize(10,90)));this.map.addControl(new GOverviewMapControl());new Form.Element.Observer('search_text',0.5,function(a,b){WMPG.userController.downloadUsersByName(b)});new Form.Element.Observer('show_users_radio_button',0.5,function(a,b){WMPG.userController.setBounds=true;if(!WMPG.model.downloadPublicUsers()){WMPG.map.removePublicUserMarkers()}WMPG.userController.downloadUsersByBounds(WMPG.map.map.getBounds())});this.publicUserMarkers=new Hash();this.privateUserMarkers=new Hash();this.map.setCenter(new GLatLng(0,0),2);this.map.setMapType(o);this.clusterer=new Clusterer(this.map);this.trailOverlays=[]},loadUsersOnMove:function(){this.moveEndEventHandle=GEvent.addListener(this.map,"moveend",function(){WMPG.map.handleMoveEnd()})},handleMoveEnd:function(){WMPG.userController.handleMoveEnd()},setBoundsToArray:function(a){bounds=new GLatLngBounds;for(var i=0;i<a.length;i++){if(a[i].lat){bounds.extend(new GLatLng(a[i].lat,a[i].lng))}}center=bounds.getCenter();zoomLevel=this.map.getBoundsZoomLevel(bounds);this.map.setCenter(center,zoomLevel)},handleTransportError:function(){this.userReloadByBoundsOustanding=false;this.userReloadByNameOustanding=false;this.downloadingUsers=false},removePublicUserMarkers:function(){this.publicUserMarkers.each(function(a){WMPG.map.removeOverlay(a.value)});this.publicUserMarkers=new Hash()},createMarker:function(a){latlng=new GLatLng(a.lat,a.lng);var b=new GMarker(latlng,{icon:G_DEFAULT_ICON});b.user=a;GEvent.addListener(b,"click",function(){WMPG.map.openUserInfoWindow(this.user)});return b},updateUserMarkers:function(a){if(a.pub&&a.pub.length){this.doUpdateUserMarkers(a.pub,this.publicUserMarkers)}if(a.pri&&a.pri.length){this.doUpdateUserMarkers(a.pri,this.privateUserMarkers)}},doUpdateUserMarkers:function(a,b){for(i=0;i<a.length;i++){user=a[i];if(user.lat){marker=b.get(user.id.toString());if(marker){latlng=marker.getLatLng();if(!(latlng.lat()==user.lat&&latlng.lng()==user.lng)){b.unset(user.id.toString());this.removeOverlay(marker);marker=this.createMarker(user);b.set(user.id.toString(),marker);this.addOverlay(marker)}}else{marker=this.createMarker(user);b.set(user.id.toString(),marker);this.addOverlay(marker)}}}},openUserInfoWindow:function(a){date=new Date;date.setTime(a.time_stamp*1000);userName="Unregistered User";if(a.name){userName=a.name}if(WMPG.trailController.userId==a.id){if(WMPG.trailController.downloadingTrail){}}if(!this.infoWindowNode){this.infoWindowNode=WMPG.model.infoWindowNode()}x=this.infoWindowNode.firstChild;while(x){if(x.id=="user_name"){x.innerHTML=userName+" "}if(x.id=="show_trail"){if(a.tp){x.style.visibility='visible';x.user=a;Event.observe(x,'click',function(){WMPG.trailController.downloadTrail(this.user)})}else{x.style.visibility='hidden';Event.stopObserving(el,'click',WMPG.trailController.downloadTrail)}}if(x.id=="last_update"){x.innerHTML=STR_LAST_UPDATE+" "+date+" "}if(x.id=="altitude"){x.innerHTML=STR_LAST_ALTITUDE+a.alt+STR_METERS_SYMBOL}x=x.nextSibling}this.map.openInfoWindow(new GLatLng(a.lat,a.lng),this.infoWindowNode)},addOverlay:function(a){this.clusterer.AddMarker(a,"")},removeOverlay:function(a){this.clusterer.RemoveMarker(a)},getColorString:function(a,b){color=((b-a)/b)*255|0;colorString=color.toString(16);if(colorString.length==1){colorString="0"+colorString}return"#"+colorString+"0000"},drawTrails:function(a,b){this.trailOverlays=[];numberOfShades=10;pointsPerShadeCount=(b/numberOfShades)|0;pointsPerShade=pointsPerShadeCount;var c=0;for(var i=a.length-1;i>-1;i--){if(a[i].length>1){arrayStartIndex=b-1;for(var j=a[i].length-1;j>-1;j--){c++;breakLine=false;if(pointsPerShade--==0){breakLine=true;pointsPerShade=pointsPerShadeCount}if(breakLine||j==0){colorString=this.getColorString(c,b);drawArray=a[i].slice(j,arrayStartIndex+1);var d=new GPolyline(drawArray,colorString,4,0.7);this.trailOverlays.push(d);this.map.addOverlay(d);arrayStartIndex=j}}}else{}}},clearTrailOverlay:function(){this.trailArray=[];this.trailOverlays.each(function(a){WMPG.map.map.removeOverlay(a)})},drawTrail:function(a){var b=[];for(var i=a.length-1;i>-1;--i){update=a[i];b.push(new GLatLng(update.lat,update.lng))}polyLine=new GPolyline(b,"#FF0000",4,0.7);this.map.addOverlay(polyLine);this.trailOverlays.push(polyLine)},drawTrailOld:function(a){var b=[];numberOfShades=10;pointsPerShadeCount=(a.length/numberOfShades)|0;pointsPerShade=pointsPerShadeCount;test=false;for(var i=a.length-1;i>-1;--i){update=a[i];if(i>0){previousUpdate=a[i-1]}else{previousUpdate=a[0]}var c=this.map.getBounds();var d=(c.containsLatLng(new GLatLng(update.location.latitude,update.location.longitude))||c.containsLatLng(new GLatLng(previousUpdate.location.latitude,previousUpdate.location.longitude)));if(d){b.push(new GLatLng(update.location.latitude,update.location.longitude))}breakLine=!d||i==0;if(pointsPerShade--==0){breakLine=true;pointsPerShade=pointsPerShadeCount}if(breakLine&&b.length>1){color=(a.length-i)/a.length*255|0;colorString=color.toString(16);if(colorString.length==1){colorString="0"+colorString}this.map.addOverlay(new GPolyline(b,"#"+colorString+"0000",4,0.7));if(d){lastPoint=b[b.length-1];b=[];b.push(lastPoint)}else{b=[]}}}}};