Y.use('node', 'anim','ua', function(Y) {
Y.on('domready', function(o) {
	var allVisibile = false;
	var onImageclickUrl;

	var h = 0;dh = 0 , w = 0, dw = 0, lw = 0, lh = 0;

	var overlay = Y.Node.create('<div></div>');
	overlay.set('id','redirect-overlay');
	
	var box = Y.Node.create('<div></div>');
	box.set('id','redirect-box');

	var layer = Y.Node.create('<div></div>');
	layer.set('id','redirect-layer');
	layer.set('innerHTML','<img src="/assets/images/logo.jpg"><br /><strong>Achtung</strong><br />Du wirst jetzt automatisch zu unserem Zahlungsdienstleister MEGABill weitergeleitet.<br /><br /> Falls sich kein Fenster öffnet <a href="#" onClick="document.getElementById(\'aufladenform\').submit();return false;">klicke hier</a>');
	
	var navigation = Y.Node.create('<div><a href="#" id="redirect-navigation-close">(x) Schliessen</a></div>');
	navigation.set('id','redirect-navigation');


	
    var onClick = function( formid ) {
		overlay.setStyle('visibility','visible');
		overlay.setStyle('display','block');
		animIn.run();

		window.setTimeout(function(){Y.get('#' + formid).submit();window.setTimeout(hideAll,4000);}, 2000);
	
	};

	function reposition()
	{
		bw = box.get('offsetWidth');
		bh = box.get('offsetHeight');

		box.setStyle('left', ((w-bw)/2)+'px');
		box.setStyle('top', ((h-bh)/2)+'px');

		
	}



	function loadImage() {

		box.setStyle('display','block');

		reposition();

		box.setStyle('visibility','visible');

		layer.setStyle('visibility','visible');
		

		
    }

	function hideAll()
	{
		

		box.setStyle('visibility','hidden');
		box.setStyle('display','none');
		overlay.setStyle('visibility','hidden');
		overlay.setStyle('display','none');


		allVisibile = false;

	}


	var animIn = new Y.Anim({
			node: overlay,
			duration:0.4,
			to: {opacity: 0.8}
	});

	animIn.on('end', loadImage );


	Y.on('resize', function(e) {
		h = this.get('winHeight');
		w = this.get('winWidth');
		dh = this.get('docHeight');
		dw = this.get('docWidth');

		reposition();
	});

	Y.on('load', function(o) {

		Y.one('body').appendChild(overlay);
		Y.one('body').appendChild(box);
			box.appendChild(layer);
			box.appendChild(navigation);

		layer.setStyle('display','block');
		lw = layer.get('offsetWidth');
		lh = layer.get('offsetHeight');
		
		navigation.setStyle('display','none');

		if ( Y.UA.ie >= 5 && Y.UA.ie <= 6 ) {
			overlay.setStyle('position', 'absolute');
			box.setStyle('position', 'absolute');
		}
		
		Y.all('.paket').each(function(node) {
			if ( node.getAttribute('rel') == 'aufladen') {

				node.on('click', function(e) {

					e.preventDefault();

					h = this.get('winHeight');
					w = this.get('winWidth');
					dh = this.get('docHeight');
					dw = this.get('docWidth');

					if ( Y.UA.ie >= 5 && Y.UA.ie <= 6 ) {

						overlay.setStyle('height', dh+'px');
						overlay.setStyle('width', dw+'px');

					}
					var id = this.get('id');
					id = id.replace(/div/g,"form")
					onClick(id);
				});
			}
		});

		if ( Y.get('#aufladensubmit') ) {
			Y.one('#aufladensubmit').on('click', function(e) {

				e.preventDefault();
				h = this.get('winHeight');
				w = this.get('winWidth');
				dh = this.get('docHeight');
				dw = this.get('docWidth');

				if ( Y.UA.ie >= 5 && Y.UA.ie <= 6 ) {

					overlay.setStyle('height', dh+'px');
					overlay.setStyle('width', dw+'px');

				}


				if ( Y.one('#aufladenform') ) {
					onClick('aufladenform');
				}
			});
		}
	});

});

	
});

