var fader_c = function()
{
	this.random_a = [];
	this.timeout_a = [];
	this.fading_a = [];

	this.getRandomByRange = function(min_i, max_i)
	{
	    return Math.floor(Math.random() * (max_i - min_i + 1)) + min_i;
	};

	this.setOpacity = function(element_o, value_i)
	{
		element_o.style.opacity = value_i / 100;
		element_o.style.filter = 'alpha(opacity:' + value_i + ')';
	};

	this.setFadeStart = function(element_o, out_b)
	{
		var this_o = this;
		var counter_i = 0;
		var interval_i = 0;
		var success_b = false;

		var setFadeStep = function()
		{
			if (counter_i <= 100)
			{
				counter_i += (counter_i / 70) + 5;

				this_o.setOpacity(element_o, out_b ? counter_i : (100 - counter_i));
			}
			else
			{
				clearInterval(interval_i);

				this_o.fading_a[element_o.id] = false;
				this_o.setOpacity(element_o, out_b ? 100 : 100);
			}
		};

		if (element_o)
		{
			if (!this.fading_a[element_o.id])
			{
				this.fading_a[element_o.id] = true;
				success_b = true;

				interval_i = setInterval(setFadeStep, 4);
			}
		}

		return success_b;
	};

	this.setRandomImage = function(id_s)
	{
		document.getElementById(id_s).style.opacity = 0;
		document.getElementById(id_s).style.filter = 'alpha(opacity:0)';
		this.random_a.push(id_s);
	};

	this.setRandom = function()
	{
		var this_o = this;
		var active_a = [];

		var setRandomFade = function()
		{
			var random_i = this_o.getRandomByRange(0, this_o.random_a.length);

			if (!active_a[random_i])
			{
				var element_o = document.getElementById(this_o.random_a[random_i]);

				active_a[random_i] = true;
				var success_b = this_o.setFadeStart(element_o, true);

				if (success_b)
				{
					var setFadeStop = function()
					{
						active_a[random_i] = false;
						this_o.setFadeStart(element_o, false);
					};

					//setTimeout(setFadeStop, 4000);
				}
			}
		};

		setInterval(setRandomFade, 10);
	};

	this.setLinear = function()
	{
		var this_o = this;

		var counter_i = 0;
		var active_a = [];

		var setLinearFade = function()
		{
			var random_i = (counter_i++ % this_o.random_a.length);

			if (!active_a[random_i])
			{
				var element_o = document.getElementById(this_o.random_a[random_i]);

				active_a[random_i] = true;
				this_o.setFadeStart(element_o, true);

				var setFadeStop = function()
				{
					active_a[random_i] = false;
					this_o.setFadeStart(element_o, false);
				};

				setTimeout(setFadeStop, 2000);
			}
		};

		setInterval(setLinearFade, 400);
	};

	this.setFade = function(id_s, out_b)
	{
		clearTimeout(this.timeout_a[id_s]);

		var this_o = this;

		var setFade = function()
		{
			this_o.setFadeStart(document.getElementById(id_s), out_b);
		};

		this.timeout_a[id_s] = setTimeout(setFade, 200);
	};
};
