var tweetquote=function(){var config={"refreshRate":10000,"phrase":false,"username":false,"hashtag":false,"geocode":false,"advancedquery":false,"includeauthor":false,"stripurls":false,"stripTwitterTags":false,"classname":false,"lang":"en","animationtype":"fade","animationspeed":"slow","defaulttext":"Hold up, we&#8217;re just loading lessons from our mothers."};
var rootId="tweet_quote",wrapId="tweet_quote_wrapper",textId="tweet_quote_text",authorId="tweet_quote_author",rootDom,quoteDom,intId,sinceId,handlerTextParser,handlerQuoteUpdate;(function(){if(!window["jQuery"]){document.write('<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"><\/script>');
}})();function init(){try{if(config.phrase||config.username||config.hashtag||config.advancedquery){document.write('<div id="'+rootId+'"></div>');rootDom=$("#"+rootId);if(config.classname.constructor===String){rootDom.addClass(config.classname);}if(config.defaulttext.constructor===String){rootDom.html('<div id="'+wrapId+'"><span id="'+textId+'">'+config.defaulttext+"</span></div>");
}}}catch(e){logError(e);return;}getTweet();initRefresh();}function initRefresh(){intId=setInterval(getTweet,config.refreshRate);}function stopRefresh(){clearInterval(intId);}function getTweet(){var api="http://search.twitter.com/search.json?rpp=1&callback=tweetquote.onApiCallback&lang="+config.lang+"&";
if(sinceId){api+="since_id="+sinceId+"&";}if(config.phrase){api+="q="+config.phrase;}else{if(config.username){api+="q=from%3A"+config.username;}else{if(config.hashtag){api+="q=%23"+config.hashtag;}else{if(config.advancedquery){api+="q="+config.advancedquery;}}}}if(config.geocode){api+="&geocode="+config.geocode;
}try{rootDom.before('<script type="text/javascript" src="'+api+'"><\/script>');}catch(e){logError(e);}}function filterTweet(json){if(json.results&&json.results.length>0){var tweet=json.results[0];sinceId=tweet.id;html='<div id="'+wrapId+'">'+getTweetText(tweet)+"</div>";if(rootDom.html()!=html){rootDom.html(html);
wrapperNode=$("#"+wrapId);wrapperNode.hide();switch(config.animationtype){case"fade":wrapperNode.fadeIn(config.animationspeed);break;case"slide":wrapperNode.slideIn(config.animationspeed);break;default:wrapperNode.show();break;}if(handlerQuoteUpdate){handlerQuoteUpdate(wrapperNode);}}}}function getTweetText(tweet){var text=tweet.text;
if(config.stripurls){var pattern_url=/https?:\/\/([\-\w\.]+)+(:\d+)?(\/([\w\/_\.]*(\?\S+)?)?)?/ig;text=text.replace(pattern_url,"");}if(config.stripTwitterTags){var pattern_tags=/RT|\'|\"|/ig;text=text.replace(pattern_tags,"");}var html='<span id="'+textId+'">'+text+"</span>";if(config.includeauthor){html+=' <span id="'+authorId+'">from '+'<a href="http://www.twitter.com/'+tweet.from_user+'">'+tweet.from_user+"</a></span>";
}if(handlerTextParser){return(handlerTextParser(html,tweet));}return(html.replace(/^\s+|\s+$/g,""));}function logError(e){if(console&&console.log){console.log("TQ: "+e);}}return{load:function(options){if(options.constructor===String){config.phrase=options;}else{$.extend(config,options);}init();},stop:function(){stopRefresh();
},onApiCallback:function(json){filterTweet(json);},onTextParse:function(func){handlerTextParser=func;},onQuoteUpdate:function(func){handlerQuoteUpdate=func;}};}();window.tweetquote=tweetquote;
