window.addEvent('domready', function() {
	
	var overlaystyle = {};
	overlaystyle['position'] = 'absolute';
	overlaystyle['top'] = '0px';
	overlaystyle['left'] = '0px';
	overlaystyle['width'] = '100%';
	overlaystyle['height'] = '100%';
	overlaystyle['z-index'] = '10';
	overlaystyle['background-image'] = $(document.body).getStyle('background-image');
	overlaystyle['opacity'] = '0';
    
    var overlay = new Element('div', {
    	'id': 'vdOverlay',
	    'styles': overlaystyle,
	    'events': {
	        'click': function(){
	        	
	        	this.effect('opacity', {duration: 200, transition: Fx.Transitions.linear}).start(1,0);
	        	$('vdCenter').remove();
	        	
	        }
	    }
	}).injectInside(document.body);
	
	$each(document.links, function(el){
		if (el.rel && el.rel.test(/^vidbox/i)){
			var video = el.rel.split(":");
			var titel = el.title;
			
			el.addEvent('click', function(e){
				
				var center = new Element('div', {
			    	'id': 'vdCenter',
				    'styles': {
				        'position': 'absolute',
				        'top': '60px',
				        'left': '500px',
				        'width': '450px',
				    }
				}).injectInside('vdOverlay');
				
				var cVideo = new Element('div', {
				    'styles': {
				        'position': 'absolute',
				        'top': '0px',
				        'left': '0px',
				        'width': '450px',
				    },
				    'events': {
				        'click': function(event){
     						
     						event.stopPropagation();
				        	
				        }
				    }
				}).injectInside(center);
				
				var videoobject = new Element('object', {
				    'width': '450',
				    'height': '340'
				}).injectInside(cVideo);
				
				var param01 = new Element('param', {
				    'allowfullscreen': 'true'
				}).injectInside(videoobject);
				
				var param02 = new Element('param', {
				    'allowscriptaccess': 'always'
				}).injectInside(videoobject);
				
				var param03var = {};
				param03var['name'] = 'movie';
				param03var['value'] = 'http://vimeo.com/moogaloop.swf?clip_id='+video[1]+'&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1';
				
				var param03 = new Element('param', param03var).injectInside(videoobject);
				
				var videoembedvar = {};
				videoembedvar['src'] = 'http://vimeo.com/moogaloop.swf?clip_id='+video[1]+'&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1',
				videoembedvar['type'] = 'application/x-shockwave-flash';
				videoembedvar['allowfullscreen'] = 'true';
				videoembedvar['allowscriptaccess'] = 'always';
				videoembedvar['width'] = '450';
				videoembedvar['height'] = '340';
				
				var videoembed = new Element('embed', videoembedvar).injectInside(videoobject);
				
				var cTitel = new Element('div', {
					'class': 'linien',
				    'styles': {
				    	'position': 'absolute',
				    	'top': '355px',
				    	'padding-top': '5px',
				    	'padding-bottom': '5px',
				        'width': '450px'
				    }
				}).injectInside(center);
				
				var cClose = new Element('div', {
				    'styles': {
				        'width': '20px',
				        'float': 'right',
				        'text-align': 'right',
				        'cursor': 'pointer'
				    }, 'events': {
				        'click': function(){
				        	
				        	this.effect('opacity', {duration: 200, transition: Fx.Transitions.linear}).start(1,0);
				        	$('vdCenter').remove();
				        	
				        }
				    }
				}).injectInside(cTitel);
				
				cClose.setText("X");
				
				var cText = new Element('div', {
				    'styles': {
				        'margin-right': '71px'
				    }
				}).injectInside(cTitel);
				
				cText.setText(titel);
				
				$('vdOverlay').effect('opacity', {duration: 200, transition: Fx.Transitions.linear}).start(0,1);
				
				e.preventDefault();
				
			});
		}
	});
    
});
