$(function() { 
	
	$('.tabbed-nav .selected').each(function() {
		if ($(this).hasClass('first')) $(this).addClass('first-selected');
		if ($(this).hasClass('last')) $(this).addClass('last-selected');
	});
	
	$('.section.inactive + .expandable').hide();
	
	$('.section > .expander').click(function() {
		var heading = $(this.parentNode);
		heading.toggleClass('inactive');
		$('+ .expandable', heading)[heading.hasClass('inactive') ? 'hide' : 'show']();
	});
	
	$('a[rel=help]').click(function() {
		window.open('/help/new/!SSL!/FlashHelp/Priceyourmeal_Help.htm', '_blank');
		return false;
	});

});

$.fn.businessAutocomplete = function(options) {
	
	var defaultOptions = {
		selectFirst:true,
		delay:10,
		minChars:2,
		matchSubset:1,
		matchContains:0,
		cacheLength:10,
		maxItemsToShow:10,
		autofill:true,
		width:500,
		formatItem: businessAutocompleter.formatItem
	};
	
	return $(this).autocomplete('/community/business/find', $.fn.extend(defaultOptions, options || {}));
};

var businessAutocompleter = {
  formatItem: function(row) {  
    var o = "<b style='margin-left: 5px; margin-right: 10px'>" + row[0] + "</b>";
    var address = [row[2],row[5]];
    o += "<span>" + address.join(', ') + "</span>";
    return o;
  }
}
