var DynamicTextReplacement = new Class({
	Implements: Options,
	options: {
		scriptURL: 'http://www.50todeath.com/dtr/font.php',
		classArray: ['blog_title_dtr', 'regular_dtr', 'menu_link_dtr', 'menu_regular_dtr', 'medium_dtr', 'menu_title_dtr', 'menu_link_over_dtr', 'video_link_dtr', 'site_seeing_link_dtr']
	},
	initialize: function(options) {
		this.setOptions(options);
		this.options.classArray.each(function(dtr_class) {
			$$('.' + 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'));
					});
					if (dtr_class == 'menu_link_dtr')
					{
						theImage.store('main_src', this.options.scriptURL + '?text=' + encodeURIComponent(theText) + '&style=' + 'menu_link_dtr');
						theImage.store('hover_src', this.options.scriptURL + '?text=' + encodeURIComponent(theText) + '&style=' + 'menu_link_over_dtr');
						
						var preLoadImage = new Asset.image(this.options.scriptURL + '?text=' + encodeURIComponent(theText) + '&style=' + 'menu_link_over_dtr');
						theImage.addEvent('mouseenter', function() {
							this.setProperty('src', this.retrieve('hover_src'));
						});
						theImage.addEvent('mouseleave', function() {
							this.setProperty('src', this.retrieve('main_src'));
						});
					}
					if (dtr_class == 'video_link_dtr')
					{
						theImage.store('main_src', this.options.scriptURL + '?text=' + encodeURIComponent(theText) + '&style=' + 'video_link_dtr');
						theImage.store('hover_src', this.options.scriptURL + '?text=' + encodeURIComponent(theText) + '&style=' + 'video_link_over_dtr');
						
						var preLoadImage = new Asset.image(this.options.scriptURL + '?text=' + encodeURIComponent(theText) + '&style=' + 'video_link_over_dtr');
						theImage.addEvent('mouseenter', function() {
							this.setProperty('src', this.retrieve('hover_src'));
						});
						theImage.addEvent('mouseleave', function() {
							this.setProperty('src', this.retrieve('main_src'));
						});
					}
					
					if (dtr_class == 'site_seeing_link_dtr')
					{
						theImage.store('main_src', this.options.scriptURL + '?text=' + encodeURIComponent(theText) + '&style=' + 'site_seeing_link_dtr');
						theImage.store('hover_src', this.options.scriptURL + '?text=' + encodeURIComponent(theText) + '&style=' + 'site_seeing_link_over_dtr');
						
						var preLoadImage = new Asset.image(this.options.scriptURL + '?text=' + encodeURIComponent(theText) + '&style=' + 'site_seeing_link_over_dtr');
						theImage.addEvent('mouseenter', function() {
							this.setProperty('src', this.retrieve('hover_src'));
						});
						theImage.addEvent('mouseleave', function() {
							this.setProperty('src', this.retrieve('main_src'));
						});
					}
					
					//append the image to the original object
					element.grab(theImage);	
				}
				//set the objects css to display
				element.setStyle('display', 'block');
				element.removeClass(dtr_class);
			}, this);
		}, this);
	}					   
});