$(function(){
	//Sort the results
	function defineLevels(val){
		switch(val)
		{
		case "listing free":
			val="3";
			return(val);
		break;
		case "listing premium":
			val="2";
			return(val);
		break;
		case "listing top5":
			val="1";
			return(val);
		break;
			default:
			val="3";
			return(val);
		break;
		}
	}

	//Sort the membership items
	var mylist = $('.sortme .webappsearchresults');
	//Sorting
	if(mylist.length != 0){ 
		var listitems = mylist.children('.listing').get();
		listitems.sort(function(a, b) {	
			var valA = $(a).attr('class');
			var valB = $(b).attr('class');
			return (defineLevels(valA) < defineLevels(valB)) ? -1 : (defineLevels(valA) > defineLevels(valB)) ? 1 : 0;
		})
		$.each(listitems, function(idx, itm) { mylist.append(itm); });
	}
	
	//Hide blank images
	
	$('img[src*="value"]').remove();
	
	//Change 'no results found' text
	if($('div#webappsearchresults10050').html() == "No results found."){
		$('#webappsearchresults10050').html("Apologies, that search returned no results")};
	
	//Go through the detailed directory list and remove headings from blank entries
	
	$('#listingDetails dd').each(
    function(){
		$val = $(this).html();
        if($val == "" || $val == " " || $val == '<a href="http://" rel="nofollow" target="_blank"></a>' || $val == '<a href="mailto:&amp;subject=Enquiry%20From%20Limodirectory.com.au"></a>'){ 
			$(this).prev().remove();
			$(this).remove();
		}
    })
		
})
