// NB. assumes "photo_metadata" variable is already available and populated

// write out a photo img tag to document based on photo's title
function photo(title, size)
{
  if (title in photo_metadata)
  {
    output = html_flickr_img(photo_metadata[title].flickr_path, size, title);
  }
  else
  {
    output = "(Unknown photo " + title + " )";
  }
  document.write(output);
}

// write out photo img tag to document based on flickr path
function img(path, size)
{
  document.write(html_flickr_img(path, size));
}

// construct HTML that displays a flickr photo based on flickr path
function html_flickr_img(path, size, title)
{
  var img_id = path.match(/\d{9}/);
  //output = "<a href='http://www.flickr.com/photos/michalg/" + img_id + "/'><img border=0 src='http://static.flickr.com" + path + "'</a>";

  if (title) { title = "View larger photo (" + title + ")"; }
  else       { title = "View larger photo"; }

  output = "<a title='" + title + "' href='http://www.flickr.com/photo_zoom.gne?id=" + img_id + "&size=o'><img border=0 src='http://static.flickr.com" + path;
  if (size) { output += "_" + size; }
  output += ".jpg'></a>";

  return output;
}

function taggedwith(tag)
{
  flickrtag = "<span style='color: #0063DC;'>" + tag.substring(0,tag.length-1) + "</span><span style='color: #FF0084'>" + tag.substring(tag.length-1,tag.length) + "</span>";
  document.write("<a style='font: sans-serif; font-weight: bold; text-decoration: none;' title=\"Michal's photos tagged with " + tag + "\" href='http://www.flickr.com/photos/michalg/tags/" + tag + "'>" + flickrtag + "</a>");
}

function flickr2js(url)
{
  var thing = url.match(/\/..\/........._........../);
  if (thing)
  {
    return '<script>img("' + thing + '","m")</script>';
  }
  else
  {
    return 'Unparsable URL';
  }
}

function el(x) { return document.getElementById(x); }

