document.observe("dom:loaded", function() {
	if ( $('openfilter') ) {
		$('openfilter').observe('click', function( event ) {
			Event.stop( event );
			$('overlay').toggleClassName('invisible');
			$('filterbox').toggleClassName('invisible');
		});
	}
	
	if ( $('openmap') ) {
		$('openmap').observe('click', function( event ) {
			Event.stop( event );
			$('overlay').addClassName('invisible');
			$('filterbox').addClassName('invisible');
			$('legendabox').addClassName('invisible');
		});
	}
	
	if ( $('openlegenda') ) {
		$('openlegenda').observe('click', function( event ) {
			Event.stop( event );
			$('overlay').toggleClassName('invisible');
			$('legendabox').toggleClassName('invisible');
		});
	}
	
	if ( $('newroutedown') ) {
		$('newroutedown').observe('click', function( event ) {
			Event.stop( event );
			$('newroute_overlay').toggleClassName('invisible');
			$('newroute').toggleClassName('invisible');
			$('newroutedown').toggleClassName('up');
		});
	}
	
	if ( $('newroutedown-opslaan') ) {
		$('newroutedown-opslaan').observe('click', function( event ) {
			Event.stop( event );
			$('newroute_overlay').toggleClassName('invisible');
			$('newroute').toggleClassName('invisible');
			$('newroutedown').toggleClassName('up');
		});
	}
	
	if ( $('specificaties') ) {
		$('specificaties').observe('click', function( event ) {
			Event.stop( event );
			$('lidmaatschap-overview').style.display = 'none';
			$('lidmaatschap-specs').style.display = 'block';
			this.addClassName('active');
			$('vergelijken').removeClassName('active');
		});
	}
	
	if ( $('vergelijken' ) ) {
		$('vergelijken').observe('click', function( event ) {
			Event.stop( event );
			$('lidmaatschap-overview').style.display = 'block';
			$('lidmaatschap-specs').style.display = 'none';
			this.addClassName('active');
			$('specificaties').removeClassName('active');
		});
	}
	
	if($('hoofd_anders')) {
		$('hoofd_anders').next().hide();
		$('hoofd_anders').observe('click', function(e){
			$('hoofd_anders').next().toggle();
		});
	}

	/*	Klasses	*/
	
	$$('a.sluit').each( function ( element ) {
		element.observe('click', function( event ){
			Event.stop( event );
			$('overlay').addClassName('invisible');
			$('filterbox').addClassName('invisible');
			$('legendabox').addClassName('invisible');
		});
	});

	var active_popup	= null;
	$$('a.popup').each( function( element ) {
		element.observe('click', function( event ) {
			event.stop();
			if ( active_popup )
				active_popup.removeClassName( 'over' );
			var span		= element.next('.target');
			span.addClassName('over');
			active_popup	= span;			
		});
	});
	document.observe( 'click' , function ( event ) {
		if ( active_popup )
			active_popup.removeClassName( 'over' );
	});
	
	$$('a.back').each( function ( a ) {
		a.observe( 'click' , function( event ) {			
			window.history.back();
			Event.stop( event );
		});
	});

	$$('a.print').each( function ( a ) {
		a.observe( 'click' , function( event ) {
			Event.stop( event );
			var url	= a.href;
			
			//	toevoeging:
			if ( a.readAttribute( 'rel' ) && !a.readAttribute( 'rel' ).empty() )
				if ( url.indexOf( '?' ) != -1 )
					url += '&' + a.readAttribute( 'rel' );
				else
					url += '?' + a.readAttribute( 'rel' );
			
			print( url );
		});
	});
	
});

function getFullUrl() {
	var url = getStrippedUrl();
	var divider = hasQueryParams(url) ? '&' : '?';
	return url + divider + 'actie=print';
}

function getStrippedUrl() {
	var url = location.href;
	var index = url.lastIndexOf('#');
	return index != -1 ? url.substr( 0, index ) : url;
}

function print( url ) {
  popup = window.open( url, "help", "width=720, height=700, top=100, left=100, toolbar=0, resizable=1, scrollbars=1, status=0.menubar=0, location=0, directories=0");
  popup.focus();
}