window.QFS={animate:!1,mouseOutDelay:null,limit:parseInt("29"),source:function(a,b){$QF.ajax({url:QF.approot+"search/json/",dataType:"jsonp",data:{type:"geo",search:a.term},success:function(c){b(c.data.filter(QFS.filter).slice(0,QFS.limit))}})},select:function(a,b){a.preventDefault();a.stopPropagation();a=$QF("nav."+QF.cssPrefix+"topnav","#qfcontent").attr("data-primedataset");var c=QF.addGeomUrl(b.item.id);"undefined"!=typeof b.item.dataSet&&(b.item.dataSet==a?QF.atMaxGeos()?QFS.maxGeo():
QFS.load(c,QF.view,!0):QFS.dSetChange(b.item.id,QF.view,!0))},filter:function(a){return!QF.isSelectedGeo(a.geoid)},open:function(a,b){a=$QF(this).parent();b=a.attr("data-balloon-pos");a.data("balloon-pos",b);a.attr("data-balloon-pos","hide");$QF(this).data("is_open",!0)},close:function(a,b){a=$QF(this).parent();b=a.data("balloon-pos");a.attr("data-balloon-pos",b);$QF(this).data("is_open",!1)},response:function(a,b){},load:function(a,b,c){"undefined"==typeof b&&(b=QF.view);"undefined"==typeof c&&(c=
!0);switch(b){case "table":QF.loadTable(a);break;case "map":QF.loadMap(a,c);break;case "chart":QF.loadChart(a,!0);break;case "dashboard":QF.loadDashboard(a)}},initSearch:function(){var a=$QF("#qfcontent #lookahead"),b=$QF("#"+QF.cssPrefix+"search-box"),c=$QF("div."+QF.cssPrefix+"nav-dropdown"),d=$QF("div."+QF.cssPrefix+"more-drop");c.length&&c.hide();d.hide();b.length&&(b.autocomplete({minLength:2,autoFocus:!0,appendTo:a,source:QFS.source,select:QFS.select,open:QFS.open,close:QFS.close,response:QFS.response}),
b.data("uiAutocomplete").menu._isDivider=function(f){return!1},a.show())},dSetChange:function(a,b,c){var d=$QF("#qfcontent #dialog-small");d.dialog("option","buttons",[{text:"OK",showText:!0,icons:{primary:"ui-icon-check"},click:function(){$QF(this).dialog("close");load=[QF.approot+QF.model,QF.view,$QF(this).data("geoid"),QF.getFacts().join()].join("/");QFS.load(load,b,c)}},{text:"Cancel",showText:!0,icons:{primary:"ui-icon-close"},click:function(){$QF(this).dialog("close")}}]);d.data("geoid",a).load(QF.approot+
"template/datasets").dialog("open")},maxGeo:function(){var a=$QF("#qfcontent #dialog-small");a.dialog("option","buttons",[{text:"OK",showText:!0,icons:{primary:"ui-icon-check"},click:function(){$QF(this).dialog("close")}}]);a.load(QF.approot+"template/geolimit").dialog("open")}};
(function(a){a(document).on("click","div."+QF.cssPrefix+"view[data-toggled]",function(b){b.preventDefault();b.stopPropagation();var c=a(this),d=a("div."+QF.cssPrefix+'icon[data-toggled="on"]').not(c);b=a("div."+QF.cssPrefix+"nav-dropdown",c);var f=a("div."+QF.cssPrefix+"nav-geolist",b),k=a("span."+QF.cssPrefix+"nav-geo",f),m=a("div."+QF.cssPrefix+"nav-left",b),n=a("div."+QF.cssPrefix+"nav-right",b),l=a("nav."+QF.cssPrefix+"topnav"),p=l.offset(),t=l.outerHeight(!0);l=l.outerWidth(!0);var w=p.left,
q=c.offset(),u=c.outerWidth();q=q.left+u;var r=n.outerWidth(!0);u=b.outerWidth(!0);p=p.top+t-2;t=q-w;var g=0,x=c.attr("data-index");d.each(function(){a(this).click()});"off"==c.attr("data-toggled")?(c.attr("data-toggled","on"),c.css({color:"#ff7043","background-color":"#63a2da"}),b.css({width:l}).show(),k.each(function(e){e=Math.ceil(a(this).outerWidth());g+=e}),f.width(g),d=k.eq(x),d=d.position().left+d.outerWidth(!0)-g+r,limit=-(g-u)-r,g>l?(m.show().on("click",function(e){e.stopPropagation();e=
c.attr("data-index");var h=a("span."+QF.cssPrefix+"nav-geo",a(this).parent()).filter(":visible");if(h.length&&0<e){e--;var v=h.eq(e).position().left+h.eq(e).outerWidth(!0)-g+r;h.eq(e).flashBG();f.css("right",Math.max(v,limit));c.attr("data-index",e)}}),n.show().on("click",function(e){e.stopPropagation();e=c.attr("data-index");var h=a("span."+QF.cssPrefix+"nav-geo",a(this).parent()).filter(":visible");if(h.length&&e<k.length-1){e++;var v=h.eq(e).position().left+h.eq(e).outerWidth(!0)-g+r;h.eq(e).flashBG();
f.css("right",Math.max(v,limit));c.attr("data-index",e)}}),b.offset({top:p,left:w}),f.css({top:0,right:Math.max(d,limit)})):(b.width(g),m.hide(),n.hide(),b.offset({top:p,left:q-Math.min(g,t)}),f.css({top:0,right:0}))):"on"==c.attr("data-toggled")&&(c.attr("data-toggled","off"),c.css({color:"","background-color":"#63a2da"}),m.off("click"),n.off("click"),b.hide())});a(document).on("click","div."+QF.cssPrefix+"nav-dropdown a",function(b){b.stopPropagation();var c=a(this).attr("href"),d=a(this).parents("div."+
QF.cssPrefix+"icon[data-view]").attr("data-view");d==QF.view&&(b.preventDefault(),QFS.load(c,d,!0))});a(document).on("change","#qfcontent #"+QF.cssPrefix+"fact-select select",function(b){b.preventDefault();b.stopPropagation();if((b=a("#"+window.QF.cssPrefix+"topic-select","#qfcontent"))&&"all"!=b.val()){var c=a("option:selected",this).parent("optgroup").attr("label");b.val(c).change()}QF.addFact(a("option:selected",this).attr("data-mnemonic"));QFS.load(a(this).val(),QF.view,!1)});a(document).on("click",
"div."+QF.cssPrefix+"more[data-toggled]",function(b){b.preventDefault();b.stopPropagation();var c=a(this),d=a("div."+QF.cssPrefix+'icon[data-toggled="on"]').not(c);b=a("div."+QF.cssPrefix+"more-drop",c);var f=c.offset(),k=c.outerHeight(!0),m=c.outerWidth(!0),n=b.outerWidth(!0);m=Math.floor(f.left+m-n);f=Math.floor(f.top+k-3);k="on"==c.attr("data-toggled");d.each(function(){a(this).click()});k?(c.attr("data-toggled","off"),b.hide()):(d=[QF.approot+QF.model,"gogov",QF.getGeos().slice(0,QF.maxGeoCount).join(),
QF.getFacts().join()].join("/"),c.attr("data-toggled","on"),b.show(),b.offset({top:f,left:m}),$QF.get(d,function(l){$QF('a[href*="%%shorturl%%"]',c).each(function(){$QF(this).attr("href",$QF(this).attr("href").replace("%%shorturl%%",l))})},"text"))});a(document).on("click","div."+QF.cssPrefix+"more-drop div",function(b){b.stopPropagation();var c=a(this);c.hasClass(QF.cssPrefix+"more-print")&&(b.preventDefault(),window.print());if(c.hasClass(QF.cssPrefix+"more-facebook")){b.preventDefault();var d=
a("#"+QF.cssPrefix+"fact-select option.selected").text();FB.ui({method:"share",quote:d+" "+QF.censusAtTag+" "+QF.appTitle,href:a('meta[property="og:url"]').attr("content")},function(k){})}if(c.hasClass(QF.cssPrefix+"more-embed")){b.preventDefault();var f=a("#qfcontent #dialog");b=QF.approot+"embed";f.dialog("option","title","Embed QuickFacts");f.dialog("option","height",380);f.dialog("option","position",{my:"center",at:"center",of:window});f.load(b,function(){f.dialog("open")})}});
QFS.initSearch()})($QF);