(function(a){a.fn.sortNodes=function(b){b=b||(function(f,e){return f.text()>e.text()?1:-1});var d=this.parent();if(d.length>1){return this}this.detach();var c=a(Array.prototype.sort.call(this,function(g,e){var f=b(a(g),a(e));if(f!=null){return f}else{return 0}}));d.append(c);return c}})(jQuery);(function(){GeoUtilities={getDistance:function(b,a){return Math.sqrt(GeoUtilities.getSquaredDistance(b,a))},getSquaredDistance:function(f,e){var d=Math.abs(e[0]-f[0]);var c=Math.abs(e[1]-f[1]);return d*d+c*c}};window.GeoUtilities=GeoUtilities})();if(typeof Object.create!=="function"){Object.create=function(b){function a(){}a.prototype=b;return new a()}}(function($){Utilities={mixin:function(obj,obj2){for(var i in obj2){if(obj2.hasOwnProperty(i)){obj[i]=obj2[i]}}return obj},createNamespace:function(nsString){try{eval(nsString);return false}catch(e){}var namespaceRegex=/([^\.]+)/g;var currentNamespace=window;var match=[];while(match=namespaceRegex.exec(nsString)){if(match[1]===undefined){throw new Error("improperly-formatted namespace string")}var space=match[1];if(currentNamespace[space]===undefined){currentNamespace[space]={}}currentNamespace=currentNamespace[space]}return true},hitch:function(scope,fn){return function(){return fn.apply(scope,Array.prototype.slice.call(arguments))}},force:function(scope,fn,args){return function(){return fn.apply(scope,args)}},hexToRGB:function(hex){if(Utilities.hexToRGB.cache==null){Utilities.hexToRGB.cache={}}if(Utilities.hexToRGB.cache[hex]!=null){return Utilities.hexToRGB.cache[hex]}var result=[parseInt(hex.substr(1,2),16),parseInt(hex.substr(3,2),16),parseInt(hex.substr(5,2),16)];Utilities.hexToRGB.cache[hex]=result;return result},clone:function(obj){if($.isArray(obj)){return $.extend(true,[],obj)}return $.extend(true,{},obj)},ajax:function(settings){var def={type:"GET",url:"/api/routes",data:{},contentType:"application/json"};settings=$.extend(def,settings);var ajaxSettings={type:settings.type,url:settings.url,data:settings.type=="GET"?settings.data:JSON.stringify(settings.data),contentType:settings.contentType,processData:settings.type=="GET"?true:false,beforeSend:function(xhr){$.publish("transloc/ajax/start",[])},error:function(xhr,status,error){$.publish("transloc/ajax/error",[status,error]);$.publish("transloc/ajax/end",[]);var json={};try{json=JSON.parse(xhr.responseText)}catch(e){}settings.error.call(null,status,json)},success:function(data,status,xhr){$.publish("transloc/ajax/success",[data,status]);$.publish("transloc/ajax/end",[]);settings.success.call(null,data,status)}};$.ajax(ajaxSettings)},loadScript:function(src){var script=document.createElement("script");script.src=src;script.type="text/javascript";$("body").append(script)}};window.Utilities=Utilities})(jQuery);(function(d){var a={$messageDialog:null};var b='<div class="message"></div>';function c(f,e){return function(g){if(e.call(null,g)){f.dialog("close")}}}UIUtilities={showMessageDialog:function(g){var j={title:"Message",message:"This is a message.",buttons:{OK:function(){return true}},modal:true,type:UIUtilities.MESSAGE_TYPE_INFO};g=d.extend(j,g);if(a.$messageDialog==null){a.$messageDialog=d('<div class="translocjs_message">'+b+"</div>").dialog({autoOpen:false,modal:true,minWidth:640,width:640,resizable:false})}var h=a.$messageDialog;h.find(".message").html(g.message);var f={};for(var e in g.buttons){if(g.buttons.hasOwnProperty(e)){f[e]=c(h,g.buttons[e])}}h.dialog("option",{title:g.title,buttons:f,dialogClass:g.type}).dialog("open");return h},showErrorDialog:function(e){var f={title:"Error",message:"An error occurred!",type:UIUtilities.MESSAGE_TYPE_ERROR};e=d.extend(f,e);return UIUtilities.showMessageDialog(e)},showWarningDialog:function(e){var f={title:"Warning",message:"Warning! Something happened...",type:UIUtilities.MESSAGE_TYPE_WARNING};e=d.extend(f,e);return UIUtilities.showMessageDialog(e)},showInfoDialog:function(e){var f={title:"Information",message:"Your message here."};e=d.extend(f,e);return UIUtilities.showMessageDialog(e)},validate:function(o){var g={validationType:"nonempty",message:"This field not be empty."};var h=true;for(var n in o){if(o.hasOwnProperty(n)){var k=[];if(d.isArray(o[n])){k=o[n]}else{k.push(o[n])}for(var m=0,p=k.length;m<p;m++){var l=d.extend(g,k[m]);var e=true;var f=d(n);var q=f.val();if(l.validationType=="nonempty"){e=q!=""&&q!=null}else{if(l.validationType=="equals"){e=q==l.value}else{if(l.validationType=="callback"){e=l.callback.call(null,q)}}}if(l.message==q){e=false}if(!e){f.addClass("validate_error");f.val(l.message);f.click(function(){d(this).val("");d(this).removeClass("validate_error")});h=false;break}}}}return h},resetValidation:function(e){for(var f in e){if(e.hasOwnProperty(f)){d(f).removeClass("validate_error").val("")}}},templateReplace:function(h,g){var e=h;for(var f in g){if(g.hasOwnProperty(f)){var i=new RegExp("%%"+f+"%%","g");e=e.replace(i,g[f])}}return e},_$spinner:null,showSpinner:function(){if(UIUtilities._$spinner===null){UIUtilities._$spinner=d('<div class="translocjs-spinner"><div class="translocjs-spinner-icon"></div></div>').appendTo("body").hide()}UIUtilities._$spinner.fadeIn("fast")},_hideTimer:null,hideSpinner:function(){if(UIUtilities._hideTimer!=null){clearTimeout(UIUtilities._hideTimer)}UIUtilities._hideTimer=setTimeout(function(){if(UIUtilities._$spinner!=null){UIUtilities._$spinner.fadeOut("fast")}UIUtilities._hideTimer=null},100)}};UIUtilities.MESSAGE_TYPE_INFO="info_message";UIUtilities.MESSAGE_TYPE_ERROR="error_message";UIUtilities.MESSAGE_TYPE_WARNING="warning_message";Utilities.createNamespace("transloc.UIUtilities");transloc.UIUtilities=UIUtilities})(jQuery);(function(){function a(b){settigns=b||{};Utilities.mixin(this,b)}a.prototype={position:[35.78,-78.67],imageUrl:null,imageSize:[21,32],imageOffset:[0,0],infoWindow:null,shape:null,clickHandler:function(b){throw new Error("clickHandler should be implemented either by a setting at construction, or by an extending class.")}};Utilities.createNamespace("transloc.map._Marker");transloc.map._Marker=a})();(function(){function a(b){b=b||{};Utilities.mixin(this,b)}a.prototype={title:"",contents:"",fetchContents:function(b){b.call(null,this.contents)}};Utilities.createNamespace("transloc.map._InfoWindow");transloc.map._InfoWindow=a})();(function(){function a(b){b=b||{};Utilities.mixin(this,b);if(this.points.length==0){if(this.encodedString.length>0){this.points=a.decode(this.encodedString)}else{throw new Error("Cannot instantiate a _Polyline without either 'points' or 'encodedString'")}}}a.prototype={points:[],color:"#000000",width:3,encodedString:""};a.decode=function(l){var e=l.length;var d=0;var g=[];var i=0;var j=0;while(d<e){var k;var c=0;var m=0;do{k=l.charCodeAt(d++)-63;m|=(k&31)<<c;c+=5}while(k>=32);var f=((m&1)?~(m>>1):(m>>1));i+=f;c=0;m=0;do{k=l.charCodeAt(d++)-63;m|=(k&31)<<c;c+=5}while(k>=32);var h=((m&1)?~(m>>1):(m>>1));j+=h;g.push([i*0.00001,j*0.00001])}return g};Utilities.createNamespace("transloc.map._Polyline");transloc.map._Polyline=a})();(function(){function a(c,b){b=b||{};this.domNode=c||null;Utilities.mixin(this,b)}a.prototype={domNode:null,center:[35.78,-78.67],zoomLevel:14,mapStyle:null,showControls:true,init:function(){throw new Error("Initialize hasn't been implemented.")},drawPolyline:function(b){throw new Error("drawPolyline not implemented yet.")},clearPolylines:function(){throw new Error("clearPolylines not implemented yet.")},drawMarker:function(b){throw new Error("drawMarker not implemented yet.")},clearMarker:function(b){throw new Error("clearMarker not implemented yet.")},moveMarker:function(b,c,d,e){throw new Error("moveMarker not implemented yet.")},changeMarker:function(c,b){throw new Error("changeMarker not implemented yet.")},getZoomLevel:function(){throw new Error("getZoomLevel not implemented yet.")},getCenter:function(){throw new Error("getCenter not implemented yet.")},setBounds:function(b){throw new Error("setBounds not implemented yet.")},animateMarkerMovement:function(e,g,i,c,h){var d=(new Date()).getTime();var b=d+i;function f(p,k,o,l,r){var m=(new Date()).getTime();var q=[];var n=false;if(m>r||o==0){q=k;n=true}else{var j=(m-l)/o;q=[(k[0]-p[0])*j+p[0],(k[1]-p[1])*j+p[1]]}try{c.apply(null,q)}catch(s){throw new Error("trouble animating: "+s)}if(!n){setTimeout(Utilities.force(null,f,[p,k,o,l,r]),20)}else{h()}}setTimeout(Utilities.force(null,f,[e,g,i,d,b]),20)},resize:function(){throw new Error("getCenter not implemented yet.")}};Utilities.createNamespace("transloc.map._Map");transloc.map._Map=a})();(function(b){var a=0;function c(e,d){c.superclass.call(this,e,d);a++}c.superclass=transloc.map._Map;c.prototype=b.extend(Object.create(c.superclass.prototype),{map:null,domNodeId:"",apiKey:"AgrRQp85D9svCKlcH9K8TE9rGLvVOmZibLx5SdTB3n7LJ61NLNzqy4BmV878ObTj",mapStyle:"r",fixed:false,mode:window.VEMapMode!=null?VEMapMode.Mode2D:null,showSwitch:false,_markers:[],_polylines:[],_infoWindows:[],_markerOffset:[13,13],init:function(){if(this.domNode.id!=null){this.domNodeId=this.domNode.id}else{this._generateDomNodeId()}this.map=new VEMap(this.domNodeId);if(!this.showControls){this.map.HideDashboard()}this.map.AttachEvent("oncredentialserror",Utilities.hitch(this,this._bingCredentialsError));this.map.AttachEvent("oncredentialsvalid",Utilities.hitch(this,this._bingCredentialsSuccess));this.map.AttachEvent("onendzoom",Utilities.hitch(this,this._handleZoomFinish));this.map.SetCredentials(this.apiKey);this.map.LoadMap(new VELatLong(this.center[0],this.center[1]),this.zoomLevel,this.mapStyle,this.fixed,this.mode,this.showSwitch);var d=this;b(window).resize(function(){})},drawMarker:function(d){var e=new VEShape(VEShapeType.Pushpin,new VELatLong(d.position[0],d.position[1]));if(d.infoWindow!==null){}if(d.imageUrl!=null){e.SetCustomIcon(this._makeCustomIcon(d.imageUrl,d.imageOffset,d.imageSize))}this.map.AddShape(e);d.shape=e;this._markers.push(e);return d},clearMarker:function(d){if(d.shape!==null){this.map.DeleteShape(d.shape);delete d.shape;d.shape=null}return d},moveMarker:function(d,e,g,h){h=h||function(){};g=g||100;var f=d.position;d.position=e;if(d.shape==null){d._shapeInvalidWhenMoved=true;return d}this.animateMarkerMovement(f,e,d._shapeInvalidWhenMoved?0:g,function(j,i){if(d.shape){d.shape.SetPoints([new VELatLong(j,i)])}},function(){h(d)});d._shapeInvalidWhenMoved=false;return d},changeMarker:function(d,e){if(e.position!=null){d=this.moveMarker(d,e.position)}if(e.imageUrl!=null){d.imageUrl=e.imageUrl;if(d.shape){d.shape.SetCustomIcon(this._makeCustomIcon(d.imageUrl,d.imageOffset,d.imageSize))}}if(e.infoWindow!=null){d.shape.SetTitle(e.infoWindow.title);d.shape.SetDescription(e.infoWindow.contents);d.infoWindow=e.infoWindow}return d},_makeCustomIcon:function(d,g,e){var f=new VECustomIconSpecification();f.CustomHTML='<img src="'+d+'" style="position: relative; left: '+(-g[0]+this._markerOffset[0])+"px; top: "+(-g[1]+this._markerOffset[1])+'px; cursor: move"/>';return f},drawPolyline:function(g){var j=[];var e=g.points;for(var h=0,d=e.length;h<d;h++){j.push(new VELatLong(e[h][0],e[h][1]))}var f=new VEShape(VEShapeType.Polyline,j);f.SetLineWidth(g.width);f.HideIcon();var k=Utilities.hexToRGB(g.color);f.SetLineColor(new VEColor(k[0],k[1],k[2],1));this.map.AddShape(f);this._polylines.push(f)},clearPolylines:function(){for(var e=0,d=this._polylines.length;e<d;e++){this.map.DeleteShape(this._polylines[e])}this._polylines=[]},getZoomLevel:function(){if(this.map.GetMapStyle()===VEMapStyle.Birdsye||this.map.GetMapStyle()===VEMapStyle.BirdseyeHybrid){return 18}return this.map.GetZoomLevel()},getCenter:function(){var d=this.map.GetCenter();return[d.Latitude,d.Longitude]},setBounds:function(d){this.map.SetMapView([new VELatLong(d[0][0],d[0][1]),new VELatLong(d[1][0],d[1][1])])},setZoomLevel:function(d){this.map.SetZoomLevel(d)},_generateDomNodeId:function(){this.domNodeId=this.domNode.id="transloc_map_BingMap_"+a},_bingCredentialsError:function(d){b.publish("bingMap/credentials/error",[d])},_bingCredentialsSuccess:function(d){b.publish("bingMap/credentials/success",[d])},_handleZoomFinish:function(d){b.publish("transloc/map/"+this.domNode.id+"/zoom",[d.zoomLevel])},resize:function(){if(this.map!=null){try{var d=this.map.GetCenter();this.map.Resize();this.map.PanToLatLong(d)}catch(f){}}}});Utilities.createNamespace("transloc.map.BingMap");transloc.map.BingMap=c})(jQuery);(function(){function a(c,b){a.superclass.call(this,c,b)}a.superclass=transloc.map._Map;a.prototype=$.extend(Object.create(a.superclass.prototype),{map:null,mapStyle:"roadmap",_markers:[],_polylines:[],_infoWindows:[],init:function(){this.map=new google.maps.Map(this.domNode,{zoom:this.zoomLevel,center:new google.maps.LatLng(this.center[0],this.center[1]),mapTypeId:this.mapStyle,disableDefaultUI:!this.showControls});google.maps.event.addListener(this.map,"zoom_changed",Utilities.hitch(this,this._handleZoomChanged));var b=this;$(window).resize(function(){b.resize()})},drawMarker:function(b){var d={position:new google.maps.LatLng(b.position[0],b.position[1])};if(b.imageUrl!=""){d.icon=new google.maps.MarkerImage(b.imageUrl,new google.maps.Size(b.imageSize[0],b.imageSize[1]),new google.maps.Point(0,0),new google.maps.Point(b.imageOffset[0],b.imageOffset[1]))}var c=new google.maps.Marker(d);if(b.infoWindow&&b.infoWindow!==null){var f=this;var e=null;google.maps.event.addListener(c,"click",function(){if(e!=null){e.close()}b.infoWindow.fetchContents(function(h){var g=h;if(b.infoWindow.title.length>0){g="<h1>"+b.infoWindow.title+"</h1>"+g}e=new google.maps.InfoWindow({content:g});e.open(f.map,c)})})}b.shape=c;c.setMap(this.map);this._markers.push(c);return b},clearMarker:function(b){if(b.shape!==null){b.shape.setMap(null);delete b.shape;b.shape=null}return b},moveMarker:function(b,c,e,f){f=f||function(){};e=e||100;if(b==null){return b}var d=b.position;b.position=c;if(b.shape==null){b._shapeInvalidWhenMoved=true;return b}this.animateMarkerMovement(d,c,b._shapeInvalidWhenMoved?0:e,function(h,g){if(b.shape){b.shape.setPosition(new google.maps.LatLng(h,g))}},function(){f(b)});b._shapeInvalidWhenMoved=false;return b},changeMarker:function(b,c){if(c.position!=null){b=this.moveMarker(b,c.position)}if(c.imageUrl!=null){if(b.shape){b.shape.setIcon(new google.maps.MarkerImage(c.imageUrl,new google.maps.Size(b.imageSize[0],b.imageSize[1]),new google.maps.Point(0,0),new google.maps.Point(b.imageOffset[0],b.imageOffset[1])))}b.imageUrl=c.imageUrl}if(c.infoWindow!=null){var f=c.infoWindow.contents;if(c.infoWindow.title.length>0){f="<h1>"+c.infoWindow.title+"</h1>"+f}var e=new google.maps.InfoWindow({content:f});var d=this;google.maps.event.addListener(b.shape,"click",Utilities.hitch(this,function(){e.open(this.map,b.shape)}));b.infoWindow=c.infoWindow}return b},drawPolyline:function(f){var h=[];var d=f.points;for(var g=0,b=d.length;g<b;g++){h.push(new google.maps.LatLng(d[g][0],d[g][1]))}var e={strokeColor:f.color,strokeWidth:f.width,path:h};var c=new google.maps.Polyline(e);c.setMap(this.map);this._polylines.push(c)},clearPolylines:function(){for(var c=0,b=this._polylines.length;c<b;c++){this._polylines[c].setMap(null)}this._polylines=[]},getZoomLevel:function(){return this.map.getZoom()},getCenter:function(){var b=this.map.getCenter();return[b.lat(),b.lng()]},_handleZoomChanged:function(){$.publish("transloc/map/"+this.domNode.id+"/zoom",[this.getZoomLevel()])},resize:function(){google.maps.event.trigger(this.map,"resize")}});Utilities.createNamespace("transloc.map.GoogleMap");transloc.map.GoogleMap=a})();(function(b){function a(c){Utilities.mixin(this,c);if(this.route==null){throw new Error("Vehicle must be associated with a route.")}if(this.map==null){throw new Error("map must be specified when creating a vehicle.")}a.ALL_VEHICLES[this.id]=this}a.ALL_VEHICLES={};a.prototype={id:"",route:null,position:[35.78,-78.67],heading:0,lastUpdateTime:0,map:null,getPosition:function(){return this.position},setPosition:function(d,c){this.marker=this.map.moveMarker(this.marker,[d,c],0);this.position=this.marker.position},getRoute:function(){return this.routeId},setRoute:function(c){this.route=c;this._setupMarkerIcon()},getHeading:function(){return this.heading},setHeading:function(c){this.heading=c;this._setupMarkerIcon()},_setupMarkerIcon:function(){var d="n";var c=this.heading%360;if(c<22.5){d="n"}else{if(c<67.5){d="ne"}else{if(c<112.5){d="e"}else{if(c<157.5){d="se"}else{if(c<202.5){d="s"}else{if(c<247.5){d="sw"}else{if(c<292.5){d="w"}else{if(c<337.5){d="nw"}else{d="n"}}}}}}}}this.markerIcon="http://feeds.transloc.com/markers/vehicle.png?c="+this.route.color+"&h="+d+"&.png";if(this.marker){this.map.changeMarker(this.marker,{imageUrl:this.markerIcon,imageSize:[26,43]})}},update:function(c){var d={measurement:(new Date()).getTime()/1000};Utilities.mixin(d,c);if(d.route!=null){this.setRoute(d.route)}if(d.position!=null){var e=Math.abs(d.sampleTime-this.lastUpdateTime);if(e>3000){e=0}this.position=d.position;this.marker=this.map.moveMarker(this.marker,d.position,e)}if(c.sampleTime!=null){this.lastUpdateTime=d.sampleTime}if(d.heading!=null){this.setHeading(d.heading)}},show:function(){var c=this;if(this.marker==null||this.marker.shape==null){this._setupMarkerIcon();this.marker=this.map.drawMarker(new transloc.map._Marker({imageUrl:this.markerIcon,imageSize:[26,43],imageOffset:[13,43],position:this.position,infoWindow:new transloc.map._InfoWindow({title:"Vehicle "+this.id,fetchContents:function(d){b.publish("transloc/vehicles/predictions/request",[{vehicleId:c.id,onPredictions:function(j){j=j.sort(function(l,i){return l.timestamp-i.timestamp});var e=[];for(var h=0;h<3;h++){var k=j[h];var g=transloc.tvs.Stop.ALL_STOPS[k.stop_id];var f=Math.round((k.timestamp*1000-(new Date()).getTime())/60000);if(f<1){f="< 1"}e.push("<b>"+g.name+"</b> in "+f+" minute(s)")}d.call(null,"<h2>Next stops:</h2>"+e.join("<br/>"))}}])}})}))}},hide:function(){if(this.marker!=null){this.marker=this.map.clearMarker(this.marker)}}};Utilities.createNamespace("transloc.tvs._Vehicle");transloc.tvs._Vehicle=a})(jQuery);(function(a){function b(c){b.superclass.call(this,c)}b.superclass=transloc.tvs._Vehicle;b.prototype=a.extend(Object.create(b.superclass.prototype),{});Utilities.createNamespace("transloc.tvs.Bus");transloc.tvs.Bus=b})(jQuery);(function(b){function a(c){Utilities.mixin(this,c);a.ALL_STOPS[this.id]=this}a.ALL_STOPS={};a.prototype={id:9,name:"Quincy St at Lamont Library",position:[42.372862,-71.115046],associatedRoutes:[],marker:null,map:null,radius:5,baseIconUrl:"http://feeds.transloc.com/markers/stop.png?",markerIcon:"",markerRadii:{"0":5,"1":5,"2":8,"3":8,"4":8,"5":10,"6":10,"7":10,"8":12,"else":12},_setupMarkerIcon:function(){var e=[];for(var f=0,d=this.associatedRoutes.length;f<d;f++){e.push(this.associatedRoutes[f].color)}var c=this.markerRadii[e.length+""];if(c==null){c=this.markerRadii["else"]}this.markerIcon=this.baseIconUrl+"m=stop&c[]="+e.join("&c[]=")+"&s="+c;if(this.marker!=null){this.map.changeMarker(this.marker,{imageUrl:this.markerIcon,imageSize:[c*2,c*2],imageOffset:[c,c]})}return c},show:function(){var d=this;if(this.marker==null||this.marker.shape==null){var c=this._setupMarkerIcon();this.marker=this.map.drawMarker(new transloc.map._Marker({imageUrl:this.markerIcon,position:this.position,imageSize:[c*2,c*2],imageOffset:[c,c],infoWindow:new transloc.map._InfoWindow({title:this.name,fetchContents:function(e){b.publish("transloc/stops/predictions/request",[{stopId:d.id,onPredictions:function(j){j=j.sort(function(m,i){return m.timestamp-i.timestamp});var f=[];for(var h=0;h<3;h++){var l=j[h];if(l==null){continue}var k=transloc.tvs._Vehicle.ALL_VEHICLES[l.vehicle_id];var g=Math.round((l.timestamp*1000-(new Date()).getTime())/60000);if(g<1){g="< 1"}f.push('<b style="color: #'+k.route.color+'">'+l.vehicle_id+"</b> in "+g+" minute(s)")}e.call(null,"<h2>Next vehicles:</h2>"+f.join("<br/>"))}}])}})}))}},hide:function(){if(this.marker!=null){this.marker=this.map.clearMarker(this.marker)}},setAssociatedRoutes:function(c){this.associatedRoutes=c;this._setupMarkerIcon()},getAssociatedRoutes:function(){return this.associatedRoutes},setPosition:function(c){if(this.marker!=null){this.map.changeMarker(this.marker,{position:c})}this.position=c},getPosition:function(){return this.position}};Utilities.createNamespace("transloc.tvs.Stop");transloc.tvs.Stop=a})(jQuery);(function(b){var a=transloc.map._Polyline;var c={braidLengthsByZoom:{"1":1,"2":0.8,"3":0.4,"4":0.2,"5":0.1,"6":0.08,"7":0.06,"8":0.04,"9":0.02,"10":0.016,"11":0.008,"12":0.004,"13":0.002,"14":0.001,"15":0.0008,"16":0.0006,"17":0.0004,"18":0.0002,"19":0.00009,"20":0.00007},strokeWeightByZoom:{"1":1,"2":1,"3":1,"4":1,"5":1,"6":1,"7":1,"8":2,"9":2,"10":2,"11":2,"12":2,"13":2,"14":3,"15":3,"16":6,"17":10,"18":15,"19":15,"20":20},makePolylinesFromSegments:function(m){var e={segments:[],routeEnablement:{},zoomLevel:14,onPolyline:function(){},onFinish:function(){}};Utilities.mixin(e,m);var k=[];function d(){for(var o=0,n=e.segments.length;o<n;o++){if(k[o]!==true){return false}}return true}var f=[];var h=e.segments;for(var g=0,l=h.length;g<l;g++){var j=h[g];setTimeout(Utilities.force(null,function(q,o,p){var i=c.getRoutesFromSegment(q,e.routeEnablement);if(i.length==0){}else{if(i.length>=1){var s=c.makePolylinesFromSegment(q,i,e.zoomLevel);for(var n=0,r=s.length;n<r;n++){p.push(s[n]);setTimeout(Utilities.force(null,e.onPolyline,[q,s[n]]),1)}}}k[o]=true;if(d()){setTimeout(Utilities.force(null,e.onFinish,p),1)}},[j,g,f]),1)}},makePolylinesFromSegment:function(h,l,e){var f=a.decode(h.points);var d=l.length==1?[f]:c.partitionPolyline(f,e);var m=[];var k={};for(var g=0,j=d.length;g<j;g++){k={points:d[g],width:c.strokeWeightByZoom[e+""],color:"#"+l[g%l.length].color};m.push(new a(k))}return m},partitionPolyline:function(f,h){var g=this.braidLengthsByZoom[h+""];var d=[];f=f.slice(0);function e(t,j,u){u=u||j/2;if(t.length<2){throw new Error("points must be of length more than one")}var s=0;var w=[t[0]];var q=t[0];var o=1;var p=t.length;var k=0;do{k=GeoUtilities.getDistance(t[o],q);s=s+k;w.push(t[o]);o++}while(s<j&&o<p);var n=false;var m=s-j;if(o<=p&&m>u){var r=w.pop();var q=w[w.length-1];var l=[(r[0]-q[0])/k,(r[1]-q[1])/k];w.push([q[0]+l[0]*j,q[1]+l[1]*j]);n=true}if(w.length==1){w.push(t[1])}var v=n===true?w.length-1:w.length;for(o=0;o<v;o++){t.shift()}if(t.length>0){t.unshift(w[w.length-1])}return w}while(f.length>0){d.push(e(f,g))}return d},getRoutesFromSegment:function(h,f){var j=false;if(f==null){f={};j=true}var d=[];var e=h.routes;for(var g in e){if(e.hasOwnProperty(g)&&(f[e[g].id]===true||j)){d.push(e[g])}}return d}};Utilities.createNamespace("transloc.tvs.MapUtilities");transloc.tvs.MapUtilities=c})(jQuery);(function(b){var c=transloc.tvs.MapUtilities;function a(e,d){if(e==null||e.innerHTML===undefined){throw new Error("You must specify a DOM Node to associate with a Map.")}this.domNode=e;d=d||{};Utilities.mixin(this,d);this.init()}a.GOOGLE_MAP="google";a.BING_MAP="bing";a.FLASH_MAP="flash";a.prototype={domNode:null,mapType:a.GOOGLE_MAP,_userEnabledRouteIds:{},_feedEnabledRouteIds:{},_overallEnabledRouteIds:{},_subscriptions:[],_setupFeedData:null,_vehicles:{},_routes:{},_stops:{},init:function(){var d={center:[35.78,-78.67]};Utilities.mixin(d,this.mapSettings);this._vehicles={};if(this.mapType===a.GOOGLE_MAP){this.map=new transloc.map.GoogleMap(this.domNode,this.mapSettings)}else{if(this.mapType===a.BING_MAP){this.map=new transloc.map.BingMap(this.domNode,this.mapSettings)}else{if(this.mapType===a.FLASH_MAP){}else{throw new Error("Invalid map type: "+this.mapType)}}}this.map.init();this._subscriptions.push(b.subscribe("transloc/map/"+this.domNode.id+"/zoom",Utilities.hitch(this,this._handleZoomChange)));this._subscriptions.push(b.subscribe("transloc/feeds/setup",Utilities.hitch(this,this._handleSetupFeed)));this._subscriptions.push(b.subscribe("transloc/feeds/update",Utilities.hitch(this,this._handleUpdateFeed)));this._subscriptions.push(b.subscribe("transloc/feeds/stops",Utilities.hitch(this,this._handleStopsFeed)));this._subscriptions.push(b.subscribe("transloc/route/show",Utilities.hitch(this,this.showRoute)));this._subscriptions.push(b.subscribe("transloc/route/hide",Utilities.hitch(this,this.hideRoute)));this._subscriptions.push(b.subscribe("transloc/route/hideAllButOne",Utilities.hitch(this,this.hideAllRoutesButOne)))},destroy:function(){b.each(this._subscriptions,function(d){b.unsubscribe(d)});this._subscriptions=[]},drawRoutes:function(){if(this._drawRoutesTimeout!==null){clearTimeout(this._drawRoutesTimeout);this._drawRoutesTimeout=null}this._drawRoutesTimeout=setTimeout(Utilities.hitch(this,function(){if(this._setupFeedData==null){return}var q=this._setupFeedData.agencies;var n=this._setupFeedData.segments;this._clearRoutes();for(var l=0,e=q.length;l<e;l++){var u=q[l].routes;for(var h=0,p=u.length;h<p;h++){var t=u[h];var s=t.segments;var o;if(s==null){continue}for(var g=0,f=s.length;g<f;g++){var v=Math.abs(s[g]);for(var d=0,r=n.length;d<r;d++){if(n[d].id===v){o=n[d];o.routes=o.routes||{};o.routes[t.id]=t;break}}}}}this._showOrHideVehicles();c.makePolylinesFromSegments({segments:n,routeEnablement:this._overallEnabledRouteIds,zoomLevel:this.map.getZoomLevel(),onPolyline:Utilities.hitch(this,function(j,i){this.map.drawPolyline(i)}),onFinish:Utilities.hitch(this,function(){console.log("Finished!");b(this.domNode).css("background-color","#fff")})})}),100)},_drawRoutesTimeout:null,_clearRoutes:function(){this.map.clearPolylines()},showRoute:function(d){this._userEnabledRouteIds[d]=true;this._overallEnabledRouteIds[d]=this._feedEnabledRouteIds[d]&&this._userEnabledRouteIds[d];this.drawRoutes();this._updateStops()},hideRoute:function(d){this._overallEnabledRouteIds[d]=this._userEnabledRouteIds[d]=false;this.drawRoutes();this._updateStops()},hideAllRoutesButOne:function(f){var e=f;for(var d in this._feedEnabledRouteIds){if(this._feedEnabledRouteIds.hasOwnProperty(d)){if(d!=e){this._userEnabledRouteIds[d]=false}else{this._userEnabledRouteIds[d]=true}this._overallEnabledRouteIds[d]=this._feedEnabledRouteIds[d]&&this._userEnabledRouteIds[d]}}this.drawRoutes();this._updateStops()},_handleSetupFeed:function(k){this._setupFeedData=k;var l=this._setupFeedData.agencies;for(var h=0,d=l.length;h<d;h++){var e=l[h].routes;for(var g=0,f=e.length;g<f;g++){this._routes[e[g].id]=e[g]}}this.drawRoutes()},_handleUpdateFeed:function(j){var m=j.active_routes;var n=j.vehicles;var g=j.time*1000;if(m.length>0){var e={};var h={};for(var k=0,l=m.length;k<l;k++){e[m[k]]=true}var d=false;for(var k in e){if(e.hasOwnProperty(k)){if(e[k]!==this._feedEnabledRouteIds[k]){d=true}h[k]=e[k]}}for(var k in this._feedEnabledRouteIds){if(this._feedEnabledRouteIds.hasOwnProperty(k)){if(this._feedEnabledRouteIds[k]!==e[k]){d=true}}}this._feedEnabledRouteIds=e;if(d){for(var k in this._userEnabledRouteIds){if(this._userEnabledRouteIds.hasOwnProperty(k)){h[k]=e[k]&&this._userEnabledRouteIds[k]}}this._overallEnabledRouteIds=h;this.drawRoutes();this._updateStops()}}else{this._feedEnabledRouteIds={};setTimeout(Utilities.hitch(this,this._clearRoutes),1)}this._showOrHideVehicles();for(var k=0,l=n.length;k<l;k++){if(this._vehicles[n[k].id]==null){if(this._routes[n[k].r]==undefined){continue}var f=new transloc.tvs.Bus({id:n[k].id,route:this._routes[n[k].r],position:n[k].ll,heading:n[k].h,map:this.map,lastUpdateTime:g-n[k].t});this._vehicles[f.id]=f}else{var f=this._vehicles[n[k].id];f.update({route:this._routes[n[k].r],position:n[k].ll,heading:n[k].h,sampleTime:g-n[k].t})}}},_handleStopsFeed:function(k){var j=[];for(var h=0,d=k.stops.length;h<d;h++){var g=k.stops[h];var f=new transloc.tvs.Stop({map:this.map,id:g.id,name:g.name,position:g.ll});this._stops[f.id+""]=f}for(var h=0,d=k.routes.length;h<d;h++){var e=k.routes[h];this._routes[e.id].stops=e.stops}this._updateStops()},_showOrHideVehicles:function(){for(var d in this._vehicles){if(this._vehicles.hasOwnProperty(d)){var e=this._vehicles[d];if(this._overallEnabledRouteIds[e.route.id]===true){e.show()}else{e.hide()}}}},_updateStops:function(){for(var f in this._stops){if(this._stops.hasOwnProperty(f)){var e=this._stops[f];var d=this._getActiveRoutesForStop(e.id);if(d.length==0){e.hide()}else{e.setAssociatedRoutes(d);e.show()}}}},_getActiveRoutesForStop:function(g){var f=[];var e=this._overallEnabledRouteIds;for(var l in e){if(e.hasOwnProperty(l)&&e[l]===true){if(this._routes[l]==null){continue}var h=this._routes[l];var m=h.stops;if(m==null){continue}for(var k=0,d=m.length;k<d;k++){if(m[k]==g){f.push(h)}}}}return f},_handleZoomChange:function(d){this.drawRoutes()}};Utilities.createNamespace("transloc.tvs.Map");transloc.tvs.Map=a})(jQuery);
