/**
 * Function allowing to change the slider image in the Search form
 * according to the selected type of Property
 */
function changeSliderImage() {
	var background = $('price_slider_background');
	$('btn_rent', 'btn_buy').invoke('removeClassName', 'selected');
	if($('PropertyType').value == 'rent') {
		background.style.backgroundImage='url(/img/images/buyer_side/slider4.png)';
		$('btn_rent').addClassName('selected');
	} else {
		background.style.backgroundImage='url(/img/images/buyer_side/slider3.png)';
		$('btn_buy').addClassName('selected');
	}
}

/**
 * Initialize the slider widget
 */
function initSlider() {
	var handles = ['price_slider_handle_min', 'price_slider_handle_max'];
	new Control.Slider(handles, 'price_slider', {
		range: $R(0, 100),
		values: $R(0, 100),
		increment:1,
		sliderValue: [0, 100],
		restricted: true,
		onChange: function(values) {
			$('PropertyMin').value = values[0];
			$('PropertyMax').value = values[1];
		}
	});
	changeSliderImage();
}

/**
 * Function allowing to update the property type hidden input
 */
function selectRadio(type) {
	$('PropertyType').value = type;
}

/**
 * Update the total number of results matching the search criteria
 */
function updateTotalResults(number) {
	$('count-value').update(number);
	$('results-count').addClassName('initialized');
	Effect.Pulsate('results-count', { pulses: 2, duration: 1 });
}

document.observe('dom:loaded', initSlider);
