
/**
 * Setup the Paybox
 */
window.setupPaybox = function ()
{
	if (!jQuery || window.mbetaal) {
		return;
	}
	
	jQuery.noConflict();
	
	// Define a closure for the jQuery symbol $
	(function ($)
	{
		var hidden_items = [];

		window.mbetaal = function (extra)
		{
			paybox_intro(extra);
		}

		window.paybox_reposition_box = function ()
		{
			var window_height = 0; 
	
			(window_height = window.innerHeight) || 
			(window_height = document.documentElement.clientHeight) || 
			(window_height = document.body.clientHeight);
	
			$('#paybox_box').css('top', $(window).scrollTop() + (window_height - $('#paybox_box').height()) / 2);
			$('#paybox_close').css('top', $(window).scrollTop() + (window_height - $('#paybox_box').height()) / 2 + 5);
		}
	
		window.paybox_intro = function (extra)
		{
			$('#paybox_box, #paybox_wall, #paybox_close').remove();
	
			$(document.body).append('<div id="paybox_wall" style="display:none; background:#000; z-index:9997; position:absolute; top:0; left:0; width:4096px; height:3078px"></div><iframe id="paybox_box" style="background:url(http://www.mollie.nl/images/icons/aquaspinner.gif) no-repeat fixed center; display:none; padding:0; margin-left:-200px; border:1px solid #555; position:absolute; z-index:9998; top:0; left:50%; -webkit-box-shadow:1px 2px 10px rgba(0,0,0,0.6); box-shadow:1px 2px 10px rgba(0,0,0,0.6); -moz-box-shadow:1px 2px 10px rgba(0,0,0,0.6); " src="http://www.mollie.nl/partners/betaal/?partnerid=437605&'+extra+'" width="400" height="450" border="no" frameborder="0" marginheight="0" marginwidth="0" scrolling="no">iframes niet ondersteund, andere browser gebruiken</iframe><a id="paybox_close" style="display:none;opacity:0;cursor:pointer;position:absolute;z-index:9999;margin-left:180px;left:50%;" onclick="paybox_outro()"><img src="http://www.mollie.nl/partners/images/close.png"></a>');	
				
			paybox_reposition_box();
	
			$('object, embed, select, option').each(function (index) 
			{
				hidden_items[index] = { object:this, visibility:this.style.visibility };
				$(this).css('visibility', 'hidden');
			});

			$(document.body).css({overflow:'hidden'});
			$('#paybox_wall').css({opacity: 0}).show().fadeTo(400, 0.7);		
			$('#paybox_box').css({opacity: 1}).show();
			$('#paybox_close').css({opacity: 0.5, display:'block'})
				.hover(function () { $(this).fadeTo(200, 1); }, function () { $(this).fadeTo(100, 0.5); });
		
			// Firefox is a little slower, so reposition the paybox again
			paybox_reposition_box();
		}

		window.paybox_outro = function ()
		{
			$(hidden_items).each(function (index, item)
			{
				$(item['object']).css('visibility', item['visibility']);
			});

			$(document.body).css({overflow:'auto'});
			$('#paybox_wall').css({opacity: 0.7}).fadeTo(400, 0, function(){$(this).remove();} );	
			$('#paybox_box').attr({src:''}).remove();
			$('#paybox_close').remove();
		}

		$(window).resize(paybox_reposition_box);
		
	}) (jQuery); // Call the closure
}


/**
 * Import jQuery from Google
 */
var head      = document.getElementsByTagName('head')[0];
var jquery    = document.createElement('script');

jquery.type   = 'text/javascript';
jquery.src    = 'https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js';
jquery.onload = jquery.onreadystatechange = function () { window.setupPaybox() };

head.appendChild(jquery);


