(function(){var a;a="undefined"!==typeof exports?exports:this.Backbone={};a.VERSION="0.3.1";var b=this._;!b&&"undefined"!==typeof require&&(b=require("underscore")._);var c=this.jQuery;a.emulateHTTP=!1;a.emulateJSON=!1;a.Events={bind:function(a,b){this._callbacks||(this._callbacks={});(this._callbacks[a]||(this._callbacks[a]=[])).push(b);return this},unbind:function(a,b){var c;if(a){if(c=this._callbacks)if(b){c=c[a];if(!c)return this;for(var d=0,e=c.length;d<e;d++)if(b===c[d]){c.splice(d,1);break}}else c[a]=
[]}else this._callbacks={};return this},trigger:function(a){var b,c,d,e;if(!(c=this._callbacks))return this;if(b=c[a]){d=0;for(e=b.length;d<e;d++)b[d].apply(this,Array.prototype.slice.call(arguments,1))}if(b=c.all){d=0;for(e=b.length;d<e;d++)b[d].apply(this,arguments)}return this}};a.Model=function(a,c){this.attributes={};this.cid=b.uniqueId("c");this.set(a||{},{silent:!0});this._previousAttributes=b.clone(this.attributes);c&&c.collection&&(this.collection=c.collection);this.initialize&&this.initialize(a,
c)};b.extend(a.Model.prototype,a.Events,{_previousAttributes:null,_changed:!1,toJSON:function(){return b.clone(this.attributes)},get:function(a){return this.attributes[a]},set:function(a,c){c||(c={});if(!a)return this;a.attributes&&(a=a.attributes);var d=this.attributes;if(!c.silent&&this.validate&&!this._performValidation(a,c))return!1;"id"in a&&(this.id=a.id);for(var e in a){var f=a[e];b.isEqual(d[e],f)||(d[e]=f,c.silent||(this._changed=!0,this.trigger("change:"+e,this,f)))}!c.silent&&this._changed&&
this.change();return this},unset:function(a,b){b||(b={});var c={};c[a]=void 0;if(!b.silent&&this.validate&&!this._performValidation(c,b))return!1;delete this.attributes[a];b.silent||(this._changed=!0,this.trigger("change:"+a,this),this.change());return this},clear:function(a){a||(a={});var b=this.attributes,c={};for(attr in b)c[attr]=void 0;if(!a.silent&&this.validate&&!this._performValidation(c,a))return!1;this.attributes={};if(!a.silent){this._changed=!0;for(attr in b)this.trigger("change:"+attr,
this);this.change()}return this},fetch:function(g){g||(g={});var c=this,d=g.error&&b.bind(g.error,null,c);a.sync("read",this,function(a){if(!c.set(c.parse(a),g))return!1;g.success&&g.success(c,a)},d);return this},save:function(g,c){g||(g={});c||(c={});if(!this.set(g,c))return!1;var d=this,e=c.error&&b.bind(c.error,null,d),f=this.isNew()?"create":"update";a.sync(f,this,function(a){if(!d.set(d.parse(a),c))return!1;c.success&&c.success(d,a)},e);return this},destroy:function(g){g||(g={});var c=this,d=
g.error&&b.bind(g.error,null,c);a.sync("delete",this,function(a){c.collection&&c.collection.remove(c);g.success&&g.success(c,a)},d);return this},url:function(){var a=j(this.collection);return this.isNew()?a:a+"/"+this.id},parse:function(a){return a},clone:function(){return new this.constructor(this)},isNew:function(){return!this.id},change:function(){this.trigger("change",this);this._previousAttributes=b.clone(this.attributes);this._changed=!1},hasChanged:function(a){return a?this._previousAttributes[a]!=
this.attributes[a]:this._changed},changedAttributes:function(a){a||(a=this.attributes);var c=this._previousAttributes,d=!1,e;for(e in a)b.isEqual(c[e],a[e])||(d=d||{},d[e]=a[e]);return d},previous:function(a){return!a||!this._previousAttributes?null:this._previousAttributes[a]},previousAttributes:function(){return b.clone(this._previousAttributes)},_performValidation:function(a,b){var c=this.validate(a);return c?(b.error?b.error(this,c):this.trigger("error",this,c),!1):!0}});a.Collection=function(a,
c){c||(c={});c.comparator&&(this.comparator=c.comparator,delete c.comparator);this._boundOnModelEvent=b.bind(this._onModelEvent,this);this._reset();a&&this.refresh(a,{silent:!0});this.initialize&&this.initialize(a,c)};b.extend(a.Collection.prototype,a.Events,{model:a.Model,toJSON:function(){return this.map(function(a){return a.toJSON()})},add:function(a,c){if(b.isArray(a))for(var d=0,e=a.length;d<e;d++)this._add(a[d],c);else this._add(a,c);return this},remove:function(a,c){if(b.isArray(a))for(var d=
0,e=a.length;d<e;d++)this._remove(a[d],c);else this._remove(a,c);return this},get:function(a){return a&&this._byId[null!=a.id?a.id:a]},getByCid:function(a){return a&&this._byCid[a.cid||a]},at:function(a){return this.models[a]},sort:function(a){a||(a={});if(!this.comparator)throw Error("Cannot sort a set without a comparator");this.models=this.sortBy(this.comparator);a.silent||this.trigger("refresh",this);return this},pluck:function(a){return b.map(this.models,function(b){return b.get(a)})},refresh:function(a,
b){a||(a=[]);b||(b={});this._reset();this.add(a,{silent:!0});b.silent||this.trigger("refresh",this);return this},fetch:function(c){c||(c={});var d=this,e=c.error&&b.bind(c.error,null,d);a.sync("read",this,function(a){d.refresh(d.parse(a));c.success&&c.success(d,a)},e);return this},create:function(b,c){var d=this;c||(c={});b instanceof a.Model?b.collection=d:b=new this.model(b,{collection:d});return b.save(null,{success:function(a,b){d.add(a);c.success&&c.success(a,b)},error:c.error})},parse:function(a){return a},
chain:function(){return b(this.models).chain()},_reset:function(){this.length=0;this.models=[];this._byId={};this._byCid={}},_add:function(b,c){c||(c={});b instanceof a.Model||(b=new this.model(b,{collection:this}));var d=this.getByCid(b);if(d)throw Error(["Can't add the same model to a set twice",d.id]);this._byId[b.id]=b;this._byCid[b.cid]=b;b.collection=this;d=this.comparator?this.sortedIndex(b,this.comparator):this.length;this.models.splice(d,0,b);b.bind("all",this._boundOnModelEvent);this.length++;
c.silent||b.trigger("add",b,this);return b},_remove:function(a,b){b||(b={});a=this.getByCid(a);if(!a)return null;delete this._byId[a.id];delete this._byCid[a.cid];delete a.collection;this.models.splice(this.indexOf(a),1);this.length--;b.silent||a.trigger("remove",a,this);a.unbind("all",this._boundOnModelEvent);return a},_onModelEvent:function(a,b){"change:id"===a&&(delete this._byId[b.previous("id")],this._byId[b.id]=b);this.trigger.apply(this,arguments)}});b.each("forEach each map reduce reduceRight find detect filter select reject every all some any include invoke max min sortBy sortedIndex toArray size first rest last without indexOf lastIndexOf isEmpty".split(" "),
function(c){a.Collection.prototype[c]=function(){return b[c].apply(b,[this.models].concat(b.toArray(arguments)))}});a.Controller=function(a){a||(a={});a.routes&&(this.routes=a.routes);this._bindRoutes();this.initialize&&this.initialize(a)};var d=/:([\w\d]+)/g,e=/\*([\w\d]+)/g;b.extend(a.Controller.prototype,a.Events,{route:function(c,d,e){a.history||(a.history=new a.History);b.isRegExp(c)||(c=this._routeToRegExp(c));a.history.route(c,b.bind(function(a){a=this._extractParameters(c,a);e.apply(this,
a);this.trigger.apply(this,["route:"+d].concat(a))},this))},saveLocation:function(b){a.history.saveLocation(b)},_bindRoutes:function(){if(this.routes)for(var a in this.routes){var b=this.routes[a];this.route(a,b,this[b])}},_routeToRegExp:function(a){a=a.replace(d,"([^/]*)").replace(e,"(.*?)");return RegExp("^"+a+"$")},_extractParameters:function(a,b){return a.exec(b).slice(1)}});a.History=function(){this.handlers=[];this.fragment=this.getFragment();b.bindAll(this,"checkUrl")};var f=/^#*/;b.extend(a.History.prototype,
{interval:50,getFragment:function(a){return(a||window.location).hash.replace(f,"")},start:function(){var a=document.documentMode;if(a=c.browser.msie&&7>a)this.iframe=c('<iframe src="javascript:0" tabindex="-1" />').hide().appendTo("body")[0].contentWindow;"onhashchange"in window&&!a?c(window).bind("hashchange",this.checkUrl):setInterval(this.checkUrl,this.interval);return this.loadUrl()},route:function(a,b){this.handlers.push({route:a,callback:b})},checkUrl:function(){var a=this.getFragment();a==
this.fragment&&this.iframe&&(a=this.getFragment(this.iframe.location));if(a==this.fragment||a==decodeURIComponent(this.fragment))return!1;this.iframe&&(window.location.hash=this.iframe.location.hash=a);this.loadUrl()},loadUrl:function(){var a=this.fragment=this.getFragment();return b.any(this.handlers,function(b){if(b.route.test(a))return b.callback(a),!0})},saveLocation:function(a){a=(a||"").replace(f,"");this.fragment!=a&&(window.location.hash=this.fragment=a,this.iframe&&a!=this.getFragment(this.iframe.location)&&
(this.iframe.document.open().close(),this.iframe.location.hash=a))}});a.View=function(a){this._configure(a||{});this._ensureElement();this.delegateEvents();this.initialize&&this.initialize(a)};var k=function(a){return c(a,this.el)},n=/^(\w+)\s*(.*)$/;b.extend(a.View.prototype,a.Events,{tagName:"div",$:k,jQuery:k,render:function(){return this},remove:function(){c(this.el).remove();return this},make:function(a,b,d){a=document.createElement(a);b&&c(a).attr(b);d&&c(a).html(d);return a},delegateEvents:function(a){if(a||
(a=this.events)){c(this.el).unbind();for(var d in a){var e=a[d],f=d.match(n),h=f[1],f=f[2],e=b.bind(this[e],this);""===f?c(this.el).bind(h,e):c(this.el).delegate(f,h,e)}}},_configure:function(a){this.options&&(a=b.extend({},this.options,a));a.model&&(this.model=a.model);a.collection&&(this.collection=a.collection);a.el&&(this.el=a.el);a.id&&(this.id=a.id);a.className&&(this.className=a.className);a.tagName&&(this.tagName=a.tagName);this.options=a},_ensureElement:function(){if(!this.el){var a={};this.id&&
(a.id=this.id);this.className&&(a.className=this.className);this.el=this.make(this.tagName,a)}}});var m=function(a,c){var d=this,e;e=a&&a.hasOwnProperty("constructor")?a.constructor:function(){return d.apply(this,arguments)};l.prototype=d.prototype;e.prototype=new l;a&&b.extend(e.prototype,a);c&&b.extend(e,c);e.prototype.constructor=e;e.__super__=d.prototype;e.extend=m;return e};a.Model.extend=a.Collection.extend=a.Controller.extend=a.View.extend=m;var p={create:"POST",update:"PUT","delete":"DELETE",
read:"GET"};a.sync=function(b,d,e,f){var h=p[b];b="create"===b||"update"===b?JSON.stringify(d.toJSON()):null;d={url:j(d),type:h,contentType:"application/json",data:b,dataType:"json",processData:!1,success:e,error:f};a.emulateJSON&&(d.contentType="application/x-www-form-urlencoded",d.processData=!0,d.data=b?{model:b}:{});if(a.emulateHTTP&&("PUT"===h||"DELETE"===h))a.emulateJSON&&(d.data._method=h),d.type="POST",d.beforeSend=function(a){a.setRequestHeader("X-HTTP-Method-Override",h)};c.ajax(d)};var l=
function(){},j=function(a){if(!a||!a.url)throw Error("A 'url' property or function must be specified");return b.isFunction(a.url)?a.url():a.url}})();
function MarkerClusterer(a,b,c){this.extend(MarkerClusterer,google.maps.OverlayView);this.map_=a;this.markers_=[];this.clusters_=[];this.sizes=[15,15,40];this.styles_=[];this.ready_=!1;c=c||{};this.gridSize_=c.gridSize||60;this.maxZoom_=c.maxZoom||null;this.styles_=c.styles||[];this.imagePath_=c.imagePath||this.MARKER_CLUSTER_IMAGE_PATH_;this.imageExtension_=c.imageExtension||this.MARKER_CLUSTER_IMAGE_EXTENSION_;this.zoomOnClick_=c.zoomOnClick||!0;this.setupStyles_();this.setMap(a);this.prevZoom_=
this.map_.getZoom();var d=this;google.maps.event.addListener(this.map_,"zoom_changed",function(){var a=d.map_.mapTypes[d.map_.getMapTypeId()].maxZoom,b=d.map_.getZoom();if(!(0>b||b>a)&&d.prevZoom_!=b)d.prevZoom_=d.map_.getZoom(),d.resetViewport()});google.maps.event.addListener(this.map_,"bounds_changed",function(){d.redraw()});b&&b.length&&this.addMarkers(b,!1)}MarkerClusterer.prototype.MARKER_CLUSTER_IMAGE_PATH_=RAILS_ROOT+"images/dot";MarkerClusterer.prototype.MARKER_CLUSTER_IMAGE_EXTENSION_="png";
MarkerClusterer.prototype.extend=function(a,b){return function(a){for(property in a.prototype)this.prototype[property]=a.prototype[property];return this}.apply(a,[b])};MarkerClusterer.prototype.onAdd=function(){this.setReady_(!0)};MarkerClusterer.prototype.idle=function(){};MarkerClusterer.prototype.draw=function(){};MarkerClusterer.prototype.setupStyles_=function(){for(var a=0,b;b=this.sizes[a];a++)this.styles_.push({url:this.imagePath_+(a+1)+"."+this.imageExtension_,height:b,width:b})};
MarkerClusterer.prototype.setStyles=function(a){this.styles_=a};MarkerClusterer.prototype.getStyles=function(){return this.styles_};MarkerClusterer.prototype.isZoomOnClick=function(){return this.zoomOnClick_};MarkerClusterer.prototype.getMarkers=function(){return this.markers_};MarkerClusterer.prototype.getTotalMarkers=function(){return this.markers_};MarkerClusterer.prototype.setMaxZoom=function(a){this.maxZoom_=a};MarkerClusterer.prototype.getMaxZoom=function(){return this.maxZoom_||this.map_.mapTypes[this.map_.getMapTypeId()].maxZoom};
MarkerClusterer.prototype.calculator_=function(a,b){for(var c=0,d=a.length,e=d;0!==e;)e=parseInt(e/10,10),c++;c=Math.min(c,b);return{text:d,index:c}};MarkerClusterer.prototype.setCalculator=function(a){this.calculator_=a};MarkerClusterer.prototype.getCalculator=function(){return this.calculator_};MarkerClusterer.prototype.addMarkers=function(a,b){for(var c=0,d;d=a[c];c++)this.pushMarkerTo_(d);b||this.redraw()};
MarkerClusterer.prototype.pushMarkerTo_=function(a){a.setVisible(!1);a.setMap(null);a.isAdded=!1;if(a.draggable){var b=this;google.maps.event.addListener(a,"dragend",function(){a.isAdded=!1;b.resetViewport();b.redraw()})}this.markers_.push(a)};MarkerClusterer.prototype.addMarker=function(a,b){this.pushMarkerTo_(a);b||this.redraw()};
MarkerClusterer.prototype.removeMarker=function(a){var b=-1;if(this.markers_.indexOf)b=this.markers_.indexOf(a);else for(var c=0,d;d=this.markers_[c];c++)d==a&&(b=c);if(-1==b)return!1;this.markers_.splice(b,1);a.setVisible(!1);a.setMap(null);this.resetViewport();this.redraw();return!0};MarkerClusterer.prototype.setReady_=function(a){this.ready_||(this.ready_=a,this.createClusters_())};MarkerClusterer.prototype.getTotalClusters=function(){return this.clusters_.length};
MarkerClusterer.prototype.getMap=function(){return this.map_};MarkerClusterer.prototype.setMap=function(a){this.map_=a};MarkerClusterer.prototype.getGridSize=function(){return this.gridSize_};MarkerClusterer.prototype.setGridSize=function(a){this.gridSize_=a};
MarkerClusterer.prototype.getExtendedBounds=function(a){var b=this.getProjection(),c=new google.maps.LatLng(a.getNorthEast().lat(),a.getNorthEast().lng()),d=new google.maps.LatLng(a.getSouthWest().lat(),a.getSouthWest().lng()),c=b.fromLatLngToDivPixel(c);c.x+=this.gridSize_;c.y-=this.gridSize_;d=b.fromLatLngToDivPixel(d);d.x-=this.gridSize_;d.y+=this.gridSize_;c=b.fromDivPixelToLatLng(c);b=b.fromDivPixelToLatLng(d);a.extend(c);a.extend(b);return a};
MarkerClusterer.prototype.isMarkerInBounds_=function(a,b){return b.contains(a.getPosition())};MarkerClusterer.prototype.clearMarkers=function(){this.resetViewport();this.markers_=[]};MarkerClusterer.prototype.resetViewport=function(){for(var a=0,b;b=this.clusters_[a];a++)b.remove();for(a=0;b=this.markers_[a];a++)b.isAdded=!1,b.setMap(null),b.setVisible(!1);this.clusters_=[]};MarkerClusterer.prototype.redraw=function(){this.createClusters_()};
MarkerClusterer.prototype.createClusters_=function(){if(this.ready_){for(var a=new google.maps.LatLngBounds(this.map_.getBounds().getSouthWest(),this.map_.getBounds().getNorthEast()),a=this.getExtendedBounds(a),b=0,c;c=this.markers_[b];b++){var d=!1;if(!c.isAdded&&this.isMarkerInBounds_(c,a)){for(var e=0,f;f=this.clusters_[e];e++)if(!d&&f.getCenter()&&f.isMarkerInClusterBounds(c)){d=!0;f.addMarker(c);break}d||(f=new Cluster(this),f.addMarker(c),this.clusters_.push(f))}}google.maps.event.trigger(this,
"clustered",this.clusters_)}};function Cluster(a){this.markerClusterer_=a;this.map_=a.getMap();this.gridSize_=a.getGridSize();this.center_=null;this.markers_=[];this.bounds_=null;this.clusterIcon_=new ClusterIcon(this,a.getStyles(),a.getGridSize())}Cluster.prototype.isMarkerAlreadyAdded=function(a){if(this.markers_.indexOf)return-1!=this.markers_.indexOf(a);for(var b=0,c;c=this.markers_[b];b++)if(c==a)return!0;return!1};
Cluster.prototype.addMarker=function(a){if(this.isMarkerAlreadyAdded(a))return!1;this.center_||(this.center_=a.getPosition(),this.calculateBounds_());0==this.markers_.length?(a.setMap(this.map_),a.setVisible(!0)):1==this.markers_.length&&(this.markers_[0].setMap(null),this.markers_[0].setVisible(!1));a.isAdded=!0;this.markers_.push(a);this.updateIcon();return!0};Cluster.prototype.getMarkerClusterer=function(){return this.markerClusterer_};
Cluster.prototype.getBounds=function(){this.calculateBounds_();return this.bounds_};Cluster.prototype.remove=function(){this.clusterIcon_.remove();delete this.markers_};Cluster.prototype.getCenter=function(){return this.center_};Cluster.prototype.calculateBounds_=function(){var a=new google.maps.LatLngBounds(this.center_,this.center_);this.bounds_=this.markerClusterer_.getExtendedBounds(a)};Cluster.prototype.isMarkerInClusterBounds=function(a){return this.bounds_.contains(a.getPosition())};
Cluster.prototype.getMap=function(){return this.map_};Cluster.prototype.updateIcon=function(){var a=this.map_.getZoom(),b=this.markerClusterer_.getMaxZoom();if(a>b)for(a=0;b=this.markers_[a];a++)b.setMap(this.map_),b.setVisible(!0);else 2>this.markers_.length?this.clusterIcon_.hide():(a=this.markerClusterer_.getStyles().length,a=this.markerClusterer_.getCalculator()(this.markers_,a),this.clusterIcon_.setCenter(this.center_),this.clusterIcon_.setSums(a),this.clusterIcon_.show())};
function ClusterIcon(a,b,c){this.styles_=b;google.maps.Marker.call(this,{flat:!0});this.padding_=c||0;this.cluster_=a;this.center_=null;this.map_=a.getMap();this.sums_=this.div_=null;this.visible_=!1;var d=this;google.maps.event.addListener(this,"click",function(){d.triggerClusterClick()});this.setMap(this.map_)}ClusterIcon.prototype=new google.maps.Marker;
ClusterIcon.prototype.triggerClusterClick=function(){var a=this.cluster_.getMarkerClusterer();google.maps.event.trigger(a,"clusterclick",[this.cluster_]);a.isZoomOnClick()&&(this.map_.panTo(this.cluster_.getCenter()),this.map_.fitBounds(this.cluster_.getBounds()))};ClusterIcon.prototype.hide=function(){this.setVisible(!1)};ClusterIcon.prototype.show=function(){this.setPosition(this.center_);this.setVisible(!0)};ClusterIcon.prototype.remove=function(){this.setMap(null)};
ClusterIcon.prototype.setSums=function(a){this.sums_=a;this.text_=a.text;this.index_=a.index;this.useStyle()};ClusterIcon.prototype.useStyle=function(){var a=Math.max(0,this.sums_.index-1),a=Math.min(this.styles_.length-1,a),a=this.styles_[a];this.url_=a.url;this.height_=a.height;this.width_=a.width;a=new google.maps.MarkerImage(this.url_,new google.maps.Size(this.width_,this.height_,"px","px"),new google.maps.Point(0,0),new google.maps.Point(this.width_/2,this.height_/2));this.setIcon(a)};
ClusterIcon.prototype.setCenter=function(a){this.center_=a};window.MarkerClusterer=MarkerClusterer;MarkerClusterer.prototype.addMarker=MarkerClusterer.prototype.addMarker;MarkerClusterer.prototype.addMarkers=MarkerClusterer.prototype.addMarkers;MarkerClusterer.prototype.clearMarkers=MarkerClusterer.prototype.clearMarkers;MarkerClusterer.prototype.getCalculator=MarkerClusterer.prototype.getCalculator;MarkerClusterer.prototype.getGridSize=MarkerClusterer.prototype.getGridSize;
MarkerClusterer.prototype.getMap=MarkerClusterer.prototype.getMap;MarkerClusterer.prototype.getMarkers=MarkerClusterer.prototype.getMarkers;MarkerClusterer.prototype.getMaxZoom=MarkerClusterer.prototype.getMaxZoom;MarkerClusterer.prototype.getStyles=MarkerClusterer.prototype.getStyles;MarkerClusterer.prototype.getTotalClusters=MarkerClusterer.prototype.getTotalClusters;MarkerClusterer.prototype.getTotalMarkers=MarkerClusterer.prototype.getTotalMarkers;MarkerClusterer.prototype.redraw=MarkerClusterer.prototype.redraw;
MarkerClusterer.prototype.removeMarker=MarkerClusterer.prototype.removeMarker;MarkerClusterer.prototype.resetViewport=MarkerClusterer.prototype.resetViewport;MarkerClusterer.prototype.setCalculator=MarkerClusterer.prototype.setCalculator;MarkerClusterer.prototype.setGridSize=MarkerClusterer.prototype.setGridSize;MarkerClusterer.prototype.onAdd=MarkerClusterer.prototype.onAdd;MarkerClusterer.prototype.draw=MarkerClusterer.prototype.draw;MarkerClusterer.prototype.idle=MarkerClusterer.prototype.idle;
ClusterIcon.prototype.onAdd=ClusterIcon.prototype.onAdd;ClusterIcon.prototype.draw=ClusterIcon.prototype.draw;ClusterIcon.prototype.onRemove=ClusterIcon.prototype.onRemove;propublica.Profiler=function(){};propublica.Profiler.prototype.start=function(){if("development"!=RAILS_ENV)return this;this.start_ts=(new Date).getTime();return this};propublica.Profiler.prototype.stop=function(a){"development"==RAILS_ENV&&(this.stop_ts=(new Date).getTime(),console.log(a+": "+(this.stop_ts-this.start_ts)+"ms"))};
propublica.models.Fetcher=propublica.models.RESTClient.extend({shapes:null,init:function(a){_.isString(a)&&(a={url:a+".json"});this._super(a);a.url||(this.url=null)},load:function(a,b){b=_.extend({},b);$.browser.msie&&(b=_.extend(b,{slow_browser:4}));this.url?this.get(b,a):a(this._attrs);return!1}});
propublica.models.Address=propublica.Model.extend({init:function(a){this._super(a);this.read("line_items")&&(this.line_items=_(this.read("line_items")).map(function(a){return new propublica.models.LineItem(a)}))},source:function(){switch(this.read("current_state")){case "lawsuit_county":return"Lawsuit and County Data";case "lawsuit":return"Lawsuit Data";case "county":return"County Data"}},_filterBySource:function(a){return _(this.line_items).select(function(b){return b.read("source")==a})},countyItems:function(){return this._filterBySource("county")},
lawsuitItems:function(){return this._filterBySource("lawsuit")}});propublica.models.AddressCatcher=propublica.models.RESTClient.extend({url:function(){return RAILS_ROOT+"addresses/"+this.read("id")+".json"},fetch:function(){this.get({},function(a){a.address&&(a=new propublica.models.Address(a.address),$("#map-items").trigger("center",[a.read("lat_lon").y,a.read("lat_lon").x]),$("#sortable-container").trigger("onAddress",[a]))})}});
propublica.models.Aggregates=propublica.Model.extend({ON_SHAPES:"shapes",colors:["#A6BDDB","#74A9CF","#0570B0","#045A8D","#023858"],items:function(){return this._attrs},populate:function(a){var b=this._fetchers=this._fetchers||{};this.shapes=this.shapes||{};var c=this;a=this._attrs=a;_.each(a.resources,function(d,e){b[e]=new propublica.models.Fetcher(d);b[e].load(function(b){b=_.compact(b);c._shapes(b,e);c.bind(e,function(){c.shapes[e]&&c.shapes[e].shapes&&c.fire(c.ON_SHAPES,c.shapes[e].shapes);c.shapes[e]&&
c.shapes[e].points&&c.fire(c.ON_MARKERS,c.shapes[e].points)});e===a.def&&$(function(){c.fire(e);Backbone.history.start()})})})},_shapes:function(a,b){var c=this;a&&(this.shapes[b]={},this.shapes[b].shapes=_.map(a,function(a){var b=0;_.include(_.range(1),a.c)&&(b=0);_.include(_.range(2,4),a.c)&&(b=1);_.include(_.range(5,30),a.c)&&(b=2);_.include(_.range(31,99),a.c)&&(b=3);_.include(_.range(100,1E4),a.c)&&(b=4);b=new google.maps.Polygon({paths:_.map(a.p,function(a){return new google.maps.LatLng(a[1],
a[0])}),strokeColor:"#111111",strokeOpacity:1,strokeWeight:0.5,fillColor:c.colors[b],fillOpacity:0.9});if(!_.isUndefined(b))return b.message=a.m,b.sid=a.s,b.numEvents=a.c,b}))}});window.Aggregates=new propublica.models.Aggregates;
propublica.models.Items=propublica.models.Aggregates.extend({ON_MARKERS:"markers",init:function(a){this.color="#cc0000";this._super(a)},createPoints:function(a){for(var b=a.p.length,c=[];b--;){var d=a.p[b];d&&c.push(d)}return c},_point:function(a){return new google.maps.LatLng(a[1],a[0])},createShapes:function(a){return[new google.maps.Polygon({paths:_.map(a.s[0],this._point),strokeColor:"#111111",strokeOpacity:1,strokeWeight:0.5,fillOpacity:0})]},_shapes:function(a,b){for(var c=[],d=[],e=0,f;f=a[e];e++)c=
c.concat(this.createPoints(f)),f.s&&(d=d.concat(this.createShapes(f)));this.shapes[b]={points:c,shapes:d}}});window.Items=new propublica.models.Items;propublica.models.Collection=propublica.models.Fetcher.extend({init:function(a){this.url=window.location.pathname+".json";this._super(a)},map:function(a,b){var c=this;this.shapes=[];_.each(b,function(a){var b=new propublica.models.Items;b.createPoints(a);c.shapes=c.shapes.concat(b.shapes)});a(this.shapes)}});
propublica.models.itemMarker=function(a){this.WIDTH=this.HEIGHT=15;a=_.extend({},a,{flat:!0});_.isString(a.icon)&&(a.icon=new google.maps.MarkerImage(a.icon,new google.maps.Size(this.WIDTH,this.HEIGHT,"px","px"),new google.maps.Point(0,0),new google.maps.Point(this.WIDTH/2,this.HEIGHT/2)));google.maps.Marker.call(this,a)};propublica.models.itemMarker.prototype=new google.maps.Marker;propublica.models.LineItem=propublica.Model.extend({});
propublica.views.Mapper=propublica.View.extend({cssClass:"",tag:"",mapOpts:{zoom:4,mapTypeControl:!1,scrollwheel:!1},mapStyleOpts:[{featureType:"road",elementType:"geometry",stylers:[{lightness:75}]},{featureType:"all",elementType:"all",stylers:[{saturation:-80}]},{featureType:"poi",elementType:"labels",stylers:[{visibility:"off"}]},{featureType:"landscape",elementType:"labels",stylers:[{visibility:"off"}]},{featureType:"administrative.locality",elementType:"labels",stylers:[{visibility:"off"}]},
{featureType:"administrative.land_parcel",elementType:"labels",stylers:[{visibility:"off"}]}],bindings:{clear:"clearMap",center:"center",reset:"_box",marker:"marker"},init:function(){this.mapStyleOpts=_.clone(this.mapStyleOpts);this._super();this.resetShapes();this.models=[];_.bindAll(this,"_box");window.Aggregates.items().resources&&this.models.push(window.Aggregates);window.Items.items().resources&&this.models.push(window.Items);this.hashMarker=new google.maps.Marker},resetShapes:function(){this.currentShapes=
{shapes:[],markers:[]}},setupMap:function(){window.CENTER?_.extend(this.mapOpts,{center:new google.maps.LatLng(CENTER.y,CENTER.x)}):_.extend(this.mapOpts,{center:new google.maps.LatLng(38,-95)});this.map=new google.maps.Map(this.el[0],this.mapOpts);this.mapTypeOpts={map:this.map,name:"propublica"};this.mapType=new google.maps.StyledMapType(this.mapStyleOpts,this.mapTypeOpts);this.map.mapTypes.set("propublica",this.mapType);this.map.setMapTypeId("propublica");this.overlay=new propublica.models.ToolTipOverlay(this.map);
var a=this;google.maps.event.addListener(this.map,"mousemove",function(b){a.overlay.updatePosition(b)});google.maps.event.addListener(this.map,"bounds_changed",function(){a.overlay.close()});google.maps.event.addListener(this.map,"zoom_changed",function(){a.overlay.close()});this._box();this.setupClusturer()},_box:function(){window.BOX&&this.map.fitBounds(new google.maps.LatLngBounds(new google.maps.LatLng(BOX[0].y,BOX[0].x),new google.maps.LatLng(BOX[1].y,BOX[1].x)))},setupClusturer:function(){this.markerClusterer=
new MarkerClusterer(this.map,[],{gridSize:$.browser.msie?20:4,maxZoom:14,zoomOnClick:!1});var a=this;google.maps.event.addListener(this.markerClusterer,"clustered",function(b){_.each(b,function(b){b.clusterIcon_.unbindAll();a._objectEvents(b.clusterIcon_,"<p>"+b.markers_.length+" Homes Represented</p><p><em>click to zoom</em></p>")})})},clearMap:function(){this.markerClusterer.clearMarkers();this.currentShapes.shapes&&_.each(this.currentShapes.shapes,function(a){a.setMap(null)});this.resetShapes()},
center:function(a,b,c){this.map.setZoom(16);this.map.panTo(new google.maps.LatLng(b,c))},marker:function(a,b,c){a=new google.maps.LatLng(b,c);this.hashMarker.setPosition(a);this.hashMarker.setMap(this.map);this.map.setZoom(15);this.map.panTo(a)},render:function(){this.setupMap();for(var a=0;a<this.models.length;a++)this.models[a].ON_MARKERS&&this.models[a].bind(this.models[a].ON_MARKERS,_.bind(this._onmarkers,this)),this.models[a].ON_SHAPES&&this.models[a].bind(this.models[a].ON_SHAPES,_.bind(this._onshapes,
this))},dispatch:function(a){this.model.fire(a.type)},_onmarkers:function(a,b){var c=this,d=(new propublica.Profiler).start();this.currentShapes.points=_(b).map(function(a){return a=c._placeMarker(a)});c.markerClusterer.addMarkers(this.currentShapes.points);d.stop("Marker cluster in")},_placeMarker:function(a){var b=new propublica.models.itemMarker({position:new google.maps.LatLng(a.y,a.x),icon:RAILS_ROOT+"images/dot.png"});this._objectEvents(b,a.a);google.maps.event.addListener(b,"click",function(){window.location.hash=
"addresses/"+a.id;return!1});return b},_objectEvents:function(a,b){var c=this;google.maps.event.addListener(a,"mouseover",function(a){c.overlay.open(this,b,a)});google.maps.event.addListener(a,"mouseout",function(){c.overlay.close()})},_onshapes:function(a,b){var c=(new propublica.Profiler).start(),d=this;_.each(b,function(a){a.setMap(d.map);a.sid&&(a.message&&a.numEvents)&&d._objectEvents(a,a.message+": "+a.numEvents+" home"+(1<a.numEvents?"s":""))});this.currentShapes.shapes=b;c.stop("Shapes rendered in")}});
propublica.views.mapperAggregate=propublica.views.Mapper.extend({id:"map-aggregate",init:function(){this._super();this.mapStyleOpts=_.clone(this.mapStyleOpts);this.mapStyleOpts.push({featureType:"administrative.neighbourhood",elementType:"labels",stylers:[{visibility:"off"}]})}});
propublica.views.mapperCollection=propublica.views.mapperAggregate.extend({id:"map-collection",init:function(){this._super();this.mapOpts=_.clone(this.mapOpts);this.mapOpts=_.extend(this.mapOpts,{draggable:!1,disableDefaultUI:!0,disableDoubleClickZoom:!0})}});propublica.views.mapperItems=propublica.views.Mapper.extend({id:"map-items"});
propublica.views.mapperToggler=propublica.View.extend({scope:"div#map-tabs",tag:"ul",init:function(){_.bindAll(this,"dispatch");this._super()},render:function(){this.models=[window.Aggregates];this.hash=this.models[0].items();window.Items.items().resources&&(this.models.push(window.Items),this.hash.resources=_.extend(this.hash.resources,window.Items.items().resources),this.hash.def=window.Items.items().def);var a=propublica.utils.begat;$(this.scope);for(var b in this.hash.resources){var c=a("li",
{id:b}).html(a("a",{href:"#"}).text(b.replace(/(Aggregates?)/," Data").replace(/Items?/," Items")));b===this.hash.def?this.el.prepend(c.addClass(this.toggleClass)):this.el.append(c);c.bind("click",this.dispatch)}},dispatch:function(a){a.preventDefault();var b=$(a.currentTarget);a.type=b.attr("id");this.el.children("li").removeClass(this.toggleClass);b.addClass(this.toggleClass);$(".map").trigger("clear");for(var b=0,c;c=this.models[b];b++)c.fire(a.type)}});
propublica.models.ToolTipOverlay=function(a){google.maps.OverlayView.call(this);this.marker_=this.div_=null;this.setMap(a)};propublica.models.ToolTipOverlay.prototype=new google.maps.OverlayView;propublica.models.ToolTipOverlay.prototype.onAdd=function(){var a=propublica.utils.begat("div",{id:"tip"});a.css({position:"absolute"}).hide();this.div_=a;this.div_.text();var b=this.getPanes();$(b.overlayMouseTarget).append(a)};
propublica.models.ToolTipOverlay.prototype.open=function(a,b){this.div_&&(this.marker_=a,this.div_.html(b),this.div_.stop(!0,!1).show().animate({opacity:0.9},50))};propublica.models.ToolTipOverlay.prototype.close=function(){this.div_&&this.div_.stop(!0,!1).delay(50).animate({opacity:0},50,function(){$(this).hide()})};propublica.models.ToolTipOverlay.prototype.draw=function(){};
propublica.models.ToolTipOverlay.prototype.updatePosition=function(a){this.div_&&(a=this.getProjection().fromLatLngToDivPixel(a.latLng),this.div_.css({left:a.x+10+"px",top:a.y+10+"px"}))};propublica.models.ToolTipOverlay.prototype.onRemove=function(){this.div_&&(this.div_.remove(),this.div_=null)};
propublica.views.DrywallSearch=propublica.View.extend({tag:"input",id:"drywall-search",bindings:{click:"dispatch"},init:function(){this._super();this.geocoder=new google.maps.Geocoder;this.geoClient=new propublica.models.RESTClient({url:RAILS_ROOT+"county/search"});this.builderClient=new propublica.models.RESTClient({url:RAILS_ROOT+"company/search"});_.bindAll(this,"dispatch","_removeResults","_stopNotifying")},render:function(){this.el.parent("form").bind("submit",this.dispatch);$("a.close").live("click",
this._removeResults)},dispatch:function(a){a.preventDefault();a=this.el.siblings("input").val();this.prof=(new propublica.Profiler).start();this.geocode(a)},_removeResults:function(a){a.preventDefault();$(".notification",this.el.parent()).remove();$("#company_results",this.el.parent()).remove()},geocode:function(a){var b=this;this.geocoder.geocode({address:a},function(a,d){if(d==google.maps.GeocoderStatus.OK){var e=a[0].geometry.location;b.geoClient.get({lat:e.lat(),lon:e.lng()},function(a){b.prof.stop("Searched in: ");
"OK"===a.status?window.location=a.url+"#marker/"+e.lat()+"/"+e.lng():b.notify("warn","There is no data on tainted drywall in this county.")})}else b.notify("warn","Couldn't find your address")})},isNotifying:!1,_stopNotifying:function(){this.isNotifying=!1},notify:function(a,b){!1===this.isNotifying&&(this.isNotifying=!0,setTimeout(this._stopNotifying,4E3),$('<div class="notification '+a+'">'+b+"</div>").addClass(a).appendTo(this.el.parent()).delay(4E3).slideUp(100))}});
propublica.views.sortableSingle=propublica.View.extend({tag:"div",id:"sortable-container",bindings:{replace:"replace",reset:"reset",onAddress:"onAddress"},init:function(a){var b=/[$\u00a3\u20ac\,]/g;$.tablesorter.addParser({id:"newNumbers",is:function(a){a=a.replace(b,"");return parseFloat(a,10).toString()===a},format:function(a){return parseFloat(a.replace(b,""),10)},type:"numeric"});_.bindAll(this,"sortPlease","reset");this._super(a)},render:function(){this.originalHTML=this.el.html();this.el.hasClass("sort-now")&&
this.sortPlease();return this},replace:function(a,b,c,d){this.el.replaceWith('<div id="'+this.id+'">'+b+"</div>");this.el=$(this.query().string);this._setResetBinding();$(this.el).undelegate(".address","click");$(this.el).delegate(".address","click",function(a){a.preventDefault();a=($(this).attr("id")||"").replace("address-","");a.length&&(window.location.hash="addresses/"+a)});this.sortPlease(c,d)},onAddress:function(a,b){var c=window.JST.address({address:b});this.el.html(c);this._setResetBinding()},
_setResetBinding:function(){$(".reset",this.el).bind("click",function(a){a.preventDefault();$(this).text("Loading...");$(this).addClass("loading");$(this).unbind();window.location.hash="reset";return!1})},sortPlease:function(a,b){b=b||{};var c=window.TSConfig||{};b=_.extend({widgets:["zebra"],widthFixed:!0},b);b=_.extend(b,c);if($("table.sortable tbody td",this.el).is("*")){var d=(new propublica.Profiler).start(),e=$("table.sortable",this.el).tablesorter(b);b.noPage||e.tablesorterPager({container:$("#pager"),
positionFixed:!1,size:a||c.numRows||36});d.stop("Table built in: ")}},reset:function(a){$("#map-items").trigger("reset");this.replace(a,this.originalHTML)}});
propublica.views.Timeline=propublica.View.extend({id:"federal-timeline",bindings:{mouseenter:"renderTooltip",mouseleave:"removeTooltip",mousemove:"moveTooltip",renderTable:"renderTable"},init:function(){this._super();this.client=new propublica.models.RESTClient({url:(window.location.pathname+"/federal_items.json").replace("//","/")})},renderTooltip:function(){$("#federal-tip").is("*")||$("body").append(propublica.utils.begat("div",{id:"federal-tip"}))},removeTooltip:function(){$("#federal-tip").remove()},
moveTooltip:function(a){$("#federal-timeline").offset();$("#federal-tip").css({left:a.pageX,top:a.pageY+10})},renderTable:function(a,b){this.client.get({flattened_date:decodeURI(b)},function(a){$("#sortable-container").trigger("replace",[window.JST.federal_items_table({items:a}),24])});return!1}});
propublica.views.TimelineHover=propublica.View.extend({scope:"#federal-timeline",tag:"a",bindings:{mousemove:"renderToolTip",click:"notifyTable"},renderToolTip:function(a){var b=$(a.currentTarget).attr("id");if(b!=this.currentKey){try{var c=JSON.parse($(a.currentTarget).attr("data-info"));c.federal_item?($("#federal-tip").show(),$("#federal-tip").replaceWith(window.JST.federal_tooltip(c))):$("#federal-tip").hide()}catch(d){}this.currentKey=b}},notifyTable:function(a){var b={};try{b=JSON.parse($(a.currentTarget).attr("data-info"))}catch(c){}if(b.federal_item)return window.location.hash=
"federal_items/"+encodeURIComponent(b.federal_item.flattened_date),!1}});propublica.controllers=propublica.controllers||{};
propublica.controllers.AddressController=Backbone.Controller.extend({routes:{"addresses/:id":"onAddress","federal_items/:date":"onDate","marker/:lat/:lon":"marker",reset:"reset","":"reset"},onAddress:function(a){(new propublica.models.AddressCatcher({id:a})).fetch()},reset:function(){$("#sortable-container").trigger("reset")},marker:function(a,b){$("#map-items").trigger("marker",[a,b]);this.reset();$("#map-items").trigger("move",[a,b])},onDate:function(a){$("#federal-timeline").trigger("renderTable",
[a])}});var AddressController=new propublica.controllers.AddressController;
(function(){window.JST=window.JST||{};var a=function(a){return new Function("obj","var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('"+a.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(/<%=([\s\S]+?)%>/g,function(a,b){return"',"+b.replace(/\\'/g,"'")+",'"}).replace(/<%([\s\S]+?)%>/g,function(a,b){return"');"+b.replace(/\\'/g,"'").replace(/[\r\n\t]/g," ")+"__p.push('"}).replace(/\r/g,"\\r").replace(/\n/g,"\\n").replace(/\t/g,"\\t")+"');}return __p.join('');")};window.JST.address=
a('<h3>Address data for <%= address.read("street_address") %> <%= address.read("city") %>, <%= address.read("state") %> <%= address.read("zip_code") %>  <a class="reset" href="">Show All Addresses &raquo;</a></h3>\n<div class="address-detail">\n  <p><strong>Source:</strong> <%= address.source() %></p>\n  <p><strong>Number of Units:</strong> <%= address.read("num_units") %></p>\n  <strong>How We Learned This Address has Tainted Drywall</strong>\n  <p>To assemble this data, we merged records from county property appraiser\n    data and from a lawsuit filed in New Orleans federal court.\n    The address in this record was found in\n    <%= address.read("current_state").match(/^(county|lawsuit)$/) ? "the" : "both" %>\n    <%= address.source().toLowerCase() %>.\n    <a href="https://www.propublica.org/article/methodology-drywall">See our methodology &raquo;</a>\n  </p>\n  <table class="sortable">\n    <tbody>\n      <tr>\n        <% if(address.lawsuitItems().length) { %>\n          <td>\n            <strong>From the Lawsuit Data</strong>\n            <ul>\n              <% _(address.lawsuitItems()).each(function(lineItem){ %>\n              <li><%= lineItem.read("street_address") %> <%= lineItem.read("city") %>, <%= lineItem.read("state") %> <%= lineItem.read("zip_code") %> </li>\n              <% }); %>\n            </ul>\n          </td>\n        <% }; %>\n\n        <% if(address.countyItems().length) { %>\n          <td>\n            <strong>From the County Data</strong>\n            <ul>\n              <% _(address.countyItems()).each(function(countyItem){ %>\n                <li><%= countyItem.read("street_address") %> <%= countyItem.read("city") %>, <%= countyItem.read("state") %> <%= countyItem.read("zip_code") %> </li>\n                <% }); %>\n            </ul>\n          </td>\n        <% }; %>\n\n      </tr>\n    </tbody>\n  </table>\n  <br clear="all">\n  <div class="wrong_addr_notice">\n    <h3>Corrections</h3>\n    <p>If you think this address has been included in this database in error, please contact <a href="mailto:jeff.larson@propublica.org">Susan White</a>.</p>\n  </div>\n</div>\n');
window.JST.federal_items_table=a('<div id="controls">\n  <div id="pager" class="pager">\n    <form>\n      <div class="pagination-menu">\n        <a href="#" class="prev">prev</a>\n        <span class="pagedisplay"></span>\n        <a href="#" class="next">next</a>\n      </div>\n    </form>\n  </div>\n</div>\n<h3>CPSC Reports for <%= _.first(items).federal_item.flattened_date %> <a class="reset" href="">Show Addresses &raquo;</a></h3>\n<div id="cpsc_notice">\n<p>The CPSC does not track individual addresses. Without accurate\n  address data from the CPSC, it is impossible to compute overlap between ProPublica\'s\n  database and the CPSC reports.</p>\n</div>\n<table class="sortable">\n  <thead>\n    <tr>\n      <th>Date Injured</th>\n      <th>Narrative</th>\n    </tr>\n  </thead>\n  <tbody>\n    <% _(items).each(function(it){ %>\n      <tr>\n        <td><%= it.federal_item.flattened_date %></td>\n        <td><%= it.federal_item.narrative %></td>\n      </tr>\n    <% }); %>\n  </tbody>\n  <tfoot></tfoot>\n</table>\n');
window.JST.federal_tooltip=a('<div id="federal-tip">\n  <div class="inner">\n    <p><strong>Month:</strong> <%= federal_item.flattened_date %></p>\n    <p><strong>Number of Reports:</strong> <%= federal_item.num_events %></p>\n    <p><strong>Sample Report:</strong> <em><%= federal_item.narrative %></em></p>\n    <p><strong>Click to see all reports for <%= federal_item.flattened_date %></strong></p>\n  </div>\n</div>');window.JST.mapping_tooltip=a("")})();
