	
//tabs background if tabs page, SIMPLES
jQuery(document).ready(function(){
	
	jQuery('a[rel="external"]').each(function(i){
        if(jQuery(this).attr('href') != '' && jQuery(this).attr('href') != '#'){
            jQuery(this).attr('target','_blank');
        }
    })
	
	if (jQuery('ul#tabs, ul.tabs_style').size() > 0)
	{
		if (jQuery('div#headerblock').hasClass('luxury'))
		{
			jQuery('div.wrapper').css('background', 'url(/images/luxury/tab-content-bg.png) top center repeat-y');
		}
		else
		{			
			jQuery('div.wrapper').css('background', 'url(/images/tab-content-bg.png) top center repeat-y');
		}
	}
});

(
	function($){
	$(function() {
		$('.modify-search').click(function() {
			if ($('.config-modify').css('display') == 'none')
			{
				$('.config-text, .search-remove').fadeOut(400, function() {
					$('.config-modify').fadeIn(400);
				});
			}
			else if ($('.config-text').css('display') == 'none') 
			{
				$('.config-modify, .search-remove').fadeOut(400, function() {
					$('.config-text').fadeIn(400);
				});
			}
			return false;
		});
		$('#search-submit').click(function() {
			$('#search-again').submit();
			return false;
		});
	});
	
	$(function() {
		$('#tabbedcontainer #tabs a').click(function() {
			$('div.tabcontent div.tab').stop(true, true);
			var tab = $(this).attr('class');
			$(this).parent().parent().find('li').removeClass('active');
			$(this).parent().addClass('active');
			$('div.tabcontent div.tab:visible').fadeOut(400, function() {
				$('div.' + tab).fadeIn(400);
				if (tab == 'map_tab' || tab == 'streetview_tab') {
					map_setup();
				}
				if (tab == 'enquire_tab')
				{
					$('#enquire_success').hide();
					$('#enquiry_form').show();
				}
				if (tab == 'valuation_tab')
				{
					$('#valuation_success').hide();
					$('#valuation_form').show();
				}
				if (tab == 'friend_tab')
				{
					$('#share_success').hide();
					$('#share_form').show();
				}
				if (tab == 'enquiry_tab')
				{
					$('#enquiry_success').hide();
					$('#enquiry_form').show();
				}
				if (tab == 'submit_testimonial') {
					$('#testimonial_success').hide();
					$('#testimonial_form').show();
				}
				
			});
			return false;
		})
	});
	
	$(function() {
		$('.alertbox a').click(function() {
			if ($(this).hasClass('alertoff')) {
				$(this).addClass('alerton').removeClass('alertoff');
				$(this).parent().find('fieldset').slideDown();
				$(this).parent().find('input.group_checked').val(1);
			}
			else {
				$(this).addClass('alertoff').removeClass('alerton');
				$(this).parent().find('fieldset').slideUp();
				$(this).parent().find('input.group_checked').val(0);
			}
			return false;
		})
	});
	
	
	$(function() {	
		$('#livesearch').autocomplete('/search/all/quick/', 
		{ 
		  minChars: 3, mustMatch: false, selectFirst: false, autoFill: false, dataType: 'json',
		  matchSubset: false,  scroll: false,  width: 360,
		  
		  parse: function(jdata) {
			var parsed_data = []; 
			if (!jdata || jdata.length == 0) {
				 // handle no results case specially
				parsed_data[0] = {data: {id:-1, url:'#'}};
			}
			else {
				for (var i=0; i<jdata.length; i++){
					obj = jdata[i];
					parsed_data[i] = { 
						data: obj, id: obj.id
					};
				}
			}
			return parsed_data;
		  },
		  formatItem: function(property, i, n){
			if(property.id==-1){	
				return '<div class="ajax">Sorry, no results<\/div>';
			}
			var html = '<div class="ajax clearfix">';
			if(property.image){
				html += '<img src="' + property.image + '" style="float:left; width: 100px; height: 75px;" \/>';
			}

			html += '<p class="address" style="display: inline; width: 100px; padding-top: 15px;" ><strong>' + property.address + '<\/strong><br \/>';
			if(property.bedrooms>1) html += property.bedrooms + ' Bed ';
			if(property.name) html +=  property.name;
			html += '<\/p><p class="price_str">' + property.price_str + '<\/p><\/div>';
			return html;
		  }
		}).result(function(event, item){
			location.href = item.url;
		});
	});
	
	}
)(jQuery);

function getCriteriaPropertiesNumber()
{
	if (jQuery(".number").size() > 0)
	{
		var the_property_type = jQuery("#section").val();
		var the_search_type = jQuery("#search_type").val();
		if (the_property_type == "residential")
		{
			if (the_search_type == 0) //residential sales
			{
				jQuery.post("/search/countajaxresults", 
				{
					min_bedrooms: jQuery("#minbeds_replaced input").val(),
					max_bedrooms: jQuery("#maxbeds_replaced input").val(),
					min_price_sales: jQuery("#minprice_replaced input").val(),
					max_price_sales: jQuery("#maxprice_replaced input").val(),
					property_type_id: jQuery("#property_type_id_replaced input").val(),
					property_type: jQuery("#section").val(),
					search_type: the_search_type,
					property_type: the_property_type,
					keywords: jQuery('#rsale_keywords').val()
				},
				updatePropertyNumber, "json" );	
			}
			else if (the_search_type == 1)  //residential lettings
			{ 
				jQuery.post("/search/countajaxresults", 
				{
					min_bedrooms: jQuery("#minbeds_replaced input").val(),
					max_bedrooms: jQuery("#maxbeds_replaced input").val(),
					min_price_lettings: jQuery("#minprice_replaced input").val(),
					max_price_lettings: jQuery("#maxprice_replaced input").val(),
					property_type_id: jQuery("#property_type_id_replaced input").val(),
					property_type: jQuery("#section").val(),
					search_type: the_search_type,
					property_type: the_property_type,
					keywords: jQuery('#rsale_keywords').val()
				},
				updatePropertyNumber, "json" );	
			}
		}
		else if (the_property_type == "commercial")
		{
			if (the_search_type == 0) //commercial sales
			{
				jQuery.post("/search/countajaxresults", 
				{
					min_footage: jQuery("#minarea_replaced input").val(),
					max_footage: jQuery("#maxarea_replaced input").val(),
					min_price_sales: jQuery("#minprice_replaced input").val(),
					max_price_sales: jQuery("#maxprice_replaced input").val(),
					property_type_id: jQuery("#property_type_id_replaced input").val(),
					property_type: jQuery("#section").val(),
					search_type: the_search_type,
					property_type: the_property_type,
					keywords: jQuery('#rsale_keywords').val()
				},
				updatePropertyNumber, "json" );	
			}
			else if (the_search_type == 1)  //commercial lettings
			{ 
				jQuery.post("/search/countajaxresults", 
				{
					min_footage: jQuery("#minarea_replaced input").val(),
					max_footage: jQuery("#maxarea_replaced input").val(),
					min_price_lettings: jQuery("#minprice_replaced input").val(),
					max_price_lettings: jQuery("#maxprice_replaced input").val(),
					property_type_id: jQuery("#property_type_id_replaced input").val(),
					property_type: jQuery("#section").val(),
					search_type: the_search_type,
					property_type: the_property_type,
					keywords: jQuery('#rsale_keywords').val()
				},
				updatePropertyNumber, "json" );	
			}
		}
	}
}

function updatePropertyNumber(data)
{
	jQuery('.quickresult .number').html(data);
}

function more_testimonials() {
	for(var i=0;i<3; i++){
		var quote = $('.hidden').first();
		quote.slideDown(400);
		quote.removeClass('hidden');
	}
	if ( $('.hidden').size() <= 0) {	
		$('.tabcontent a').hide();
	}
}

