function FadeImage(fid, container, img1, img2, link, posTop, posLeft, factor)
{
	this.fid = fid;
	this.Container = container;
	this.Img1 = img1;
	this.Img2 = img2;
	this.Link = link;
	this.PosTop = posTop;
	this.PosLeft = posLeft;
	this.StepFactor = factor%200;
	this.Generate = function()
	{
		var code = "<div id='dfiA" + this.fid + "' style='position:absolute;top:" + this.PosTop + "px;left:" + this.PosLeft + "px;'><img id='fiA" + this.fid + "' src='" + this.Img1 + "' onclick='window.location=\"" + this.Link + "\"'/></div>" +
	 		   "<div id='dfiB" + this.fid + "' style='position:absolute;top:" + this.PosTop + "px;left:" + this.PosLeft + "px;'><img id='fiB" + this.fid + "' src='" + this.Img2 + "'  onclick='window.location=\"" + this.Link + "\"'/></div>";
        
        var divElement = document.createElement('div');
        divElement.innerHTML = code;

		document.getElementById(container).appendChild(divElement); // .innerHTML = divElement.innerHTML;
	}
	this.Step = function()
	{
		var dir = (this.StepFactor < 100);
		if(dir) inc = this.StepFactor;
		else inc = 200-this.StepFactor;

		var fiA = document.getElementById("dfiA" + this.fid);
		var fiB = document.getElementById("dfiB" + this.fid);
		// Para IE
		fiA.style.filter = "alpha(opacity=" + inc + ")";
		fiB.style.filter = "alpha(opacity=" + Number(100-inc*7) + ")";
		// Para Firefox
		fiA.style.opacity = Number(inc) / 100;
		fiB.style.opacity = Number(100-inc*7) / 100;
		
		this.StepFactor = (this.StepFactor + 1)%200;
	}
}

var bannerCells = null;
function GenerateBanner(container, images_A, images_B, links, numRows, numCols)
{
    bannerCells = new Array();
	if(images_A.length == images_B.length && images_A.length == links.length && (numRows*numCols == images_A.length))
	{
		var oLeft = 0;
		var oTop = 0;
		var oWidth = 102;
		var oHeight = 78;
        
		for(var i = 0; i < numRows; i++)
		{
			for(var j = 0; j < numCols; j++)
			{
				var index = i * numRows + j;
				var factor = 200 - ((200 / images_A.length) * index);
				bannerCells[index] = new FadeImage(index, container, images_A[index], images_B[index], links[index], oTop + (oHeight * i), oLeft + (oWidth * j), factor);
				bannerCells[index].Generate();
			}
		}
	}
	else
	{
		alert("Error en configuracion de banner.");
	}
}

var speed = 50;
function AnimateBanner()
{
	for(var ai = 0; ai < bannerCells.length; ai++)
	{ 
		if(bannerCells[ai] != null)
			bannerCells[ai].Step();
	}
	setTimeout('AnimateBanner()',speed);
}
