window.addEventListener&&window.addEventListener("load",function(){for(var a=document.getElementsByTagName("script"),d=0;d<a.length;d++)if(a[d].type=="application/processing"){var f=a[d].src,c=a[d].nextSibling;if(f&&f.indexOf("#"))c=document.getElementById(f.substr(f.indexOf("#")+1));else for(;c&&c.nodeName.toUpperCase()!="CANVAS";)c=c.nextSibling;c&&Processing(c,a[d].text)}},false);function Timekeeper(){var a,d,f=0;Date();this.checkNight=function(c){c=f+c/15*3600;c%=86400;c=c/3600;out=1-c/12;if(c>12)out=-out;return out};this.update=function(c){c=Date.parse(c);f=c/1E3;if(a==0)a=c;a=c<a?c:a;d=c>d?c:d};this.reset=function(){d=a=0};this.getFirstLast=function(){return[a,d]};this.getDifference=function(){var c=(d-a)/1E3,b;if(c<60){b="second";c=c}else if(c<7200){b="minute";c=Math.round(c/60)}else if(c<175200){b="hour";c=Math.round(c/3600)}else{b="day";c=Math.round(c/87600)}if(c>1)b+="s";return c+" "+b};this.getSentence=function(){return"Tweets from the last "+this.getDifference()};this.reset()};if(!Array.prototype.forEach)Array.prototype.forEach=function(a,d){var f=this.length;if(typeof a!="function")throw new TypeError;for(var c=0;c<f;c++)c in this&&a.call(d,this[c],c,this)};Model=function(){this.displayList=[];this.old=[];this.SWAP_THRESH=50;this.portion=[];globalTitle="";this.append=function(a){this.displayList=this.displayList.concat(a)};this.getPrevLength=function(){return this.old.length};this.getCurrentLength=function(){return this.displayList.length};this.getBlendedList=function(a){oldPortion=this.old.slice(0,this.old.length*a);return this.portion=this.displayList.concat(oldPortion)};this.regetSlice=function(a){if(this.portion.length>0)return this.portion.slice(0,this.portion.length*a);return[]};this.swap=function(){if(this.displayList.length>this.SWAP_THRESH)this.old=this.displayList;this.displayList=[]};this.clear=function(){this.displayList=[];this.old=[]};this.getDisplayListLength=function(){return this.displayList.length};this.setViewBox=function(a,d){this.lat_c=a;this.lon_c=d};this.setFetchRadius=function(a){this.radiusF=a};this.getFetchRadius=function(){return this.radiusF};this.setViewRadius=function(a){this.radius=a};this.getViewRadius=function(){return this.radius};this.getViewBox=function(){return[this.lat,this.lon]}};getPl=fetcher=1;firstTime=0;model=new Model;timeKeeper=new Timekeeper;placeKeeper=new PlaceKeeper;PAGE_COUNT=15;pageWidth=window.innerWidth-236;pageHeight=window.innerHeight;function setBoundingBox(a,d,f){model.setViewRadius(f);long_c=d;lat_c=a}oldCount=geoCount=0;global_first_no_loc=false;function storeTweet(a){viewPage++;var d=PAGE_COUNT-3;d=viewPage<d?Math.round(100*viewPage/d):100;$("#progressbar").progressbar({value:d});$(".ui-progressbar-value").html("<div id='dist'>"+d+"%</div>");var f=[];if(!a.error){d="";if(a.next_page)d+=a.next_page;if(a.previous_page)d+=a.previous_page;if(d.match(c_lat)&&d.match(c_lon)&&d.match(model.getFetchRadius())){$.each(a.results,function(c,b){tweetKeeper.add(b);var e=c=0;timeKeeper.update(b.created_at);if(b.geo){e=b.geo.coordinates;c=-e[0];e=e[1];geoCount++;b.place&&placeKeeper.addPlace(b.place.full_name,c,e,model.getFetchRadius())}else if(b.location){b=b.location;var g=b.match(/[0-9\-\.]*.*,.*[0-9\-\.]*/g);if(b=g=b.match(/[0-9\.\-]*/g).filter(function(h){return h?h:null})){c=-parseFloat(b[0]);e=parseFloat(b[1]);oldCount++}}else{global_first_no_loc||$("#warning").show();global_first_no_loc=true}if(e&&c){b=timeKeeper.checkNight(e);f.push([e,c,b])}});model.append(f.unique());betterPlaces=placeKeeper.processWordCount()}}}
function toPng(){if($("canvas").length>0){var a=$("canvas")[0].toDataURL();document.location.href=a}}function getData(a,d,f,c){c=Math.floor(c);$.getScript("http://search.twitter.com/search.json?geocode="+a+"%2C"+d+"%2C"+f+"km&rpp=100&callback=storeTweet&page="+c)}resultsPage=1;viewPage=0;move=false;places=[];betterPlaces=null;function processPlaces(a){places=[];var d=a.geonames.length;if(d){var f=a.geonames[Math.floor(d/2)].population;$.each(a.geonames,function(c,b){if(f>0&&b.population>f){c=Math.log(b.population/f)/12;c=c>0.9?0.9:c}else c=0.4;b=[-b.lat,b.lng,accentsTidy(b.name),c*1.4];places.push(b)})}}
function accentsTidy(a){a=a;a=a.replace(new RegExp("[\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5]","g"),"a");a=a.replace(new RegExp("\u00e6","g"),"ae");a=a.replace(new RegExp("\u00e7","g"),"c");a=a.replace(new RegExp("[\u00e8\u00e9\u00ea\u00eb]","g"),"e");a=a.replace(new RegExp("[\u00ec\u00ed\u00ee\u00ef]","g"),"i");a=a.replace(new RegExp("\u00f1","g"),"n");a=a.replace(new RegExp("[\u00f2\u00f3\u00f4\u00f5\u00f6]","g"),"o");a=a.replace(new RegExp("\u0153","g"),"oe");a=a.replace(new RegExp("[\u00f9\u00fa\u00fb\u00fc]","g"),"u");return a=a.replace(new RegExp("[\u00fd\u00ff]","g"),"y")}function getPlaceNames(){var a=model.getFetchRadius()/110;$.getScript("http://paris.ws.geonames.org/citiesJSON?north="+(c_lat+a*0.7)+"&south="+(c_lat-a*0.7)+"&east="+(c_lon+a)+"&west="+(c_lon-a)+"&lang=en&callback=processPlaces&maxRows=12")}
function setURL(){url="#lat="+Math.round(c_lat*100)/100;url+="*lon="+Math.round(c_lon*100)/100;url+="*dist="+Math.round(model.getFetchRadius()*100)/100;url=url.replace(/\./g,",");var a="http://n96.org/"+url;base='<iframe allowtransparency="true" frameborder="0" scrolling="no" src="'+("http://platform.twitter.com/widgets/tweet_button.html?count=none&amp;counturl=http%3A%2F%2Fn96.org&amp;lang=en&amp;related=nikibobb&amp;text=The%20View%20from%20Above&amp;via=nikibobb&amp;url="+fixedEncodeURIComponent(a))+'" style="width:65px; height:20px;"></iframe> ';$("#share").html(base);$("#url").val(a);window.location.href=url}function fixedEncodeURIComponent(a){return encodeURIComponent(a).replace(/!/g,"%21").replace(/'/g,"%27").replace(/\(/g,"%28").replace(/\)/g,"%29").replace(/\*/g,"%2A")}
function resetFetchLoop(){if(fetcher){clearTimeout(fetcher);betterPlaces=null;placeKeeper=new PlaceKeeper;tweetKeeper=new TweetKeeper;setURL();clearTimeout(getPl);timeKeeper.reset()}getPl=setTimeout("getPlaceNames()",4E3);model.swap();resultsPage=1;viewPage=0;fetcher=setTimeout("fetchLoop()",300)}
function fetchLoop(){c_lat=Math.round(c_lat*100)/100;c_lon=Math.round(c_lon*100)/100;model.setFetchRadius(Math.round(model.getFetchRadius()*100)/100);getData(c_lat,c_lon,model.getFetchRadius(),resultsPage);if(resultsPage==1)globalTitle=matchLocation(c_lat,c_lon,model.getFetchRadius());resultsPage++;if(resultsPage<16)fetcher=setTimeout("fetchLoop()",1600)}
function histCallback(){var a=-6.26,d=106.82,f=32;strs=window.location.hash.slice(1);strs=strs.replace(/\,/g,".");strs=strs.replace(/\&/g,"*");strs=strs.split("*");$(strs).each(function(c,b){c=b.split("=");switch(c[0]){case"lat":a=parseFloat(c[1]);break;case"lon":d=parseFloat(c[1]);break;case"dist":f=parseFloat(c[1]);break}});return[a,d,f]}
function grabURL(){var a=histCallback();coord=a;c_lat=a[0];c_lon=a[1];model.setFetchRadius(a[2]);a=model.getFetchRadius()/1.9;a=a<1?1:a;$("#slider-zoom").slider({value:45-4*Math.log(a/Math.log(2))});setBoundingBox(coord[0],coord[1],coord[2]/111);model.clear();resetFetchLoop()}moverDetect=true;moverTimer=setTimeout("moverDetect = false",12E3);$(document).ready(function(){function a(b){var e=model.getViewRadius(),g=b.target.offsetLeft;lat=-((b.pageY-b.target.offsetTop)/pageHeight*2*e)+e+lat_c;lon=long_c+((b.pageX-g)/pageWidth*2*e-e);return[lat,lon]}$("#tabs").tabs({});setTimeout("$('#waiting').fadeOut()",5300);grabURL();createTopBar();$("body").mousemove(function(){moverDetect=true;moverTimer&&clearTimeout(moverTimer);moverTimer=setTimeout("moverDetect = false",6E3)});var d,f,c;$("canvas")[0].addEventListener("touchstart",function(b){var e=0,g=0;d=[];d.push(b.targetTouches[0]);b.targetTouches[1]&&d.push(b.targetTouches[1]);d=d.map(function(h){h=a(h);e+=h[0];g+=h[1];return h});c=e/d.length;originalLon=g/d.length},false);$("canvas")[0].addEventListener("gesturechange",function(b){b.preventDefault();b=b.scale;b=b>15?15:b;$("canvas").css("-webkit-transform","scale3d("+b+","+b+", 1)");b=(b-1)/15;var e=long_c*(2-b)+b*originalLon;lat_c=lat_c*(1-b)+b*c;long_c=e;move=true},false);$("canvas")[0].addEventListener("gesturestart",function(){f=model.getViewRadius()},false);$("canvas")[0].addEventListener("gestureend",function(b){if(move){c_lon=long_c;c_lat=lat_c;model.setFetchRadius(110*(f/b.scale));resetFetchLoop();$("canvas").css("-webkit-transform","scale3d(1, 1, 1)");move=false}},false);$(".button").button().click(function(){toPng()});$("#slider-zoom").slider({orientation:"vertical",min:0,max:45,value:45-4*Math.log(model.getFetchRadius())/Math.log(2),slide:function(b,e){b=Math.pow(2,(45-e.value)/4);model.setViewRadius(b/111)},stop:function(b,e){b=Math.pow(2,(45-e.value)/4);model.setViewRadius(b/111);model.setFetchRadius(b);resetFetchLoop()}});$("canvas").mousedown(function(b){oldTime=firstTime;firstTime=(new Date).getTime();if(firstTime-oldTime<500){b=a(b);lat=b[0];lon=b[1];b=model.getViewRadius()/1.9;var e=model.getFetchRadius()/1.9;e=e<1?1:e;long_c=lon;lat_c=lat;c_lon=long_c;c_lat=lat_c;model.setViewRadius(b);model.setFetchRadius(e);resetFetchLoop();$("#slider-zoom").slider("value",45-4*Math.log(e/Math.log(2)));return true}var g=b.pageX,h=b.pageY,i=long_c,j=lat_c;$("canvas").mousemove(function(k){var l=model.getViewRadius();dx=(k.pageX-g)/pageWidth*l*2;dy=(k.pageY-h)/pageHeight*l*2;long_c=i-dx;lat_c=j+dy;move=true});$("canvas").mouseup(function(){$("canvas").unbind("mousemove");$("canvas").unbind("mouseup");if(move){c_lon=long_c;c_lat=lat_c;resetFetchLoop();move=false}})})});var topBar_items=[["Florida","lat=27.26&lon=-81.18&dist=256"],["Miami Area","lat=26.03&lon=-80.37&dist=70.91"],["Boston","lat=42.35&lon=-71.07&dist=3.41"],["The United States","lat=34.94&lon=-99.11&dist=2500"],["Las Vegas","lat=36.08&lon=-115.17&dist=14.72"],["The Las Vegas Strip","lat=36.11&lon=-115.17&dist=2.15"],["Atlanta","lat=33.76&lon=-84.3&dist=32"],["NYC Area","lat=40.75&lon=-73.97&dist=19.27"],["New York","lat=40.76&lon=-73.91&dist=11.31"],["The San Francisco Area","lat=37.61&lon=-122.22&dist=53.14"],["Sacramento","lat=38.58&lon=-121.35&dist=26.91"],["Guadalajara","lat=20.67&lon=-103.37&dist=14.72"],["Baltimore","lat=39.34&lon=-76.62&dist=14.72"],["Kingston","lat=18.02&lon=-76.78&dist=7.75"],["Santo Domingo","lat=18.47&lon=-69.95&dist=3.97"],["Venezuela","lat=10.17&lon=-67.51&dist=82.71"],["Caracas","lat=10.48&lon=-66.88&dist=6.35"],["Mexico City","lat=19.39&lon=-99.19&dist=16.2"],["Seoul","lat=35.15&lon=129.08&dist=12"],["Jakarta","lat=-6.26&lon=106.82&dist=32"],["Kuwait","lat=29,26*lon=48,01*dist=14,34"],["Bangkok","lat=13.76&lon=100.58&dist=14.34"],["The Middle East","lat=25.4&lon=50.23&dist=674.65"],["Medan","lat=3.56&lon=98.67&dist=7.55"],["Manila","lat=14.59&lon=121.07&dist=16"],["Singapore","lat=1.34&lon=103.89&dist=22.63"],["Kuala Lumpur","lat=3.13&lon=101.69&dist=12.94"],["Tokyo","lat=35.67&lon=139.68&dist=22.63"],["Mumbai","lat=19.04&lon=72.87&dist=19.03"],["New Delhi","lat=28.46&lon=77.18&dist=36.61"],["Dubai","lat=25.19&lon=55.22&dist=31.38"],["Aceh","lat=5.55&lon=95.33&dist=9.51"],["Phuket","lat=7.9&lon=98.37&dist=7.55"],["Chiang Mai","lat=18.78&lon=99&dist=14.62"],["Riyadh","lat=24.7&lon=46.71&dist=14.34"],["Britain","lat=52.4&lon=-1.78&dist=186.88"],["Glasgow","lat=55.85&lon=-4.25&dist=14"],["Amsterdam","lat=52.35&lon=4.9&dist=14.34"],["The United Kingdom","lat=52.44&lon=-1.88&dist=355.08"],["Milan","lat=45.49&lon=9.21&dist=7.55"],["Budapest","lat=47.49&lon=19.06&dist=4.26"],["Paris","lat=48.87&lon=2.31&dist=7.55"],["London","lat=51.47&lon=-0.14&dist=22.63"]];function matchLocation(a,d,f){var c=null;$.each(topBar_items,function(b,e){i_value=e[1];var g=i_value.split("&");if(g.length==1)g=i_value.split("*");b=g[0].split("=")[1];var h=g[1].split("=")[1];g=g[2].split("=")[1];if(Math.abs((a-b)/a)<0.01&&Math.abs((d-h)/d)<0.01&&Math.abs((f-g)/f)<0.4)c=e[0]});return c}
function createTopBar(){for(var a=topBar_items,d=a.length,f=0;f<25;f++){var c=a[Math.floor(Math.random()*d)];c=$("<a>").attr("href","#"+c[1]).attr("innerHTML",c[0]).append("<br>").click(function(){setTimeout("grabURL()",400)});$("#suggested").append(c)}};function PlaceKeeper(){var a={},d=[];this.processWordCount=function(){var f={};for(var c in a){var b=a[c],e=0,g=0;b.forEach(function(i){e+=i[0];g+=i[1]});b=b.length;var h=Math.log(b)/3+0.5;f[c]=[e/b,g/b,h]}d=[];for(c in f){b=f[c];d.push([b[0],b[1],c,b[2]])}d=d.sort(function(i,j){return j[3]-i[3]});return(d=d.length?d:null)?d.slice(0,18):null};this.getSortedWordCount=function(){return d};this.addPlace=function(f,c,b,e){e=e>80?1:0;[f.split(",")[e]].forEach(function(g){if(g){g=g.trim();a[g]||(a[g]=[]);a[g].push([c,b])}})}};function TweetKeeper(){var a=[],d="",f=0,c="",b={},e={},g=$("#dial").dialog({autoOpen:false,height:window.innerHeight,draggable:false,position:[236,0],resizable:false,width:window.innerWidth-236}),h=$('<a id="close">').button({label:"x"});$("#progressbar").progressbar({});$("#text").html("");h=$("<button>").attr("id","loader").html("Load people").click(function(){$("button").remove();$("#text").append(d)});$("#text").append(h);d="";this.show=function(i){i=i.children[0].src;var j=b[i][0];img_big=i.replace("_bigger","");var k='<div class="profile_wrapper"><img class="profile" src="'+img_big+'"></div>';k+='<p><a class="twitter info" target="_blank" href="http://twitter.com/'+j.from_user+'">twitter.com/'+j.from_user+"</a>";b[i].forEach(function(l){k+='<span class="tweet_txt">';if(l.place)k+="<p><em>"+j.place.full_name+"</em></p>";k+="<p>"+l.text+"</p><span>"});k+="</div>";g.html(k);g.prepend(h);h.click(function(){$(g).dialog("close")});g.dialog("open")};this.add=function(i){if(f++<200){var j=i.profile_image_url.replace("normal","bigger");if(e[i.id])return null;a.push(i);e[i.id]=true;if(b[j])b[j].push(i);else{b[j]=[i];c='<a onclick="tweetKeeper.show(this)" target="_blank"><img class="tweetbar_image" src="'+j+'"></a>';d+=c}}}};
