(function($) {
  Cufon.replace("#content h1, .blog #body h2");

  $(function() {
    // slideshow jank
    var slideshow = $("#slideshow ol"),
        slides    = $("#slideshow li"),
        nav       = $("#slideshow-nav");

    slideshow.css("width", slides.size() * 590);

    slides.each(function(i) {
      nav.append(
        '<li>' +
          '<a href="#">' + (i + 1) + '</a>' +
        '</li>'
      );
    });
    nav = nav.find('li');
    nav.eq(0).addClass("current");
    var current = nav.eq(0);

    nav.each(function(i) {
      $(this).data('index', i);
    });

    nav.find("a").click(function() {
      var index = $(this).parent().data('index');

      slideshow.animate({
        left: -1*(590*index)
      });

      current.removeClass("current");
      current = $(this).parent().addClass("current");

      location.hash = "slide-" + (index + 1)
      return false;
    });

    if (location.hash && /^#slide-(\d+)$/.test(location.hash)) {
      var index = parseInt(location.hash.match(/^#slide-(\d+)$/)[1]) - 1
      nav.eq(index).find("a").click();
    }
  });
})(jQuery);
