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 roturl1 = false;
	var roturl2 = false;
	var roturl3 = false;
	var rotimg = false;
	var rottimg = false;
	var rottext = false;
	var rotcon = false;

	if (document.getElementById)
	{
		roturl1 = document.getElementById('roturl1');
		roturl2 = document.getElementById('roturl2');
		roturl3 = document.getElementById('roturl3');
		rotimg = document.getElementById('rotimg');
		rottimg = document.getElementById('rottimg');
		rottext = document.getElementById('rottext');
		rotcon = document.getElementById('rotcon');
	}
	else if (document.all)
	{
		roturl1 = document.all['roturl1'];
		roturl2 = document.all['roturl2'];
		roturl3 = document.all['roturl3'];
		rotimg = document.all['rotimg'];
		rottimg = document.all['rottimg'];
		rottext = document.all['rottext'];
		rotcon = document.all['rotcon'];
	}
	else
	{
		return 0;
	}

	// ensure that the objects were successfully fetched
	if (!roturl1 || !roturl2 || !roturl3 || !rotimg || !rottimg || !rottext || !rotcon)
		return 0;

	// ensure that the attributes that we want to change exist
	if (!roturl1.href || !rotimg.src)
		return 0;
	if (!roturl2.innerHTML && !(roturl2.firstChild && roturl2.firstChild.nodeValue))
		return 0;

	rotimg.src = rotatingPlacards[nr][2];

	rottimg.src = '/lay/' + rotatingPlacards[nr][4];
	rottimg.alt = rotatingPlacards[nr][5];

	if (roturl2.innerHTML) // microsoft extension
	{
		roturl2.innerHTML = rotatingPlacards[nr][0];
		roturl3.innerHTML = rotatingPlacards[nr][7];
		rottext.innerHTML = rotatingPlacards[nr][3];
		rotcon.innerHTML = rotatingPlacards[nr][6];
	}
	else // modern W3C DOM standard
	{
		roturl2.firstChild.nodeValue = rotatingPlacards[nr][0];
		roturl3.firstChild.nodeValue = rotatingPlacards[nr][7];
		rottext.firstChild.nodeValue = rotatingPlacards[nr][3];
		rotcon.firstChild.nodeValue = rotatingPlacards[nr][6];
	}

	roturl1.href = rotatingPlacards[nr][1];
	roturl2.href = rotatingPlacards[nr][1];
	roturl3.href = rotatingPlacards[nr][1];

	for (var i = 0; i < rotatingPlacards.length; i++)
	{
		var rotswitch = false;
		if (document.getElementById)
			rotswitch = document.getElementById('rotswitch'+i);
		else // if (document.all)
			rotswitch = document.all['rotswitch'+i];

		if (!rotswitch)
			break;

		if (i == nr)
		{
			if (rotswitch.src.indexOf('a.gif') < 0)
				rotswitch.src = '/lay/r' + (i+1) + 'a.gif';
		}
		else
		{
			if (rotswitch.src.indexOf('a.gif') >= 0)
				rotswitch.src = '/lay/r' + (i+1) + '.gif';
		}
	}

	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);
}
