"use strict";function getOpenTableData(){restaurantsViewModel.zipSearch()&&$.ajax({url:"http://opentable.herokuapp.com/api/restaurants",method:"GET",data:"zip="+restaurantsViewModel.zipSearch(),dataType:"jsonp",success:function(e){for(var a=0;a<e.restaurants.length;a++){var r,t=e.restaurants[a],s=t.address+", "+t.postal_code;switch(t.price){case 1:r="$";break;case 2:r="$$";break;case 3:r="$$$";break;case 4:r="$$$$";break;default:r=""}restaurantsViewModel.restaurants.push(new Restaurant(t.id,t.name,s,t.lat,t.lng,t.phone,r,t.image_url,t.reserve_url))}populateMap(restaurantsViewModel.restaurants()),restaurantsViewModel.isVisible(!0)}}).fail(function(){restaurantsViewModel.message("Could load Restaurant data. Please try again later.")})}var changed=!1;$(document).ready(function(){ko.applyBindings(restaurantsViewModel)});var Restaurant=function(e,a,r,t,s,i,n,o,l){this.id=e,this.name=a,this.address=r,this.lat=t,this.lng=s,this.phone=i,this.price=n,this.image=o,this.link=l,this.marker="",this.infowindow=new google.maps.InfoWindow},RestaurantsViewModel=function(){var e=this;e.restaurantId=ko.observable(""),e.restaurants=ko.observableArray(),e.filterName=ko.observable(""),e.filterAddress=ko.observable(""),e.filterPrice=ko.observable("Any"),e.zipSearch=ko.observable("60602"),e.isVisible=ko.observable(!1),e.message=ko.observable("Restaurant data is provided by OpenTable"),e.searchZip=function(){5!=e.zipSearch().length||isNaN(e.zipSearch())?$(".search").addClass("has-error"):(changed=!1,e.filterName(""),e.filterAddress(""),e.filterPrice("Any"),e.restaurants().length=0,getMapData())},e.enableMarker=function(e){return displayMarker(e),!0},e.disableMarker=function(e){isHighlighted&&revertMarker(e.marker,e.infowindow)},e.filterRestaurants=ko.computed(function(){if(e.filterName()||e.filterAddress()||"Any"!=e.filterPrice()){changed=!0;var a=ko.utils.arrayFilter(e.restaurants(),function(a){return"Any"==e.filterPrice()?-1!==a.name.toLowerCase().indexOf(e.filterName().toLowerCase())&&-1!==a.address.toLowerCase().indexOf(e.filterAddress().toLowerCase()):-1!==a.name.toLowerCase().indexOf(e.filterName().toLowerCase())&&-1!==a.address.toLowerCase().indexOf(e.filterAddress().toLowerCase())&&a.price==e.filterPrice()});return hideMarkers(a),a}return changed&&hideMarkers(e.restaurants()),e.restaurants()})},restaurantsViewModel=new RestaurantsViewModel;