$(document).ready(function(){		
	 $('#fsearch').val('Enter Street, Suburb, Postcode').focus(function(){ $(this).val(''); }).blur(function(){ if($(this).val() == '') $(this).val('Enter Street, Suburb, Postcode'); });
	
	select_options = $('.option');
	$('.rent').remove();
	$('#quick_search_form label').click(function() {
		if($(this).children('input:checked').length > 0) {
			var type = $(this).children('input:checked').attr('id');
			var min_price = select_options.filter('.'+type).filter('.min-price');
			var max_price = select_options.filter('.'+type).filter('.max-price');
			$('.option').remove();
			$('#select'+$('#rs-min-price').attr('name')).html("Min Price");
			$('#select'+$('#rs-max-price').attr('name')).html("Max Price");
			$('#rs-min-price').append(min_price);
			$('#rs-max-price').append(max_price);
		}
	});
	//$('label').trigger('click');
	
	
	options = { serviceUrl: SITE_PATH+'sbsearch.php',
			minChars:3, 
			delimiter: /(,|;)\s*/, // regex or character
			maxHeight:200,
			width:248,
			zIndex: 100000,
			deferRequestBy: 0, //miliseconds
			noCache: true, //default is false, set to true to disable caching
			// callback function:
			onSelect: function(value, data){ $('#suburb_id').val(data); }
			};
	$('#fsearch').autocomplete(options);
	
	$('#quick_search_form input.search_btn').click(function() {
		if($(this).parents('form').find('input:checked').val() == 'buy') {
			$('#quick_search_form').attr('action', SITE_PATH+'buying/listings.php');
			if($('#suburb_id').val() != "" && $('#fsearch').val() == "") {$('#suburb_id').val('');}
		}else if($(this).parents('form').find('input:checked').val() == 'rent') {
			$('#quick_search_form').attr('action', SITE_PATH+'renting/rental-listings.php');
			if($('#suburb_id').val() != "" && $('#fsearch').val() == "") {$('#suburb_id').val('');}
		}
		$('#quick_search_form').submit();
	});
	
	if($('.error').length >0) {
		$('.error').parent().children('input[type="text"], input[type="password"], select, textarea').css('border', '1px solid #c00');
		if($('.error').siblings('div#PropertyType').length>0) {
			$('.error').siblings('div#PropertyType').css('border', '1px solid #c00');
		}
	}
	
	
	$("a.youtube").click(function() {
		$.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'			: 680,
			'height'		: 495,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf',
			'swf'			: {
				'wmode'		: 'transparent',
				'allowfullscreen'	: 'true'
			}
		});
		return false;
	});			

});

