window.onunload = function(){};

var randomThings = [
    ["Clara Nunes", "/offtopic/clara-nunes.html"],
    ["Totó La Momposina", "/offtopic/toto-la-momposina.html"],
    ["Elis Regina", "http://www.last.fm/music/Elis+Regina"],
    ["Marisa Monte", "http://www.last.fm/music/Marisa+Monte"],
    ["Caetano Veloso", "http://www.last.fm/music/Caetano+Veloso"],
    ["Gilberto Gil", "http://www.last.fm/music/Gilberto+Gil"],
    ["The New York Yankees", "http://yankees.lhblogs.com/"],
    ["Lo de Paka", "http://www.guiaoleo.com.ar/detail.php?ID=1958"],
    ["Conrad Aiken", "http://en.wikipedia.org/wiki/Conrad_Aiken"],
    ["Jorge Luis Borges", "http://www.themodernword.com/borges/"],
    ["Ruby", "http://www.ruby-lang.org/"],
    ["Lua", "http://www.lua.org/"],
    ["Etymology", "http://www.etymonline.com/"],
    ["Plato's Republic", "http://classics.mit.edu/Plato/republic.html"],
    ["Mae Phim", "http://www.yelp.com/biz/mae-phim-thai-seattle-3"],
    ["Ilha Grande", "http://www.flickr.com/search/?q=Ilha%20Grande%2C%20Brazil&amp;w=all"],
    ["Pipa", "http://www.flickr.com/search/?w=all&amp;q=Pipa%2C+Brazil&amp;m=text"],
    ["Chipotle Tabasco Sauce", "http://www.tabasco.com/tabasco_tent/pepper_sauce/chipotle_pepper_sauce.cfm"],
    ["Theoretical Linguistics", "http://web.mit.edu/linguistics/"],
    ["Sierra Nevada Celebration Ale", "http://www.sierranevada.com/beers/celebrationale.html"],
    ["German Beer", "http://www.germanbeerinstitute.com/"],
    ["Homebrewing", "http://beertown.org/homebrewing/index.html"],
    ["Dashi", "http://www.dashi.com.ar/"],
    ["Birds of Argentina &amp; Uruguay", "http://www.amazon.com/Birds-Argentina-Uruguay-Tito-Narosky/dp/9509906336"],
    ["Jasper National Park", "http://www.pc.gc.ca/pn-np/ab/jasper/index_e.asp"],
    ["Ruby on Rails", "http://rubyonrails.org/"],
    ["Javascript", "http://www.crockford.com/javascript/"],
    ["Ernesto Jerez", "http://en.wikipedia.org/wiki/Ernesto_Jerez"],
    ["Bagels", "http://elbagelazo.blogspot.com/"],
    ["Belgrano", "http://www.mibelgrano.com.ar/"],
    ["Big Daddy Kane", "http://www.last.fm/music/Big+Daddy+Kane"],
    ["Debian Linux", "http://debian.org"],
    ["Bahía Blanca", "http://www.welcomeargentina.com/bahiablanca/index_i.html"],
    ["Compass", "http://compass-style.org/"],
    ["Haml", "http://haml-lang.com"],
    ["Buenos Aires", "http://www.flickr.com/search/?q=Buenos%20Aires&w=all"],
    ["Song of Senlin", "http://www.infoplease.com/t/poetry/modern-verse/morning-song.html"],
];

function shuffle(arr) {
    for(
        var j, x, i = arr.length; i;
        j = parseInt(Math.random() * i),
        x = arr[--i], arr[i] = arr[j], arr[j] = x
    );
    return arr;
}

function shuffleRandomThings() {
    var buffer = [];
    shuffle(randomThings)
    buffer.push("<ul>");
    for (var i = 0; i < 10; i++) {
     buffer.push(['<li><a href="', randomThings[i][1], '">', randomThings[i][0], '</a></li>'].join(''));
    }
    buffer.push("</ul>");
    $('#random-things nav')[0].innerHTML = buffer.join("\n");
}

function loadDisqusThreads() {
  var query = '?';
  $("a.disqus-thread").each(function(i) {
    this.href = this.href + "#disqus_thread";
    var url = this.getAttribute("data-disqus-url")
    if (!url) { url = this.href; }
    query += 'url' + i + '=' + encodeURIComponent(url) + '&';
  });
  var script = document.createElement('script');
  script.type = "text/javascript";
  script.charset = "utf-8";
  script.src = "http://disqus.com/forums/randomba/get_num_replies.js" + query;
  $('head').append(script);
}

jQuery(function() {
  $("time").toRelativeTime()
  shuffleRandomThings();
  loadDisqusThreads();
  $('#more-random-things').click(function(event) {
    shuffleRandomThings();
    return false;
  });
});

if (!document.location.href.match("^http://127\.0\.0\.1")) {
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-3592613-1']);
  _gaq.push(['_trackPageview']);
  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
  })();
}


