// JavaScript Document

var currAjax;

function overlay_popup(loadURL, w, h){

	if(!loadURL) loadURL = server_path + 'googlemaps/testmap.php';
	if(!w) w = 910;
	if(!h) h = 456;
	if (arguments[3]) var func = arguments[3];

	// Heights
	shadowHeight	= (h!='auto') ? (h+2)+'px' : h;
	borderHeight	= (h!='auto') ? h : h;
	contentHeight	= (h!='auto') ? (h-20)+'px' : h;

	$('#background_shadow').remove();
	$('#overlay_shadow').remove();
	$('#overlay_close').remove();

	$('body')
		.append('<div id="background_shadow"></div><div id="overlay_shadow"><div id="overlay_border"><div id="overlay_content"></div></div></div><div id="overlay_close"><div>');

	$('#background_shadow')
		.css(
			 {
				position			: 'absolute',
				top					: 0,
				left				: 0,
				width				: '100%',
				height				: $(document).height(),
				backgroundColor		: '#000000',
				opacity				: 0.5,
				zIndex				: 99
			 }
		)
		.hide()
		.fadeIn('normal')
	;

	$('#overlay_shadow')
		.css(
			 {
				'position'				: 'absolute',
				'left'					: '50%',
				'top'					: '140px',
				'width'					: (w+2)+'px',
				'height'				: shadowHeight,
				'margin-left'			: '-'+((w-4)/2)+'px',
				'background-color'		: '#ffffff',
				'border'				: '1px solid #f3f3ed',
				'background-image'		: 'url(img/ajax_loader.gif)',
				'background-repeat'		: 'no-repeat',
				'background-position'	: 'center center',
				'z-index'				: '100'
			 }
		)
		.hide()
		.fadeIn('normal')
	;

	$('#overlay_border')
		.css(
			 {
				'width'					: (w)+'px',
				'height'				: borderHeight,
				'border'				: '1px solid #d5d5cf'
			 }
		)
	;

	$('#overlay_content')
		.css(
			 {
				'width'					: (w-20)+'px',
				'height'				: contentHeight,
				'margin'				: '10px',
				'visibility'			: 'hidden'
			 }
		)
	;

	$('#overlay_close')
		.css(
			{
				'position'				: 'absolute',
				'left'					: '50%',
				'top'					: '132px',
				'width'					: '20px',
				'height'				: '20px',
				'margin-left'			: (w/2)+6-12+'px',
				'background-image'		: (IE6) ? 'url(img/popup_close.gif)' : 'url(img/popup_close.png)',
				'background-repeat'		: 'no-repeat',
				'background-position'	: 'center center',
				'cursor'				: 'pointer',
				'z-index'				: '101'
			}
		)
		.click(
			function(){
				// Abort ajax, only usefull when waiting long
				if (typeof(currAjax)=='object')
					currAjax.abort();
				$('#overlay_shadow, #background_shadow').add(this).fadeOut('slow', function() {
					$(this).remove();
					$('#flashmovie, #wumboswf').css('visibility','visible');
					if (IE6)
						$('select').css('visibility','visible');
				});
			}
		);
	;

	var currAjax = $.ajax({
		url:		loadURL,
		cache:		false,
		success:	function(html){
						$("#overlay_content")
							.html(html);

						// Execute callback function, since html is added to DOM
						if (func) $(func);

						window.scroll(0,0);

						$("#overlay_content")
							.hide()
							.css('visibility', 'visible')
							.fadeIn('slow', function() {
								// Loader wordt gehide
								$('#overlay_shadow').css('background-image', '');
							});
					},
		timeout:	5000,
		error:		function(html){
						$("#overlay_content").html('Er ging iets mis...');
					}
	});

	$('#flashmovie, #wumboswf').css('visibility','hidden');
	if (IE6)
		$('select').css('visibility','hidden');
}
