var Ping={maxrequests:2,requests:0,periodical:{queue:null,json:null},timestamp:null,timer:null,active:true,queue:[],msg:null,init:function(){if($("actividad")){Ping.timer=$time();Ping.index=$("ping-timestamp").getProperty("title").toInt();Ping.timestamp=Ping.strtotime($$("#ping-update span.updated")[0].getProperty("title"));Ping.periodical.queue=Ping.update.periodical(5000,Ping);Ping.periodical.json=Ping.load.periodical(60000,Ping);Ping.load.delay(2000,Ping);$("ping-update").addEvent("mouseenter",Ping.stop).addEvent("mouseleave",Ping.start);$("ping-end").removeEvents("click");Ping.msg=$("ping-end").getParent().getParent();$("ping-end").addEvent("click",function(a){new Event(a).stop();$("ping-update").setOpacity(1);Ping.msg.toggleClass("hide")});$("ping-start").addEvent("click",function(b){new Event(b).stop();Ping.msg.toggleClass("hide");$("ping-update").setOpacity(1);Ping.requests=0;Ping.periodical.queue=Ping.update.periodical(5000,Ping);Ping.periodical.json=Ping.load.periodical(60000,Ping);Ping.load.delay(2000,Ping);var a=Math.round(($time()-Ping.timer)/1000);Ping.timestamp=Ping.index+a;Ping.queue=[]})}},start:function(){if(Ping.active){Ping.periodical.queue=Ping.update.periodical(5000,Ping)}},stop:function(){if(Ping.active){$clear(Ping.periodical.queue)}},update:function(){if(Ping.queue.length>0){var a=Ping.queue.shift();a=Ping.create(a).injectTop($("ping-update"));var b=Math.round(($time()-Ping.timer)/1000);$$("#ping-update span.updated").each(function(c){c.set("text",Ping.timediff((Ping.index-Ping.strtotime(c.getProperty("title")))+b))});a.fade(1);$("ping-update").getLast().fade(0)}},top:function(){Ping.scroll.toBottom();this.remove()},load:function(){if($("actividad").hasClass("hide")){return}Ping.requests++;if(Ping.requests>Ping.maxrequests){$clear(Ping.periodical.queue);$clear(Ping.periodical.json);$("ping-update").setOpacity(0.5).removeEvent("mouseenter",Ping.stop).removeEvent("mouseleave",Ping.start);Ping.msg.toggleClass("hide");return}new Request.JSON({url:Site.base+"/ajax/json/"+Ping.timestamp,onComplete:function(a){if(a.length){Ping.timestamp=Ping.strtotime(a.getLast().fecha_anotacion)}Ping.queue.extend(a)}}).send()},create:function(c){return new Element("li",{"class":"hentry "+(c.tipo==1?"entry-new":"entry-voted")}).adopt(new Element("div",{"class":"entry-avatar"}).adopt(a(c)),new Element("h3",{"class":"entry-title"}).adopt(new Element("a",{href:c.url_anotacion}).set("html",c.titulo_anotacion)),new Element("div",{"class":"entry-info"}).adopt(b(c),new Element("a",{href:c.url_bitacora}).set("html",c.nombre),new Element("span").set("html"," · "),new Element("a",{href:Site.base+"anotaciones/"+c.url_anotacion.substring(7)}).set("html","Votar"),new Element("span").set("html"," · "+c.votos+" puntos  · "),new Element("span",{"class":"updated published",href:c.url_anotacion,title:c.fecha_anotacion}).set("html",c.timediff)));function b(d){return new Element("span").set("text","En ");if(d.autor_anotacion){return[new Element("span").set("text","Por "),new Element("a",{href:d.url_usuario}).set("html",d.autor_anotacion),new Element("span").set("text"," en ")]}else{return new Element("span").set("text","En ")}}function a(d){if(d.alias){return new Element("a",{href:d.url_usuario,title:"Ver perfil de "+d.alias,"class":"entry-avatar-info"}).adopt(new Element("img",{src:"http://static3.bitacoras.com/thumb/"+d.alias}))}else{return new Element("a",{href:"/registro",title:"Usuario sin registrar","class":"entry-avatar-info"}).adopt(new Element("img",{src:"/images/system/user-thumbnail.png"}))}}},tags:function(b){var a=[];b.etiquetas_anotacion.each(function(c){a.push(new Element("li").adopt(new Element("a",{href:"canales/"+encodeURIComponent(c),rel:"tag"}).set("html",(c)?c:"Sin etiquetas")))});return a},strtotime:function(b){var a;if(a=b.match(/(\d{4})-(\d{2})-(\d{2})\s(\d{2}):(\d{2}):(\d{2})/)){return(new Date(a[1],a[2]-1,a[3],a[4],a[5],a[6])).getTime()/1000}},timediff:function(c){var c=Math.round(Math.abs(c));var b={age:0,month:0,day:0,hour:0,minute:0};if((c/(60*60*24))>365){b.age=Math.round((c/(60*60*24*365))%(60*60*365))}if((c/(60*60*24))>30){b.month=Math.round((c/(60*60*24*30))%(60*60*30))}if((c/(60*60))>24){b.day=Math.round((c/(60*60*24))-(b.month*30))}if((c/60)>60){b.hour=Math.round((c/(60*60))-(b.day*24))}b.minute=Math.round((c/60)-(b.hour*60));if(!b.minute){b.minute=1}var a="";if(b.age){a=b.age+(b.age==1?" año":" años")}else{if(b.month){a=b.month+(b.month==1?" mes":" meses")}else{if(b.day){a=b.day+(b.day==1?" dia":" dias")}else{if(b.hour){a=b.hour+(b.hour==1?" Hr":" Hr")}else{a=b.minute+(b.minute==1?" Min":" Min")}}}}return a}};function tabs_sidebar(){$$("#sidebar .tabs li a").each(function(a){a.addEvent("click",function(){$$(a.parentNode.parentNode).getElements("a").each(function(c){c.toggleClass("active")});var b=a.href.substring(a.href.indexOf("#"));$$(b).each(function(c){$(c.parentNode).getElements("ul[id]").toggleClass("hide")});return false})})}window.addEvent("domready",function(){Ping.init();tabs_sidebar()});