var DynamicTextReplacement = new Class({
	Implements: Options,
	options: {
		scriptURL: 'http://www.sutter-group.com/assets/dtr/font.php',
		classArray: ['legend_label_dtr','quote_type', 'quote_title', 'quote_text']
	},
	initialize: function(options) {
		this.setOptions(options);
		this.options.classArray.each( function(dtr_class, class_index) {
			$$('.' + dtr_class).each( function(element, index) {
				//get the text inside the element
				var theText = element.get('text');
				
				if (theText)
				{
					//removes the existing text from the element
					element.set('text', '');
					
					//create an image object and set its source and alt to the text, and give the image a class
					var theImage = new Element('img', {'src':this.options.scriptURL + '?text=' + encodeURIComponent(theText) + '&style=' + dtr_class});
					theImage.store('altText', theText);
					theImage.addEvent('load', function(theText) {
						this.setProperty('alt', this.retrieve('altText'));
					});
					
					//append the image to the original object
					element.grab(theImage);	
				}
				//set the objects css to display
				if (dtr_class == 'legend_label_dtr')
				{
					element.setStyle('display', 'inline');
				}
				else
				{
					element.setStyle('display', 'block');
				}
				if ((dtr_class != 'quote_type') && (dtr_class != 'quote_title') && (dtr_class != 'quote_text'))
				{element.removeClass(dtr_class);}
			}, this);
		}, this);
	}					   
});