var TB_version="2.1.1",TB_minTweetID,TB_maxTweetID,TB_tweetsShown=0,TB_rateLimitData,TB_mode="widget",TB_tmp,TB_started=false,TB_monthNumber={Jan:1,Feb:2,Mar:3,Apr:4,May:5,Jun:6,Jul:7,Aug:8,Sep:9,Oct:10,Nov:11,Dec:12},TB_timePeriods=new Array("second","minute","hour","day","week","month","year","decade"),TB_timePeriodLengths=new Array("60","60","24","7","4.35","12","10");function TB_init(){if(TB_started){return}else{TB_started=true}if(jQuery("#tweetblender").hasClass("archive")){TB_mode="archive"}if(typeof(TB_config)!="undefined"){if(typeof(TB_config.general_source_ids)=="undefined"||TB_config.general_source_ids==""){TB_showMessage("Twitter sources to blend are not defined",true);jQuery("#refreshlink").remove()}else{TB_initInfoBox();TB_makeAjaxURLs(TB_config.general_source_ids);TB_showLoader();TB_blend()}}else{TB_showMessage("Cannot retrieve Tweet Blender configuration options",true);jQuery("#refreshlink").remove()}}function TB_makeAjaxURLs(a){TB_config.ajaxURLs=new Array();var b=new Array();jQuery.each(a.split(","),function(c,d){if(d.charAt(0)=="@"){TB_config.ajaxURLs.push("http://twitter.com/statuses/user_timeline.json?screen_name="+d.substr(1)+"&count="+TB_config[TB_mode+"_tweets_num"])}else{b.push(d)}});if(b.length>0){TB_config.ajaxURLs.push("http://search.twitter.com/search.json?q=&ors="+escape(b.join(" "))+"&rpp="+TB_config[TB_mode+"_tweets_num"]+"&page=1")}}function TB_initInfoBox(){TB_config.sourcesHTML="";TB_config.sourcesCount=0;jQuery.each(TB_config.general_source_ids.split(","),function(a,b){TB_config.sourcesHTML+='<a target="_blank" href="';if(b.charAt(0)=="@"){TB_config.sourcesHTML+="http://twitter.com/"+b.substr(1)}else{TB_config.sourcesHTML+="http://search.twitter.com/search?q="+escape(b)}TB_config.sourcesHTML+='">'+b+"</a> ";TB_config.sourcesCount++});jQuery("#twitterlogo").click(function(){TB_showMessage("Powered by Tweet Blender plugin v"+TB_version+" blending "+TB_config.sourcesHTML,false)});if(parseInt(TB_config.widget_refresh_rate)>0){setInterval("TB_showLoader();TB_blend();",parseInt(TB_config.widget_refresh_rate)*1000)}}function TB_blend(){jQuery("#tb_loading").html("Loading...");jQuery.ajax({url:"http://twitter.com/account/rate_limit_status.json",dataType:"jsonp",success:function(a){if(a.remaining_hits<TB_config.ajaxURLs.length){TB_showMessage("You reached your twitter connection limit. Next reset "+TB_verbalTime(TB_str2date(a.reset_time)),false)}else{TB_getTweets()}},error:function(){TB_getTweets()}})}function TB_checkComplete(){if(TB_config.urlsDone==TB_config.ajaxURLs.length){if(jQuery("#tweetlist").children("li").size()==0){TB_showMessage("No tweets found for "+TB_config.sourcesHTML,true)}}}function TB_getTweets(){TB_config.urlsDone=0;jQuery("#tb_loading").html("Loading...");jQuery.each(TB_config.ajaxURLs,function(b,a){TB_getFreshTweets(a)})}function TB_getFreshTweets(a){jQuery.ajax({dataType:"jsonp",url:a,success:function(b){TB_addTweets(b)},error:function(){TB_config.urlsDone++;TB_checkComplete()}})}function TB_addTweets(a){TB_showTweetList();var b=a;if(typeof(a.results)!="undefined"){b=a.results}jQuery.each(b,function(d,e){if(jQuery("#"+e.id).length>0){return true}else{if(TB_tweetsShown==0){TB_tweetsShown++;TB_minTweetID=e.id;TB_maxTweetID=e.id;jQuery("#tweetlist").append(TB_makeHTML(e))}else{if(TB_minTweetID>0&&e.id<TB_minTweetID){if(TB_tweetsShown>=TB_config[TB_mode+"_tweets_num"]){return false}else{TB_tweetsShown++;jQuery("#tweetlist").append(TB_makeHTML(e));TB_minTweetID=e.id}}else{if(TB_maxTweetID>0&&e.id>TB_maxTweetID){TB_enforceLimit();jQuery("#tweetlist").prepend(TB_makeHTML(e));TB_tweetsShown++;TB_maxTweetID=e.id}else{TB_enforceLimit();var c=TB_maxTweetID;jQuery("#tweetlist li").each(function(f,g){if(e.id<c&&e.id>g.id){jQuery("#"+c).after(TB_makeHTML(e));TB_tweetsShown++;return false}c=g.id});if(jQuery("#"+e.id).length<=0){jQuery("#"+TB_minTweetID).after(TB_makeHTML(e));TB_minTweetID=e.id;TB_tweetsShown++}}}}}jQuery("#"+e.id).hover(function(){jQuery(this).find("div:last").slideDown()},function(){jQuery(this).find("div:last").slideUp()})});if(b.length>0&&TB_mode!="archive"&&TB_config.archive_is_disabled==""){jQuery("#archivelink").show()}TB_config.urlsDone++;TB_checkComplete()}function TB_enforceLimit(){if(TB_tweetsShown==TB_config[TB_mode+"_tweets_num"]){var a=jQuery("#"+TB_minTweetID),b=a.prev("li");a.remove();TB_tweetsShown--;TB_minTweetID=parseInt(b.attr("id"))}}function TB_makeHTML(c){var b="",a;if(typeof(c.user)=="undefined"&&c.from_user){c.user={screen_name:c.from_user}}b+='<li id="'+c.id+'">';if(TB_config[TB_mode+"_show_photos"]){if(!c.user.profile_image_url&&c.profile_image_url){c.user.profile_image_url=c.profile_image_url}b+='<a class="tb_photo" href="http://twitter.com/'+c.user.screen_name+'" target="_blank">';b+='<img src="'+c.user.profile_image_url+'" alt="'+c.user.screen_name+'"/>';b+="</a>"}b+='<span class="tb_author"><a href="http://twitter.com/'+c.user.screen_name+'" target="_blank">'+c.user.screen_name+"</a>: </span> ";if(TB_config.general_link_urls){c.text=c.text.replace(/(https?:\/\/\S+)/gi,'<a href="$1" target="_blank">$1</a>')}if(TB_config.general_link_screen_names){c.text=c.text.replace(/\@([^\s\.\:]+)/gi,'<a href="http://twitter.com/$1" target="_blank">@$1</a>')}if(TB_config.general_link_hash_tags){c.text=c.text.replace(/\#([^\s\,]+)/gi,'<a href="http://search.twitter.com/search?q=%23$1" target="_blank">#$1</a>')}b+='<span class="tb_msg">'+c.text+"</span><br/>";b+=' <span class="tb_tweetinfo">';b+='<a href="http://twitter.com/'+c.user.screen_name+"/statuses/"+c.id+'">';a=TB_str2date(c.created_at);if(TB_config.general_timestamp_format){b+=jQuery.PHPDate(TB_config.general_timestamp_format,a)}else{b+=TB_verbalTime(a)}b+="</a>";if(TB_config[TB_mode+"_show_source"]&&c.source){b+=" from ";if(c.source.indexOf("&lt;")>=0){b+=jQuery("<textarea/>").html(c.source).val()}else{b+=c.source}}b+="</span>";b+='<div class="tweet-tools" style="display:none;"><a href="http://twitter.com/home?status=@'+c.user.screen_name+"%20&in_reply_to_status_id="+c.id+"&in_reply_to="+c.user.screen_name+'" target="_blank">reply<a/> | <a href="http://twitter.com/'+c.user.screen_name+'" target="_blank">follow '+c.user.screen_name+"</a></div>";b+="</li>\n";return b}function TB_showLoader(){jQuery("#refreshlink img").attr("src",TB_pluginPath+"/img/ajax-refresh.gif");jQuery("#refreshlink").addClass("loading")}function TB_hideLoader(){jQuery("#tb_loading").hide();jQuery("#refreshlink img").attr("src",TB_pluginPath+"/img/ajax-refresh-icon.gif");jQuery("#refreshlink").removeClass("loading")}function TB_showTweetList(){TB_hideLoader();jQuery("#tweetlist").show()}function TB_showMessage(b,a){TB_hideLoader();jQuery("#tweetlist").before('<div class="tb_msg" style="display:none;">'+b+"</div>");jQuery("div.tb_msg").slideDown();if(!a){setTimeout("TB_hideMessages()",8000)}}function TB_hideMessages(){jQuery("div.tb_msg").slideUp(1000,function(){jQuery("div.tb_msg").remove()})}function TB_str2date(c){var a=new Date(),b=c.split(/[\s\:]/);if(c.indexOf(",")>=0){a.setUTCFullYear(b[3],TB_monthNumber[""+b[2]]-1,b[1]);a.setUTCHours(b[4],b[5],b[6])}else{a.setUTCFullYear(b[7],TB_monthNumber[""+b[1]]-1,b[2]);a.setUTCHours(b[3],b[4],b[5])}return a}function TB_verbalTime(a){var c,b=new Date(),g,d,e="",f="";if(b.getTime()>a.getTime()){g=Math.round((b.getTime()-a.getTime())/1000);f=" ago"}else{g=Math.round((a.getTime()-b.getTime())/1000);e="in "}for(c=0;g>=TB_timePeriodLengths[c]&&c<TB_timePeriodLengths.length;c++){g=g/TB_timePeriodLengths[c]}g=Math.round(g);d=TB_timePeriods[c];if(g!=1){d+="s"}return e+g+" "+d+f}jQuery(document).ready(function(){TB_init()});TB_tmp=setTimeout("TB_init()",4000);