/*
	jQuery Scrolling Tweet Ticker 1.1.2 (June 25, 2011)
	Copyright 2010-2011 Scott Langendyk. All Rights Reserved.
	
	==============================================================================
	Basic Usage
	==============================================================================
		$('#tweetticker').tweetTicker({
			username : 'username'
		});
	
	*For additional documentation please reference readme.txt
*/

(function(a){a.fn.tweetTicker=function(c){var c=a.extend({},a.fn.tweetTicker.defaults,c);var t;var j;var k;var d;var p;var v;var r;var l;var f;var y=false;var e=true;var u=0;var m=0;var x={tweets:new Array()};var o={tweets:new Array(),sinceID:c.sinceID};return this.each(function(){if(c.tickerOnly==false){t=q()}else{t=a('<div class="tweetticker"><div class="tweetticker-replace"></div></div>')}a(this).append(t);j=a('<ul class="tweetticker-tweets-list"></ul>');k=a('<div class="tweetticker-overflow-container"></div>');d=a('<li class="tweetticker-loading"></li>');t.find("div.tweetticker-username ").html("@"+c.username);k.wrapInner(j);t.find("div.tweetticker-replace").replaceWith(k);j.append(d);b();a(window).resize(function(){w()});k.mouseover(function(){l=c.hoverRate});k.mouseout(function(){l=c.normalRate})});function h(){var A=parseInt(j.css("left").substr(0,j.css("left").length-2));if(A<f){var B=x.tweets.pop();g(B);m++}if(A<p){var z=v;v=v.next("li.tweetticker-tweet");z.remove();if(m>0){var B=x.tweets.pop();g(B)}else{m--;w()}j.css("left",A-p+"px");p=v.outerWidth(true)*-1}if(l>0){j.animate({left:"-=1px"},l,"linear",h)}else{h()}if(y==true){setTimeout(n,c.updateInterval)}y=false}function b(){d.text("Loading tweets...");n()}function n(){var z="http://api.twitter.com/1/statuses/user_timeline.json?screen_name="+c.username+"&include_entities=1&include_rts=1";if(c.sinceID>0){z=z+"&since_id="+o.sinceID}if(e){z=z+"&count="+c.maxInitialTweets}else{z=z+"&count="+c.maxTweetsPerUpdate}a.ajax({url:z,dataType:"jsonp",timeout:10000,success:function(E,G,D){if(E.length>0){if(!e){var B=new Array()}for(var A=0;A<E.length;A++){if(A==0){if(e){c.sinceID=E[A].id;o.sinceID=c.sinceID}else{o.sinceID=E[A].id}}var F=s(E[A]);if(F){if(e){x.tweets.unshift(F);j.append(F)}else{B.push(F)}}}if(x.tweets.length>0){if(e){v=j.children("li.tweetticker-tweet").first();p=v.outerWidth(true)*-1;w();l=c.normalRate}else{for(var C=0;C<B.length;C++){o.tweets.push(B.pop())}}if(c.liveUpdating==true){y=true}u=0}if(e){if(x.tweets.length>0){if(c.startOffScreen==true){j.css("left",k.width())}d.remove();h();e=false}else{if(u<c.maxFailedFetchAttempts){d.text("Tweets loaded incorrectly. Trying again momentarily...");u++;setTimeout(b,5000)}else{d.text("There was a problem parsing the Twitter feed.")}}}}else{d.text("User hasn't tweeted yet.")}},error:function(B,F,D){u++;console.log("There was an error");var A="Failed to load tweets.";var C=5000;var E=true;a.ajax({url:"http://api.twitter.com/1/account/rate_limit_status.json",dataType:"jsonp",success:function(H,I,G){if(H.remaining_hits<1){A="You are being rate limited by Twitter.";C=H.reset_time_in_seconds*1000;E=true}}});setTimeout(function(){if(u<c.maxFailedFetchAttempts||c.maxFailedFetchAttempts==0){if(!E){if(F=="error"){F="Error"}if(F=="timeout"){F="Timeout"}A=F+" while attempting to load tweets. Trying again momentarily..."}setTimeout(b,C)}if(e){d.text(A)}},1000)},complete:function(A,B){if(u<c.maxFailedFetchAttempts||c.maxFailedFetchAttempts==0){y=true}}})}function g(A){if(parseInt(a(A).attr("id"))==c.sinceID){if(o.tweets.length>0){var z=o.tweets.length;for(i=0;i<z;i++){var B=o.tweets.pop();x.tweets.unshift(B);j.append(B)}c.sinceID=o.sinceID}}x.tweets.unshift(A);j.append(A);w()}function w(){f=k.width()-j.width()}function s(C){var H=C.text;var A="http://twitter.com/"+c.username+"/statuses/"+C.id;var F=C.created_at;var G=F.substring(19,25);F=F.replace(G,"");F=Date.parseExact(F,"ddd MMM dd HH:mm:ss yyyy");if(F){if(G){F=F.setTimezoneOffset(G)}F=F.toString(c.dateFormat)}else{return null}var E=new Array();var B=null;var D=0;if(C.entities.urls.length>0){for(D=0;D<C.entities.urls.length;D++){B={};B.index1=C.entities.urls[D].indices[0];B.index2=C.entities.urls[D].indices[1];B.newText='<a rel="nofollow" href="'+C.entities.urls[D].url+'">'+H.substring(B.index1,B.index2)+"</a>";E.push(B)}}if(C.entities.hashtags.length>0){for(D=0;D<C.entities.hashtags.length;D++){B={};B.index1=C.entities.hashtags[D].indices[0];B.index2=C.entities.hashtags[D].indices[1];B.newText='<a rel="nofollow" href="http://search.twitter.com/search?q='+C.entities.hashtags[D].text+'">'+H.substring(B.index1,B.index2)+"</a>";E.push(B)}}if(C.entities.user_mentions.length>0){for(D=0;D<C.entities.user_mentions.length;D++){B={};B.index1=C.entities.user_mentions[D].indices[0];B.index2=C.entities.user_mentions[D].indices[1];B.newText='<a rel="nofollow" href="http://twitter.com/'+C.entities.user_mentions[D].screen_name+'">'+H.substring(B.index1,B.index2)+"</a>";E.push(B)}}if(E.length>0){E.sort(function(J,I){return J.index1-I.index1});var z=H.substring(0,E[0].index1);for(D=0;D<E.length;D++){z=z+E[D].newText;if(D+1<E.length){z=z+H.substring(E[D].index2,E[D+1].index1)}else{z=z+H.substring(E[D].index2)}}H=z}return'<li class="tweetticker-tweet" id="'+C.id+'"><span class="tweetticker-date"><a href="'+A+'">'+F+"</a></span>"+H+"</li>"}function q(){var z;z+='<div class="tweetticker">';z+='<div class="tweetticker-container">';z+='<div class="tweetticker-container-left"></div>';z+='<div class="tweetticker-container-content">';z+='<div class="tweetticker-username"><a href="#">@username</a></div>';z+='<div class="tweetticker-twitter-link"></div>';z+='<div class="tweetticker-tweetbox">';z+='<div class="tweetticker-tweetbox-left"></div>';z+='<div class="tweetticker-tweetbox-right"></div>';z+='<div class="tweetticker-tweetbox-content">';z+='<div class="tweetticker-replace"></div>';z+="</div>";z+="</div>";z+="</div>";z+='<div class="tweetticker-container-right"></div>';z+="</div>";z+="</div>";return a(z)}};a.fn.tweetTicker.defaults={username:"twitter",maxInitialTweets:20,maxTweetsPerUpdate:20,normalRate:25,hoverRate:100,sinceID:0,startOffScreen:true,liveUpdating:true,updateInterval:60000,maxFailedFetchAttempts:5,dateFormat:"dd/MM/yyyy h:mm tt",tickerOnly:false}})(jQuery);
