/* ------------------------------------
	Smooth TopButton Scroller
	(c) 2004 Netdesign
	2004/06/04 M. Sgaier
------------------------------------ */
//  edited for XHTML documents

// remarks arnoud:

// browser check
var agent			= window.navigator.userAgent; 
var i				= agent.indexOf("MSIE ")+5;
var isIE5plus		= (parseInt(agent.substr(i)) >= 5 && agent.indexOf("5.0b1") < 0);
var isMac			= ((agent.indexOf("Mac")!=-1)||(agent.indexOf("mac")!=-1)); 
var isIE6			= ( agent.indexOf("MSIE 6") != -1 );
var isMozilla		= agent.toLowerCase().indexOf("gecko")!= -1 && agent.toLowerCase().indexOf("firefox") == -1
var isFirefox		= agent.toLowerCase().indexOf("firefox") != -1

var iconsOffsetTop = 20;
var scrollOffset   = 220; // pixels the document has to scroll before our little icon pops up

var contentWidth   = 1003; // this is the size of the table with all the content
var iconPadding    = 719; // this actually is the offset of the icon relative to the content's startoffset
var mozPadding 	   = 7;  // Mozilla correction on above's padding

var fader 	  	   = null;
var fadespeed 	   = 20;
var fadestep	   = 10;

var scroller	   = null;
var scrollstep	   = 40;
var scrollint	   = 30;
var scrollwait     = 500;

var leftOffsetSafari = (navigator.userAgent.toLowerCase().indexOf("safari") != -1 ) ? 8 : 0;

// init the to-top button
initUpIcon();
onload = positionIcon;

function initUpIcon() {
	// write the icon on screen
	
	document.write ('<div id="iconup" style="visibility: hidden; position: absolute; width: 27px; left: 0px; top: 0px; padding-top: 66px;">' +
					'	<a title="Print page" href="#" onclick="print(); return false;"><img id="iconimage" src="/prototype/images/iconPrint.gif" border="0"></a>' +
					'</div>');
	
	
	document.write ('<div id="iconupTop" style="visibility: hidden; position: absolute; width: 27px; left: 0px; top: 0px; padding-top: 96px;">' +
					'	<a title="Back to top" href="javascript:scrollToTop();"><img style="margin-top: 3px" src="/prototype/images/iconUp.gif" alt="Scroll to top" border="0"></a>' + 
					'</div>');
	// set scroll & resize event
	if (document.all) {
		window.onscroll  = smoothIconScroll;
	} else {
		window.onmousemove = smoothIconScroll;
	}
	window.onresize = positionIcon;
}

function smoothIconScroll() {
	clearTimeout(scroller);
	scroller = setTimeout("positionIcon()", scrollwait);
}

function positionIcon() {
	clearTimeout(scroller);
	showIcon();
	placeIcon(getPageOffset());
}

function getPageOffset() {
	if (document.body && document.body.scrollTop && document.body.scrollTop > 0) {
		return document.body.scrollTop;
	} else if (document.documentElement && document.documentElement.scrollTop && document.documentElement.scrollTop > 0) {
		return document.documentElement.scrollTop;
	} else if (window.scrollY > 0) {
		return window.scrollY;
	} else {
		hideIcon();
		return 0;
	}
}

function placeIcon(offset) {
	if (!iconup()) {
		return;
	} else {
		// calculate left offset
		var docwidth 	 = (window.innerWidth) ? window.innerWidth - mozPadding : document.body.clientWidth;
		var leftOffset 	 = Math.round( (docwidth-contentWidth > 0) ? (docwidth-contentWidth)/2 + iconPadding : iconPadding );
		iconup().style.left = (leftOffset + leftOffsetSafari) + "px";
		iconupTop().style.left = (leftOffset + leftOffsetSafari) + "px";
		if (offset < scrollOffset) {
			moveIconTo(scrollOffset);
		} else {
			moveIconTo(offset + iconsOffsetTop);
		}
	}
}

function moveIconTo(goal_y) {
	if (!iconup()) return;
	var docheight = (window.innerHeight) ? window.innerHeight : document.body.clientHeight;
	var cur_y = parseInt( iconup().style.top.substring(0, iconup().style.top.length-2) );
	var distance = Math.abs(cur_y - goal_y);
	var step = (distance <= scrollstep) ? Math.round(distance / 2) : ( ( distance >  docheight) ?  docheight : scrollstep );
	var new_y = (cur_y < goal_y) ? cur_y + step : cur_y - step;
	if ( (cur_y > goal_y && new_y <= goal_y) || (cur_y < goal_y && new_y >= goal_y) ) {
		iconup().style.top = goal_y + "px";
		iconupTop().style.top = goal_y + "px";
	} else {
		iconup().style.top = new_y + "px";
		iconupTop().style.top = new_y + "px";
		if (goal_y != new_y) {
			scroller = setTimeout("moveIconTo("+goal_y+")", scrollint);
		}
	}	
}

function scrollToTop () {
	smoothScroll();
}

function smoothScroll() {
	var docheight = (window.innerHeight) ? window.innerHeight : document.body.clientHeight;
	var pageoffset = getPageOffset();
	var step = (pageoffset <= scrollstep) ? Math.round(pageoffset / 2) : ( ( pageoffset >  docheight) ?  docheight : scrollstep );	
	var new_y = pageoffset - step;
	if (new_y < 0 ) new_y = 0;
	window.scrollTo(0, new_y);
	if (new_y > 0) setTimeout("smoothScroll()", scrollint);
}

function iconup() {
	return document.getElementById("iconup");
}

function iconupTop() {
	return document.getElementById("iconupTop");
}

function iconimage() {
	return document.getElementById("iconimage");
}

function hideIcon() {
	if (!iconup()) return;
	iconup().style.visibility = "visible"; // don't hide
	iconupTop().style.visibility = "hidden"; 
	//iconup().style.visibility = "hidden"; 
}

function showIcon() {
	if (!iconup()) return;
	iconup().style.visibility = "visible"; 
	iconupTop().style.visibility = "visible"; 
}

function fadeIcon(perc) {
	// arnoud
	showIcon(); return;
	
	if (perc>100) perc = 100;
	if (perc<0) perc = 0;
	if (iconimage().filters) {
		iconimage().filters[0].opacity = perc;
	} else {
		iconimage().style.MozOpacity = perc+"%";
	}
}

function fadeOutIcon(msg) {
	// arnoud
	showIcon();	return;
	
	if (!iconimage().filters) {
		hideIcon();
		return;
	}
	perc = iconimage().filters[0].opacity - fadestep;
	if (perc < 0) perc = 0;
	iconimage().filters[0].opacity = perc;
	if (perc > 0) setTimeout("fadeOutIcon('')", fadespeed);
	else hideIcon();
}

function fadeInIcon() {
	// arnoud
	showIcon();	return;
	
	if (!iconimage().filters) {
		showIcon();
		return;
	}
	perc = iconimage().filters[0].opacity + fadestep;
	if (perc > 100) perc = 100;
	iconimage().filters[0].opacity = perc;
	if (perc < 100) setTimeout("fadeInIcon()", fadespeed);
	showIcon();
}

function startPrint() {
	printPage();
}


// print functions

function printPage() {


	return false; //
		
	renderNotIds("topmiddle","topmenuitems","topright","middleleft","middlemiddle","middleright","bottomleft","contentfooter","iconup", "iconupTop");
	
	//crumbtrail
	var crumb = document.getElementById("crumbtrail");
	
	// logo	
	var toptable = document.getElementById("topTable");
	toptable.style.width = "600px";
	toptable.style.marginRight =  "387px";
	
	//determine table tag of contentleft
	var contentTd = document.getElementById("contentleft");
	var table = contentTd.parentNode;
	while (table.tagName.toLowerCase() != "table") {
		table = table.parentNode;
	}
	table.style.width = "600px";
	table.style.marginRight = "387px";
	
	//determine table tag of middleright
	var middleright = document.getElementById("middleright");
	var table = middleright.parentNode;
	while (table.tagName.toLowerCase() != "table") {
		table = table.parentNode;
	}
	table.style.width = "600px";
	table.style.marginRight = "387px";
	
	// gecko & safari --> just render right column
	if (! isIE5plus) {
	
		// non ie only body hack
		document.body.style.display = "block";
		document.body.style.width = "798px";
		document.body.style.overflow = "hidden";
		
		// crumbtrail
		crumb.style.width = (600 - 29) + "px";
		crumb.style.borderTop = "20px solid white";
		
		// right column
		var bottomright = document.getElementById("bottomright");
		bottomright.style.borderTop = "20px solid white";
			
	} else { // ie5+ --> clone node
		renderNotIds("bottomright");
		
		crumb.style.marginTop = "20px";
		crumb.style.overflow = "visible"
		
		// create the extra node
		var d = document.createElement("div");
		d.id = "specialPrintDiv";
		d.innerHTML = document.getElementById("bottomright").innerHTML;
		d.className = "no-overflow-198 floatRight";
		var s = crumb.nextSibling;
		crumb.parentNode.insertBefore(d, crumb);
	}
	
	// print dialog
	if (window.print) {
		window.print();
	} else {
		alert("This function is not available.\nPlease use the print function of your browser.");
	}
	
	// restore the page
	if (! isIE5plus) {
		setTimeout('restorePage()' , 2000);
	} else {
		restorePage();
	}
}

function restorePage() {
	
	var crumb = document.getElementById("crumbtrail");
	
	var toptable = document.getElementById("topTable");
	toptable.style.width = "";
	toptable.style.marginRight = "";
	
	//determine table tag of contentleft
	var contentTd = document.getElementById("contentleft");
	var table = contentTd.parentNode;
	while (table.tagName.toLowerCase() != "table") {
		table = table.parentNode;
	}
	table.style.width = "";
	table.style.marginRight = "";
	
	//determine table tag of middleright
	var middleright = document.getElementById("middleright");
	var table = middleright.parentNode;
	while (table.tagName.toLowerCase() != "table") {
		table = table.parentNode;
	}
	table.style.width = "";
	table.style.marginRight = "";
	
	// gecko & safari 
	if (! isIE5plus) {
		
		document.body.style.display = "";
		document.body.style.width = "";
		document.body.style.overflow = "";
		
		crumb.style.width = "";
		crumb.style.borderTop = "0px";
		
		// right column
		var bottomright = document.getElementById("bottomright");
		bottomright.style.borderTop = "0px";
		
	} else { // ie5+ 
	
		crumb.style.marginTop = "0px";
		crumb.style.overflow = ""
	
		// remove the extra created node for the print
		var pdiv = document.getElementById("specialPrintDiv");
		if (pdiv) {
		var pparent = pdiv.parentNode;
			pparent.removeChild(pdiv);
		}  	
	}
	
	// reposition the icon
	positionIcon();
	
	renderIds("topmiddle","topmenuitems","topright","middleleft","middlemiddle","middleright","bottomleft","bottomright","contentfooter","iconup", "iconupTop");
}