﻿var MAX_RESULTS=40;var divtiempo=0;function html_entity_decode(str){var ta=document.createElement("textarea");ta.innerHTML=str.replace(/</g,"&lt;").replace(/>/g,"&gt;");return ta.value;}function ruwhL(text){var exp=/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;return text.replace(exp,"<a href='$1'>$1</a>");}function rawhL(text){var exp=/\@([a-zñA-Z0-9_]+?\s)/gi;text=text.replace(exp,"<a href='http://twitter.com/$1'>@$1</a>");var exp1=/\@([a-zñA-Z0-9_]+?)[:,.)?!]/gi;return text.replace(exp1,"<a href='http://twitter.com/$1'>@$1</a>");}function rhtwhL(text){var exp=/\#([a-zñA-Z0-9_]+?\s)/ig;text=text.replace(exp,"<a href='http://taiper.com/temas/?t=%23$1'>#$1</a>");var exp1=/\#([a-zñA-Z0-9_]+?)[:,.!?")]/ig;return text.replace(exp1,"<a href='http://taiper.com/temas/?t=%23$1'>#$1</a>");}function sS(num){var tiempo=parseInt(num)+5;return tiempo;}function taE(tiempo,usuario,status){var mtim=tiempo;var ae=' ';if(mtim<=60){ae='<a href="http://twitter.com/'+usuario+'/status/'+status+'"> hace '+mtim+' segundos </a>';}else{if((mtim>60)&&(mtim<120)){ae='<a href="http://twitter.com/'+usuario+'/status/'+status+'"> hace 1 minuto '+Math.floor(((mtim/60)-Math.floor(mtim/60))*60)+' segundos </a>';}else{if((mtim>60)&&(mtim<=3600)){ae='<a href="http://twitter.com/'+usuario+'/status/'+status+'"> hace '+Math.floor(mtim/60)+' minutos '+Math.floor(((mtim/60)-Math.floor(mtim/60))*60)+' segundos </a>';}else{if((mtim>3600)&&(mtim<7200)){ae='<a href="http://twitter.com/'+usuario+'/status/'+status+'"> hace 1 hora '+Math.floor(((mtim/3600)-Math.floor(mtim/3600))*60)+' minutos </a>';}else{if((mtim>7200)&&(mtim<=86400)){ae='<a href="http://twitter.com/'+usuario+'/status/'+status+'"> hace '+Math.floor(mtim/3600)+' horas '+Math.floor(((mtim/3600)-Math.floor(mtim/3600))*60)+' minutos </a>';}else{if((mtim>86400)&&(mtim<172800)){ae='<a href="http://twitter.com/'+usuario+'/status/'+status+'"> hace 1 d&iacute;a '+Math.floor(((mtim/86400)-Math.floor(mtim/86400))*60)+' horas </a>';}else{ae='<a href="http://twitter.com/'+usuario+'/status/'+status+'"> hace '+Math.floor(mtim/86400)+' d&iacute;as '+Math.floor(((mtim/86400)-Math.floor(mtim/86400))*60)+' horas </a>';}}}}}}return ae;}function twitter_search(){var url='http://search.twitter.com/search.json?lang=es&geocode=-12.078692,-76.981169,650km&rpp=40&callback=?';$('.twitter_search').each(function(){var container=$(this);var search=container.attr('title');if(search){if(container.siblings('h1').length==0){if(search=='#'){container.parent().prepend('<br/><br/><h1> Peruanos Tweeteando (beta) </h1>');}else{container.parent().prepend('<br/><br/><h1> Peruanos Tweeteando sobre '+search+' o #'+search+'</h1>');}}var since_id=0;if(container.children().length){since_id=container.children(':first').attr('id').replace('#','');}$.getJSON(url,{'q':search,'since_id':since_id},function(data){if(data.results.length){for(i in data.results.reverse()){var r=data.results[i];var div=$('<div id="#'+r.id+'"></div>');div.hide();div.addClass('twitter_result');div.append('<a href="http://www.twitter.com/'+r.from_user+'"> <img src="'+r.profile_image_url+'" /> </a>');div.append('<a href="http://twitter.com/'+r.from_user+'">'+r.from_user+': </a>');var mt=r.text;mt=ruwhL(mt);mt=rawhL(mt);mt=rhtwhL(mt);div.append('<span> '+mt+'</span>');var dive=$('<div id="xi#'+r.id+'" class="extra_info"></div>');var currentTime=new Date();var mtim=strtotime(r.created_at);var mu=r.from_user;dive.append('<div class="escondido" id="mu'+divtiempo+'">'+mu+'</div>');var ms=r.id;dive.append('<div class="escondido" id="ms'+divtiempo+'">'+ms+'</div>');mtim=(Math.floor(currentTime.getTime()/1000))-mtim;dive.append('<div class="escondido" id="mtim'+divtiempo+'">'+mtim+'</div>');var tiempoa=taE(mtim,mu,ms);dive.append('<br/><div style="display:inline" id="hace'+divtiempo+'">'+tiempoa+'</div>');divtiempo++;if(r.to_user!=undefined){dive.append('<a href="http://twitter.com/'+r.from_user+'/status/'+r.id+'"> en respuesta a '+r.to_user+'</a>');}dive.append(' desde '+html_entity_decode(r.source));dive.append('<span style="float: right;"><a href="http://twitter.com/?status=RT @'+html_entity_decode(r.from_user)+' '+html_entity_decode(r.text)+'"> Retweetear </a></span>');dive.append('<span style="float: right;"><a href="http://twitter.com/?status=@'+r.from_user+' &in_reply_to_status_id='+r.id+'&in_reply_to='+r.from_user+'"> Responder </a></span>');div.append(dive);div.corner();container.prepend(div);div.slideDown('slow');}}if(container.children().length>MAX_RESULTS)
{to_remove=MAX_RESULTS-container.children().length;container.children().slice(to_remove).each(function(){$(this).slideUp();});}});}else{location.href="http://taiper.com/temas/?t=%23";}});};$(document).ready(function(){twitter_search();setInterval("twitter_search();",25000);setInterval(function(){for(var i=0;i<divtiempo;i++){var mti=sS(document.getElementById("mtim"+i+"").innerHTML);var mus=document.getElementById("mu"+i+"").innerHTML;var me=document.getElementById("ms"+i+"").innerHTML;var tiempo=taE(mti,mus,me);document.getElementById('mtim'+i+'').innerHTML=mti;document.getElementById('hace'+i+'').innerHTML=tiempo;}},5000)});
