// http://bit.ly/ishiv | WTFPL License
window.innerShiv=function(){function a(a,b,c){return/^(?:area|br|col|embed|hr|img|input|link|meta|param)$/i.test(c)?a:b+"></"+c+">"}var b,c=document,d,e="abbr article aside audio canvas datalist details figcaption figure footer header hgroup mark meter nav output progress section summary time video".split(" ");return function(f,i){if(!b&&(b=c.createElement("div"),b.innerHTML="<nav></nav>",d=b.childNodes.length!==1)){for(var k=c.createDocumentFragment(),l=e.length;l--;)k.createElement(e[l]);k.appendChild(b)}f=f.replace(/^\s\s*/,"").replace(/\s\s*$/,"").replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").replace(/(<([\w:]+)[^>]*?)\/>/g,a),b.innerHTML=(k=f.match(/^<(tbody|tr|td|col|colgroup|thead|tfoot)/i))?"<table>"+f+"</table>":f,k=k?b.getElementsByTagName(k[1])[0].parentNode:b;if(i===!1)return k.childNodes;for(var l=c.createDocumentFragment(),m=k.childNodes.length;m--;)l.appendChild(k.firstChild);return l}}(),window.log=function(){log.history=log.history||[],log.history.push(arguments),arguments.callee=arguments.callee.caller,this.console&&console.log(Array.prototype.slice.call(arguments))},function(a){function b(){}for(var c="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(","),d;d=c.pop();)a[d]=a[d]||b}(window.console=window.console||{}),jQuery.fn.exists=function(){return jQuery(this).length>0},function(a){var b={};a.publish=function(c,e){if(!b[c])return;a.each(b[c],function(){this.apply(a,e||[])})},a.subscribe=function(a,c){return b[a]||(b[a]=[]),b[a].push(c),[a,c]},a.unsubscribe=function(c){var e=c[0];b[e]&&a.each(b[e],function(a){this==c[1]&&b[e].splice(a,1)})}}(jQuery),function(){var a=this,b=a._,c={},d=Array.prototype,e=Object.prototype,f=d.slice,g=d.unshift,h=e.toString,i=e.hasOwnProperty,j=d.forEach,k=d.map,l=d.reduce,m=d.reduceRight,n=d.filter,o=d.every,p=d.some,q=d.indexOf,r=d.lastIndexOf;e=Array.isArray;var s=Object.keys,t=Function.prototype.bind,u=function(a){return new z(a)};typeof module!="undefined"&&module.exports?(module.exports=u,u._=u):a._=u,u.VERSION="1.1.7";var v=u.each=u.forEach=function(a,b,d){if(a!=null)if(j&&a.forEach===j)a.forEach(b,d);else if(a.length===+a.length){for(var e=0,f=a.length;e<f;e++)if(e in a&&b.call(d,a[e],e,a)===c)break}else for(e in a)if(i.call(a,e)&&b.call(d,a[e],e,a)===c)break};u.map=function(a,b,c){var d=[];return a==null?d:k&&a.map===k?a.map(b,c):(v(a,function(a,e,f){d[d.length]=b.call(c,a,e,f)}),d)},u.reduce=u.foldl=u.inject=function(a,b,c,d){var e=c!==void 0;a==null&&(a=[]);if(l&&a.reduce===l)return d&&(b=u.bind(b,d)),e?a.reduce(b,c):a.reduce(b);v(a,function(a,f,g){e?c=b.call(d,c,a,f,g):(c=a,e=!0)});if(!e)throw new TypeError("Reduce of empty array with no initial value");return c},u.reduceRight=u.foldr=function(a,b,c,d){return a==null&&(a=[]),m&&a.reduceRight===m?(d&&(b=u.bind(b,d)),c!==void 0?a.reduceRight(b,c):a.reduceRight(b)):(a=(u.isArray(a)?a.slice():u.toArray(a)).reverse(),u.reduce(a,b,c,d))},u.find=u.detect=function(a,b,c){var d;return w(a,function(a,e,f){if(b.call(c,a,e,f))return d=a,!0}),d},u.filter=u.select=function(a,b,c){var d=[];return a==null?d:n&&a.filter===n?a.filter(b,c):(v(a,function(a,e,f){b.call(c,a,e,f)&&(d[d.length]=a)}),d)},u.reject=function(a,b,c){var d=[];return a==null?d:(v(a,function(a,e,f){b.call(c,a,e,f)||(d[d.length]=a)}),d)},u.every=u.all=function(a,b,d){var e=!0;return a==null?e:o&&a.every===o?a.every(b,d):(v(a,function(a,f,g){if(!(e=e&&b.call(d,a,f,g)))return c}),e)};var w=u.some=u.any=function(a,b,d){b=b||u.identity;var e=!1;return a==null?e:p&&a.some===p?a.some(b,d):(v(a,function(a,f,g){if(e|=b.call(d,a,f,g))return c}),!!e)};u.include=u.contains=function(a,b){var c=!1;return a==null?c:q&&a.indexOf===q?a.indexOf(b)!=-1:(w(a,function(a){if(c=a===b)return!0}),c)},u.invoke=function(a,b){var c=f.call(arguments,2);return u.map(a,function(a){return(b.call?b||a:a[b]).apply(a,c)})},u.pluck=function(a,b){return u.map(a,function(a){return a[b]})},u.max=function(a,b,c){if(!b&&u.isArray(a))return Math.max.apply(Math,a);var d={computed:-Infinity};return v(a,function(a,e,f){e=b?b.call(c,a,e,f):a,e>=d.computed&&(d={value:a,computed:e})}),d.value},u.min=function(a,b,c){if(!b&&u.isArray(a))return Math.min.apply(Math,a);var d={computed:Infinity};return v(a,function(a,e,f){e=b?b.call(c,a,e,f):a,e<d.computed&&(d={value:a,computed:e})}),d.value},u.sortBy=function(a,b,c){return u.pluck(u.map(a,function(a,d,e){return{value:a,criteria:b.call(c,a,d,e)}}).sort(function(a,b){var c=a.criteria,d=b.criteria;return c<d?-1:c>d?1:0}),"value")},u.groupBy=function(a,b){var c={};return v(a,function(a,d){var e=b(a,d);(c[e]||(c[e]=[])).push(a)}),c},u.sortedIndex=function(a,b,c){c||(c=u.identity);for(var d=0,e=a.length;d<e;){var f=d+e>>1;c(a[f])<c(b)?d=f+1:e=f}return d},u.toArray=function(a){return a?a.toArray?a.toArray():u.isArray(a)?f.call(a):u.isArguments(a)?f.call(a):u.values(a):[]},u.size=function(a){return u.toArray(a).length},u.first=u.head=function(a,b,c){return b!=null&&!c?f.call(a,0,b):a[0]},u.rest=u.tail=function(a,b,c){return f.call(a,b==null||c?1:b)},u.last=function(a){return a[a.length-1]},u.compact=function(a){return u.filter(a,function(a){return!!a})},u.flatten=function(a){return u.reduce(a,function(a,b){return u.isArray(b)?a.concat(u.flatten(b)):(a[a.length]=b,a)},[])},u.without=function(a){return u.difference(a,f.call(arguments,1))},u.uniq=u.unique=function(a,b){return u.reduce(a,function(a,c,d){if(0==d||(b===!0?u.last(a)!=c:!u.include(a,c)))a[a.length]=c;return a},[])},u.union=function(){return u.uniq(u.flatten(arguments))},u.intersection=u.intersect=function(a){var b=f.call(arguments,1);return u.filter(u.uniq(a),function(a){return u.every(b,function(b){return u.indexOf(b,a)>=0})})},u.difference=function(a,b){return u.filter(a,function(a){return!u.include(b,a)})},u.zip=function(){for(var a=f.call(arguments),b=u.max(u.pluck(a,"length")),c=Array(b),d=0;d<b;d++)c[d]=u.pluck(a,""+d);return c},u.indexOf=function(a,b,c){if(a==null)return-1;var d;if(c)return c=u.sortedIndex(a,b),a[c]===b?c:-1;if(q&&a.indexOf===q)return a.indexOf(b);c=0;for(d=a.length;c<d;c++)if(a[c]===b)return c;return-1},u.lastIndexOf=function(a,b){if(a==null)return-1;if(r&&a.lastIndexOf===r)return a.lastIndexOf(b);for(var c=a.length;c--;)if(a[c]===b)return c;return-1},u.range=function(a,b,c){arguments.length<=1&&(b=a||0,a=0),c=arguments[2]||1;for(var d=Math.max(Math.ceil((b-a)/c),0),e=0,f=Array(d);e<d;)f[e++]=a,a+=c;return f},u.bind=function(a,b){if(a.bind===t&&t)return t.apply(a,f.call(arguments,1));var c=f.call(arguments,2);return function(){return a.apply(b,c.concat(f.call(arguments)))}},u.bindAll=function(a){var b=f.call(arguments,1);return b.length==0&&(b=u.functions(a)),v(b,function(b){a[b]=u.bind(a[b],a)}),a},u.memoize=function(a,b){var c={};return b||(b=u.identity),function(){var d=b.apply(this,arguments);return i.call(c,d)?c[d]:c[d]=a.apply(this,arguments)}},u.delay=function(a,b){var c=f.call(arguments,2);return setTimeout(function(){return a.apply(a,c)},b)},u.defer=function(a){return u.delay.apply(u,[a,1].concat(f.call(arguments,1)))};var x=function(a,b,c){var d;return function(){var e=this,f=arguments,g=function(){d=null,a.apply(e,f)};c&&clearTimeout(d);if(c||!d)d=setTimeout(g,b)}};u.throttle=function(a,b){return x(a,b,!1)},u.debounce=function(a,b){return x(a,b,!0)},u.once=function(a){var b=!1,c;return function(){return b?c:(b=!0,c=a.apply(this,arguments))}},u.wrap=function(a,b){return function(){var c=[a].concat(f.call(arguments));return b.apply(this,c)}},u.compose=function(){var a=f.call(arguments);return function(){for(var b=f.call(arguments),c=a.length-1;c>=0;c--)b=[a[c].apply(this,b)];return b[0]}},u.after=function(a,b){return function(){if(--a<1)return b.apply(this,arguments)}},u.keys=s||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var b=[],c;for(c in a)i.call(a,c)&&(b[b.length]=c);return b},u.values=function(a){return u.map(a,u.identity)},u.functions=u.methods=function(a){var b=[],c;for(c in a)u.isFunction(a[c])&&b.push(c);return b.sort()},u.extend=function(a){return v(f.call(arguments,1),function(b){for(var c in b)b[c]!==void 0&&(a[c]=b[c])}),a},u.defaults=function(a){return v(f.call(arguments,1),function(b){for(var c in b)a[c]==null&&(a[c]=b[c])}),a},u.clone=function(a){return u.isArray(a)?a.slice():u.extend({},a)},u.tap=function(a,b){return b(a),a},u.isEqual=function(a,b){if(a===b)return!0;var c=typeof a;if(c!=typeof b)return!1;if(a==b)return!0;if(!a&&b||a&&!b)return!1;a._chain&&(a=a._wrapped),b._chain&&(b=b._wrapped);if(a.isEqual)return a.isEqual(b);if(b.isEqual)return b.isEqual(a);if(u.isDate(a)&&u.isDate(b))return a.getTime()===b.getTime();if(u.isNaN(a)&&u.isNaN(b))return!1;if(u.isRegExp(a)&&u.isRegExp(b))return a.source===b.source&&a.global===b.global&&a.ignoreCase===b.ignoreCase&&a.multiline===b.multiline;if(c!=="object")return!1;if(a.length&&a.length!==b.length)return!1;c=u.keys(a);var d=u.keys(b);if(c.length!=d.length)return!1;for(var e in a)if(!(e in b)||!u.isEqual(a[e],b[e]))return!1;return!0},u.isEmpty=function(a){if(u.isArray(a)||u.isString(a))return a.length===0;for(var b in a)if(i.call(a,b))return!1;return!0},u.isElement=function(a){return!!a&&a.nodeType==1},u.isArray=e||function(a){return h.call(a)==="[object Array]"},u.isObject=function(a){return a===Object(a)},u.isArguments=function(a){return!!a&&!!i.call(a,"callee")},u.isFunction=function(a){return!(!a||!a.constructor||!a.call||!a.apply)},u.isString=function(a){return!!(a===""||a&&a.charCodeAt&&a.substr)},u.isNumber=function(a){return!!(a===0||a&&a.toExponential&&a.toFixed)},u.isNaN=function(a){return a!==a},u.isBoolean=function(a){return a===!0||a===!1},u.isDate=function(a){return!(!a||!a.getTimezoneOffset||!a.setUTCFullYear)},u.isRegExp=function(a){return!(!a||!a.test||!a.exec||!a.ignoreCase&&a.ignoreCase!==!1)},u.isNull=function(a){return a===null},u.isUndefined=function(a){return a===void 0},u.noConflict=function(){return a._=b,this},u.identity=function(a){return a},u.times=function(a,b,c){for(var d=0;d<a;d++)b.call(c,d)},u.mixin=function(a){v(u.functions(a),function(b){B(b,u[b]=a[b])})};var y=0;u.uniqueId=function(a){var b=y++;return a?a+b:b},u.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g},u.template=function(a,b){var c=u.templateSettings;return c="var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('"+a.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(c.interpolate,function(a,b){return"',"+b.replace(/\\'/g,"'")+",'"}).replace(c.evaluate||null,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('');",c=new Function("obj",c),b?c(b):c};var z=function(a){this._wrapped=a};u.prototype=z.prototype;var A=function(a,b){return b?u(a).chain():a},B=function(a,b){z.prototype[a]=function(){var a=f.call(arguments);return g.call(a,this._wrapped),A(b.apply(u,a),this._chain)}};u.mixin(u),v(["pop","push","reverse","shift","sort","splice","unshift"],function(a){var b=d[a];z.prototype[a]=function(){return b.apply(this._wrapped,arguments),A(this._wrapped,this._chain)}}),v(["concat","join","slice"],function(a){var b=d[a];z.prototype[a]=function(){return A(b.apply(this._wrapped,arguments),this._chain)}}),z.prototype.chain=function(){return this._chain=!0,this},z.prototype.value=function(){return this._wrapped}}(),function(a){var b='<a href="#close" class="warning-close close-modal" id="warning-close">Close</a>',c='  <div class="overlay">    <div class="wrap">      <div class="modal-window"></div>    </div>  </div>',d=function(b){a(".modal-window").html(""),a("body").removeClass("overlaid"),Modernizr.csstransforms||a(".overlay").hide(),b.preventDefault()},e=function(){var b=a(".modal-window"),c=a(document),d=b.width(),e=c.width(),f=e/2-d/2,g=b.height(),h=c.height(),i=h/2-g/2;a(".modal-window").css({position:"absolute",left:f+"px",top:i+"px"})};a(".overlay").size()===0&&(a("body").append(c),Modernizr.csstransforms||a(".overlay").hide()),a(".modal-window").delegate(".close-modal","click",d),a.fn.modal=function(){return this.each(function(c,d){a(".modal-window").html(a(this).html()+b),Modernizr.csstransforms||a(".overlay").show(),a("body").addClass("overlaid"),Modernizr.flexbox||e()})},a.modal=function(c){a(".modal-window").html(innerShiv(c+b)),Modernizr.csstransforms||a(".overlay").show(),a("body").addClass("overlaid"),Modernizr.flexbox||e()},a.modalUrl=function(b){a.ajax({url:b.url,dataType:"html",context:this,success:function(c){a.modal(c),b.success&&b.success()}})}}($),function(){var a="Mappeo is now available on the Chrome Web Store",b="https://chrome.google.com/webstore/detail/lnempicjilmahngopecohbcbldlijkib",c="/images/mappeo-white-logo.png",d="_webstore_preference",e="/css/chrome.css",f=["_trackEvent","Web","Chrome-bar","Click"];if(navigator&&navigator.userAgent&&navigator.userAgent.indexOf("Chrome")!=-1){var g=window.chrome&&window.chrome.app&&window.chrome.app.isInstalled,h=document.cookie.indexOf(d+"=true")>=0;createNotificationBar=function(){var e=document.createElement("div");e.id="chrome-bar",e.style.display="none";var g=document.createElement("div");g.className="right";var h=document.createElement("button");h.id="chrome-install",h.innerText="Install",h.addEventListener("click",function(){return f&&window._gaq&&_gaq.push(f),chrome&&chrome.webstore&&chrome.webstore.install?chrome.webstore.install():window.open(b),!1});var i=document.createElement("span");i.innerText="x",i.addEventListener("click",function(){return e.style.display="none",document.cookie=d+"=true",!1}),g.appendChild(h),g.appendChild(i),e.appendChild(g);if(c){var j=document.createElement("img");j.src=c,e.appendChild(j)}var k=document.createElement("p");k.innerHTML=a,e.appendChild(k),document.body.insertBefore(e,document.body.childNodes[0])},addStylesheet=function(){if(e){var a=document.createElement("link");a.rel="stylesheet",a.href=e,document.head.appendChild(a)}},showAnimatedNotification=function(){var a=document.getElementById("chrome-bar");window.addEventListener("load",function(){a.style.display="block",setTimeout(function(){a.className="visible"},700)})},!g&&!h&&(createNotificationBar(),addStylesheet(),showAnimatedNotification())}}(),function(){this.AppView=function(){this.initialize()},_.extend(this.AppView.prototype,{initialize:function(){this.resize(),this.initKeyboardShortcuts(),$(window).bind("resize",this.resize),$.subscribe("/search/started",this.showLoadingWindow),$.subscribe("/markers/loaded",this.hideLoadingWindow),$("a.lightbox").bind("click",this.showFooterLightBox),$("a.link").bind("click",this.trackClick),this.trackSocialEvents()},resize:function(){$("#map_canvas").width($("#container").width()-150),$("#map_canvas").height($(window).height()-200),$("#videos").height($(window).height()-200),$.publish("/window/resize")},showLoadingWindow:function(){$("#loading-window").show()},hideLoadingWindow:function(){$("#loading-window").hide()},initKeyboardShortcuts:function(){$("input").bind("keydown",function(a){var b=a.keyCode?a.keyCode:a.which?a.which:a.charCode;return b==13?($("button").click(),!1):!0})},showFooterLightBox:function(){var a=$(this),b=$(this).attr("href"),c=$(b).html();return $.modal(c),!1},trackClick:function(){var a=$(this).attr("name");return _gaq.push(["_trackEvent","Web","Link",a]),!0},trackSocialEvents:function(){window.FB&&FB.Event.subscribe("edge.create",function(a){_gaq.push(["_trackSocial","facebook","like",a])}),window.twttr&&twttr.events.bind("tweet",function(a){if(a){var b;a.target&&a.target.nodeName=="IFRAME"&&(b=extractParamFromUri(a.target.src,"url")),_gaq.push(["_trackSocial","twitter","tweet",b])}})}})}(),function(){this.SearchView=function(){this.initialize()},_.extend(this.SearchView.prototype,{initialize:function(){$("button.search").bind("click",this.searchKeywordPressed)},getSearchTerm:function(){return $("#keyword-filter").val()},searchKeywordPressed:function(){var a=$("#keyword-filter").val();_gaq.push(["_trackEvent","Web","Keyword",a]),$.publish("/search/clicked",[a])}})}(),function(){this.MapView=function(){this.initialize()},_.extend(this.MapView.prototype,{initialize:function(){$(".window .close").live("click",function(){$(".window").hide()}),$("video-window .close").live("click",function(){$("#video-window").remove()}),$("#videos li").live("click",function(){var a=$(this).attr("data-video");$.publish("/map/list/click",[!1,a])}),$("#video-window footer div").live("click",function(){var a=$(this).attr("data-video");$.publish("/map/list/click",[!1,a])})}})}();var _gaq=_gaq||[];(function(){this.AppController=function(){this.initialize()},_.extend(this.AppController.prototype,{initialize:function(){new AppView,new MapController,new GeolocationController,new VideosController,new SearchController,this.analytics()},analytics:function(){_gaq.push(["_setAccount","UA-212686-6"]),_gaq.push(["_trackPageview"]),_gaq.push(["_trackPageLoadTime"])}})})(),function(){this.MapController=function(){this.initialize()},_.extend(this.MapController.prototype,{initialize:function(){this.map=!1,this.markers=!1,this.videos=!1,_.bindAll(this,"resizeMap","refreshMap","displayMarkers","clearMarkers","setupMap","mapChanged","queueSearch","centerMap"),$.subscribe("/geo/located",this.centerMap),$.subscribe("/videos/ready",this.displayMarkers),$.subscribe("/window/resize",this.resizeMap),$.subscribe("/search/requested",this.refreshMap),$.subscribe("/center/map",this.centerMap),this.view=new MapView},setupMap:function(a){var b=new google.maps.LatLng(a.coords.latitude,a.coords.longitude),c={zoom:10,center:b,mapTypeId:google.maps.MapTypeId.ROADMAP,scrollwheel:!0};this.map=new google.maps.Map(document.getElementById("map_canvas"),c),google.maps.event.addListener(this.map,"bounds_changed",this.mapChanged),google.maps.event.addListener(this.map,"zoom_changed",this.queueSearch)},canMove:function(){var a=$("#loading-window").get(0).style.display=="block",b=this.map.getProjection().fromLatLngToPoint(this.map.getCenter());if(!this.previous_center)return this.previous_center=b,!0;var c=this.previous_center||b,d=Math.sqrt((c.x-b.x)*(c.x-b.x)+(c.y-b.y)*(c.y-b.y));return log(d),a||d<.1?!1:(this.previous_center=this.map.getProjection().fromLatLngToPoint(this.map.getCenter()),!0)},queueSearch:function(){clearTimeout(this.timeout);var a=this;this.timeout=setTimeout(function(){a.clearMarkers(),$.publish("/search",[a.map.getCenter(),a.map.getBounds()])},1e3)},mapChanged:function(){if(!this.canMove())return;this.queueSearch()},refreshMap:function(){var a=this;clearTimeout(this.timeout),a.clearMarkers(),$.publish("/search",[a.map.getCenter(),a.map.getBounds()])},centerMap:function(a){if(!this.map)this.setupMap(a);else if(a.geometry)this.map.setCenter(a.geometry.location);else{var b=new google.maps.LatLng(a.coords.latitude,a.coords.longitude);this.map.setCenter(b)}},displayMarkers:function(a){this.clearMarkers(),this.videos=a;var b=a.length;for(var c=0;c<b;c++){var d=a[c],e=new google.maps.Marker({position:d.position,map:this.map,title:d.title,icon:"http://mappeo.net/images/video.png"});this.setupMarkerEvents(e,c),this.markers.push(e)}$.publish("/markers/loaded")},setupMarkerEvents:function(a,b){google.maps.event.addListener(a,"click",function(c,d){$.publish("/map/marker/open",[a,b])})},clearMarkers:function(){if(this.markers)for(var a=0;a<this.markers.length;a++)this.markers[a].setMap(null);this.markers=[]},resizeMap:function(){google.maps.event.trigger(this.map,"resize")}})}(),function(){var a=37.7749295,b=-122.4194155;this.GeolocationController=function(){this.initialize()},_.extend(this.GeolocationController.prototype,{initialize:function(){$.subscribe("/geolocate/html5/failed",this.geolocateWithAlternateMethod),$.subscribe("/geocode",this.geocode),$("p.geolocation img").bind("click",this.findPosition),this.findPosition()},findPosition:function(){$("p.geolocation span").text("Current position"),navigator.geolocation?navigator.geolocation.getCurrentPosition(function(a){$.publish("/geo/located",[a])},function(a){$.publish("/geolocate/html5/failed")}):(log("html5 geolocation not supported"),$.publish("/geolocate/html5/failed"))},geolocateWithAlternateMethod:function(){var c={coords:{}};google.loader.ClientLocation?(c.coords.latitude=google.loader.ClientLocation.latitude,c.coords.longitude=google.loader.ClientLocation.longitude,log("Geolocated with google client loader")):(c.coords.latitude=a,c.coords.longitude=b,log("Geolocation failed, fallback to San Francisco, CA"),$("p.geolocation span").text("Geolocation failed to get your current position")),$.publish("/geo/located",[c])},geocode:function(a){var b=new google.maps.Geocoder;b.geocode({address:a},function(b,c){c==google.maps.GeocoderStatus.OK?(_gaq.push(["_trackEvent","Web","Geocode",b[0].formatted_address]),$("p.geolocation span").text(b[0].formatted_address),$.publish("/center/map",[b[0]])):(log("Geocode was not successful for the following reason: "+c),$.publish("/search/keyword",[a]))})}})}(),function(){this.SearchController=function(){this.initialize()},_.extend(this.SearchController.prototype,{initialize:function(){_.bindAll(this,"search","processSearchTerms","setKeywordFilter"),$.subscribe("/search",this.search),$.subscribe("/search/complete",this.searchResult),$.subscribe("/search/clicked",this.processSearchTerms),$.subscribe("/search/keyword",this.setKeywordFilter)},search:function(a,b){$.publish("/search/started"),this.view||(this.view=new SearchView);var c=this.searchTerm,d=new google.maps.LatLng(a.lat(),a.lng()),e=new google.maps.LatLng(b.getSouthWest().lat(),b.getCenter().lng()),f=google.maps.geometry.spherical.computeDistanceBetween(d,e);f=Math.round(f)/1e3;var g=document.getElementsByTagName("head")[0],h=document.createElement("script");h.type="text/javascript";var i="alt=jsonc&v=2&max-results=50&location="+a.lat()+","+a.lng()+"!&location-radius="+f+"km&callback=app.searchCallback";i=c?"q="+c+"&"+i:i;var i=encodeURI(i);log(i),h.src="http://gdata.youtube.com/feeds/api/videos?"+i,g.appendChild(h),_gaq.push(["_trackEvent","Web","Search","Called"])},calculateSearchRadius:function(a,b){var c=new LatLng(a.lat(),a.lng()),d=new LatLng(b.getSouthWest.lat(),b.getSouthWest.lng()),e=google.maps.geometry.spherical.computeDistanceBetween(c,d);return e},searchResult:function(a){app.videos=new Array;var b=a.data,c=b.items||[];for(var d=0;d<c.length;d++){var e=c[d];app.videos.push(e)}$.publish("/videos/loaded",[app.videos])},processSearchTerms:function(a){var b=!1,c=[" near "," at "," around "," close to "];for(var d=0;d<c.length;d++){var e=c[d];if(a.lastIndexOf(e)!=-1){b=!0,a=a.replace(e,"#"),a=a.split("#");break}}this.searchTerm=b?a[0]:"";var f=b?a[1]:a;$.publish("/geocode",[f])},setKeywordFilter:function(a){this.searchTerm=a,$.publish("/search/requested")}})}(),function(){this.VideosController=function(){this.initialize()},_.extend(this.VideosController.prototype,{initialize:function(){_.bindAll(this,"prepare","displayList","display"),$.subscribe("/videos/loaded",this.prepare),$.subscribe("/videos/ready",this.displayList),$.subscribe("/map/marker/open",this.display),$.subscribe("/map/list/click",this.display)},prepare:function(a){var b=new Array;if(a)for(var c=0;c<a.length;c++){var d=a[c],e={},f=d.geoCoordinates.latitude,g=d.geoCoordinates.longitude;e.position=new google.maps.LatLng(f,g),e.id=d.id,e.title=d.title,e.description=d.description,e.thumbnailURL=d.thumbnail.hqDefault,e.playerUrl=d.player["default"],e.mobileUrl=d.player.mobile,b.push(e)}$.publish("/videos/ready",[b])},displayList:function(a){this.videos=a,$("#videos-list").html("");var b=a.length;for(var c=0;c<b;c++){var d=a[c];$("#videos-list").append('<li data-video="'+c+'"><img src="'+d.thumbnailURL+'" alt="'+d.title+'" width="96" height="72" /></li>')}},display:function(a,b){this.videos[b].i=parseInt(b);var c=_.template($("#video-window-template").html()),d=c(this.videos[b]);$.modal(d)}})}();var app={setup:function(){google.load("maps","3",{callback:app.init,other_params:"sensor=false&libraries=geometry"})},init:function(){new AppController},searchCallback:function(a){$.publish("/search/complete",[a])}};$(document).ready(function(){app.setup()})

