/* 
 * Copyright (c) Day Barr 2009. All rights reserved.
 * By http://www.DayBarr.com for use at http://www.FeedRunner.net
 */
$(function(){var q=[],g=$("#gobutton").click(function(){if(g.value()=="Go"){c()}return false}),j=setTimeout(function(){var u=5,t=$("#countdown");var s=function(){t.text(u).show().fadeOut(1000,function(){if(u===0){c()}else{--u;s()}})};s()},1000),o={},e=$("#content"),c=function(){var s=$("#url").val(),t=$("<ul>").hide().appendTo(e);n(s,t);clearTimeout(j);$("#countdown").remove()},b=function(s){return s.replace(/^(https?:\/\/[^\/]+)\/.*/,"$1")},n=function(s,t){t.append($('<p class="loading">').text("Loading feed...")).fadeIn();$.ajax({url:"http://pipes.yahoo.com/pipes/pipe.run?_id=jLS87ckf3hG8m90APm7D0g&_render=json&url="+encodeURIComponent(s)+"&_callback=?",dataType:"jsonp",success:function(u){t.empty().hide();if(!u.value||!u.value.items||!u.value.items.length){t.append('<div class="error">No feed or empty feed');return}$.each(u.value.items,function(v,w){t.append($('<li class="feed-link">').append($("<a>").attr({href:w.link,id:"link"+i++,title:w.title}).text(w.title)))});d++},error:function(){t.append('<div class="error"><code>:(')},complete:function(){p(t)}})},r=function(s,v){var t=b(s),u="javascript";v.append($('<p class="loading">').text("Loading page content...")).fadeIn();$.ajax({url:"http://query.yahooapis.com/v1/public/yql?q="+encodeURIComponent("select * from html where url='")+encodeURIComponent(s)+encodeURIComponent("' and xpath=\"//a[not(starts-with('"+u+":',@href))]\"")+"&format=json&callback=?",dataType:"jsonp",success:function(y){v.empty().hide();if(!y.query||!y.query.results||!y.query.results.a||!y.query.results.a.length){v.append('<div class="error">No content');return}var w=y.query.results.a,x={};$.each(w,function(z,A){if(A.href.substr(0,t.length)!=t&&A.href.match("https?://")&&!x[A.href]){x[A.href]=1;var B=$.trim(A.content)||$.trim(A.title)||$.trim(A.img?A.img.alt:"")||((A.href.length<63)?A.href:(A.href.slice(0,60)+"..."));v.append($('<li class="page-link">').append($("<a>").attr({href:A.href,id:"link"+i++,title:B}).text(B)))}})},error:function(){v.append('<div class="error"><code>:(')},complete:function(){p(v)}})},p=function(t){var v=t.parent("li").data("depth")||0,u=v+1,s=q[u%(q.length-1)],w=f(s,0.75);if(u>m){m=u}t.children("li").each(function(y,x){$(x).data("depth",u).addClass("depth"+u).css({"background-color":"#"+s,"border-color":"#"+w})});t.find(">li>a").each(function(y,x){$(x).wrapInner($("<span>").css({"background-color":"#"+s,"padding-left":2})).css({background:"transparent url("+b($(x).attr("href"))+"/favicon.ico) no-repeat scroll center left","padding-left":18})});if(t.children("li").length){t.slideDown(2000,k)}else{t.show();setTimeout(k,100)}},i=0,h=0,d=0,m=0,k=function(){var v=$("li:not(.done)"),x=function(){return v.eq(Math.floor(Math.random()*v.length))},t=x();$("#current-depth").text(m);$("#link-count").text(i);$("#feed-count").text(d);if(t.length){var u=t.find(">a").attr("href").replace(/#.*$/,"");t.addClass("done");if(o[u]){t.append("Already visited");o[u].find(">a").after(" +");setTimeout(k,0);return}var w=$("<ul>").hide();t.append(w);o[u]=t;h++;var s=0;$("html,body").animate({scrollTop:t.offset().top-100},2000,function(){if(++s==2){if(t.hasClass("feed-link")){r(u,w)}else{n(u,w)}}})}else{if(confirm("Can't find any more feeds. Restart?")){location.reload()}}},a=function(s){return(65536*s.r+256*s.g+s.b).toString(16)},l=function(s){return{r:parseInt(s.slice(0,2),16),g:parseInt(s.slice(2,4),16),b:parseInt(s.slice(4,6),16)}},f=function(u,t){var s={};$.each(l(u),function(v,w){s[v]=Math.min(Math.floor(w*t),255)});return a(s)};(function(){var x=20,v=255,w=175,u={r:v,g:v,b:w},t=function(){q.push(a(u))},s=function(z,A){var y=(A>u[z])?1:-1;while(y*u[z]<=y*A){t();u[z]+=x*y}u[z]-=x*y};s("r",w);s("b",v);s("g",w);s("r",v);s("b",w);s("g",v)})();$("body").css("background-color","#"+q[0]);if(location.search){$.each(location.search.slice(1).split("&"),function(s,t){t=t.split("=");if(t[0]=="url"){$("#url").attr("value",decodeURIComponent(t[1]))}})}(function(){var s=(("https:"==document.location.protocol)?"https://ssl.":"http://www.");jQuery.getScript(s+"google-analytics.com/ga.js",function(){_gat._getTracker("UA-5628626-3")._trackPageview()})})()});
