function fix_dropdowns(c) {
	c.find('#clet_minft, #clet_maxft, #clet_minrent, #clet_maxrent').kaSelect({ width: 90, height: 16});
	c.find('#clet_property_type_id').kaSelect({checkboxes: true, select_all: true, width: 201, height: 16, select_all_name: 'Any', override_selection: 'all'});
	c.find('#clet_sortby').kaSelect({ width: 201, height: 16});
	c.find('#rsale_minbeds, #rsale_maxbeds, #rsale_minprice, #rsale_maxprice').kaSelect({ width: 90, height: 16});
	c.find('#rsale_property_type_id').kaSelect({checkboxes: true, select_all: true, width: 201, height: 16, select_all_name: 'Any', override_selection: 'all'});
	c.find('#rsale_sortby').kaSelect({ width: 201, height: 16});
	c.find('#rlet_minbeds, #rlet_maxbeds, #rlet_minrent, #rlet_maxrent').kaSelect({ width: 90, height: 16});
	c.find('#rlet_property_type_id').kaSelect({checkboxes: true, select_all: true, width: 201, height: 16, select_all_name: 'Any', override_selection: 'all'});
	c.find('#rlet_sortby').kaSelect({ width: 201, height: 16});
	c.find('#csale_minft, #csale_maxft, #csale_minprice, #csale_maxprice').kaSelect({ width: 90, height: 16});
	c.find('#csale_property_type_id').kaSelect({checkboxes: true, select_all: true, width: 201, height: 16, select_all_name: 'Any', override_selection: 'all'});
	c.find('#csale_sortby').kaSelect({ width: 201, height: 16});
}

function flipper(n) 
{
	$('#' + n + ' .front a').click(function(e) {
		$(this).parent().fadeOut(300, function() {
			$('#' + n + ' .back').fadeIn(500);
			fix_dropdowns($('#' + n + ' .back'));
		});
		return false;
	});

}

$(function() {
	flipper('propertiesforsale');
	flipper('propertiestolet');
	flipper('commercialproperties');

	$('#com_sales_button').click(function(){
		if (!$('#com_sales_button').hasClass('com_sales_on'))
		{
			$('#com_sales_button').addClass('com_sales_on');
			$('#com_lets_button').removeClass('com_lets_on');
				$('#commercial_lettings_form').fadeOut(200, function() {
				$('#commercial_sales_form').fadeIn(200);
			});
		}
	});
									
	$('#com_lets_button').click(function(){
		if (!$('#com_lets_button').hasClass('com_lets_on'))
		{
			$('#com_sales_button').removeClass('com_sales_on');
			$('#com_lets_button').addClass('com_lets_on');
			$('#commercial_sales_form').fadeOut(200, function() {
				$('#commercial_lettings_form').fadeIn(200);
			});
		}
	})

	$('a.commercial-to-let').click(function() {
		$('.commercial-buttons').css('float', 'left').animate({'margin-left': '-350px'}, 500);
		$('fieldset.commercial-to-let').css('float', 'left').css('display', 'block');
		return false;
	});
	
	$('a.commercial-for-sale').click(function() {
		$('.commercial-buttons').css('float', 'left').animate({'margin-left': '-350px'}, 500);
		$('fieldset.commercial-for-sale').css('float', 'left').css('display', 'block');
		return false;
	});

	if (location.hash == '#new_search') $('#propertiesforsale .front a,#propertiestolet .front a').click();
});
