function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}

function replacePage(element,page,title, onlytitle, lang, filename) {
	/**
	/*  element - reference of the clicked navigation link
	/* page - the url of the requested page (the 'p' variable)
	/* title the title of the requested page
	*/
	
	// move animation div
	var container = $('container');
	$('animationdiv').style.left = findPos(element)[0] - findPos(container)[0] + "px";
	$('animationdiv').style.top = findPos(element)[1] + "px";
	// clear pagecontent div
	$('pagecontent').innerHTML = '';
	// update the browser's title
	document.title = title;
	// defocus the clicked link
	element.blur();
	// remove the underlines from all navigation links
	var elements = $$('.navitem');
	var j = 0;
	var navlinks = new Array();
	for (var i = 0; i < elements.length; i++) {
		navlinks[j] = elements[i];
		++j;
	}
	for (var i = 0; i < navlinks.length; i++) {
		navlinks[i].style.textDecoration = 'none';
	}
	// underline the selected navigation links
	element.style.textDecoration = 'underline';
	// update headline div
	$('banner').innerHTML = '<object type="application/x-shockwave-flash" data="flash/header.swf?image='+filename+'&lang='+lang+'" width="990" height="250"><param name="movie" value="flash/'+filename+'.swf?lang='+lang+'" /></object>';
	
	$('headline').innerHTML = '<object type="application/x-shockwave-flash" data="images/headline2.swf" width="723" height="63"><param name="movie" value="images/headline2.swf" /><param name="FlashVars" value="text=' + onlytitle + '" /></object>';
	// start animation	
	var myEffects = new Fx.Styles('animationdiv', {duration: 500, transition: Fx.Transitions.linear});
	myEffects.start({
	    'width': 723,
	    'height': 361,
		'top': 460,
		'left': 456,
		'opacity': 0
	}).addEvent('onComplete',
		function() {
			// reset animation div
			$('animationdiv').style.width = '0';
			$('animationdiv').style.height = '0';
			$('animationdiv').style.opacity = '1';
			// insert loading animation into pagecontent div
			$('pagecontent').innerHTML = '<div id="loading"><img src="images/page_loading.gif" alt="" class="icon" /></div>';
			// get the requested page with AJAX
			new Ajax('page.php?p=' + page, {
				method: 'get',
				update: $('pagecontent')
			}).request();
			// get the updated menu with AJAX
			new Ajax('menu.php?p=' + page, {
				method: 'get',
				update: $('main-menu')
			}).request();
		}
	);
}