
var redirectHtml = '<div class="redirectoverlaydisable" style="display:none; overflow:hidden; position: fixed; z-index: 10000; background: #000000; opacity: 0.6; filter:alpha(opacity=60); width: 100%; height: 100%; top: 0; left: 0;"></div>' +
								'<div class="redirectclose redirectcloseoverlay" style="display:none;  overflow:hidden; position: fixed; cursor: pointer; top: 5px; left: 5px; z-index: 10002;"><img src="/site/' + ys_site + '/design/graphics/close.png" width="24" height="24" alt="close" title="close"/></div>' +
								'<div class="" style=" position: fixed; cursor: pointer; bottom: 0px; left: 15px; color: #FFFFFF; font-size: 0.8em; z-index: 10002;"><a style="color: #FFFFFF;" class="disableredirectoverlay" target="_blank" href=""></a></div>' +
								'<div class="redirecttooverlay" style="display:none; overflow:hidden; background: white; margin: auto; padding: 1px; position: fixed; z-index: 10001; top: 0; left: 0;">' +
								'<div class="redirectloading" style="position: fixed; color: #000000; font-size: 1.1em; width: 300px; height: 25px; text-align:center; z-index: 10001;"><img src="/site/' + ys_site + '/design/graphics/loading.gif" alt="loading" width="16" height="16" />&nbsp;Loading page</div>' +
								'<iframe class="redirectframe" src="" width="100%" height="100%" frameborder="0" style="margin: 0; padding: 0; overflow: auto;  display: block; z-index: 10002;"></iframe>' +
							'</div>' +
							'<div class="redirecttitle" style="display:none; overflow:hidden; position: fixed; bottom: 0; right: 12px; color: #FFFFFF; font-size: 0.8em; z-index: 100001;"><a style="color: #FFFFFF;" target="_blank" href="http://www.yellowmind.nl/lees-meer-over/overlay-advertising/">' + YM_trans("Overlay advertising by ") + ' Yellowmind.com</a></div>';

var hideRedirectOverlay = function()
{
	$('.redirecttitle').hide();
	$('.redirectloading').hide();
	$('.redirecttooverlay').hide();
	$('.redirectframe').attr('src', '');
	$('.redirectclose').hide();
	$('.disableredirectoverlay').hide();
	$('.redirectoverlaydisable').hide();
	$('html').css('overflow', 'auto');
	
	return false;
}

var showRedirectOverlay = function(url)
{
	if (url.substring(0,1) != '/')
	{
		var height 				= $(window).height() - 30;
		var width 				= $(window).width() - 15;
		var loadingWidth 	= $('.redirectloading').css('width');
		var loadingHeight 	= $('.redirectloading').css('height');
		loadingWidth 			= loadingWidth.substring(0, (loadingWidth.length-2));
		loadingHeight 		= loadingHeight.substring(0, (loadingHeight.length-2));
		
		$('html').css('overflow', 'hidden');
		$('.redirectoverlaydisable').height($(document).height());
		$('.redirectoverlaydisable').show();
		$('.redirectclose').show();
		$('.disableredirectoverlay').attr('href', url);
		$('.disableredirectoverlay').html(YM_trans('Open in nieuw venster'));
		$('.disableredirectoverlay').show();
		$('.redirectloading').css('top', ((height/2)-(loadingHeight/2)));
		$('.redirectloading').css('left', ((width/2)-(loadingWidth/2)));
		$('.redirectloading').show();
		$('.redirecttooverlay').height(height);
		$('.redirecttooverlay').css('margin', 15);
		$('.redirecttooverlay').show(500);
		$('.redirecttitle').show();
		$('.redirectframe').width(width);
		$('.redirectframe').height(height);
		$('.redirectframe').attr( 'src', url);
		
		setTimeout(function()
		{
			$(".redirectloading").hide()
		}, 3000);
		
		return false;
	}
}

$(
	function ()
	{
		if (redirectActOnArray)
		{
			$(document.body).append(redirectHtml);
			
			$(document).bind('keydown', 
				function (e)
				{
					if ($('.redirecttooverlay').is(':visible'))
					{
						// ctrl = 17, apple = firefox / IE 224 safari 91
						if (e.which == 17 || e.which == 224 || e.which == 91)
							isCtrl = true;
		
						// w = 87
						if (e.which == 87 && isCtrl == true)
						{
							isCtrl = false;
							hideRedirectOverlay();
							
							return false;
						}
					}
				}
			);
			
			for (i = 0; i < redirectActOnArray.length; i++)
			{
				if (redirectActOnArray[i].toLowerCase() == '_blank')
				{
					$('a[target="' + redirectActOnArray[i].toLowerCase() + '"]:not(.disableredirectoverlay)').click(function()
						{
							var url = $(this).attr('href');
							
							if (typeof(pageTracker) != "undefined")
								pageTracker._trackPageview('/outgoing/' + url);
							
							return showRedirectOverlay(url);
						}
					);
				}
				else
				{					
					$('.' + redirectActOnArray[i]).click(function()
						{
							var url = $(this).attr('href');
							
							if (typeof(pageTracker) != "undefined")
								pageTracker._trackPageview('/outgoing/' + url);
							
							return showRedirectOverlay(url);
						}
					);
				}
			}
			
			$('.redirectcloseoverlay').click(function()
				{
					return hideRedirectOverlay();
				}
			);
			
			$('.redirectframe').load(function()
				{
					$(".redirectloading").hide();
				}
			)
			
			$('.disableredirectoverlay').click(function()
				{
					hideRedirectOverlay();
				}
			);
		}
	}
);

$('document').ready(function ()
	{
		if (redirectActOnArray)
		{
			hideRedirectOverlay();
		}
	}
);
