var TB_version="2.0.0",TB_ws,TB_config,TB_minTweetID,TB_maxTweetID,TB_tweetsShown=0,TB_rateLimitData,TB_mode="widget";function TB_init(){TB_ws=TB_pluginPath+"/ws.php";TB_showLoader();if(jQuery("#tweetblender").hasClass("archive")){TB_mode="archive"}jQuery("#twitterlogo").click(function(){var a="Powered by Tweet Blender plugin v"+TB_version+" blending ";jQuery.each(TB_config.general_source_ids.split(","),function(b,c){a+='<a target="_blank" href="';if(c.charAt(0)=="#"){a+="http://search.twitter.com/search?"+escape(c)}else{a+="http://twitter.com/"+c}a+='">'+c+"</a> "});TB_showMessage(a)});jQuery.ajax({url:TB_ws+"?action=get_config",dataType:"json",success:function(a){if(typeof(a.general_source_ids)=="undefined"){TB_showMessage("Twitter sources to blend are not defined")}else{TB_config=a;TB_blend()}},error:TB_ajaxError})}function TB_blend(){var a=TB_config.general_source_ids.split(",");jQuery.each(a,function(b,c){TB_getTweets(c)})}function TB_getTweets(a){jQuery.ajax({url:"http://twitter.com/account/rate_limit_status.json",dataType:"jsonp",success:function(b){if(b.remaining_hits==0){TB_getCachedTweets(a)}else{TB_getFreshTweets(a)}},error:function(){TB_getCachedTweets(a)}})}function TB_getCachedTweets(a){jQuery.ajax({url:TB_pluginPath+"/cache/"+escape(a)+".json",dataType:"json",success:TB_addTweets,error:function(){TB_showMessage("Can't get tweets for "+a+". You've reached your maximum Twitter connection limit and cache is not available.")}})}function TB_getFreshTweets(a){if(a.charAt(0)=="#"){jQuery.ajax({dataType:"jsonp",url:"http://search.twitter.com/search.json",data:({q:a,rpp:TB_config.archive_tweets_num,page:1}),success:function(b){TB_cacheData(a,b);TB_addTweets(b)},error:function(){TB_getCachedTweets(a)}})}else{jQuery.ajax({url:"http://twitter.com/statuses/user_timeline.json",dataType:"jsonp",data:({screen_name:a,count:TB_config.archive_tweets_num}),success:function(b){TB_cacheData(a,b);TB_addTweets(b)},error:function(){TB_getCachedTweets(a)}})}}function TB_cacheData(b,a){jQuery.ajax({url:TB_ws+"?action=cache_data",type:"POST",dataType:"json",data:({source:b,data:jQuery.toJSON(a)})})}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_minTweetID=e.id;TB_maxTweetID=e.id;jQuery("#tweetlist").append(TB_makeHTML(e));TB_tweetsShown++}else{if(TB_minTweetID>0&&e.id<TB_minTweetID){if(TB_tweetsShown==TB_config[TB_mode+"_tweets_num"]){return false}else{jQuery("#tweetlist").append(TB_makeHTML(e));TB_tweetsShown++;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(b.length>0&&TB_mode!="archive"){jQuery("#archivelink").show()}}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=new Date();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.setTime(Date.parse(c.created_at));if(TB_config.general_timestamp_format){b+=jQuery.PHPDate(TB_config.general_timestamp_format,a)}else{b+=jQuery.timeago(a)}b+="</a>";if(TB_config[TB_mode+"_show_source"]&&c.source){b+=" from "+jQuery("<textarea/>").html(c.source).val()}b+="</span>";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(a){TB_hideLoader();jQuery("#tweetlist").before('<div class="tb_msg">'+a+"</div>");jQuery("div.tb_msg").slideDown();setTimeout("TB_hideMessage()",10000)}function TB_hideMessage(){jQuery("div.tb_msg").slideUp()}function TB_ajaxError(a,c,b){TB_showMessage("Error: "+c)}jQuery(document).ready(function(){TB_init()});