var dragobjekt = false;

if(top.location != self.location){top.location = self.location.href;}

function navi(diese)
{
	document.getElementById('an1').style.backgroundColor = '#daeaf2';
	document.getElementById('an2').style.backgroundColor = '#daeaf2';
	document.getElementById('an3').style.backgroundColor = '#daeaf2';
	document.getElementById('an4').style.backgroundColor = '#daeaf2';
	document.getElementById('an5').style.backgroundColor = '#daeaf2';
	document.getElementById('an6').style.backgroundColor = '#daeaf2';
	document.getElementById('an7').style.backgroundColor = '#daeaf2';
	document.getElementById(diese).style.backgroundColor = '#a9daf2';
}

function dragstart(ff)
{
	bro = document.getElementById && !document.all;
	el = bro ? ff.target : event.srcElement;

	if(el.className == 'figur1' || el.className == 'figur2' || el.className == 'figur3' || el.className == 'figur4')
	{
		dragobjekt = el;
		dragobjekt.style.zIndex++;
		document.body.style.cursor = 'move';
		dragx = posx - dragobjekt.offsetLeft;
		dragy = posy - dragobjekt.offsetTop;
		return false;
	}
}

function drag(ff)
{
	bro = document.getElementById && !document.all;
	posx = bro ? ff.clientX : event.clientX;
	posy = bro ? ff.clientY : event.clientY;

	if(dragobjekt != false)
	{
		dragobjekt.style.left = Math.round((posx - dragx)/38)*38 + 'px';
		dragobjekt.style.top = Math.round((posy - dragy)/36)*36 + 'px';
		return false;
	}
}

function dragstop()
{
	if(dragobjekt != false)
	{
		for(i = 0; i < document.images.length; i++)
		{
			el = document.images[i];

			if(el != dragobjekt && (el.className == 'figur1' || el.className == 'figur2' || el.className == 'figur3' || el.className == 'figur4'))
			{
				if(el.style.left == dragobjekt.style.left && el.style.top == dragobjekt.style.top)
				{
					if(el.className == dragobjekt.className)
					{
						el.style.left = '760px';
						el.parentNode.appendChild(el);
					}
				}
			}
		}

		dragobjekt.style.zIndex--;
		dragobjekt = false;
		document.body.style.cursor = 'default';
		return false;
	}
}

document.onmousedown = dragstart;
document.onmousemove = drag;
document.onmouseup = dragstop;
