/* ALL CODE COPYRIGHT ZEHN 2009 */

/* finds tag spans, replaces them with a nice link and other stuff */

// call other functions on page load
document.observe("dom:loaded", function()
{
  The6YardBox.add_tag_links();
  document.observe('moreContent:added', The6YardBox.add_tag_links);
});

The6YardBox.add_tag_links = function()
{
  $$('span.tag').each(function(tagSpan) { new The6YardBox.TagLink(tagSpan); });
};

// representing a tag link
The6YardBox.TagLink = Class.create({
  initialize: function(span)
  {
    // first get the inner html of the span
    this.tag = span.innerHTML;
    this.tagURL = TO_WEB + 'tag/' +
      escape(this.tag.toLowerCase().replace(' ', '-')) + '/';
    
    // build the new link with which we will replace the span
    this.link = new Element('a', {
      'href': this.tagURL,
      'class': 'tag' });
    this.link.update(this.tag);
    
    span.hide();
    span.insert({ before: this.link });
    span.remove();
  }
});