$(document).ready(function() {

  // slideshow
  if ($('.slider-canvas').length > 0) {
 
   var pagerSelector = '.slider-nav ul';
 
   // remove content on static slider controls
   $(pagerSelector).empty();
 
   $('.slider-canvas').cycle({
     fx: 'fade',
     pager: pagerSelector,
     pagerAnchorBuilder: function(index, element) {
       return '<li><a href="#">&bull;</a></li>';
     },
     pause: 1,
     timeout: 10000,
     speed: 900
   });
  }

  // load news
  $.getJSON("http://news.heroku.com/feed.js?format=json&callback=?", function(posts){
    var html = "<h2><a href='http://news.heroku.com'>Recent News</a></h2><dl>";
    $(posts).each(function(i, post){
      var date_parts = post.created_at.split('-')
      html += '<dt><a class="title" href="'+post.url+'">'+post.title+'</a></dt><dd>'+post.created_at+' - <a class="host" href="'+post.url+'">'+post.host+'</a></dd>';
      if (i == 4) return false // limit to 5 for now
    });
    html += "</dl>";
    $('#heroku-news').append(html);
  });
  // load events
  $.getJSON("http://news.heroku.com/events.js?format=json&callback=?", function(posts){
    var html = "<h2><a href='http://news.heroku.com/event'>Upcoming Events</a></h2><dl>";
    $(posts).each(function(i, post){
      html += '<dt><a class="title" href="'+post.url+'">'+post.title+'</a></dt><dd>'+post.date+' | '+ post.location +'</dd>';
      if (i == 4) return false // limit to 5 for now
    });
    html += "</dl>";
    $('#heroku-events').append(html);
  });
});
