function fetchDribbbleImages() {
  var request = new Xhr('./dribbbleshots.php', {
    evalJSON: true
  });
  
  request.on({
    success: function() {
      var dribbbleimages = $('dribbleimages');
      
      dribbbleimages.clean();
      
      var shots = this.responseJSON;
      
      for (var i = 0; i < 3 && i < shots.length; i++) {
        var shot = shots[i];
        
        var listitem = new Element('li');
        
        var figure = new Element('figure').insertTo(listitem);
        
        var link = new Element('a', {
          href: shot.link,
          title: shot.title,
          target: '_blank'
        }).insertTo(figure);
        
        var image = new Element('img', {
          src: shot.image,
          alt: shot.title
        }).insertTo(link);
        
        listitem.insertTo(dribbbleimages);
      }
    }
  });
  
  request.send();
}

$(document).on('ready', function() {
  fetchDribbbleImages();
});

