
function build_cloud( r ) {
  var element, html, anim, response, fontsize, max=1, min=9999, item;
  element = document.getElementById( "cloud" );
  element.innerHTML = 'Tag cloud loaded';
  response = YAHOO.lang.JSON.parse(r.responseText);
  html = '';
  for (item in response) {
    if ( response[item] > max ) {
      max = response[item];
    }
    if ( response[item] < min ) {
      min = response[item];
    }
  }
  for (item in response) {
    fontsize = 77 + ( 197-77 ) * ( response[item] - min ) / ( max - min )
    html += '<a style="font-size:' + fontsize + '%;" href="playalong_find.php?tag=' + item + '">' + item + '</a> ';
  }
  element.innerHTML = html;
  
  anim = new YAHOO.util.ColorAnim(element, { backgroundColor:{to:"#fff", from:"#f66"}, duration:1});
  anim.animate();
}

function cloud_failed() {
  var element, anim;
  element = document.getElementById( "cloud" );
  element.innerHTML = "Failed to load tag cloud";
  anim = new YAHOO.util.ColorAnim(element, { backgroundColor:{to:"#fff", from:"#f66"}, duration:1});
  anim.animate();
}

