var myElement;
var currentPage="Banner1";


function openLink(myElement)
{
    if(myElement[myElement.curIndex].id == "Banner1")
        location.href = "http://www.espaciosinmobiliarios.com.co/Default.aspx?tabid=54&proyid=70";
    else if(myElement[myElement.curIndex].id == "Banner2")
        location.href = "http://www.espaciosinmobiliarios.com.co/Default.aspx?tabid=54&proyid=70";
    else if(myElement[myElement.curIndex].id == "Banner3")
        location.href = "http://www.espaciosinmobiliarios.com.co/Default.aspx?tabid=54&proyid=70";
}

function fadeInNext()
{
	if (!myElement || myElement.length < 1)
		return;

	var curEle;

	if (typeof myElement.curIndex == "undefined")
		myElement.curIndex = myElement.length - 1;
	else
		curEle = myElement[myElement.curIndex];

	myElement.curIndex = (myElement.curIndex+1)%myElement.length;
	var nextEle = myElement[myElement.curIndex];

	currentPage = nextEle.id;

	if (curEle)
		Spry.Effect.DoFade(curEle, { from: 100, to: 0 });
	Spry.Effect.DoFade(nextEle, { to: 100, finish: function(){ setTimeout(function(){ fadeInNext(); }, fadeInNext.interval); } });
}

fadeInNext.interval = 3000;


Spry.Utils.addLoadListener(function()
{
	// Find the bannerBox and setup any quotes inside it for fading.
    Spry.$$(".bannerBox").setStyle("position: relative;");
	myElement = Spry.$$(".banner").setStyle("position: absolute; top: 0px; left: 0px; opacity: 0; filter: alpha(opacity=0); cursor:hand; ");
	Spry.$$("#Banner1, #Banner2, #Banner3").addEventListener("click", function(){openLink(myElement); return false; }, false);
	fadeInNext();
});