// Text Replace


var tr = {
	init : function() {
		var to_replace = $('.tr');
		
		$(to_replace).each(
			function() {
				var bgcolor = $(this).css('background-color'), color = $(this).css('color'), font = $(this).css('font-family'), size = $(this).css('font-size'), text = $(this).html();
				
				var loc = '/themes/default/scripts/tr/tr.php?text=' + text;
				if( bgcolor ) loc += '&bgcolor=' + tr.color(bgcolor);
				if( color ) loc += '&color=' + tr.color(color);
				if( font ) loc += '&font=' + font;
				if( size ) loc += '&size=' + size;
				
				var img = new Image();
				img.src = loc;
				
				$(this).html('<img src="' + loc + '" alt="' + text + '" />');
			}
		);
		
		
	},
	color : function( str ) {
		str = str.replace('rgb(','');
		str = str.replace('rgba(','');
		str = str.replace(/\s/,'');
		str = str.replace(/\s/,'');
		str = str.replace(')','');
		str = str.replace('#','');
		return str;
	}
}
$(document).ready(tr.init);