if (window.MooTools){
var hReplace = new Class({//implements
    Implements: [Options],
    options: {//options
      els: $$('body')[0],
      scriptLocation: 'hreplace.php'
    },initialize: function(options) {//initialization
      this.setOptions(options);//set options
      this.url = this.options.scriptLocation;
      this.els = this.options.els;
      this.els.each(function(el){
        if( el.getChildren().length == 0 ){
          this.processElement(el);
        }
      }.bind(this));

    },processElement: function(el){
      var msg = el.get('text');
      var fname = msg.toLowerCase() // change everything to lowercase
                      .replace(/^\s+|\s+$/g, "") // trim leading and trailing spaces
                      .replace(/[_|\s]+/g, "-") // change all spaces and underscores to a hyphen
                      .replace(/[^a-z0-9-]+/g, "") // remove all non-alphanumeric characters except the hyphen
                      .replace(/[-]+/g, "-") // replace multiple instances of the hyphen with a single instance
                      .replace(/^-+|-+$/g, "") // trim leading and trailing hyphens
                      ;

      switch(el.getStyle('text-transform')){
        case 'uppercase':
          msg = msg.toUpperCase();
        break;
        default:
          
          break;
      }
      var color = el.getStyle('color').hexToRgb(true);
      var qStr = new Hash({
        fname: el.get('tag').toString()+'.'+fname+'.png',
        msg: msg,
        red: color[0],
        grn: color[1],
        blu: color[2],
        size: el.getStyle('font-size').toInt()
      });
      qStr = qStr.toQueryString();
      var url = this.url+'?'+qStr;
      el.setStyles({
        'text-indent': '-33333px',
        'background': 'url('+url+') no-repeat'
      });
    }
  });
}