// Namespace some stuff
typeof fourteenteeth=="undefined"&&(fourteenteeth=function(){}),fourteenteeth.time=function(){},fourteenteeth.local=function(){},ti=function(a){return a="/interaction/"+a,_gaq.push(["_trackPageview",a]),!0},fourteenteeth.mark_new_posts=function(){$("ol li").each(function(a,b){var c=this.className.replace(/_/g," ");fourteenteeth.time.is_new_post(c)&&(this.innerHTML+=" <span>NEW!</span>",this.className="new")})},fourteenteeth.time.last_visit=null,fourteenteeth.time.is_new_post=function(a){var b=(new Date(a)).getTime();return fourteenteeth.time.last_visit?b>fourteenteeth.time.last_visit?!0:!1:!1},fourteenteeth.time.determine_previous_visit=function(){if(fourteenteeth.time.last_visit_cookie_already_existed()){var a=document.cookie,b=a.match(/ftt_last_visit=(\d{13})/);fourteenteeth.time.last_visit=parseInt(b[1]);return}var c=new Date,d=new Date(c.getTime()-1728e5);fourteenteeth.time.last_visit=d.getTime()},fourteenteeth.time.last_visit_cookie_already_existed=function(){return document.cookie&&document.cookie.match(/ftt_last_visit=(\d{13})/)?!0:!1},fourteenteeth.time.set_visit_time_cookie=function(){var a=new Date,b=new Date(a.getTime()+31536e6);document.cookie="ftt_last_visit="+a.getTime()+"; expires="+b.toGMTString()+"; path=/"},fourteenteeth.time.determine_previous_visit(),fourteenteeth.time.set_visit_time_cookie(),$(document).ready(function(){fourteenteeth.mark_new_posts(),fourteenteeth.local.determine_location(),location.hash&&location.hash=="#suggest_blog"?fourteenteeth.local.suggest_blog():fourteenteeth.local.add_suggest_blog_link()}),fourteenteeth.local.add_suggest_blog_link=function(){typeof fourteenteeth.valid_locations=="undefined"&&$(".box").length>0&&$("p.intro").after('<p class="intro"><strong>New!</strong> We\'re adding more blogs this week, including ones local to you! <a href="#" onclick="fourteenteeth.local.suggest_blog(this); return false;" class="action">Suggest a Blog.</a></p>')},typeof Number.prototype.toRad=="undefined"&&(Number.prototype.toRad=function(){return this*Math.PI/180}),fourteenteeth.local.determine_location=function(){var a=document.cookie,b=a.match(/ftt_loc=([^;]+)/);if(b)fourteenteeth.loc_guessed=!1,fourteenteeth.loc=b[1];else if(typeof google!="undefined"){fourteenteeth.loc_guessed=!0,fourteenteeth.loc_guessed_city="unknown";var c=google.loader.ClientLocation;c&&c.address&&c.address.city&&(fourteenteeth.loc_guessed_city=c.address.city);var d=c.latitude,e=c.longitude,f,g=99999;$.each(fourteenteeth.location_map_flat,function(a){var b=this.latitude,c=this.longitude,h=6371,i=(b-d).toRad(),j=(c-e).toRad(),k=Math.sin(i/2)*Math.sin(i/2)+Math.cos(d.toRad())*Math.cos(b.toRad())*Math.sin(j/2)*Math.sin(j/2),l=2*Math.atan2(Math.sqrt(k),Math.sqrt(1-k)),m=h*l;g>m&&(g=m,f=this)}),fourteenteeth.loc=f.name;var h=new Date,i=new Date(h.getTime()+31536e6);document.cookie="ftt_loc="+fourteenteeth.loc+"; expires="+i.toGMTString()+"; path=/"}fourteenteeth.local.start()},fourteenteeth.local.start=function(){if(!fourteenteeth.loc)return;if($(".box").length==0)return;if(typeof fourteenteeth.valid_locations=="undefined")return;if(-1==$.inArray(fourteenteeth.loc,fourteenteeth.valid_locations))return;$.ajax({url:"/fourteenteeth/local?l="+fourteenteeth.loc,cache:!1,success:fourteenteeth.local.loaded,dataType:"html"})},fourteenteeth.local.loaded=function(a,b,c){ti("local_blogs_loaded/"+fourteenteeth.loc),$("#local").length>0?$("#local").animate({marginLeft:fourteenteeth.local.pre_animate},250,function(){$("#local .moved").removeClass("moved").appendTo("body"),$("#local").remove(),fourteenteeth.local.show(a)}):fourteenteeth.local.show(a)},fourteenteeth.local.loc_to_proper_name=function(a){newVal="",val=a.split("_");for(var b=0;b<val.length;b++)newVal+=val[b].substring(0,1).toUpperCase()+val[b].substring(1,val[b].length)+" ";return newVal},fourteenteeth.local.show=function(a){var b='<img src="http://maps.google.com/maps/api/staticmap?zoom=11&size=100x123&center='+fourteenteeth.loc+'&sensor=false" />';html='<div id="local"><div class="summary">',html+="<h2>"+fourteenteeth.local.loc_to_proper_name(fourteenteeth.loc)+" Blogs</h2>",html+=b,fourteenteeth.loc_guessed?html+="<p>These blogs are closest to "+fourteenteeth.loc_guessed_city+'. <a href="http://blog.pedalroom.com/local-blogs-on-fourteenteeth-released" title="More information about local blogs">More about this new feature.</a></p>':html+="<p>These blogs are based in "+fourteenteeth.local.loc_to_proper_name(fourteenteeth.loc)+'. <a href="http://blog.pedalroom.com/local-blogs-on-fourteenteeth-released" title="More information about local blogs">More about this new feature.</a></p>',html+='<a href="#" onclick="fourteenteeth.local.choose_location(this); return false;" class="action">Change Location</a>',html+='<a href="#" onclick="fourteenteeth.local.suggest_blog(this); return false;" class="action">Suggest Blog, Location, or Improvements</a>',html+="</div></div>",$(".box:first").before(html),fourteenteeth.local.pre_animate=$("#local").css("marginLeft"),$("#local").animate({marginLeft:"12px"},500,"swing"),$(".location_"+fourteenteeth.loc.toLowerCase()).addClass("moved").appendTo("#local"),$("#local").append(a)},fourteenteeth.local.suggest_blog=function(a){ti("suggest_blog_open"),$("p.intro + p.intro").remove(),a&&a.blur(),$("#suggest").length>0&&($("#suggest + div.clear").remove(),$("#suggest").remove());var b='<div id="suggest"><h2>Suggest a Blog / Location / Improvement</h2><div class="row">Know of a great blog to add? Should we add a new location? Anything<br />else we can do to make FourteenTeeth better? Let us know!</div>';b+='<form method="post" action="/fourteenteeth/suggest">',b+='<div class="row"><label for="suggest_why">Your Suggestion: <span class="minor">(leave contact info if you want a reply)</span></label><textarea id="suggest_why" name="why"></textarea><div class="clear"><!-- --></div></div>',b+='<input type="submit" value="Send" />',b+="</form>",b+='</div><div class="clear" style="height: 20px;"><!-- --></div>',$("p.intro").after(b),$("#suggest_why").focus()},fourteenteeth.local.choose_location=function(a){ti("location_selector_open"),a.blur();var b='<div id="locations" style="display: none;">';b+=fourteenteeth.local.build_location_selector_html(fourteenteeth.location_map),b+="</div>",$("#local img").before(b);var c=$(a).offset().top-$("#local").offset().top-5;$("#locations .arrow").css("top",c+"px"),$("#locations").css("opacity",.81).fadeIn(200)},fourteenteeth.local.build_location_selector_html=function(a){var b="";return $.each(a,function(a){b+=fourteenteeth.local.build_location_selector_row(this)}),b},fourteenteeth.local.build_location_selector_row=function(a){var b=a.name.replace("_"," ");if(typeof a.children!="undefined"){var c="<div>"+b+"<br />";return c+=fourteenteeth.local.build_location_selector_html(a.children),c+='<div class="arrow"></div>',c+="</div>",c}return a.name==fourteenteeth.loc?"<span>"+b+"</span><br />":'<a href="#" onclick="fourteenteeth.local.change_location(\''+a.name+"', this); return false;\">"+b+"</a><br />"},fourteenteeth.local.change_location=function(a,b){ti("location_manually_chosen/"+a),$(b).blur().text("loading..."),$("#locations a").each(function(a){this.onclick=function(){return this.blur(),!1}}),fourteenteeth.loc=a;var c=new Date,d=new Date(c.getTime()+31536e6);document.cookie="ftt_loc="+a+"; expires="+d.toGMTString()+"; path=/",fourteenteeth.local.start()},fourteenteeth.local.remove_cookie=function(){var a=new Date,b=new Date(a.getTime()-86400);document.cookie="ftt_loc=gone; expires="+b.toGMTString()+"; path=/"}
