function loadSearchJson() {
	//show message when the feed is loading
	$j("#update-alert").html("<img src='/img/patience.gif'/ style='padding-right:5px; vertical-align:text-bottom;'>Fetching recent updates in "+passedCity+"...");
	
  var url = 'search.php?city='+passedCity+'&f='+passedFilter+'&st='+passedSearchType+'&' + new Date().getTime();
  var regexp = /((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi;
  
  $j.getJSON(url, function(json) {
	  //counter to count new results
		var counter = 0;

    $j.each(json.results, function(i, item) {
	  	//get the id of the div
	  	var div_id = item.id;
			//check if any div with the same id already exists
			if ($j("#twitter-update div#" + div_id).length == 0 ) {
				//if doesn't exist then prepend this div
				
	 		item.text = unescape(item.text);
			var textContent = item.text.replace(regexp,"<a href=\"$1\" target=\"_blank\">$1</a>");
			//var textContent = item.text.match(regexp);
				
        var html = '<div class="result" id="' + item.id + '"> <div class="profile_image"><a href="http://twitter.com/'+ item.from_user +'" target="_blank"><img src="'+ item.profile_image_url +'"></a></div> <div class="status"> <div class="content"> <strong><a href="http://twitter.com/'+ item.from_user +'" target="_blank">'+ item.from_user +'</a></strong> '+ textContent +' </div> <div class="time"> ' + item.from_user + ' at <a href="' + 'http://twitter.com/' + item.from_user + '/status/' + item.id + '"  target="_new">'+ item.created_at +'</a></div> </div></div>';
		//adultFilter & nameFilter
		var matchPattern = /sex|sugarrae|fuck|dick|cunt/i;
		if (!html.match(matchPattern)) {
   		$j("#twitter-update").append(html);
		}		
				//increase the counter
				counter++;
			}

    });

	 	//show the number of new results
	 	if (counter == 0) {
	 		$j("#update-alert").text("No new "+passedCity+" updates found");
    } else if(counter == 1) {
	 		$j("#update-alert").text("1 new update in "+passedCity+" added");
    } else {
	 		$j("#update-alert").text(counter + " new "+passedCity+" updates added");				
  	}

  });
}

$j(document).ready(function(){	
	loadSearchJson();
	//setInterval("loadSearchJson()",30000);
	setInterval("loadSearchJson()",120000);
});

