function FadeText(target) {
	this.color_hex_r = 0;
	this.color_hex_g = 0;
	this.color_hex_b = 0;

	this.saved_hex_r = 0;
	this.saved_hex_g = 0;
	this.saved_hex_b = 0;
	this.saved_bg_hex_r = 255;
	this.saved_bg_hex_g = 255;
	this.saved_bg_hex_b = 255;

	this.step_r = 11;
	this.step_g = 11;
	this.step_b = 11;

	this.fade_times = 23;
	this.duration = 50;

	this.target = target;
	
	this.resetfadecolor = function() {
		this.color_hex_r = this.saved_hex_r;
		this.color_hex_g = this.saved_hex_g;
		this.color_hex_b = this.saved_hex_b;
	}

	this.setbgcolor = function() {
		this.color_hex_r = this.saved_bg_hex_r;
		this.color_hex_g = this.saved_bg_hex_g;
		this.color_hex_b = this.saved_bg_hex_b;
	}

	this.setfadecolor = function(r, g, b, bg_r, bg_g, bg_b) {
		this.saved_hex_r = r;
		this.saved_hex_g = g;
		this.saved_hex_b = b;
		this.saved_bg_hex_r = bg_r;
		this.saved_bg_hex_g = bg_g;
		this.saved_bg_hex_b = bg_b;
	
		this.step_r = parseInt((this.saved_bg_hex_r - this.saved_hex_r) / this.fade_times);
		this.step_g = parseInt((this.saved_bg_hex_g - this.saved_hex_g) / this.fade_times);
		this.step_b = parseInt((this.saved_bg_hex_b - this.saved_hex_b) / this.fade_times);
	
		this.resetfadecolor();
	}

	var _self = this;

// Fade out text
	this.fadeouttext = function() {
		execute = false;
		if (this.step_r >= 0) {
			if (this.color_hex_r < this.saved_bg_hex_r) execute = true;
			if (this.color_hex_g < this.saved_bg_hex_g) execute = true;
			if (this.color_hex_b < this.saved_bg_hex_b) execute = true;
		}
		else {
			if (this.color_hex_r > this.saved_bg_hex_r) execute = true;
			if (this.color_hex_g > this.saved_bg_hex_g) execute = true;
			if (this.color_hex_b > this.saved_bg_hex_b) execute = true;
		}

		if (execute) {
			this.color_hex_r += this.step_r;
			this.color_hex_g += this.step_g;
			this.color_hex_b += this.step_b;
			document.getElementById(this.target).style.color="rgb("+this.color_hex_r+","+this.color_hex_g+","+this.color_hex_b+")";
			setTimeout(function(){_self.fadeouttext();}, this.duration); 
		}
		else {
			this.setbgcolor();
			this.fadeintext();
		}
	}
	
// Fade in text
	this.fadeintext = function() {
		execute = false;
		if (this.step_r >= 0) {
			if (this.color_hex_r > this.saved_hex_r) execute = true;
			if (this.color_hex_g > this.saved_hex_g) execute = true;
			if (this.color_hex_b > this.saved_hex_b) execute = true;
		}
		else {
			if (this.color_hex_r < this.saved_hex_r) execute = true;
			if (this.color_hex_g < this.saved_hex_g) execute = true;
			if (this.color_hex_b < this.saved_hex_b) execute = true;
		}

		if (execute) {
			this.color_hex_r -= this.step_r;
			this.color_hex_g -= this.step_g;
			this.color_hex_b -= this.step_b;
			document.getElementById(this.target).style.color="rgb("+this.color_hex_r+","+this.color_hex_g+","+this.color_hex_b+")";
			setTimeout(function(){_self.fadeintext();}, this.duration); 
		}
		else {
			this.resetfadecolor();
			setTimeout(function(){_self.fadeouttext();}, this.duration); 
		}
	}

	this.run = function() {
		this.fadeouttext();
	}
	
} // End of Class FadeText
