/*****************************************************
 * Function: Replaces <h2>#{text}</h2> tags with 
 * <h2><img src="#{text}-hyphentated" alt="#{text}" /></h2>
 * It also strips non alpha-numeric characters and changes
 * ampersands to "and".
 *
 * Useage: var something = new replacer('#css .selector', '/image/folder/path');
 ****************************************************/
var replacer = Class.create();
replacer.prototype = {
  initialize: function(element, path){
    this.replacing = $$(element);

    this.replacing.each(function(obj, ind) {
      text = obj.innerHTML.gsub("&amp;", "and").strip().stripTags();
      image_slug = text.gsub("[^A-Za-z0-9 ]", "").gsub(" ", "-").gsub(":","").gsub("/","").underscore().dasherize().gsub("'","").gsub("--", "-");
      tag = new Element('img', { src: path + image_slug + '.gif', alt: text });
      obj.update(tag);
    });
  }
}

