function setupSearch(obj){
	
	if(jQuery(obj).length > 0)
	{
		jQuery(obj).parents('form').bind('submit',function(){
			//showSearchResults(jQuery(obj).val());
			$.history.load('#!page=search&term='+jQuery(obj).val());
			return false;
		});
		jQuery(obj).bind(
			'keydown', function(){
			});
		$(obj).autocomplete({
			minLength: 3,
			source: function( request, response ) {
				$.get(
					'/api/companies/query.json/'+request.term,
					function(data){
						var suggestions = new Array();
						if(data.status == 200)
						{
							for(var i in data.data)
							{
								suggestions[i] = 
								{
									value: data.data[i].business,
									label: data.data[i].business,
									desc: data.data[i].description,
									id: data.data[i].businessid
								};

	// 								suggestions[i] = data.data[i].business;
							}
						}
						response( suggestions );
					},
					'json'
				);
			},
			select: function( event, ui ) {
				$(obj).val( ui.item.label );
				//$(obj).parents('form').trigger('submit');
				//showSearchResults(ui.item.label);
				$.history.load('#!page=search&term='+ui.item.label);
				//$( "#searchbusinessname_result, #search_result" ).val( ui.item.id );
				return false;
			}
		}).data( "autocomplete" )._renderItem = function( ul, item ) {
			return $( "<li class='autocomplete_suggestion'></li>" )
				.data( "item.autocomplete", item )
				.append( "<a>" + item.label + "<br><span class='autocomplete_description'>" + item.desc.substring(0,160) + "</span></a>" )
				.appendTo( ul );
		};
	}
	
}

function showSearchResults(term)
{
	if(welcometext)
	{
		$('#welcomehome, .content-hr:eq(0)').hide(800, function(){$(this).remove(); });
		welcometext = false;
	}
	$('.category-nav li.selected').removeClass('selected').find('span').remove();
	$('#thirdpos').load(
			'/block.php?b=brlist&term=' + escape(term),
			function(response){
				if(response == '')
				{
					$('#catlist').html('<li>There are no results for the search term: '+term+'</li>');
				}
				else
				{
					setupToolTips('#catlist');
				}
				$('#featuredprofile .coupon-block').hide(600, function(){
					$(this).remove();
					showreviews = Math.round(($('#content').innerHeight() - 230)/129);
					$('.reviews').load('/block.php?b=rblist&npp=' + showreviews);
				});
				showreviews = Math.round(($('#content').innerHeight() - 230)/129);
				$('.reviews').load('/block.php?b=rblist&npp=' + showreviews,function(){ 
					$('.newbusiness a').bind('click',function(){ openAddBusiness(); return false; });
				});
			}
	);
}
