var max_current=0;var max_history=0;var top=0;var client_height;var count=0;var i=0;var index;var state=1;var timeout;var tweet_obj;var user_obj=new Object();var speed=5000;var dbg=0;window.addEvent("domready",function(){init()});function init(){$("status").innerHTML="<h1>Hang out for a sec... (loading)</h1>";$("tweetList").set("morph",{duration:"long"});req.send()}var req=new Request({url:"index.php?route=celebapp/ajax",noCache:true,onSuccess:function(a){tweet_obj=$H(JSON.decode(a)).getValues();$("status").hide();if(typeof tweet_obj=="object"){index=0;updateUserObj();show_tweets()}else{$("status").innerHTML="<h1>Oh Noes!</h1> Our JSON is jacked! Try hitting refresh, or your monitor. Not sure if it will help, but it'll make you feel better."}},onFailure:function(a){$("status").innerHTML="<h1>Oh Noes!</h1> There was a problem downloading the tweets. Maybe you need to refresh the page, or something?<br />error:["+a+"]"}});function updateUserObj(){userHash=$A(tweet_obj);userHash.each(function(a){user_obj[a.id]={image:a.image,username:a.username,name:a.name,description:a.description}})}function show_tweets(){if(state!=1){clearTimeout(timeout);timeout=setTimeout("show_tweets()",speed);return false}if((count+1)%26==0){gc()}if(index>=tweet_obj.length){clearTimeout(timeout);alert("No More Tweets!");return false}var a=new Array("A839B2","FF0071","ACD030","58AA00","00AA78","0074AE");var b=tweet_obj[index];if(b.last_tweet>max_current){max_current=b.last_tweet}if(b.last_tweet<max_current&&b.last_tweet>max_history){max_history=b.last_tweet}json_req=JSON.encode({title:b.name+" - (@"+b.username+")",desc:b.status});twitter_link="http://twitter.com/home/?status="+url.encode("RT @"+b.username+" "+((b.name.length+b.status.length)>120?b.status.substring(0,120):b.status)+" http://bit.ly/fametweet");fb_link="http://www.facebook.com/share.php?u=http://www.celebritiesthattwitter.com/?i="+url.encode(json_req);inside='<div class="inside"><span><a style="color:#'+a[i]+';text-decoration:none;cursor:pointer" href="http://www.twitter.com/'+b.username+"/status/"+b.last_tweet+'" onMouseOver="modal.show('+b.id+',this)" target="new" onMouseOut="modal.hide()">'+b.name+"</a></span> "+b.status.replace(/(http\:\/\/[\w\.\-\?\!\&\=]+\/\S*)/gi,'<a rel="nofollow" target="new" href="$1">$1</a>')+'<span style="padding-right:10px;">&nbsp</span><span style="white-space:nowrap;vertical-align:bottom;position:relative"><a href="'+fb_link+'" title="Share This Tweet On Facebook"><img src="capsules/celebapp/public/img/fbico.png" style="opacity:0.5;bottom:0" onMouseover="this.setStyle(\'opacity\',1.0)" onMouseout="this.setStyle(\'opacity\',0.5)" width="20" height="20"></a>&nbsp;<a href="'+twitter_link+'" title="Retweet this on Twitter"><img src="capsules/celebapp/public/img/twitterico.png" style="opacity:0.5;bottom:0" onMouseover="this.setStyle(\'opacity\',1.0)" onMouseout="this.setStyle(\'opacity\',0.5)" width="20" height="20"></a></span></div>';if(i<(a.length-1)){i++}else{i=0}elem=new Element("li",{styles:{height:"auto"}});elem.set("html",inside);$("tweetList").grab(elem,"bottom");index++;count++;if(dbg==1){$("status").innerHTML="Index: "+index+" Count: "+count+" Max Current: "+max_current+" Max History: "+max_history}if(count>6){top+=elem.scrollHeight;$("tweetList").setStyle("bottom","-"+elem.scrollHeight+"px");$("tweetList").morph({bottom:"0px",top:"-"+top+"px"})}if((count==6)){$("container").morph({height:$("tweetList").scrollHeight+"px"});$("tweetList").setStyle("height","auto");client_height=$("container").scrollHeight}if(index==tweet_obj.length){if(tweet_obj.length<2){max_history=0}clearTimeout(timeout);if(dbg==1){$("status").innerHTML="Getting more tweets..."}setTimeout("req.send('&max_current='+max_current+'&max_history='+max_history)",speed)}else{timeout=setTimeout("show_tweets()",speed)}if(client_height>0){$("container").morph({height:client_height})}}function gc(){$("tweetList").setStyles({bottom:"0px",top:"-"+top+"px"});var a=0;$$("#tweetList li").slice(0,18).each(function(b){a+=b.clientHeight;b.dispose()});top=top-a;$("tweetList").setStyle("top","-"+top+"px");if(dbg==1){$("status").innerHTML="Garbage Collection ran"}}var modal={show:function(b,a){state=2;content='<div id="modal"><span><img width="60" height="60" src="'+user_obj[b]["image"]+'"></span><span style="vertical-align:top;position:absolute;padding:0 5px 0 5px"><b>'+user_obj[b]["name"]+"</b><br />"+user_obj[b]["description"]+"</span></div>";box=new StickyWin({content:content,width:300,height:250,offset:{x:15,y:-15},relativeTo:a,edge:"upperLeft",position:"right"});box.addEvent("onDisplay",function(){$("modal").setStyle("opacity",0.9)})},hide:function(){box.destroy();state=1;clearTimeout(timeout);timeout=setTimeout("show_tweets()",speed)}};var url={unicodeStr:"",hexEscStr:"",hash_map:{"'":"%27","(":"%28",")":"%29","*":"%2A","~":"%7E","!":"%21","%20":"+","\u00DC":"%DC","\u00FC":"%FC","\u00C4":"%D4","\u00E4":"%E4","\u00D6":"%D6","\u00F6":"%F6","\u00DF":"%DF","\u20AC":"%80","\u0081":"%81","\u201A":"%82","\u0192":"%83","\u201E":"%84","\u2026":"%85","\u2020":"%86","\u2021":"%87","\u02C6":"%88","\u2030":"%89","\u0160":"%8A","\u2039":"%8B","\u0152":"%8C","\u008D":"%8D","\u017D":"%8E","\u008F":"%8F","\u0090":"%90","\u2018":"%91","\u2019":"%92","\u201C":"%93","\u201D":"%94","\u2022":"%95","\u2013":"%96","\u2014":"%97","\u02DC":"%98","\u2122":"%99","\u0161":"%9A","\u203A":"%9B","\u0153":"%9C","\u009D":"%9D","\u017E":"%9E","\u0178":"%9F"},replacer:function(c,b,d){var a=[];a=d.split(c);return a.join(b)},encode:function(b){var a=encodeURIComponent((b+"").toString());for(unicodeStr in this.hash_map){hexEscStr=this.hash_map[unicodeStr];a=this.replacer(unicodeStr,hexEscStr,a)}return a.replace(/(\%([a-z0-9]{2}))/g,function(e,d,c){return"%"+c.toUpperCase()})},decode:function(b){var a=b.toString();for(unicodeStr in hash_map){hexEscStr=hash_map[unicodeStr];a=this.replacer(hexEscStr,unicodeStr,a)}return decodeURIComponent(a)}};function print_r(a){if(a.constructor==Array||a.constructor==Object){document.write("<ul>");for(var b in a){if(a[b].constructor==Array||a[b].constructor==Object){document.write("<li>["+b+"] => "+typeof(a)+"</li>");document.write("<ul>");print_r(a[b]);document.write("</ul>")}else{document.write("<li>["+b+"] => "+a[b]+"</li>")}}document.write("</ul>")}};