var restaurantBrowser=new Object();$(document).ready(function()
{$("#matching_restaurants").tablesorter({sortList:[[0,0]]});$("#matching_restaurants").hide();$("ul.chooser li").click(restaurantBrowser.filter);$('#accumulate').click(restaurantBrowser.resetAll);if(restaurantBrowser.mapEnabled())
{restaurantBrowser.map=new GMap2(document.getElementById("gmap"));restaurantBrowser.map.setCenter(new GLatLng(30.4577,-97.750962),13);restaurantBrowser.map.addControl(new GSmallMapControl());restaurantBrowser.map.addControl(new GMapTypeControl());}
else
{}});restaurantBrowser.mapEnabled=function()
{return GBrowserIsCompatible();}
restaurantBrowser.getRestaurants=function()
{return $("#matching_restaurants tbody tr");}
restaurantBrowser.selectedToggles=function()
{var selectedClassNames=new Array();var toggleUls=restaurantBrowser.getElementsByClassName(document,'chooser','UL');for(var i=0;i<toggleUls.length;i++)
{var curtoggle=toggleUls[i];for(var j=0,n=curtoggle.childNodes.length;j<n;j++)
{var tog=curtoggle.childNodes[j];if(tog.tagName=='LI'&&tog.className.search(restaurantBrowser.selectedRegex)!=-1)
{selectedClassNames.push(tog.className.replace(restaurantBrowser.selectedRegex,''));}}}
return selectedClassNames;}
restaurantBrowser.createMarker=function(lat,lon,tr)
{var marker=new GMarker(new GLatLng(lat,lon));var popupHtml=tr.cells[0].innerHTML;GEvent.addListener(marker,"click",function(){marker.openInfoWindowHtml(popupHtml);});return marker;}
restaurantBrowser.resetRestaurants=function()
{$("#matching_restaurants").hide();$("#chosenfeatures").html('');}
restaurantBrowser.resetToggles=function()
{$("ul.chooser li").each(function(){$(this).removeClass("selected");});}
restaurantBrowser.filter=function(e)
{if($("#accumulate").attr("checked"))
{restaurantBrowser.filterAccumulate(e);}
else
{restaurantBrowser.filterNoAccumulate(e);}}
restaurantBrowser.filterNoAccumulate=function(e)
{restaurantBrowser.resetToggles();var chosenFeature=e.target;var featureClassName=chosenFeature.className;var featureText=$(chosenFeature).text();chosenFeature.className+=" selected";restaurantBrowser.highlightRestaurantsWithFeature(featureClassName,featureText);}
restaurantBrowser.highlightRestaurantsWithFeature=function(featureClassName,featureText)
{$("#matching_restaurants").show();var markers=new Array();var restaurants=restaurantBrowser.getRestaurants();restaurants.each(function()
{if($(this).hasClass(featureClassName))
{$(this).show();markers.push(restaurantBrowser.createMarker($(this).attr('lat'),$(this).attr('lon'),this));}
else
{$(this).hide();}});$("matching_restaurants").trigger("sorton",[[0,0]]);$("#chosenfeatures").html($('<p class="chosenfeature"><span>Your selection:</span><br>'+featureText+'</p>'));if(restaurantBrowser.mapEnabled())
{restaurantBrowser.map.clearOverlays();var bounds=new GLatLngBounds();if(markers.length>0)
{for(var i=0,n=markers.length;i<n;i++)
{restaurantBrowser.map.addOverlay(markers[i]);bounds.extend(markers[i].getLatLng());}}
var markersZoom=restaurantBrowser.map.getBoundsZoomLevel(bounds);restaurantBrowser.map.setCenter(bounds.getCenter(),markersZoom-1);}}
restaurantBrowser.filterAccumulate=function(e)
{var markers=new Array();var featureClicked=$(e.target);featureClicked.toggleClass("selected");if($("ul.chooser li").filter(".selected").length==0)
{restaurantBrowser.resetRestaurants();return;}
chosenChoosers=$("ul.chooser li").filter(".selected").get();classesToMatch=new Array();chosenItems=new Array();for(var i=0,n=chosenChoosers.length;i<n;i++)
{var chooser=chosenChoosers[i];chosenItems.push($(chooser).text());var classes=chooser.className.split(' ');for(var j=0,jn=classes.length;j<jn;j++)
{if(classes[j]!="selected")
{classesToMatch.push(classes[j]);}}}
var foundOne=false;restaurantBrowser.getRestaurants().each(function()
{if(restaurantBrowser.hasAllClasses($(this),classesToMatch))
{foundOne=true;$(this).show();markers.push(restaurantBrowser.createMarker($(this).attr('lat'),$(this).attr('lon'),this));}
else
{$(this).hide();}});$("#chosenfeatures").html($('<p class="chosenfeature"><span>Your selections:</span><br>'+chosenItems.join('<br>')+'</p>'));if(foundOne)
{$("#matching_restaurants").show();$("matching_restaurants").trigger("sorton",[[0,0]]);}
else
{$("#matching_restaurants").hide();$("#chosenfeatures").append('<p>No matches!</p>');}
if(restaurantBrowser.mapEnabled())
{restaurantBrowser.map.clearOverlays();var bounds=new GLatLngBounds();if(markers.length>0)
{for(var i=0,n=markers.length;i<n;i++)
{restaurantBrowser.map.addOverlay(markers[i]);bounds.extend(markers[i].getLatLng());}}
var markersZoom=restaurantBrowser.map.getBoundsZoomLevel(bounds);restaurantBrowser.map.setCenter(bounds.getCenter(),markersZoom-1);}}
restaurantBrowser.hasAllClasses=function(restaurant,classesToMatch)
{for(var i=0,n=classesToMatch.length;i<n;i++)
{if(!restaurant.hasClass(classesToMatch[i]))
{return false;}}
return true;}
restaurantBrowser.resetAll=function()
{restaurantBrowser.resetToggles();restaurantBrowser.resetRestaurants();}
