var fl=new Object();fl._memberMarkers={};fl._fleetVisible=false;fl._selectedFleet=-1;fl._fleets=new Object();fl._centerMarker=null;fl._baseIcon=new GIcon();fl._baseIcon.shadow="res/markershadow.png";fl._baseIcon.iconSize=new GSize(37,56);fl._baseIcon.shadowSize=new GSize(66,56);fl._baseIcon.iconAnchor=new GPoint(18,56);fl._baseIcon.infoWindowAnchor=new GPoint(17,2);fl._baseIcon.infoShadowAnchor=new GPoint(17,30);function formatSpeed(A){return Math.round(A*3.6)}function timeStampSorter(B,A,C){return floatComparator(B.getData("timeStamp"),A.getData("timeStamp"),C)}function initFleetTable(){var C=function(F,E,G,H){F.innerHTML=Math.round(H)};var B=function(F,E,G,H){F.innerHTML=formatSpeed(H)};var D=[{key:"userId",sortable:true,resizeable:false,label:"member",width:50},{key:"timeStamp",sortable:true,sortOptions:{sortFunction:timeStampSorter},resizeable:false,label:"Last Seen",formatter:timeStampFormatter,width:75},{key:"speed",sortable:true,resizeable:false,label:"Spd.&nbsp;&nbsp;<br>km/h",formatter:B,width:40},{key:"alt",sortable:true,resizeable:false,label:"Alt.",formatter:C,width:25},{key:"statusText",sortable:true,resizeable:false,label:"Status message",width:140}];fl.ds=new YAHOO.util.DataSource("api/fleet/",{responseType:YAHOO.util.DataSource.TYPE_JSON,connXhrMode:"queueRequests",responseSchema:{resultsList:"ResultSet.Result",fields:["userId","statusText","lat","lon","alt","speed","timeStamp"]}});var A={initialLoad:false,selectionMode:"single"};fl.dt=new YAHOO.widget.DataTable("fleettable",D,fl.ds,A);fl.dt.subscribe("rowMouseoverEvent",fl.dt.onEventHighlightRow);fl.dt.subscribe("rowMouseoutEvent",fl.dt.onEventUnhighlightRow);fl.dt.subscribe("rowClickEvent",fl._onFleetRowClicked)}fl._onFleetRowClicked=function(B){if(!fl._fleetVisible){fl.showFleet()}fl.dt.onEventSelectRow(B);var A=fl.dt.getRecord(fl.dt.getSelectedRows()[0]);fl._centerMapOnUser(A.getData("userId"))};fl._centerMapOnUser=function(C){var B=fl._memberMarkers[C];if(B!=null){var A=new GLatLng(B.record.getData("lat"),B.record.getData("lon"));map.setCenter(A,map.getZoom());B.openInfoWindowHtml(B.infoText)}};fl._fleetUpdatedCallback=function(C,B,A){wo.endProgress();fl.dt.onDataReturnInitializeTable(C,B,A);fl._updateFleetOnMap();setTimeout(fl._refreshStats,100)};fl.updateFleet=function(){if(fl._selectedFleet==-1){return false}var A={success:fl._fleetUpdatedCallback,failure:fl._fleetUpdatedCallback,scope:fl.dt};wo.startProgress();fl.ds.sendRequest(fl._selectedFleet+"/view?format=json",fl._fleetUpdatedCallback);return false};function showFleetChecked(){if(wo.getEl("showfleet").checked){fl.showFleet()}else{fl.hideFleet()}}fl.showFleet=function(){var A=wo.getEl("showfleet");if(!A.chechked){A.checked=true}if(!fl._fleetVisible){wo.addNotification("Showing your bunch");fl._fleetVisible=true}fl._updateFleetOnMap();fl._refreshStats()};fl._updateFleetOnMap=function(){if(!fl._fleetVisible){return }$.each(fl.dt.getRecordSet().getRecords(),function(){var B=this.getData("userId");var A=fl._memberMarkers[B];if(A!=null){map.removeOverlay(A)}map.addOverlay(fl._memberMarkers[B]=fl.createMarker(this))})};fl.hideFleet=function(){if(fl._fleetVisible){wo.addNotification("Hiding your bunch");clearInterval(fl._fleetVisible);fl._fleetVisible=false}wo.getEl("showfleet").checked=false;fl._hideFleetMarkers();fl._fleetVisible=false;fl._refreshStats()};fl._hideFleetMarkers=function(){$.each(fl._memberMarkers,function(){map.removeOverlay(this)});fl._memberMarkers={}};fl.createMarker=function(C){var E=new GIcon(fl._baseIcon);E.image=(C.getData("active")=="1")?"res/fleetactivemember.png":"res/fleetinactivemember.png";var D="<h3>"+C.getData("userId")+"</H3>Last seen: "+prettyDate(C.getData("timeStamp"),false)+" ("+prettyDate(C.getData("timeStamp"),true)+")<br>Speed: "+formatSpeed(C.getData("speed"))+"<br>Status message: "+C.getData("statusText");var A=new GLatLng(C.getData("lat"),C.getData("lon"));var B=new GMarker(A,{icon:E});B.record=C;B.infoText=D;GEvent.addListener(B,"click",function(){B.openInfoWindowHtml(D)});return B};function updateFleetLink(A){A.href="api/fleet/"+fl._selectedFleet+"/view?format=kmlnetworklink"}fl.invite=function(){alert("This feature does'nt work yet. Please use the e-mail invitation, you will find the link below.")};fl.inviteInMail=function(){wo.openDialog("inviteInMail.jsp?fleetid="+fl._selectedFleet,true)};fl._fleetListContCb=null;fl.loadFleetList=function(A){if(A){fl._fleetListContCb=A}$.getScript("api/user/"+userId+"/fleets?cb=fl.fleetListCB")};fl.fleetListCB=function(C,A){if(A!="OK"){alert(A);return }var B=new StringBuffer();B.append("Your bunches: ");var D=0;fl.fleets={};$.each(C.Result,function(){fl.fleets[this.id]=this;if(D){B.append(" | ")}++D;B.append('<a href="" onclick="return fl.selectFleet(').append(this.id).append(')">').append(this.name).append("</a>")});if(!D){B.append("You have no bunches. Try to create one or join to one by receiving an invitation from somebody.")}else{if(fl._fleetListContCb){fl._fleetListContCb();fl._fleetListContCb=null}}$("#bunchlist").html(B.toString())};fl.selectFleet=function(A){if(fl._selectedFleet==A){return false}var B=fl.fleets[A];if(!B){return false}wo.addNotification("Loading bunch: "+B.name);fl._selectedFleet=A;$("#fleetNameDisplay").html(B.name).attr("title",B.description);displayElmnt("pubfleetcmds",B.isPublic);fl._hideFleetMarkers();fl.updateFleet();saveProperty("defaultfleet",A);displayElmnt("fleetdata",1);return false};fl._refreshStats=function(){var D=fl.dt.getRecordSet().getLength();var E=0;var B=0;var C=0;$.each(fl.dt.getRecordSet().getRecords(),function(){if(this.getData("active")==1){++E}B+=parseFloat(this.getData("lat"));C+=parseFloat(this.getData("lon"))});B/=D;C/=D;var G=new StringBuffer();G="<table><tr><td>Members displayed: "+D+"</td><td>Active: "+E+"</td></tr></table>";$("#fleetstats").html(G);if(fl._centerMarker!=null){map.removeOverlay(fl._centerMarker);fl._centerMarker=null}if(wo.getEl("showfleetcenter").checked&&fl._fleetVisible){var F="<h3>Center of fleet "+fl.fleets[fl._selectedFleet].name+"</H3>";var A=new GLatLng(B,C);fl._centerMarker=new GMarker(A);GEvent.addListener(fl._centerMarker,"click",function(){fl._centerMarker.openInfoWindowHtml(F)});map.addOverlay(fl._centerMarker)}};fl.openEmbedder=function(){wo.openDialog("embedHelper.jsp?fleetid="+fl._selectedFleet)};fl.editCurrentFleet=function(){wo.openDialog("fleetForm.jsp?fleetid="+fl._selectedFleet)};setInterval(fl.updateFleet,30000);