// Titel:  Generieke JavaScript voor Overheid.nl
// Versie: 1.5 / 20021126
// Auteur: Wouter van der Graaf, Fabrique Nieuwe Media B.V.

if( !imgPath )
	var imgPath = "images/";
function changeImage( _imgName, _suffix, _optLayer )
{
	if( _optLayer && document.layers )
		document.layers[ _optLayer ].document.images[ _imgName ].src = imgPath + _imgName + _suffix +".gif";
	else
		document.images[ _imgName ].src = imgPath + _imgName + _suffix +".gif";
}

if( !window.document.getElementById && window.document.all ){
	window.document.getElementById = function() { return this.all[ arguments[ 0 ] ]; };
}

if( document.all )
{
	getWindowWidth = new Function( 'return window.document.body.clientWidth;' );
	getWindowHeight = new Function( 'return window.document.body.clientHeight;' );
	getPageWidth = new Function( 'return window.document.body.scrollWidth;' );
	getPageHeight = new Function( 'return window.document.body.scrollHeight;' );
	getScrollX = new Function( 'return window.document.body.scrollLeft;' );
	getScrollY = new Function( 'return window.document.body.scrollTop;' );
}
else
{
	getWindowWidth = new Function( 'return window.innerWidth;' );
	getWindowHeight = new Function( 'return window.innerHeight;' );
	getPageWidth = new Function( 'return window.document.width;' );
	getPageHeight = new Function( 'return window.document.height;' );
	getScrollX = new Function( 'return window.pageXOffset;' );
	getScrollY = new Function( 'return window.pageYOffset;' );
}

function getPageX()
{
	var t = 0;
	for( var l=arguments[ 0 ]; l; l=l.offsetParent )
	{
		t += l.offsetLeft;
	}
	return t;
}

function getPageY()
{
	var t = 0;
	for( var l=arguments[ 0 ]; l; l=l.offsetParent )
	{
		t += l.offsetTop;
	}
	return t;
}

if( window.document.layers )
{
	window.getPageX = function()
	{
		if( arguments[ 0 ].x )
			return arguments[ 0 ].x;
		var t = 0;
		for( var l=arguments[ 0 ]; l; l=l.offsetParent )
		{
			t += l.offsetLeft;
		}
		return t;
	};
	window.getPageY = function()
	{
		if( arguments[ 0 ].y )
			return arguments[ 0 ].y;
		var t = 0;
		for( var l=arguments[ 0 ]; l; l=l.offsetParent )
		{
			t += l.offsetTop;
		}
		return t;
	};
}


var ScrollLastX = 0;
var ScrollLastY = 0;
function NSWatchScroll()
{	
	if( ScrollLastX != window.pageXOffset || ScrollLastY != window.pageYOffset )
	{
		ScrollLastX = window.pageXOffset; 
		ScrollLastY = window.pageYOffset; 
		if( window.onscroll )
			window.onscroll();
	}
	setTimeout( 'NSWatchScroll()', 400 ) 
}



var lift = 40;
if( navigator.appName == "Netscape" && parseFloat( navigator.appVersion ) >= 5 )
	lift += 16;
else if( navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.toLowerCase().indexOf( 'mac' ) >= 0 )
	lift += 21;
var newTop = 0;
var active = false;
if( !topKnopScrollMin )
	var topKnopScrollMin = 355;
function initTopKnop()
{
	newTop = Math.max( topKnopScrollMin, ( Math.max( lift - getScrollY(), 0 ) + getScrollY() + getWindowHeight() - lift ) );
	if( !active && ( ( navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.toLowerCase().indexOf( 'mac' ) >= 0 && getScrollY() > lift ) || ( getPageHeight() - lift > getWindowHeight() ) ) )
	{	
		if( document.layers )
		{
			document.layers[ "topknopl" ].left = 172;
			document.layers[ "topknopl" ].top = newTop;
			document.layers[ "topknopr" ].left = getPageX( document.images[ "therightspot" ] ) - 24;
			document.layers[ "topknopr" ].top = newTop;
			document.layers[ "topknopl" ].visibility = "show";
			document.layers[ "topknopr" ].visibility = "show";
		}
		else if( document.getElementById )
		{
			document.getElementById( "topknopl" ).style.left = 172;
			document.getElementById( "topknopl" ).style.top = newTop;
			document.getElementById( "topknopr" ).style.left = getPageX( document.getElementById( "therightspot" ) ) - 24;
			document.getElementById( "topknopr" ).style.top = newTop;
			document.getElementById( "topknopl" ).style.visibility = "visible";
			document.getElementById( "topknopr" ).style.visibility = "visible";
		}
		active = true;
		moveTopKnop();
	}
}

function changeTopKnopTarget()
{
	if( ( navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.toLowerCase().indexOf( 'mac' ) >= 0 && getScrollY() > lift ) || ( getPageHeight() - lift > getWindowHeight() ) )
	{
		if( document.getElementById )
			document.getElementById( "topknopr" ).style.left = getPageX( document.getElementById( "therightspot" ) ) - 24;
		initTopKnop();
	}
	else if( active )
	{
		active = false;
		if( document.layers )
		{
			document.layers[ "topknopl" ].visibility = "hide";
			document.layers[ "topknopr" ].visibility = "hide";
		}
		else
		{
			document.getElementById( "topknopl" ).style.visibility = "hidden";
			document.getElementById( "topknopr" ).style.visibility = "hidden";
		}
	}
}

function moveTopKnop()
{
	if( active )
	{
		if( document.layers )
			var curTop = document.layers[ "topknopl" ].pageY;
		else
		{
			var curTop = document.getElementById( "topknopl" ).offsetTop;
		}
		if( curTop != newTop )
		{
			var stepTop = Math.ceil( ( newTop - curTop ) * 0.3 );
			var nextTop = ( stepTop > 0 ) ? curTop + Math.max( 1, stepTop ) : curTop + Math.min( -1, stepTop );
			if( document.layers )
			{
				document.layers[ "topknopl" ].top = nextTop;
				document.layers[ "topknopr" ].top = nextTop;
			}
			else
			{
				document.getElementById( "topknopl" ).style.top = nextTop;
				document.getElementById( "topknopr" ).style.top = nextTop;
			}
			setTimeout( 'moveTopKnop();', 50 );
		}
		else
			setTimeout( 'moveTopKnop();', 250 );
	}
}

function formatTopKnop()
{
	var code = '';
	if( document.layers )
		code += '<div style="position:absolute; left:0px; top:0px; width:1px; height:1px; visibility:hidden;"></div>'
	code += '<div class="noprint" id="topknopl" style="position:absolute; left:0px; top:0px; width:24px; height:25px; visibility:hidden;"><a href="#top" onmouseover="changeImage( \'knop_topl\', \'_over\', \'topknopl\' );" onmouseout="changeImage( \'knop_topl\', \'_out\', \'topknopl\' );"><img id="knop_topl" name="knop_topl" src="'+ imgPath +'knop_topl_out.gif" border="0" width="24" height="25" alt="Terug naar bovenkant"></a></div><div class="noprint" id="topknopr" style="position:absolute; left:0px; top:0px; width:24px; height:25px; visibility:hidden;"><a href="#top" onmouseover="changeImage( \'knop_topr\', \'_over\', \'topknopr\' );" onmouseout="changeImage( \'knop_topr\', \'_out\', \'topknopr\' );"><img id="knop_topr" name="knop_topr" src="'+ imgPath +'knop_topr_out.gif" border="0" width="24" height="25" alt="Terug naar bovenkant"></a></div>';
	return code;
}

function preloadImages()
{
	for( var i=0; i<arguments.length; i++ )
	{
		eval( 'var newImage'+ i +' = new Image();' );
		eval( 'newImage'+ i +'.src = "'+ imgPath + arguments[i] +'";' );
	}
}

function openWindow( _href, _width, _height )
{
	var l = ( screen.width - _width ) / 2;
	var t = ( screen.height - _height ) / 2;
	newWindow = window.open( _href, "_blank", "width="+ _width +",height="+ _height +",left="+ l +",top="+ t +",scrollbars=yes" );
	newWindow.focus();
}

function printPage()
{
	if( parseInt( navigator.appVersion.substring( navigator.appVersion.indexOf( "MSIE " ) + 5, navigator.appVersion.length ) ) == 4 || document.layers )
			alert( "Uw browser ondersteunt deze optie niet.\nKies uit het menu Bestand, Afdrukken (File, Print) om deze pagina af te drukken." );
	else
			self.print();
}