/*CONFIG : */
	//has to be the same as in main.css
	var contentPaddingW = 56;
	var contentPaddingH = 75;


//Page currently beeing displayed
var currentpage = 1;

//Pages currently beeing faded
var fadingIn = fadingOut = null;


// Called onload: Hides all pages but the first one.
function hidepages() {
	document.getElementById( 'menulink1' ).setAttribute("class", "displaypage");
	document.getElementById( 'menulink1' ).setAttribute("className", "displaypage");

	for( var i = 1; i < 30; i++ ) {
		var menu = document.getElementById( 'menulink'+i );
		if( menu )
			menu.href = '#n';
	}
	
	for( var i = 2; i < 30; i++ ) {
		var item = document.getElementById( "page"+i );
		if( item ) {
			setOpacity( item, 0 );
			item.style.display = 'none';
		}
		else
			break;
	}
	externalLinks();
}

// Switch page from currentpage to newpage
function displaypage( newpage ) {
	if( fadingIn == null && newpage != currentpage ) {

		//change active menuentry
		document.getElementById( 'menulink'+currentpage ).setAttribute("class", "");
		document.getElementById( 'menulink'+currentpage ).setAttribute("className", ""); 
		document.getElementById( 'menulink'+currentpage ).removeAttribute("class");
		document.getElementById( 'menulink'+currentpage ).removeAttribute("className");
		document.getElementById( 'menulink'+newpage ).setAttribute("class", "displaypage");
		document.getElementById( 'menulink'+newpage ).setAttribute("className", "displaypage"); 

		//prepare fading
		fadingIn = document.getElementById( 'page'+newpage );
		fadingOut = document.getElementById( 'page'+currentpage );
		
		//fix the page width while fading:
		var content = document.getElementById( 'contentbox' );
		var width = content.clientWidth ? content.clientWidth : content.offsetWidth;
		width = parseInt( width ) - contentPaddingW;
		fadingIn.style.width = width+"px";
		fadingOut.style.width = width+"px";

		//evaluate the height during fading
		setOpacity( fadingIn, 0 );
		fadingIn.style.display = 'block';
		var height = Math.max( parseInt( fadingIn.clientHeight ), parseInt( fadingOut.clientHeight ) ) + contentPaddingH;
		content.style.height = height+"px";

		//overlay new and old page
		fadingIn.style.position = 'absolute';
		fadingOut.style.position = 'absolute';
					
		//start fading
		setTimeout( "fade( 100, 0, 15 );", 50 );
		
		//update currentpage
		currentpage = newpage;
	}
}


//crossbrowser set opacity
function setOpacity( obj, value) {
	obj.style.opacity = value/100;
	obj.style.filter = 'alpha(opacity=' + value + ')';
	obj.style.KhtmlOpacity = value/100;
}

// recursive fading
function fade( oldpageopacity, newpageopacity, speed ) {
	// stop if oldpage opacity is below stepsize
	if( oldpageopacity <= speed+1 ) {
	
		//loosen layout and restore page-position
		fadingIn.style.width = '';
		fadingOut.style.width = '';
		document.getElementById( 'contentbox' ).style.height = '';
		fadingIn.style.position = 'relative';
		fadingOut.style.position = 'relative';
		fadingOut.style.display = 'none';
		
		setOpacity( fadingOut, 0 );
		setOpacity( fadingIn, 100 );
		
		fadingIn = fadingOut = null;
		return;
		
	} else {
		oldpageopacity -= speed;
		newpageopacity += speed;
		setOpacity( fadingOut, oldpageopacity );
		setOpacity( fadingIn, newpageopacity );
		setTimeout( "fade( "+oldpageopacity+","+newpageopacity+","+speed+" );", 80 );
	}
}

function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("class") == "extlink")
     anchor.target = "_blank";
 }
}

