function hideSteps(){$(document.body).getElements(".step").each(function(a){a.addClass("hide")});window.scrollTo(0,1)}function displayVoteState(e,d,b,a){window.scrollTo(0,1);var c="result";$(c).getElements(".yes").addClass("hide");$(c).getElements(".no").addClass("hide");$(c).getElements(".not-sure").addClass("hide");$(c).getElements(".voted").addClass("hide");$(c).getElements(".not-voted").addClass("hide");if(a){$(c).getElements(".voted").removeClass("hide")}else{$(c).getElements(".not-voted").removeClass("hide")}$(c).getElements(".stats").each(function(f){f.set("text",(b==1)?"One person said":Math.max(e,d)+" out of "+b+" people agree")});if(e>d){$(c).getElements(".yes").removeClass("hide")}else{if(e<d){$(c).getElements(".no").removeClass("hide")}else{$(c).getElements(".not-sure").removeClass("hide")}}}function displayLocation(a){$("result").getElements(".restaurant-name").each(function(b){b.set("html",a.name.split("'").join("&rsquo;"))});$("yes").getElement("a").set("phone",a.phone);$("no").getElement("a").set("phone",a.phone);displayVoteState(a.yes_votes,a.no_votes,a.total_votes,a.voted);$("call").set("href","tel:"+a.phone);$("yelp").set("href",(isSmartPhone)?a.mobile_url:a.url);$("map").set("href","http://maps.google.com/maps?q="+escape(a.street)+",+"+escape(a.city)+",+"+escape(a.state)+"+"+a.zip+"+("+escape(a.name)+")");location.hash="/location/"+a.phone+"/";hideSteps();$("result").removeClass("hide")}function getLocation(b){hideSteps();$("loading").removeClass("hide");var a=new Request.JSON({url:"/api/location",onComplete:displayLocation}).send("phone="+b)}function displaySearch(){$("restaurant").set("value","");if(location.hash+""!==""){location.hash="/"}hideSteps();$("search").removeClass("hide")}function displayResults(k){var j=$("results").getElement("ul");j.empty();var o;var m;var f;var b;var g=-1;var l=function(a){a.stop();getLocation(this.get("phone"))};var p=function(){this.addClass("active")};var h=function(){this.addClass("active")};while(++g<k.length){o=new Element("li");m=new Element("a");b=k[g].name+" at "+k[g].street;f=b.substr(0,27).trim();if(f.length<b.length){f+="&hellip;"}m.set("html",f);m.set("href","#");m.set("phone",k[g].phone);m.addEvent("click",l);m.addEvent("touchstart",p);m.addEvent("touchend",h);o.adopt(m);if(g==0){o.addClass("first")}else{if(g+1==k.length){o.addClass("last")}}j.adopt(o)}if(k.length==0){o=new Element("li");m=new Element("a");m.set("text","No Results");m.set("href","#");m.addEvent("click",function(a){a.stop();displaySearch()});m.addEvent("touchstart",p);m.addEvent("touchend",h);o.adopt(m);o.addClass("first last");j.adopt(o)}hideSteps();$("search-results").removeClass("hide")}function search(c,a){$("restaurant").blur();$("location").blur();if(c===""){alert("Please enter a restaurant name.");return}if(a===""){alert("Please enter a city or ZIP.");return}$("location").set("value",a.split("-").join(" "));location.hash="/search/"+a.split(" ").join("-")+"/"+c.split(" ").join("-")+"/";hideSteps();$("loading").removeClass("hide");var b=new Request.JSON({url:"/api/search",onComplete:displayResults}).send("query="+c+"&location="+a)}function voted(a){displayVoteState(a.yes_votes,a.no_votes,a.total_votes,true);hideSteps();$("result").removeClass("hide")}function vote(b,c){hideSteps();$("loading").removeClass("hide");var a=new Request.JSON({url:"/api/vote",onComplete:voted}).send("phone="+c+"&refill="+b)}window.addEvent("domready",function(){Element.NativeEvents.touchstart=2;Element.NativeEvents.touchend=2;$("app").getElement("h1").addEvent("click",function(c){c.stop();displaySearch()});var b=function(c){c.stop();search($("restaurant").get("value"),$("location").get("value"))};$("restaurant-search").addEvent("submit",b);$("frefill").getElement("a").addEvent("click",b);$("ui").getElements(".search-again a").each(function(c){c.addEvent("click",function(d){d.stop();displaySearch()})});$("yes").getElement("a").addEvent("click",function(c){c.stop();vote(1,this.get("phone"))});$("no").getElement("a").addEvent("click",function(c){c.stop();vote(0,this.get("phone"))});var a=function(c){c.addEvent("touchstart",function(d){this.addClass("active")});c.addEvent("touchend",function(d){this.removeClass("active")})};$("vote").getElements("a").each(a);$("ui").getElements("p.lrg-btn a").each(a);$("result").getElements(".list a").each(a)});function initDeepLink(){var a=location.hash.split("/");if(a.length>=3){switch(a[1].toLowerCase()){case"location":getLocation(a[2]);break;case"search":search(a[3],a[2]);break}}}window.addEvent("load",function(){if(location.hash.split("/").length<3){setTimeout(function(){window.scrollTo(0,1)},100)}else{setTimeout(initDeepLink,100)}try{reinvigorate.track("c54d6-51pjttkv5z")}catch(a){}});