var qCurrentPic = 0;
var qLastChange = 0;

function qSetAlpha(id, alpha)
{
	var theobj = document.getElementById('img'+id);
	theobj.style.filter='progid:DXImageTransform.Microsoft.Alpha(Opacity=' + alpha*100 + ')';
	theobj.style.opacity=alpha;
}

function qShow(id, alpha)
{
	qSetAlpha(id, alpha);

	if (alpha < 1)
		setTimeout("qShow("+id+", "+(alpha+0.1)+")", 60);
}

function qHide(id, alpha)
{
	qSetAlpha(id, alpha);

	if (alpha > 0)
		setTimeout("qHide("+id+", "+(alpha-0.1)+")", 60);
}

function qChange(newPic)
{
	var data = new Date();
	var nTime = data.getTime();
	qLastChange = nTime;

	// zmiana
	// ukrywamy obecny od alpha 1
	qHide(qCurrentPic, 1);

	// pokazujemy nowy od alpha 0
	qShow(newPic, 0);

	qCurrentPic = newPic;

	setTimeout("qAnimation()", 5000);
}

function qAnimation()
{
	var data = new Date();
	var nTime = data.getTime();

	if (nTime-qLastChange >= 5000)
	{
		qChange((qCurrentPic + 1) % 3);
	}
}

function qPrev()
{
	qChange(((qCurrentPic - 1 < 0 ? 3 : qCurrentPic - 1)));
}

function qNext()
{
	qChange((qCurrentPic + 1) % 3);
}

function Start()
{
	qChange(0);
	
	setTimeout("qAnimation()", 5000);
}

window.onload=Start;
