/*!
 * http://www.reynoldsftw.com
 *
 * Created by Steve Reynolds
 */

$.extend({URLEncode:function(c){var o='';var x=0;c=c.toString();var r=/(^[a-zA-Z0-9_.]*)/;
  while(x<c.length){var m=r.exec(c.substr(x));
    if(m!=null && m.length>1 && m[1]!=''){o+=m[1];x+=m[1].length;
    }else{if(c[x]==' ')o+='+';else{var d=c.charCodeAt(x);var h=d.toString(16);
    o+='%'+(h.length<2?'0':'')+h.toUpperCase();}x++;}}return o;},
URLDecode:function(s){var o=s;var binVal,t;var r=/(%[^%]{2})/;
  while((m=r.exec(o))!=null && m.length>1 && m[1]!=''){b=parseInt(m[1].substr(1),16);
  t=String.fromCharCode(b);o=o.replace(m[1],t);}return o;}
});


var timer;   
  
$(document).ready(function() {   
  
getSearch(); 
  
});   
  
function getSearch()   
{

	clearTimeout(timer);   
	var results = "";   
	var theQuery = "#2020";

	$.post("getSearch.php", {query: theQuery},  function(xml){   
		$('entry',xml).each(function(i){   
			var title = $(this).find("title").text();
			var authorName = $(this).find("name").text();
			var authorName = authorName.split(' ')[0];
			var authorLink = $(this).find("uri").text();
			var image = $(this).find("link[rel='image']").attr("href");
			var id = $(this).find("id").text().split(',')[1];

			results = results + "<div style='background:#fff;width:99%;padding:8px 3px;margin:5px 0;border-bottom:1px solid #aaa;' id='" + id + "'><a style='color:#296B99;' href='" + authorLink + "'><img style='float:left;margin:0 5px;text-decoration;none;border:1px solid #333;' height='32' width='32' alt='" + authorName + "' src='" + image + "' /> <strong>" + authorName + "</strong></a> " + title + "<br style='height:1px;clear:both;' /><div style='margin-top:3px;margin-left:3px;clear:both;'><small><a href='http://twitter.com?status=" + $.URLEncode("RT @" + authorName + ": " + title) + "'>retweet</a> | <a href='http://twitter.com?status=" + $.URLEncode("@" + authorName + " ") + "'>reply</a></small></div></div>";   
		
		});   
		
		$("#container").html(results);


	});   
  
	timer = setTimeout('getSearch()', 5000);   
}
