// Helpers to match exact strings...
$.extend($.expr[':'],{
containsExact: function(a,i,m){
return $.trim(a.innerHTML.toLowerCase()) === m[3].toLowerCase();
},
containsExactCase: function(a,i,m){
return $.trim(a.innerHTML) === m[3];
},
containsRegex: function(a,i,m){
 var regreg =  /^\/((?:\\\/|[^\/])+)\/([mig]{0,3})$/,
  reg = regreg.exec(m[3]);
 return RegExp(reg[1], reg[2]).test($.trim(a.innerHTML));
}
});

// Manipulate the homes display...
$(document).ready(function() {
	
	// Import builder info
	var builder_link = $('p#builder_link a').attr('href');
	$('.builder_display').load(builder_link + ' #builder_details', null, function() {
        $('div.builder_logo:empty').hide();
        $('div.builder_description:empty').hide();
        $('li.builder_website span a:empty').parent().parent().hide();
        $('li.builder_email span:empty').parent().hide();
        $('li.builder_phone span:empty').parent().hide();
        //$('li.certified_builder').hide()
    	//$('li.certified_builder span:contains("True")').parent().show().html('<img class="cpb_logo" src="/images/logos/cpb-logo.png" width="69" height="69" alt="Certified Professional Builder" />');
    	//$('li.certified_green_builder').hide()
    	//$('li.certified_green_builder span:contains("True")').parent().show().html('<img class="cgb_logo" src="/images/logos/logo_cert_green_prof_69px_h.png" width="175" height="69" alt="Certified Green Professional" />');
    });

	// Hide empty fields
	$('li.price span:empty').parent().hide();
	$('li.bedrooms span:empty').parent().hide();
	$('li.bedrooms span:contains("0")').parent().hide();
	$('li.baths span:contains("NA")').parent().hide();
	$('li.baths span:contains("0")').parent().hide();
	$('li.baths span:empty').parent().hide();
	$('li.sq_footage span:containsExact(0)').parent().hide();
	$('li.sq_footage span:empty').parent().hide();
	$('div.property_features p:empty').parent().hide();
	$('div.property_directions p:empty').parent().hide();
	$('div.links p:empty').parent().hide();
	$('div.sales_info p:empty').parent().hide();
    //if ($('div.sales_info p')=="") {$('div.sales_info').hide();};
	//$('li.floor_plans a').attr('href:empty').parent().hide();
	if ($('div.floor_plans a').attr('href')=="") {$('div.floor_plans').hide();};

	// Show appropriate logos
	//$('div.gasmark_logo').hide()
	//$('div.gasmark_logo span:contains("True")').parent().show().html('<img class="gasmark_logo" src="/images/logos/Gasmark-logo.png" alt="Gasmark logo" />');
	//$('div.green_logo').hide()
	//$('div.green_logo span:contains("True")').parent().show().html('<img src="/images/logos/Gasmark-logo.png" alt="Gasmark logo" />');
});
