/* --------------------------------------------------------------------
	Exernal links (incl. overlay)
-------------------------------------------------------------------- */

$(document).ready(function() {
	
	// goto external link page
	$('[rel*="gotoExternal"]')
		.one('click', function(event) {
			$(this).attr('href', RemoteForm.recode($(this).attr('href'))); 
		})	
		.fancybox({
			'centerOnScroll': false,
			'frameWidth': 488,
			'hideOnContentClick': false,
			'overlayColor': '#47145C',
			'overlayOpacity': .7,
			'padding': 0,
			'callbackOnStart': function() {
				// remove some fancybox features
				$('#fancy_title, #fancy_left, #fancy_right').remove();
				
				// hide (for resize purposes)
				$('#fancy_outer').css('opacity', 0);
				
				// set alternative shading
				$('#fancy_bg').addClass('externalLink');
				if ($.browser.msie) {
					$(".fancy_bg").attr('style', '').fixPNG();
				}
			},
			'callbackOnShow': function() {
				
				// resize the fancybox
				var boxH = $('#fancy_ajax').height();
				var minT = $('#fancy_overlay').position().top;
				var boxT = Math.max(0,( $(window).height() - boxH ) / 2);
				
				// show
				$('#fancy_outer')
				.animate({height: boxH, top: minT + boxT}, 0)
				.animate(
					{opacity: "1"},
					250
				);
			
				// add behavior to the .back button
				$('#fancy_ajax a.back').click(function() {
					$.fn.fancybox.close();
					return false;
				});
			},
			'callbackOnClose': function() {
				$('#fancy_bg').removeClass('externalLink');
			}
		})
        .attr('title', $(this).attr('title') + ', deze link opent in een overlay');
	
	if ($.browser.msie && $.browser.version < 7) {
		$('[rel*="gotoExternal"]').addClass('gotoExternal');
	};
	
	
});
