var rotaNr = 0;
var rotaTimer;

function Lopsedel(nr) // function for the users' manual selection
{
	window.clearTimeout(rotaTimer); // stop automatic rotation

	nr--; // convert from human-ish to computer-ish
	if (rotaNr == nr)
		return;

	SwitchPlacard(nr);
}

function SwitchPlacard(nr) // internal function
{	
	var roturl2 = false;
	var roturl3 = false;
	var rottext = false;
	var rotcon = false;

	if (document.getElementById)
	{
		roturl2 = document.getElementById('roturl2');
		roturl3 = document.getElementById('roturl3');
		rottext = document.getElementById('rottext');
		rotcon = document.getElementById('rotcon');
	}
	else if (document.all)
	{
		roturl2 = document.all['roturl2'];
		roturl3 = document.all['roturl3'];
		rottext = document.all['rottext'];
		rotcon = document.all['rotcon'];
	}
	else
	{
		return 0;
	}

	// ensure that the objects were successfully fetched
	if (!roturl2 || !roturl3 || !rottext || !rotcon)
		return 0;

	// ensure that the attributes that we want to change exist
	if (!roturl2.href)
		return 0;
	if (!roturl2.innerHTML && !(roturl2.firstChild && roturl2.firstChild.nodeValue))
		return 0;

	if (roturl2.innerHTML) // microsoft extension
	{
		roturl2.innerHTML = rotatingPlacards[nr][0];
		roturl3.innerHTML = rotatingPlacards[nr][4];
		rottext.innerHTML = rotatingPlacards[nr][2];
		rotcon.innerHTML = rotatingPlacards[nr][3];
	}
	else // modern W3C DOM standard
	{
		roturl2.firstChild.nodeValue = rotatingPlacards[nr][0];
		roturl3.firstChild.nodeValue = rotatingPlacards[nr][4];
		rottext.firstChild.nodeValue = rotatingPlacards[nr][2];
		rotcon.firstChild.nodeValue = rotatingPlacards[nr][3];
	}

	roturl2.href = rotatingPlacards[nr][1];
	roturl3.href = rotatingPlacards[nr][1];

	document.getElementById('puffBig' + nr).style.display = 'block';
	document.getElementById('puffBig' + rotaNr).style.display = 'none';

	rotaNr = nr;

	return 1;
}

function RotatePlacards()
{
	if (SwitchPlacard((rotaNr + 1) % rotatingPlacards.length))
		rotaTimer = window.setTimeout(RotatePlacards, 5000);
}

if (rotatingPlacards.length)
{
	rotaTimer = window.setTimeout(RotatePlacards, 5000);
}

