/*
 * LiveTweets v1.1 - for jQuery 1.4.4
 * <link 2 codecanyon>
 *
 * Copyright 2011, Johan Dorper
 * You need to buy a license if you want use this script.
 * http://codecanyon.net/wiki/buying/howto-buying/licensing/
 *
 * Date: Jan 08 2011
 
 * Edit the tag variable below.
 * Any questions? hello@johandorper.com OR twitter.com/johandorper

 * LiveTweets is a JQuery plugin that lets you easily
 * load in Tweets from Twitter based on a valid Twitter
 * search operator.
 
 * Thx to Fox Junior for the timer Plugin: http://www.foxjunior.eu/
 */
(function(a){a.fn.liveTweets=function(b){var c={operator:"#google",timeBetweenTweets:5,showThumbnails:true,convertTextlink:true,linkHashtags:true,linkUsernames:true};var b=a.extend(c,b);return this.each(function(){tweetHolder=a(this);var r=[];var d=0;var k=0;var j=false;var i="small";var o="http://a2.twimg.com/a/1292975674/images/default_profile_2_normal.png";var m="http://www.twitter.com/";var u=escape(b.operator);var p=function(){var v="http://search.twitter.com/search.json?callback=?&rpp=5&q="+u;a.getJSON(v,function(w){a.each(w.results,function(x,y){if(!e(y.id)){r[k++]=y}});if(j==false){r.reverse();j=true}})};var q=function(v){u=escape(v);a(".tweet").remove();l();p()};a("#custSearch").click(function(){q(a("#keyword").val())});var e=function(w){var v=false;a.each(r,function(x,y){if(y.id==w){v=true}});return v};var h=function(w){var v=/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;return w.replace(v,"<a target='_blank' href='$1'>$1</a>")};var s=function(w){var v=/\#([a-zA-Z]+)([\s|\.\,:]+)*/g;return w.replace(v,"<a target='_blank' href='http://twitter.com/#search?q=%23$1'>#$1 </a>")};var g=function(w){var v=/\@([a-zA-Z]+)([\s|\.\,:]+)*/g;return w.replace(v,"<a target='_blank' href='http://twitter.com/$1'>@$1 </a>")};var f=function(v){if(b.convertTextlink){v=h(v)}if(b.linkHashtags){v=s(v)}if(b.linkUsernames){v=g(v)}return v};var t=function(y){var z=Date.parse(y);var w=new Date();var v=w.getTime();var A=parseInt((v-z)/1000);if(A<=0){return"Now"}if(A<=60){return"Seconds ago"}if(A<3600){return parseInt(A/60)+" minutes ago"}if(A<=1.5*3600){return"One hour ago"}if(A<23.5*3600){return Math.round(A/3600)+" hours ago"}if(A<1.5*24*3600){return"One day ago"}var x=y.split(" ");return x[4].replace(/\:\d+$/,"")+" "+x[2]+" "+x[1]+(x[3]!=w.getFullYear()?" "+x[3]:"")};var n=function(B,D){var C=r[B].text;var x=r[B].from_user;var v=r[B].profile_image_url;var w=r[B].created_at;var y="";if(B==0){y="first"}if(i=="large"){v=v.replace("_normal","")}if(v.indexOf("default_profile")>0){var A=a("<div class='tweet "+y+"' id='tweet_"+r[B].id+"'><img width='48' height='48' class='tweet_foto' src='"+o+"'/><div class='tweet_text'><a  class='profile' target='_blank' href='"+m+x+"'>@"+x+"</a> "+f(C)+"<span>"+t(w)+"</span></div></div>")}else{var A=a("<div class='tweet "+y+"' id='tweet_"+r[B].id+"'><img width='48' height='48' class='tweet_foto' src='"+v+"'/><div class='tweet_text'><a class='profile' target='_blank' href='"+m+x+"'>@"+x+"</a> "+f(C)+"<span>"+t(w)+"</span></div></div>")}tweetHolder.prepend(A);if(!b.showThumbnails){a("#tweet_"+r[B].id+" img").remove()}if(D=="normal"){a("#tweet_"+r[B].id).hide().slideDown(800)}if(a(".tweets div.tweet").size()>24){var z=0;a(".tweets div.tweet").each(function(){if(z>4){a(this).remove()}z++})}};var l=function(){r=[];d=0;k=0;j=false};p();jQuery.fjTimer({interval:(b.timeBetweenTweets*1000),repeat:true,tick:function(w,v){p()}});jQuery.fjTimer({interval:4000,repeat:true,tick:function(w,v){if(r[d]!=undefined){n(d++,"normal")}}})})}})(jQuery);jQuery.extend({fjFunctionQueue:function(b){if(b==null){if(jQuery.fjFunctionQueue.queue!=null&&jQuery.fjFunctionQueue.queue.queue.length>0){if(jQuery.fjFunctionQueue.queue.running){jQuery.fjTimer({interval:jQuery.fjFunctionQueue.queue.properties.interval,tick:function(d,h){var f=jQuery.fjFunctionQueue.queue.queue.shift();try{jQuery.fjFunctionQueue.queue.properties.onTick(jQuery.fjFunctionQueue.queue.index,f);jQuery.fjFunctionQueue.queue.index++}catch(g){jQuery.fjFunctionQueue();throw g}if(jQuery.fjFunctionQueue.queue.queue.length>0){jQuery.fjFunctionQueue()}else{jQuery.fjFunctionQueue.queue.running=false;jQuery.fjFunctionQueue.queue.index=0;jQuery.fjFunctionQueue.queue.properties.onComplete()}}})}else{jQuery.fjFunctionQueue.queue.running=true;jQuery.fjFunctionQueue()}}}else{if(jQuery.fjFunctionQueue.queue==null){jQuery.fjFunctionQueue.queue={index:0,running:false,queue:[],properties:{interval:1,onComplete:function(){},onStart:function(){},autoStart:true,onTick:function(d,e){e()}}}}var a=jQuery.fjFunctionQueue.queue.queue.length==0;if(jQuery.isFunction(b)){jQuery.fjFunctionQueue.queue.queue.push(b)}else{if(jQuery.isArray(b)){for(var c=0;c<b.length;c++){jQuery.fjFunctionQueue.queue.queue.push(b[c])}}else{jQuery.fjFunctionQueue.queue.properties=jQuery.extend(jQuery.fjFunctionQueue.queue.properties,b)}}if(a&&jQuery.fjFunctionQueue.queue.queue.length>0&&!jQuery.fjFunctionQueue.queue.running&&jQuery.fjFunctionQueue.queue.properties.autoStart){jQuery.fjFunctionQueue.queue.running=true;jQuery.fjFunctionQueue.queue.properties.onStart();jQuery.fjFunctionQueue.queue.running=false;jQuery.fjFunctionQueue()}}},fjTimer:function(b){b=jQuery.extend({interval:10,tick:function(){},repeat:false,random:false,onComplete:function(){},step:1},b);var a=0;var c=new function(){this.timerId=null;this.stop=function(){clearInterval(this.timerId)}};c.timerId=setInterval(function(){try{b.tick(a,c);a+=b.step}catch(d){alert(d)}if(b.repeat!==true&&((b.repeat*b.step)<=a||b.repeat===false)){c.stop();b.onComplete()}},b.interval)},fjTimerEach:function(a){var b=a.array;var c=a.tick;a.repeat=b.length;if(a.step!=null){a.repeat=Math.ceil(b.length/parseInt(a.step,10))}a.tick=function(d,e){c(d,b[d])};jQuery.fjTimer(a)}});
