if( document.documentElement )
	bodyStyle = document.documentElement.style;
else if( document.body )
	bodyStyle = document.body.style;

bodyStyle.visibility = "hidden";
var currentActiveLinkId;

function sizeContent(){
	var contentHeight = getHeight();
	document.getElementById("fbContainer").style.height = contentHeight + "px";
	var altDiv = document.getElementById("altmsg");
	
	if( altDiv ){		
		var altH = altDiv.offsetHeight;
		var altW = altDiv.offsetWidth;
		altDiv.style.top = (contentHeight / 2 - altH /2)+ "px";
		altDiv.style.left = (getWindowWidth() / 2 - altW /2)+ "px";
	}
	
	if( bodyStyle )bodyStyle.visibility = "visible";
	
	
	if(contentHeight < 700){
		
		flippingBook.settings.bookHeight = contentHeight;
		flippingBook.settings.bookWidth = contentHeight*1.4;
		flippingBook.create();
		document.getElementById("fbContainer").style.height = contentHeight + "px";
		
	}
	else if (contentHeight > flippingBook.settings.bookHeight){
		flippingBook.settings.bookHeight = contentHeight;
		flippingBook.settings.bookWidth = contentHeight*1.4;
		flippingBook.create();
		document.getElementById("fbContainer").style.height = contentHeight + "px";
	}
	
	for(var i=1;i < 21;i++){
		if(document.getElementById('tab'+i)){
			
			// Bugfix IE !!!!!  
			document.getElementById('tab'+i).style.border = 'none';
			document.getElementById('fbFooter').style.border = '1px solid #98BEE2';
			
			document.getElementById('tab'+i).parentNode.onclick = function () {
				this.blur();
				flippingBook.getFlippingBookReference().flipGotoPage(chapter[this.firstChild.id]);
			}
		}
		
	}
	if(isIE6){
		document.getElementById('fbPrintButton').onclick = flippingBook.print;
		document.getElementById('fbForwardButton').onclick = flippingBook.flipForward;
		document.getElementById('fbBackButton').onclick =  flippingBook.flipBack;
		document.getElementById('fbZoomButton').onclick = function(){
														if (flippingBook.getFlippingBookReference().isZoomedIn()) 
															flippingBook.zoomOut();
														else 
															flippingBook.zoomIn();
											};
	}
	
}

function updateNav(id,pageNumber){
	if(id === 0){
		// if called from onPutPage
		for(key in chapter){
			if(chapter[key] == pageNumber){
				id = key;
			}
		}
	}
	else {
		// if called from onClick
		pageNumber = chapter[id];
	}
	if (document.getElementById(currentActiveLinkId)) {
		document.getElementById(currentActiveLinkId).style.color = '#FFF';
		document.getElementById(currentActiveLinkId).parentNode.style.backgroundImage = 'url(fileadmin/v8-vauban/img/nav_bg_inaktiv.gif)';
	}
	for(i=1;i<id;i++){
		if(document.getElementById('tab'+i))id = 'tab' + i;
	}
	currentActiveLinkId = id;
	if (document.getElementById(id)) {
		document.getElementById(id).style.color = '#00CC00';
		document.getElementById(id).parentNode.style.backgroundImage = 'url(fileadmin/v8-vauban/img/nav_bg_aktiv.gif)';
	}

}

function getHeight(){
	var windowHeight = getWindowHeight();
	//console.log('windowHeight: ' + windowHeight);
	var footerHeight = document.getElementById("fbFooter").offsetHeight;
	var headerHeight = document.getElementById("topnav").offsetHeight;

	var contentHeight = windowHeight - footerHeight - headerHeight - 23;
	//console.log('contentHeight: ' + contentHeight);
	return contentHeight;
}

function addEvent( obj, type, fn )
{
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	else if (obj.attachEvent)
	{
		obj["e"+type+fn] = fn;
		obj.attachEvent( "on"+type, function() { obj["e"+type+fn](); } );
	}
}

function getWindowHeight() {
	var windowHeight=0;
	if ( typeof( window.innerHeight ) == 'number' ) {
		windowHeight=window.innerHeight;
	}
	else {
		if ( document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body&&document.body.clientHeight) {
				windowHeight=document.body.clientHeight;
			}
		}
	}
	
	return windowHeight;
};

function getWindowWidth() {
	var ww = 0;
	if (self.innerWidth)
		ww = self.innerWidth;
	else if (document.documentElement && document.documentElement.clientWidth)
		ww = document.documentElement.clientWidth;
	else if (document.body)
		ww = document.body.clientWidth;
	return ww;
}

addEvent( window, "load", sizeContent);
addEvent( window, "resize", sizeContent );
