function auto_fill(id, v){
	
	if( ($(id).val()) && ($(id).val()!=v) ) return;
	
	$(id).css({ color: '#7E7E7E'}).attr({ value: v }).focus(function(){
		if($(this).val()==v){
			$(this).val('').css({ color: '#333' });
		}
	}).blur(function(){
		if($(this).val()==''){
			$(this).css({ color: '#7E7E7E' }).val(v);
		}
	});

}

function toggle_prices_ajr(show_div){

	switch(show_div){
		
		case 'sales':
			$('#sales_div').show();
			$('#lettings_div').hide();
			$('#studentlets_div').hide();
			$('#all_searchform').attr('action','/property/for-sale/search/results');
		break;
		
		case 'lettings':
			$('#sales_div').hide();
			$('#lettings_div').show();
			$('#studentlets_div').hide();
			$('#all_searchform').attr('action','/property/to-let/search/results');
		break;
		
		case 'studentlets':
			$('#sales_div').hide();
			$('#lettings_div').hide();
			$('#studentlets_div').show();
			$('#all_searchform').attr('action','/property/student-lets/search/results');
		break;
		
	}
	
}

function check_all_form(){
	
	// Check a radio has been selected
	if(!$('input[name=search_type]:checked').val()){
		$('p#error').text('Please choose a search type').fadeIn();
		return false;
	}
	
	
	// Check min is less than max
	//todo
}




$(document).ready(function(){ 
	
	$('a[rel=external]').each(function(i){this.target = '_blank';});	//Jquery use for setting up rel="external" links
	$('input[type=radio]').addClass('radio');
	
	auto_fill($('#keyword'), 'Keyword / Postcode');
	auto_fill($('#email-mailing-list'), 'E-mail address');
	
		
	$('.property-holder').click(function(){
    	window.location=$(this).find("a").attr("href"); return false;
	});
	
	$('.cta').click(function(){
    	window.location=$(this).find("a").attr("href"); return false;
	})
	
		
	$('.property-holder').hover(
		function(){
			$(this).css({ 'background-image': 'url(/images/property-holder-hover.gif)' });
		}, 
		function(){
			$(this).css({ 'background-image': 'url(/images/property-holder.gif)' });
		}
    );
	
	$('.gallery_showcase').hover(
		function(){
			$(this).css({ 'background-image': 'url(/images/property-holder-showcase-hover.gif)' });
		}, 
		function(){
			$(this).css({ 'background-image': 'url(/images/property-holder-showcase.gif)' });
		}
    );
	
	
	// Affiliates Slider
	// <jon@kaweb.co.uk>
	$('#afflink').toggle(function() {
		
		$('#affhold').animate({ height: '40px' }, 500, function() { 
			$('#afflink span').html("&darr;") 
		});
		
		return false;
		
	}, function() {
	
		$('#affhold').animate({ height: '0px' }, 250, function() {
			$('#afflink span').html("&uarr;");
		});
		
		return false;
	});
	
	
	// Contact Clicker
	// <jon@kaweb.co.uk>
	$('.contact_branch h2').hover(function() { $(this).css({ cursor: 'pointer' })}).click(function() {
		location.href = $(this).find('a').attr('href');
	});

});