var previous;

function showBusiness()
{
	startSearch();
	var query=new Array();
	var venues=search.queryVenues();
	if (venues) query.push("venues="+venues);
	if (query.length>0)
	{
		query=query.join('&');
		ajaxBusiness(query,false);
	}
	else
	{
		$.get(l.url+'ajax_clear.php');
		if (gmap) gmap.clearOverlays();
		$('#results > div.box-h > div.box-h-r > h3').text('searches reset');
		$('#houses').html('<p>Choose an area or click on the bed and price buttons to continue searching.</p>');
	}
}

function nearbyBusiness(query)
{
	
}

function processBusiness(result)
{
	if (result.count>0)
	{
		var icon='';
		var html='';
		$.each(result.business,function(i,bus){
			html=miniBusiness(bus);
			if ((bus.lat!=0) && (bus.lng!=0) && (i<60))
			{
				if (gmap)
				{
					switch (bus.venue)
					{
						case 'Food':
							icon=iconFood;
							break;
						case 'Nightclub':
							icon=iconClub;
							break;
						case 'Hotel':
							icon=iconHotel;
							break;
						case 'Service':
							icon=iconService;
							break;
						case 'Shop':
							icon=iconShop;
							break;
					}
					createMarker(bus.lat,bus.lng,html,icon);
				}
			}
		});
	}
	return true;
}

$.fn.mapHouse=function(){
	return this.each(function(){
		var input=$(this).val().split(',');
		query='lat='+input[0]+'&lng='+input[1];
		$.ajax({
			type:'GET',
			url:l.url+'ajax_business.php',
			dataType:'json',
			data: query,
			success:function(result){
				if (result.count>0)
				{
					var icon='';
					var html='';
					$.each(result.business,function(i,bus){
						html=miniBusiness(bus);
						if ((bus.lat!=0) && (bus.lng!=0) && (i<60))
						{
							if (gmap)
							{
								switch (bus.venue)
								{
									case 'Food':
										icon=iconFood;
										break;
									case 'Nightclub':
										icon=iconClub;
										break;
									case 'Hotel':
										icon=iconHotel;
										break;
									case 'Service':
										icon=iconService;
										break;
									case 'Shop':
										icon=iconShop;
										break;
								}
								createMarker(bus.lat,bus.lng,html,icon);
							}
						}
					});
				}
			},
			complete: function(result){
				var icon=iconUnlet;
				createMarker(input[0],input[1],input[2],icon);
				//if (gmap) if (gpoints.length>0) fitMap();
			}
		});
	});
};

$(document).ready(function(){
	$('ul.tabnav').find('a').click(function(e){
		var rel=$(this).attr('rel');
		rel=rel.split('|');
		house=rel[0];
		type=rel[1];
		if (type!='')
		{
			$('a.current').removeClass('current');
			$('#main > div.content').slideUp('slow',function(){
				$.get(l.url+'house_'+type+'.php',{id:house,ajax:1},function(page){
					$('#main > div.content').html(page);
					$('#main > div.content').slideDown('slow',function(){
						switch (type)
						{
							case 'map':
								$('#gmap').gmapSetup();
								$('input[name="gmap-house"]').mapHouse();
							break;
							case 'photos':
								$('#slideshow').slideStart();
							break;
						}
					});
				});
			});
			$(this).addClass('current');
			e.preventDefault();
		}
	});
	$('input[name="gmap-house"]').mapHouse();
});
