

function doSearch() { // Fires the search using values from sliders etc

			$('#searchResultsWrapper').fadeIn('slow');  // Fade in the results div
			$('#searchResultsWrapper').html('<img src=\'images/ajax-loader.gif\' alt=\'Loading\' class=\'loader\' />'); // Show the loading animation
			$('#searchResults').load('ajax/ajaxPropertySearch.asp', {   // Make the ajax call
					'priceMin': $('#priceSlider').slider('values', 0), 	// Minimum price
					'priceMax': $('#priceSlider').slider('values', 1), 	// Maximum price	
					'bedsMin': $('#bedsSlider').slider('values', 0), 	// Minimum beds
					'bedsMax': $('#bedsSlider').slider('values', 1), 	// Maximum beds	
					'bath': $('#locationBath').val(), 	// In Bath
					'bristol': $('#locationBristol').val(), 	// In Bristol
					'type': $('#type').val(), 	
					'furnished':  $('#furnishing').val(),
					'studentResidential': getCookie('searchType')
			});	
			
			setCookie('priceMin', $('#priceSlider').slider('values', 0));
			setCookie('priceMax', $('#priceSlider').slider('values', 1));
			setCookie('bedsMin', $('#bedsSlider').slider('values', 0));
			setCookie('bedsMax', $('#bedsSlider').slider('values', 1));
			setCookie('bath', $('#locationBath').val());
			setCookie('bristol', $('#locationBristol').val());
			setCookie('type', $('#type').val());
			setCookie('furnished', $('#furnishing').val());
}	

$(document).ready(function() {	 
//			$('#searchResultsWrapper').fadeIn('slow');
//			$('#searchResultsWrapper').html('<img src=\'images/ajax-loader.gif\' alt=\'Loading\' class=\'loader\' />');
//			$('#searchResults').load('ajax/ajaxPropertySearch.asp', { 'priceMin': '300', 'priceMax': '1000' });
			$('#notBath').click(function() {
						$('#yesBath').toggle();
						$('#notBath').toggle();
						$('#locationBath').val('yes');
						doSearch();
						});
			$('#yesBath').click(function() {
						$('#yesBath').toggle();
						$('#notBath').toggle();
						$('#locationBath').val('no');
						doSearch();
						});
			$('#notBristol').click(function() {
						$('#yesBristol').toggle();
						$('#notBristol').toggle();
						$('#locationBristol').val('yes');
						doSearch();
						});
			$('#yesBristol').click(function() {
						$('#yesBristol').toggle();
						$('#notBristol').toggle();
						$('#locationBristol').val('no');
						doSearch();
						});	
			
			$('#notAnyType').click(function() {
						$('#yesAnyType').show();
						$('#notAnyType').hide();
						$('#notHouse').show();
						$('#yesHouse').hide();
						$('#notFlat').show();
						$('#yesFlat').hide();
						$('#type').val('Any');
						doSearch();});	
			$('#notHouse').click(function() {
						$('#yesAnyType').hide();
						$('#notAnyType').show();
						$('#notHouse').show();
						$('#yesHouse').show();
						$('#notFlat').show();
						$('#yesFlat').hide();
						$('#type').val('House');
						doSearch();});	
			$('#notFlat').click(function() {
						$('#yesAnyType').hide();
						$('#notAnyType').show();
						$('#notHouse').show();
						$('#yesHouse').hide();
						$('#notFlat').hide();
						$('#yesFlat').show();
						$('#type').val('Flat');
						doSearch();});
			       
			$('#notAnyFurn').click(function() {
						$('#yesAnyFurn').show();
						$('#notAnyFurn').hide();
						$('#notUnfurnished').show();
						$('#yesUnfurnished').hide();
						$('#notPart').show();
						$('#yesPart').hide();
						$('#notFurnished').show();
						$('#yesFurnished').hide();
						$('#furnishing').val('Any');
						doSearch();});				       
			$('#notUnfurnished').click(function() {
						$('#yesAnyFurn').hide();
						$('#notAnyFurn').show();
						$('#notUnfurnished').hide();
						$('#yesUnfurnished').show();
						$('#notPart').show();
						$('#yesPart').hide();
						$('#notFurnished').show();
						$('#yesFurnished').hide();
						$('#furnishing').val('Unfurnished');
						doSearch();});				       
			$('#notPart').click(function() {
						$('#yesAnyFurn').hide();
						$('#notAnyFurn').show();
						$('#notUnfurnished').show();
						$('#yesUnfurnished').hide();
						$('#notPart').hide();
						$('#yesPart').show();
						$('#notFurnished').show();
						$('#yesFurnished').hide();
						$('#furnishing').val('Part');
						doSearch();});					       
			$('#notFurnished').click(function() {
						$('#yesAnyFurn').hide();
						$('#notAnyFurn').show();
						$('#notUnfurnished').show();
						$('#yesUnfurnished').hide();
						$('#notPart').show();
						$('#yesPart').hide();
						$('#notFurnished').hide();
						$('#yesFurnished').show();
						$('#furnishing').val('Furnished');
						doSearch();});	
});



$(function() {
		   
	var pMin, pMax, bMin, bMax, bath, bristol, type, furnished;
	
	pMin = getCookie('priceMin');	if (pMin=='') {pMin = '300'};
	pMax = getCookie('priceMax');	if (pMax=='') {pMax = '1000'};
	bMin = getCookie('bedsMin');	if (bMin=='') {bMin = '1'};
	bMax = getCookie('bedsMax');	if (bMax=='') {bMax = '6'};
	bath = getCookie('bath');	if (bath=='no') {
		$('#yesBath').hide();
		$('#notBath').show();
		$('#locationBath').val('no');
		};
	bristol = getCookie('bristol');	if (bristol=='no') {
		$('#yesBristol').hide();
		$('#notBristol').show();
		$('#locationBristol').val('no');
		};
	type = getCookie('type');
	switch(type)
		{
		case 'Any':
			$('#yesAnyType').show();
			$('#notAnyType').hide();
			$('#notHouse').show();
			$('#yesHouse').hide();
			$('#notFlat').show();
			$('#yesFlat').hide();
			$('#type').val('Any');
			break;
		case 'House':
			$('#yesAnyType').hide();
			$('#notAnyType').show();
			$('#notHouse').show();
			$('#yesHouse').show();
			$('#notFlat').show();
			$('#yesFlat').hide();
			$('#type').val('House');
			break;
		case 'Flat':
			$('#yesAnyType').hide();
			$('#notAnyType').show();
			$('#notHouse').show();
			$('#yesHouse').hide();
			$('#notFlat').hide();
			$('#yesFlat').show();
			$('#type').val('Flat');
		  	break;
		default:
			$('#yesAnyType').show();
			$('#notAnyType').hide();
			$('#notHouse').show();
			$('#yesHouse').hide();
			$('#notFlat').show();
			$('#yesFlat').hide();
			$('#type').val('Any');
			break;
		}
		
	furnished = getCookie('furnished');	
	
	switch(furnished)
		{
		case 'Any':
			$('#yesAnyFurn').show();
			$('#notAnyFurn').hide();
			$('#notUnfurnished').show();
			$('#yesUnfurnished').hide();
			$('#notPart').show();
			$('#yesPart').hide();
			$('#notFurnished').show();
			$('#yesFurnished').hide();
			$('#furnishing').val('Any');
			break;
		case 'Unfurnished':
			$('#yesAnyFurn').hide();
			$('#notAnyFurn').show();
			$('#notUnfurnished').hide();
			$('#yesUnfurnished').show();
			$('#notPart').show();
			$('#yesPart').hide();
			$('#notFurnished').show();
			$('#yesFurnished').hide();
			$('#furnishing').val('Unfurnished');
			break;
		case 'Part':
			$('#yesAnyFurn').hide();
			$('#notAnyFurn').show();
			$('#notUnfurnished').show();
			$('#yesUnfurnished').hide();
			$('#notPart').hide();
			$('#yesPart').show();
			$('#notFurnished').show();
			$('#yesFurnished').hide();
			$('#furnishing').val('Part');
		  	break;
		case 'Furnished':
			$('#yesAnyFurn').hide();
			$('#notAnyFurn').show();
			$('#notUnfurnished').show();
			$('#yesUnfurnished').hide();
			$('#notPart').show();
			$('#yesPart').hide();
			$('#notFurnished').hide();
			$('#yesFurnished').show();
			$('#furnishing').val('Furnished');
		  	break;
		default:
			$('#yesAnyFurn').show();
			$('#notAnyFurn').hide();
			$('#notUnfurnished').show();
			$('#yesUnfurnished').hide();
			$('#notPart').show();
			$('#yesPart').hide();
			$('#notFurnished').show();
			$('#yesFurnished').hide();
			$('#furnishing').val('Any');
			break;
		}
	       
	       
	// Set up price range slider
	$('#priceSlider').slider({
		range: true,
		values: [pMin,pMax],
		min: 300,
		max: 1000,
		step: 100,
		slide: function(event, ui) {
			$('#priceMin').val($('#priceSlider').slider('values', 0));
			$('#priceMax').val($('#priceSlider').slider('values', 1));
		},
		change: function(event, ui) {
			doSearch();
		}			
	});
	
	
	// Set up number of beds slider
	$('#bedsSlider').slider({
		range: true,
		values: [bMin,bMax],
		min: 1,
		max: 6,
		step: 1,
		slide: function(event, ui) {
			$('#bedsMin').val($('#bedsSlider').slider('values', 0));
			$('#bedsMax').val($('#bedsSlider').slider('values', 1));
		},
		change: function(event, ui) {
			doSearch();
		}	
	});	
	
	
	// Attach the fade out effect to the ajax call complete event
	$('#searchResults').ajaxSuccess(function(evt, request, settings){
		$('#searchResultsWrapper').fadeOut('slow');
	});
	
	

	
});

 







