
(function(){if(YAHOO.env.ua.ie>0){document.getElementById('app-container').innerHTML='<h3 id="apology">It looks like you are using Internet Explorer.<br />'+'Rather than frustrate you (and embarrass myself) with what must only half-assedly work right now, '+'I have turned off all application functionality until I have adequately tested and confirmed that it will '+'work correctly in your browser.<br />'+'Sorry!<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&#8211;<a href="http://twitter.com/yoni" target="_blank">@yoni</a></h3>';document.getElementById('app-container').className='';return;}
YAHOO.namespace('IPO.app');YAHOO.namespace('IPO.widget');YAHOO.namespace('IPO.utils');var YUILoader=new YAHOO.util.YUILoader({combine:true,dirty:true,require:['json','connection','animation'],base:'http://yui.yahooapis.com/2.8.0r4/build/',onSuccess:function(o){YAHOO.IPO.app.AppMgr._init();}});YUILoader.insert();var Formatter={regExes:[{pat:new RegExp('(http://[^ ]+)([.,:?();]?)','gim'),sub:'<a href="$1" target="_blank">$1</a>$2'},{pat:new RegExp('([a-z0-9_.]+@[a-z0-9.]+\\.[a-z0-9]{2,4})','gim'),sub:'<a href="mailto:$1" target="_blank">$1</a>'},{pat:new RegExp('(^|[^a-z0-9_])@([a-z0-9_]{2,})','gim'),sub:'$1<a href="http://twitter.com/$2" target="_blank">@$2</a>'}],rowFormatLI:' '+'\n<li> '+'\n\t<a href="http://twitter.com/{user}" class="img" target="_blank"><img src="{img}" border="0" width="48" height="48" alt="{user}" /></a> '+'\n\t<div> '+'\n\t\t<p><strong><a href="http://twitter.com/{user}">{user}</a>:</strong> {text}</p> '+'\n\t\t<span>{created_at} &bull; <a href="http://twitter.com/{user}/statuses/{id}" target="_blank">View Tweet</a> '+'\n\t\t &bull; <a href="http://twitter.com/home?status=@{user}" target="_blank">Reply</a></span> '+'\n\t</div> '+'\n</li>\n',userFullLI:' '+'\n<li class="user-badge"> '+'\n\t<a href="http://twitter.com/{screen_name}" target="_blank" class="badge"><img height="48" width="48" border="0" alt="{name}" src="{profile_image_url}"/></a> '+'\n\t<h6><a href="http://twitter.com/{screen_name}" target="_blank">{name}</a></h6> '+'\n\t<ul class="user-stats"> '+'\n\t\t<li><a href="http://twitter.com/{screen_name}/followers" target="_blank"><span class="count">{followers_count}</span><span class="label">Followers</span></a></li> '+'\n\t\t<li><a href="http://twitter.com/{screen_name}/friends" target="_blank"><span class="count">{friends_count}</span><span class="label">Friends</span></a></li> '+'\n\t\t<li><a href="http://twitter.com/{screen_name}" target="_blank"><span class="count">{statuses_count}</span><span class="label">Updates</span></a></li> '+'\n\t\t<li><a href="http://twitter.com/{screen_name}/favourites" target="_blank"><span class="count">{favourites_count}</span><span class="label">Favorites</span></a></li> '+'\n\t</ul> '+'\n</li>\n',userBasicLI:' '+'\n<li class="user-row {user_class}"> '+'\n\t<img src="{related_user_image}" border="0" height="48" width="48" class="related-user" />'+'\n\t<a href="http://twitter.com/{screen_name}" target="_blank" class="badge"><img height="48" width="48" border="0" alt="{name}" src="{profile_image_url}" /></a> '+'\n\t<h6><a href="http://twitter.com/{screen_name}" target="_blank">{name}</a></h6> '+'\n</li>\n',userInvalidLI:' '+'\n<li class="user-badge"> '+'\n\t<h6 class="invalid">Unable to retrieve <a href="http://twitter.com/{screen_name}" target="_blank">{screen_name}</a>\'s profile. '+'Are you sure you spelled that right?</h6>'+'\n</li>\n',dateObj:new Date(),localizeDate:function(d){Formatter.dateObj.setTime(Date.parse(d));return Formatter.dateObj.toLocaleString();},formatDate:function(d){var ds=d.split(' ');return'@ '+ds[3]+' on '+ds[2]+' '+ds[1]+', '+ds[4];},formatTweet:function(text){for(var j=0,reLen=Formatter.regExes.length,re;j<reLen;j++){re=Formatter.regExes[j];text=text.replace(re.pat,re.sub);}
return text;}};var TwitterApp=function(){this.TYPE='TwitterApp';this.TIMEOUT=5000;this.MAX_TWEETS=1500;this.MAX_USERS=2000;this.LOADER_MESSAGES=['OK. Hold on a minute...','Here we go!','Still looking...','And looking...','More looking...','I\'m not sure this is what Twitter was meant for...','Twitter is *so* going to block me...','Can\'t think of what to say...','So I\'ll start repeating myself...','Still looking...','Almost there (I think)...','OK, guess not...','Still looking...','And looking...','More looking...','I\'m not sure this is what Twitter was meant for...','Twitter is *so* going to block me...','Can\'t think of what to say...','So I\'ll start repeating myself...','Still looking...'];this.F=Formatter;this.running=false;this.timer=null;this.loaderInterval=null;this.loaderID=1;this.loaderDiv=null;this.indicatorDiv=null;this.toolbar=null;this.errMsgDiv=null;this.resultElem=null;this.countElem=null;this.events={};this.exportUrl='/app/exportData.php';this.displayToolbar=function(){var sortDiv=$('sort-results');var extrasDiv=$('remove-extra-info');$$.remove(this.toolbar,'hide');$$.remove(sortDiv,'hide');$$.remove(extrasDiv,'hide');YAHOO.util.Event.on($('search-tools').tag('a'),'click',this.doAction,this);this.resultsHTML=this.resultElem.innerHTML;if(this.TYPE=='TwinCommon'){$$.add(sortDiv,'hide');$$.add(extrasDiv,'hide');}
YAHOO.util.Event.on($('start-over').tag('a'),'click',this.reset,this);};this.doAction=function(e,that){YAHOO.util.Event.stopEvent(e);var button=this;var action=button.title;switch(action){case'sort results':that.sortResults();break;case'remove extra info':that.removeExtraInfo(button);$$.remove(document.getElementById('restore-results'),'hide');$$.add(button.parentNode,'hide');break;case'restore results':that.restoreResults(button);$$.remove(document.getElementById('remove-extra-info'),'hide');$$.add(button.parentNode,'hide');break;case'filter results':var filterAnim=new YAHOO.util.Anim(button.parentNode,{width:{to:220}},0.7,YAHOO.util.Easing.easeOut);filterAnim.onStart.subscribe(function(){var innerAnim=new YAHOO.util.Anim('export-results',{width:{to:118}},0.7,YAHOO.util.Easing.easeOut);innerAnim.animate();});filterAnim.onComplete.subscribe(function(){document.getElementById('filter').focus();});filterAnim.animate();break;case'export results':var exportAnim=new YAHOO.util.Anim(button.parentNode,{width:{to:292}},0.7,YAHOO.util.Easing.easeOut);exportAnim.onStart.subscribe(function(){var innerAnim=new YAHOO.util.Anim('filter-results',{width:{to:106}},0.7,YAHOO.util.Easing.easeOut);innerAnim.animate();});exportAnim.animate();break;case'export html':that.exportResults(action);break;case'export xls':that.exportResults(action);break;case'start over':that.reset();break;}};this.filter=function(e,that){var q;if(typeof this.args!=='undefined'){that=this;q=that.args.query;$('filter').value=q;}
else{q=this.value;}
var results=that.resultElem.tag('li');var resultsLen=results.length;var count=resultsLen;for(var i=0,result;i<resultsLen;i++){result=$(results[i]);$$.remove(result,'hide');if(!$$.has(result,'user-header')){try{if(q.length>=2&&result.tag('p').first().innerHTML.toLowerCase().indexOf(q)<0){$$.add(result,'hide');count--;}}
catch(err1){try{if(q.length>=2&&result.innerHTML.toLowerCase().indexOf(q)<0){$$.add(result,'hide');count--;}}
catch(err2){}}}}
that.countElem.fill(count.toString());};this.updateLoader=function(){if(this.loaderID===this.LOADER_MESSAGES.length){this.loaderID=1;}
if(this.running){$$.add(this.loaderDiv,'active');this.indicatorDiv.fill(this.LOADER_MESSAGES[this.loaderID]);this.loaderID+=1;clearInterval(this.loaderInterval);var that=this;this.loaderInterval=setInterval(function(){that.updateLoader();},5000);}
else{$$.remove(this.loaderDiv,'active');clearInterval(this.loaderInterval);this.loaderInterval=false;}};this.displayError=function(msg){if(typeof AppMgr!=='undefined'){AppMgr.displayError(msg);}
else{if(msg){this.errMsgDiv.fill(msg);$$.add(this.errMsgDiv,'on');}}};this.createForm=function(n,v){var form=document.createElement('form');form.action=this.exportUrl;form.method='post';form.style.display='none';var input=document.createElement('input');input.setAttribute('type','hidden');input.setAttribute('name',n);input.setAttribute('value',v);form.appendChild(input);return form;};this.exportResults=function(format){var exportData='';var fn='';if(format=='export html'){exportData='<ul>\n'+this.resultElem.innerHTML+'</ul>\n';fn='exportHTMLData';}
else if(format=='export xls'){var tweets=this.tweets.get();var tweet,timestamp,row;exportData+='id\ttimestamp\tuser\ttext\n';for(var t in tweets){if(typeof tweets[t]!=='undefined'){tweet=tweets[t];timestamp=tweet.created_at.replace(/ \+0000$/,'');row=[t,timestamp,tweet.from_user,this.F.formatTweet(tweet.text)];exportData+=row.join('\t')+'\n';}}
fn='exportXLSData';}
if(exportData!==''&&fn!==''){var f=this.createForm(fn,encodeURI(exportData));var bodyElem=$('twitter');bodyElem.appendChild(f);f.submit();bodyElem.removeChild(f);}};this.sortResults=function(){var newLis=this.resultElem.tag('li');newLis.reverse();var newHTML='\n';for(var j=0,newLen=newLis.length;j<newLen;j++){newHTML+='\t<li>'+newLis[j].innerHTML+'</li>\n';}
this.resultElem.innerHTML=newHTML;};this.removeExtraInfo=function(){this.stripRe=new RegExp('<strong>.+:<\/strong>(.+)','gim');var lis=this.resultElem.tag('li');for(var i=0,lisLen=lis.length,li;i<lisLen;i++){li=$(lis[i]);try{li.fill(YAHOO.util.Lang.trim(li.tag('p').first().innerHTML.replace(this.stripRe,'$1')));}
catch(e){this.displayError('Unable to remove extraneous information from tweets.');}}};this.restoreResults=function(){this.resultElem.fill(this.resultsHTML);};this.reset=function(){var app=this;this.args={};this.running=false;this.timer=null;this.loaderInterval=null;this.loaderID=1;this.loaderDiv=$('loader');this.indicatorDiv=this.loaderDiv.tag('p').last().empty();this.usersElem=$('user-badges').empty();this.resultElem=$('result-list').empty();$$.remove(this.resultElem,'user-list');$$.add(this.resultElem,'tweet-list');this.toolbar=$('search-tools');$$.add(this.toolbar,'hide');this.countElem=$('result-count').tag('em').first().empty();$$.remove(this.countElem.parentNode,'hide');this.errMsgDiv=$('errMsg').empty();$$.remove(this.errMsgDiv,'on');this.events={onApplicationStart:new YAHOO.util.CustomEvent('onApplicationStart',this),onApplicationReady:new YAHOO.util.CustomEvent('onApplicationReady',this),onBeforeApplicationComplete:new YAHOO.util.CustomEvent('onBeforeApplicationComplete',this),onApplicationComplete:new YAHOO.util.CustomEvent('onApplicationComplete',this),onDisplayStart:new YAHOO.util.CustomEvent('onDisplayStart',this),onDisplayComplete:new YAHOO.util.CustomEvent('onDisplayComplete',this),afterFirstResult:new YAHOO.util.CustomEvent('afterFirstResult',this),onClosingDown:new YAHOO.util.CustomEvent('onClosingDown')};YAHOO.util.Event.on('cancel-link','click',function(e){YAHOO.util.Event.stopEvent(e);app.close('Cancelled!');});YAHOO.util.Event.on('filter','keyup',this.filter,this);this.events.onApplicationStart.subscribe(this.updateLoader,null,this);this.events.onApplicationComplete.subscribe(this.updateLoader,null,this);this.events.afterFirstResult.subscribe(this.displayToolbar,null,this);};this.close=function(msg){YAHOO.log('Closing down...','warn',this.TYPE);this.events.onClosingDown.fire();clearTimeout(this.timer);this.displayError('<p>'+msg+'</p>');this.end();return false;};this.start=function(startFunction){YAHOO.log('Starting...','warn',this.TYPE);AppMgr.RUNNING=true;AppMgr.RESULTS=false;this.running=true;this.events.onApplicationStart.fire();startFunction.call(this);};this.end=function(){this.events.onBeforeApplicationComplete.fire();YAHOO.log('Ending...','warn',this.TYPE);AppMgr.RUNNING=false;AppMgr.RESULTS=true;this.running=false;this.events.onApplicationComplete.fire();};this.pUserFull=function(userInfo){return YAHOO.lang.substitute(this.F.userFullLI,userInfo);};this.pUserBasic=function(userInfo){return YAHOO.lang.substitute(this.F.userBasicLI,userInfo);};this.pUserInvalid=function(userInfo){return YAHOO.lang.substitute(this.F.userInvalidLI,userInfo);};this.pTweet=function(tweetInfo){return YAHOO.lang.substitute(this.F.rowFormatLI,tweetInfo);};this.displayInvalidUser=function(e,args,userObj){YAHOO.log('Inavlid user '+userObj.screen_name,'error',this.TYPE);this.usersElem.append(this.pUserInvalid(userObj));};this.displayUser=function(e,args,userObj){var user=userObj.getInfo();user.profile_image=user.profile_image_url.replace('normal.','bigger.');YAHOO.log('Displaying user '+user.screen_name,'notice',this.TYPE);this.usersElem.append(this.pUserFull(user));};this.displayUsers=function(comparison){var alphaCompare=function(a,b){var x=a[0].screen_name;var y=b[0].screen_name;var sorter=[x,y];sorter.sort();if(sorter[0]==a[0].screen_name){return-1;}
else{return 1;}};var sameLen=comparison.same.length;$$.add($('result-count'),'hide');var u,thisHTML='';thisHTML+='\t<li class="user-header"><h5>Common Friends ('+sameLen+')</h5></li>\n';comparison.same.sort(function(a,b){return alphaCompare(a,b);});for(var i=0;i<sameLen;i++){u=comparison.same[i][0];u.user_class='same';u.profile_image=u.profile_image_url;thisHTML+=this.pUserBasic(u);}
if(this.args.users[0].type==this.args.users[1].type){var diffLen=comparison.diff.length;thisHTML+='\t<li class="user-header"><h5>Different Friends ('+diffLen+')</h5></li>\n';comparison.diff.sort(function(a,b){return alphaCompare(a,b);});for(var j=0;j<diffLen;j++){u=comparison.diff[j][0];u.user_class='diff';u.profile_image=u.profile_image_url;u.related_user_image=comparison.diff[j][1];thisHTML+=this.pUserBasic(u);}}
this.resultElem.innerHTML=thisHTML+' ';thisHTML='';};this.displayTweets=function(tweetsObj,args){var that=this.scope;var fav='favorites';var format=that.args.format?that.args.format:'html';var tweets=[];if(tweetsObj instanceof Array){tweets=tweetsObj;}
else{for(var t in tweetsObj){tweets.push(tweetsObj[t]);}}
var tweetsLen=tweets.length;YAHOO.log('Processing '+tweetsLen,'notice',this.TYPE);that.indicatorDiv.fill('Displaying '+tweetsLen+' tweets...');clearInterval(that.loaderInterval);var bunchTimer=setTimeout(function(){that.updateLoader();},2500);if(format=='html'){var thisHTML='';for(var i=0,tweet;i<tweetsLen;i++){tweet=tweets[i];if(that.args.type==fav||that.args.type=='timeline'){thisHTML+=that.pTweet({id:tweet.id,user:tweet.user.screen_name,text:that.F.formatTweet(tweet.text),img:tweet.user.profile_image_url,created_at:that.F.localizeDate(tweet.created_at)});}
else{thisHTML+=that.pTweet({id:tweet.id,user:tweet.from_user,text:that.F.formatTweet(tweet.text),img:tweet.profile_image_url,created_at:that.F.localizeDate(tweet.created_at)});}}
that.resultElem.append(thisHTML);try{that.events.afterFirstResult.fire();that.events.afterFirstResult.unsubscribe();that.countElem.fill(this.size.toString());}
catch(e){YAHOO.log(e.toString(),'error',that.TYPE);}}};this.configure=function(args){YAHOO.log('configure','info',this.TYPE);var that=this;for(var a in args){that[a]=args[a];}};};var Sortable=function(args){this.TYPE='Sortable';this.size=0;this.total=0;this.rpp=100;this.timer=false;this.page=0;this.bunch=[];this.args={};this.list={};var obj={};var keys=[];var requestUrl='/app/twitterRequest.php?';this.sort=function(order){var comp=function(a,b){if(typeof order!=='undefined'){if(order=='reverse'){return a-b;}}
return b-a;};keys=[];for(var k in this.list){keys.push(k);}
keys.sort(comp);if(this.size!==keys.length){YAHOO.log('why not?','warn',this.TYPE);this.size=keys.length;}
var values={};for(var i=0,keysLen=keys.length,key;i<keysLen;i++){key=keys[i];values[key]=this.list[key];}
this.list=values;return this.list;};this.add=function(list){if(!(list instanceof Array)){list=[list];}
for(var i=0,listLen=list.length,item,thingid;i<listLen;i++){item=list[i];if(typeof item.screen_name!=='undefined'){thingid=item.screen_name;}
else{thingid=item.id;}
if(typeof this.list[thingid]==='undefined'&&this.size<this.total){this.list[thingid]=item;this.bunch.push(item);this.size+=1;}}
if(this.bunch.length>=97){var b=this.bunch;try{this.displayer(b);}
catch(e){}
this.bunch=[];}
return this.list;};this.get=function(){return this.list;};this.getIDs=function(){return keys;};this.load=function(e,args,obj){var thisObj=this;var cancelSearch=false;var success=function(o){try{var json=YAHOO.lang.JSON.parse(o.responseText);var list;if(!(json instanceof Array)){YAHOO.log('response not an array','warn',this.TYPE);if(typeof json.next_cursor!=='undefined'){this.page=json.next_cursor;list=json.users;}
else{list=json.results;}}
else{list=json;}
json=null;if((list instanceof Array)&&list.length>0){this.add(list);if(this.scope.running){this.timer=setTimeout(function(){thisObj.onReadyToLoad.fire();},1500);if(this.page<100){this.page+=1;}}}
else{YAHOO.log('problem getting '+this.TYPE,'warn',this.TYPE);this.cleanup();this.onLoadComplete.fire();}}
catch(e){YAHOO.log('could not add to '+this.TYPE,'error',this.TYPE);this.onLoadComplete.fire();}};var failure=function(o){YAHOO.log('failed to load + '+this.TYPE,'error',this.TYPE);return this.scope.close('Unable to contact Twitter. [err: '+o.status+']');};YAHOO.log('Current Info: '+this.size+', total: '+this.total+', rpp: '+this.rpp,'info',this.TYPE);if(this.size<this.total&&this.size<this.scope.MAX_USERS&&!cancelSearch){var url=requestUrl+'type='+this.type+'&rpp='+this.rpp+this.qs+'&page='+this.page;var cb={success:success,failure:failure,scope:this};YAHOO.log('requesting: '+url,'info',this.TYPE);var request=YAHOO.util.Connect.asyncRequest('POST',url,cb,null);}
else{if(this.scope.TYPE!=='TwinCommon'){this.cleanup();}
clearTimeout(this.timer);this.timer=false;this.onLoadComplete.fire();}};this.cleanup=function(){if(typeof this.bunch!=='undefined'&&this.bunch.length>0){var b=this.bunch;this.displayer.call(this,b);this.bunch=[];}};this.compare=function(compareWith,theseusers){var results={same:[],diff:[]};var list1=this.get();var list2=compareWith.get();for(var o in list1){if(theseusers.indexOf(list1[o].screen_name.toLowerCase())<0){if(typeof list2[o]!=='undefined'&&results.same.indexOf(list1[o])<0){results.same.push([list1[o],'same']);}
else{results.diff.push([list1[o],this.scope.users[theseusers[0]].info.profile_image_url]);}}}
for(var oo in list2){if(theseusers.indexOf(list2[oo].screen_name.toLowerCase())<0){if(typeof list1[oo]=='undefined'&&results.diff.indexOf(list2[oo])<0&&results.same.indexOf(list2[oo])<0){results.diff.push([list2[oo],this.scope.users[theseusers[1]].info.profile_image_url]);}}}
return results;};this.onReadyToLoad=new YAHOO.util.CustomEvent('onReadyToLoad');this.onLoadComplete=new YAHOO.util.CustomEvent('onLoadComplete');};var UserList=function(args){Sortable.call(this,args);this.args=args;this.TYPE='UserList';this._init=function(params){this.onReadyToLoad.subscribe(this.load,this,true);this.scope=null;if(typeof params!=='undefined'){this.type=params.type;this.total=params.total;this.page=-1;if(typeof params.scope!=='undefined'){this.scope=params.scope;}
if(typeof params.displayer!=='undefined'){this.displayer=params.displayer;}
if(typeof params.list!=='undefined'){this.add(params.list);}
if(typeof params.user!=='undefined'){this.user=params.user;this.qs='&id='+this.user;this.onReadyToLoad.fire();}}};this._init(args);};var TweetList=function(args){Sortable.call(this,args);this.args=args;this.TYPE='TweetList';this._init=function(params){this.scope=null;this.onReadyToLoad.subscribe(this.load,this,true);if(typeof params!=='undefined'){this.type=params.type;this.total=params.total;this.page=1;if(typeof params.scope!=='undefined'){this.scope=params.scope;this.onLoadComplete.subscribe(this.scope.end,this.scope,this.scope);}
if(typeof params.displayer!=='undefined'){this.displayer=params.displayer;}
if(typeof params.list!=='undefined'){this.add(params.list);}
if(typeof params.qs!=='undefined'){this.qs=params.qs;this.onReadyToLoad.fire();}}};this._init(args);};var User=function(args){var requestUrl='/app/twitterRequest.php?';var info,request;var id=args.user;this.TYPE='User';this.screen_name=args.user;this.friends={};this.followers={};this.favorites={};this.onUserAvailable=new YAHOO.util.CustomEvent('onUserAvailable');this.onUserUnavailable=new YAHOO.util.CustomEvent('onUserUnavailable');this.onUserAvailable.subscribe(function(){YAHOO.log(this.screen_name+' load complete.','info',this.TYPE);},null,this);this.onUserUnavailable.subscribe(function(){YAHOO.log(this.screen_name+' load invalid.','warn',this.TYPE);},null,this);this.onGettingFriendsStart=new YAHOO.util.CustomEvent('onGettingFriendsStart',this);this.onGettingFriendsComplete=new YAHOO.util.CustomEvent('onGettingFriendsComplete',this);this.onGettingFollowersStart=new YAHOO.util.CustomEvent('onGettingFollowersStart',this);this.onGettingFollowersComplete=new YAHOO.util.CustomEvent('onGettingFollowersComplete',this);this.onGettingFavoritesStart=new YAHOO.util.CustomEvent('onGettingFavoritesStart',this);this.onGettingFavoritesComplete=new YAHOO.util.CustomEvent('onGettingFavoritesComplete',this);this.loadUserInfo=function(){var success=function(o){try{this.info=YAHOO.lang.JSON.parse(o.responseText);this.invalid=false;YAHOO.log('successfully retrieved user: '+this.screen_name,'info',this.TYPE);this.onUserAvailable.fire();}
catch(e){this.invalid=true;YAHOO.log('invalid user: '+this.screen_name,'warn',this.TYPE);this.onUserUnavailable.fire();}};var failure=function(o){YAHOO.log('failed to get user: '+this.screen_name,'error',this.TYPE);return this.scope.close('Unable to contact Twitter. [err: '+o.status+']');};var url=requestUrl+'type=user&id='+this.screen_name;var cb={success:success,failure:failure,scope:this};YAHOO.log('requesting: '+url,'info',this.TYPE);request=YAHOO.util.Connect.asyncRequest('GET',url,cb,null);};this.getFollowersCount=function(){return this.info.followers_count;};this.getFriendsCount=function(){return this.info.friends_count;};this.getFavoritesCount=function(){return this.info.favourites_count;};this.getStatusesCount=function(){return this.info.statuses_count;};this.isProtected=function(){return this.getInfo('protected');};this.getInfo=function(k){if(typeof k!=='undefined'&&typeof this.info[k]!=='undefined'){return this.info[k];}
else{return this.info;}};this.addFriends=function(e,obj,args){args.total=this.getFriendsCount();args.type='friend';args.user=this.screen_name;args.qs='&id='+this.screen_name;if(typeof this.friends.size==='undefined'){this.friends=new UserList(args);this.onGettingFriendsStart.fire();var that=this;this.friends.onLoadComplete.subscribe(function(){that.onGettingFriendsComplete.fire({user:that.screen_name,list:that.friends,type:'friends'});});}};this.addFollowers=function(e,obj,args){args.total=this.getFollowersCount();args.type='follower';args.user=this.screen_name;args.qs='&id='+this.screen_name;if(typeof this.followers.size==='undefined'){this.followers=new UserList(args);this.onGettingFollowersStart.fire();var that=this;this.followers.onLoadComplete.subscribe(function(){that.onGettingFollowersComplete.fire({user:that.screen_name,list:that.followers,type:'followers'});});}};this.addFavorites=function(e,obj,args){args.total=this.getFavoritesCount();args.type='favorites';args.user=this.screen_name;args.qs='&id='+this.screen_name;if(typeof this.favorites.size==='undefined'){this.favorites=new TweetList(args);this.onGettingFavoritesStart.fire();var that=this;this.favorites.onLoadComplete.subscribe(function(){that.onGettingFavoritesComplete.fire({user:that.screen_name,list:that.favorites,type:'favorites'});});}};this._init=function(args){this.scope=args.scope;this.loadUserInfo(this.screen_name);};this._init(args);};var DeepSearch=function(args){TwitterApp.call(this,args);this.TYPE='DeepSearch';this.search=function(){var that=this;this.tweets=new YAHOO.IPO.widget.TweetList(this.args);this.tweets.onLoadComplete.subscribe(function(){YAHOO.log('Done searching. Retrieved '+that.tweets.size+' tweets','success',that.TYPE);},that);};this._init=function(args){this.reset();this.args={scope:this,displayer:this.displayTweets,type:'search',total:args.total||this.MAX_TWEETS,query:args.query,qs:'&q='+escape(args.query.replace(' ','+'))};this.start(this.search);};if(!AppMgr.RUNNING){this._init(args);}
else{alert(AppMgr.WAIT_MSG);}};var SearchFavorites=function(args){TwitterApp.call(this,args);this.TYPE='SearchFavorites';this.tweets={};this.quitEarly=function(){this.close('Something went wrong loading user: '+this.args.user+'<br/>Please try again later.');};this.getUserFavorites=function(){var storeTweets=function(){if(this.user.favorites.size>0){this.tweets=this.user.favorites.get();}};this.user=new User({user:this.args.user,scope:this});this.user.onUserUnavailable.subscribe(this.displayInvalidUser,this.user,this);this.user.onUserUnavailable.subscribe(this.quitEarly,this,this);this.user.onUserAvailable.subscribe(this.displayUser,this.user,this);this.user.onUserAvailable.subscribe(this.user.addFavorites,this.args,this.user);this.events.onBeforeApplicationComplete.subscribe(this.filter,this.args,this);this.events.onBeforeApplicationComplete.subscribe(storeTweets,this,this);};this._init=function(args){this.reset();this.args={displayer:this.displayTweets,scope:this,type:'favorites',query:args.query,total:args.total||this.MAX_TWEETS,user:args.user};this.start(this.getUserFavorites);};if(!AppMgr.RUNNING){this._init(args);}
else{alert(AppMgr.WAIT_MSG);}};var TweetToBlog=function(args){TwitterApp.call(this,args);this.TYPE='TweetToBlog';this.search=function(){var that=this;this.tweets=new TweetList(this.args);this.tweets.onLoadComplete.subscribe(function(){YAHOO.log('Done searching. Retrieved '+that.tweets.size+' tweets','success',that.TYPE);},that);};this._init=function(args){this.reset();this.args={scope:this,displayer:this.displayTweets,type:'search',total:args.total||this.MAX_TWEETS,user:args.user,hashtag:args.hashtag,qs:'&q='+escape('#'+args.hashtag.replace(' ','+'))+'+from%3A'+args.user};this.F.regExes.push({pat:new RegExp('^#('+this.args.hashtag+')|(#'+this.args.hashtag+'$)','gi'),sub:''});this.start(this.search);};if(!AppMgr.RUNNING){this._init(args);}
else{alert(AppMgr.WAIT_MSG);}};var SearchFriends=function(args){TwitterApp.call(this,args);this.TYPE='SearchFriends';this.search=function(){var that=this;this.tweets=new YAHOO.IPO.widget.TweetList(this.args);this.tweets.onLoadComplete.subscribe(function(){YAHOO.log('Done searching. Retrieved '+that.tweets.size+' tweets','success',that.TYPE);},that);};this._init=function(args){this.reset();var fromusers=[];var args_users=args.users.split(' ');for(var i=0,usersLen=args_users.length;i<usersLen;i++){fromusers.push('from%3A'+args_users[i]);}
if(fromusers.length>0){fromusers=fromusers.join('+OR+');}
this.args={scope:this,displayer:this.displayTweets,type:'search',total:args.total||this.MAX_TWEETS,users:args.users,qs:'&q='+fromusers};this.start(this.search);};if(!AppMgr.RUNNING){this._init(args);}
else{alert(AppMgr.WAIT_MSG);}};var TwinCommon=function(args){TwitterApp.call(this,args);this.TYPE='TwinCommon';this.users={};this.userlists=[];this.quitEarly=function(e,args,user){this.close('Something went wrong loading user: '+user+'<br/>Please try again later.');};this.compareUsers=function(e,args,that){$$.remove(this.resultElem,'tweet-list');$$.add(this.resultElem,'user-list');if(args){var list=args[0];if(this.userlists.indexOf(list)<0){YAHOO.log('Adding '+list.user+'\'s stuff','info',this.TYPE);this.userlists.push(list);}
if(this.userlists.length==2){this.events.onComparisonStart.fire();YAHOO.log('Running comparison!','info',this.TYPE);this.comparison=this.userlists[0].list.compare(this.userlists[1].list,[this.userlists[0].user,this.userlists[1].user]);this.displayUsers(this.comparison);that.events.afterFirstResult.fire();that.events.afterFirstResult.unsubscribe();this.events.onComparisonComplete.fire();}}};this.getUsers=function(){var that=this;for(var i=0,usersLen=this.args.users.length;i<usersLen;i++){var u=this.args.users[i];var user=new User({user:u.name,scope:this});user.onUserUnavailable.subscribe(this.displayInvalidUser,user,this);user.onUserUnavailable.subscribe(this.quitEarly,user,this);user.onUserAvailable.subscribe(this.displayUser,user,this);if(u.type=='followers'){user.onUserAvailable.subscribe(user.addFollowers,this.args,user);user.onGettingFollowersComplete.subscribe(this.compareUsers,this,true);}
else if(u.type=='friends'){user.onUserAvailable.subscribe(user.addFriends,this.args,user);user.onGettingFriendsComplete.subscribe(this.compareUsers,this,true);}
this.users[u.name]=user;}};this._init=function(args){this.reset();this.events.onReadyToCompare=new YAHOO.util.CustomEvent('onReadyToCompare',this);this.events.onComparisonStart=new YAHOO.util.CustomEvent('onComparisonStart',this);this.events.onComparisonComplete=new YAHOO.util.CustomEvent('onComparisonComplete',this);this.args={scope:this,type:'users',total:args.total||this.MAX_TWEETS,users:args.users};this.start(this.getUsers);this.events.onComparisonComplete.subscribe(this.end);};if(!AppMgr.RUNNING){this._init(args);}
else{alert(AppMgr.WAIT_MSG);}};var AppMgr={RUNNING:false,RESULTS:false,WAIT_MSG:'Please wait for the current process to finish running, or press cancel.',PANELS:{IntroPanel:true,SearchFavorites:false,DeepSearch:false,TweetToBlog:false,CompareUsers:false},ACTIVE_PANEL:'IntroPanel',CURRENT:false,errMsgDiv:null,QS:{parseQS:function(){AppMgr.QS.items={};var qs=location.search.substr(1).split('&');for(var i=0;i<qs.length;i++){pair=qs[i].split('=');AppMgr.QS.items[pair[0]]=pair[1];}},get:function(k){if(typeof AppMgr.QS.items=='undefined'){AppMgr.QS.parseQS();}
return AppMgr.QS.items[k];}},displayError:function(msg){if(msg){if(msg.indexOf('<p>')<0){msg='<p>'+msg+'</p>';}
this.errMsgDiv.fill(msg);$$.add(this.errMsgDiv,'on');}},clearError:function(){this.errMsgDiv.empty();$$.remove(this.errMsgDiv,'on');},togglePanel:function(e,obj,fromQS){var closeActivePanel=function(){var ap=AppMgr.ACTIVE_PANEL;if(ap==='IntroPanel'){AppMgr.PANELS[ap]=false;}
else{$$.remove(ap.parentNode.parentNode,'on');$(ap.title).style.display='none';AppMgr.PANELS[ap.title]=false;AppMgr.appNav.style.marginLeft='-2px';}
AppMgr.ACTIVE_PANEL=false;};var that;if(e){YAHOO.util.Event.stopEvent(e);that=this;}
else{that=obj;}
var panel=that.title;if(fromQS){var fields=document.forms[panel].elements;for(var i=0,fieldsLen=fields.length,field;i<fieldsLen;i++){var val=AppMgr.QS.get(fields[i].name);if(typeof(val)!=='undefined'){fields[i].value=val;$$.add(fields[i],'focus');}}
AppMgr.parseOptions(null,document.forms[panel]);}
var myAnim;if(AppMgr.PANELS[panel]){var ap=AppMgr.ACTIVE_PANEL;myAnim=new YAHOO.util.Anim(ap.title,{marginTop:{from:0,to:-140}},0.7,YAHOO.util.Easing.easeOut);myAnim.onComplete.subscribe(closeActivePanel);}
else{if(AppMgr.ACTIVE_PANEL){closeActivePanel();}
myAnim=new YAHOO.util.Motion(panel,{marginTop:{from:-140,to:0}},0.7,YAHOO.util.Easing.easeOut);myAnim.onStart.subscribe(function(){$$.add(that.parentNode.parentNode,'on');$(panel).style.display='block';AppMgr.appNav.style.marginLeft='0px';AppMgr.PANELS[panel]=true;AppMgr.ACTIVE_PANEL=that;});}
myAnim.animate();},activatePanels:function(){var showDesc=function(e){var thisApp;if(this.tagName.toLowerCase()=='a'){thisApp=this.title.toLowerCase();}
else{thisApp=this.id.toLowerCase();}
var descs=AppMgr.descDiv.tag('p');for(var i=0,descsLen=descs.length,desc;i<descsLen;i++){desc=descs[i];$$.add(desc,'hide');if(desc.id.split('-')[1]==thisApp){$$.remove(desc,'hide');}}};this.appNav=$('app-nav');var appLinks=this.appNav.tag('a');YAHOO.util.Event.on(appLinks,'click',this.togglePanel,true);YAHOO.util.Event.on(appLinks,'mouseover',showDesc,true);YAHOO.util.Event.on($$.all('frm-roll'),'mouseover',showDesc,true);var preOpen=$$.all('on',this.appNav,'li');if(preOpen.length>0){this.togglePanel(null,preOpen[0].tag('a')[0],true);}},parseOptions:function(e,that){var getType=function(u){var opts=$(u+'-opt').tag('input');for(var i=0,optsLen=opts.length,opt;i<optsLen;i++){opt=opts[i];if(opt.checked){return opt.value;}}};if(e){YAHOO.util.Event.stopEvent(e);that=this;}
AppMgr.clearError();var args={};var errors=[];var queryString='';var fields=that.elements;var stripElems=['user','hashtag','user1','user2','users','query'];for(var i=0,fieldsLen=fields.length,field,fn,fv;i<fieldsLen;i++){field=fields[i];if(field.type=='text'){fn=field.name;if($$.has(field,'number')){fv=Number(field.value);if(isNaN(fv)||fv<100||fv>1500){field.value=fv;errors.push('<p>Sorry. Max Results must be a valid number between 100 and 1500.</p>');continue;}}
else{fv=YAHOO.util.Lang.trim(field.value);if(stripElems.indexOf(fn)>=0){fv=fv.replace(/^[@#]/,'');if(fn=='users'){fv=fv.replace(/[@;, ]+/g,' ');var fv_split=fv.split(' ');for(var u=0,uLen=fv_split.length;u<uLen;u++){if(!(/^[A-Za-z0-9_]+$/i).test(fv_split[u])){field.value=fv_split.join(' ');errors.push('<p>'+fn.substr(0,1).toUpperCase()+fn.substr(1)+' is invalid.</p>');continue;}}
fv=fv_split.join(' ');}
else{if(!(/^[A-Za-z0-9_]+$/i).test(fv)){field.value=fv;errors.push('<p>'+fn.substr(0,1).toUpperCase()+fn.substr(1)+' is invalid.</p>');continue;}}}}
if(fv=='<'+fn+'>'){fv='';}
if($$.has(field,'required')){if(fv===''){field.value=fv;errors.push('<p>'+fn.substr(0,1).toUpperCase()+fn.substr(1)+' is a required field.</p>');continue;}}
field.value=fv;if(typeof args[fn]=='undefined'){if((/^user[1-2]/i).test(fn)){var fv_type=getType(fn);args[fn]={name:fv,type:fv_type};fv=fv+'|'+fv_type;}
else{args[fn]=fv;}}
queryString+=fn+':'+fv+',';}}
if(typeof args.user1!=='undefined'&&typeof args.user2!=='undefined'){args.users=[args.user1,args.user2];delete args.user1;delete args.user2;}
if(errors.length>0){AppMgr.displayError(errors.join('\n'));}
else{AppMgr.startApp(that.name,args);if(document.domain.indexOf('infinityplusone.dev')<=0){queryString='http://twitter.infinityplusone.com/?app='+that.name.toLowerCase()+'&qs='+queryString;AppMgr.logInstats(queryString);}}},activateForms:function(){var clearField=function(e){if(this.type=='text'&&!$$.has(this,'focus')){if(this.name!=='total'){this.value='';}
$$.add(this,'focus');}
YAHOO.util.Event.removeListener(this,'focus');};YAHOO.util.Event.on($('twitter').tag('input'),'focus',clearField);YAHOO.util.Event.on($.tag('form'),'submit',this.parseOptions);},startApp:function(app,args){switch(app){case'SearchFavorites':AppMgr.CURRENT=new YAHOO.IPO.app.SearchFavorites(args);break;case'DeepSearch':AppMgr.CURRENT=new YAHOO.IPO.app.DeepSearch(args);break;case'TweetToBlog':AppMgr.CURRENT=new YAHOO.IPO.app.TweetToBlog(args);break;case'SearchFriends':AppMgr.CURRENT=new YAHOO.IPO.app.SearchFriends(args);break;case'TwinCommon':AppMgr.CURRENT=new YAHOO.IPO.app.TwinCommon(args);break;}},logInstats:function(queryString){},_init:function(){this.errMsgDiv=$('errMsg').empty();this.descDiv=$('app-desc');this.activateForms();this.activatePanels();$$.remove(document.getElementById('app-container'),'loading');}};YAHOO.IPO.widget.Sortable=Sortable;YAHOO.IPO.widget.TweetList=TweetList;YAHOO.IPO.widget.UserList=UserList;YAHOO.IPO.widget.User=User;YAHOO.IPO.app.AppMgr=AppMgr;YAHOO.IPO.app.TwitterApp=TwitterApp;YAHOO.IPO.app.DeepSearch=DeepSearch;YAHOO.IPO.app.SearchFavorites=SearchFavorites;YAHOO.IPO.app.TweetToBlog=TweetToBlog;YAHOO.IPO.app.SearchFriends=SearchFriends;YAHOO.IPO.app.TwinCommon=TwinCommon;})();