var searchSel = 'sales';
var lock = false;

$(function(){
	var salesPrices = {
		175000:"£175,000",
		350000:"£350,000",
		525000:"£525,000",
		700000:"£700,000",
		825000:"£825,000"
	}

	var rentPrices = {
		400:"£400",
		550:"£550",
		700:"£700",
		850:"£850",
		1000:"£1000"
	}

	var bedrooms = {
		1:"One",
		2:"Two",
		3:"Three",
		4:"Four",
		5:"Five",
		6:"Six"
	}

	function t(type,obj)
	{
		var x={0:'No minimum'};
		if (type=='max') x={0:'No maximum'};
		for (i in obj) x[i]=obj[i];
		return x;
	}

	$("#salessearch select[name=minprice]").addOption(t('min',salesPrices), false);
	$("#salessearch select[name=maxprice]").addOption(t('max',salesPrices), false);
	$("#rentsearch select[name=minprice]").addOption(t('min',rentPrices), false);
	$("#rentsearch select[name=maxprice]").addOption(t('max',rentPrices), false);
	$("div.spanel form select[name=minbeds]").addOption(t('min',bedrooms), false);
	$("div.spanel form select[name=maxbeds]").addOption(t('max',bedrooms), false);
	$("#searchtype tr .sales a").toggleClass('seltype');
	$("div.sbpanel form select[name=minbeds]").addOption(t('min',bedrooms), false);
	$("div.sbpanel form select[name=maxbeds]").addOption(t('max',bedrooms), false);
});

function searchSales() {
	searchSwap('sales', '#rentsearch', '#salessearch');
}

function searchLettings() {
	searchSwap('lettings', '#salessearch', '#rentsearch');
}

function searchSwap(a,b,c) {
	if (searchSel == a) return;
	if (lock == true) return;
	lock = true;
	$(b).slideUp("normal",function(){
		$(c).slideDown("normal",function(){
			lock=false;
		});
	});
	$("#searchtype tr .sales a").toggleClass('seltype');
	$("#searchtype tr .lettings a").toggleClass('seltype');
	searchSel = a;
}
