(function(){
  // Download (bigger) images
  if (screen.width > 480) {
    var list = document.getElementsByClassName('project');
    for (i in list) {
      try {
        var id = list[i].id;
        var a = list[i].getElementsByTagName('a')[0];
        if (a.className !== 'noimage') {
          var title = a.textContent;
          a.innerHTML = '<img src="/images/' + id + '.png" alt="' + title + '">';
        }
      } catch (err) {}
    }
  }
  // COTW Video
  var v = document.getElementById('cotw-video');
  v.innerHTML = '<iframe src="http://player.vimeo.com/video/12772935?title=0&amp;byline=0&amp;portrait=0" width="228" height="128" frameborder="0" webkitAllowFullScreen allowFullScreen></iframe>';
  var w, h, i = v.getElementsByTagName('iframe')[0];
  var videoResize = function(){
    w = v.clientWidth;
    w = w > 600 ? 600 : w; // Max width is 600px
    h = w / 1.7778;
    i.setAttribute('width', w);
    i.setAttribute('height', h);
  };
  // Resize now
  videoResize();
  // Detect orientation change
  window.addEventListener('orientationchange', videoResize, false);
}).call(this);
