var FaderSeeder = function (s1, s2) 
{
	this._images = [];
	this._locked = [];
	var img;
	var s1 = s1.replace(/\s+/g, "");
	var s1 = s1.replace(/,$/, "");

	var s2 = s2.replace(/\s+/g, "");
	var s2 = s2.replace(/,$/, "");

	var a1 = s1.split(",");
	var a2 = s2.split(",");
//	print_r(a);
	var tempKey = 0;
	var key1 = 0;
	var key2 = 0;
	var key3 = 0;
	var usedKeys = [];	
	var sources = [];	

	for (var i in a1)
	{
		key1 = Math.random();
		sources.push("<key>" + key1 + "</key>" + a1[i]);
		this._locked.push(false);
	}	

	for (var j in a2)
	{
		key2 = Math.floor(Math.random()*100);
		if (key2>85) {
			key3 = Math.random();
			sources.push("<key>" + key3 + "</key>" + a2[j]);
			this._locked.push(false);
		}
	}	
	
	sources.sort();
	
	for (i in a1)
	{
		img = document.createElement("img");
		img.src = sources[i].replace(/<key>.+<\/key>/, "");
		this._images.push(img);
	}
};


FaderSeeder.prototype.getImage = function (o)
{ 
//	print_r(this._locked);
	if (o == undefined)
	{
		for (i in this._images)
		{
			if (! this._locked[i])
			{
				this._locked[i] = true;
				return this._images[i];
			}
		}
	}
	else
	{
		for (var i in this._images)
		{
//			alert(o.src);
			if (this._images[i].src == o.src)
			{ 
//				alert(this._images[i].src);
//				alert(i);
				if (i == this._images.length -1)
				{ 
					for (i in this._images)
					{
						if (! this._locked[i])
						{
							this._locked[i] = true;
							return this._images[i];
						}
					}
				}
				else
				{ 
//					alert(i);
					for (i = parseInt(i) + 1; i < this._images.length; i++)
					{
//						alert("t" + i);
						if (! this._locked[i])
						{ 
//							alert(this._images[i].src);
							this._locked[i] = true;
							return this._images[i];
						}
					}
					
					for (i in this._images)
					{
						if (! this._locked[i])
						{
							this._locked[i] = true;
							return this._images[i];
						}
					}
				}
			}
		}
	}
};

FaderSeeder.prototype.freeImage = function (o)
{ 
	for (var i in this._images)
	{ 
		if (o.src == this._images[i].src)
		{ 
			this._locked[i] = false;
		}
	}
};