$('document').ready(function() {

	if ($('a.videolink').length > 0) {
		// Overlay für Vorschau einbauen
		var e_prev =	'<div class="overlay_video">';
		e_prev +=		'	<div class="video_close" title="Schließen">X</div>';
		e_prev +=		'	<div id="videoplayer">';
		e_prev +=		'	</div>';
		e_prev +=		'</div>';
		$('body').prepend(e_prev);


			// overlay einrichten
		$('.overlay_video').overlay({
			mask: {
				color: '#000',
				loadSpeed: 500,
				opacity: 0.6
			},
			close: '.video_close',
			onClose: function() {
				$('div#videoplayer').html('');
			},
			top: 'center'
		});
		var videoLayer = $(".overlay_video").data("overlay");



			// klick-event fuer videolinks einrichten
		$('a.videolink').click(function() {

			var videoPath = $(this).attr('href'),
				videoConfig = 'config={\'playlist\':[{\'url\': \'' + videoPath + '\',\'autoPlay\':false,\'autoBuffering\':true}]}';


				// videolayer mit videojs-code fuellen und initialisieren
			$('div#videoplayer').html(function(){
				return  '<div class="video-js-box">' +
						'<video id="videocontent" class="video-js" width="720" height="400" controls="controls" preload="auto">' + 
						'<source src="' + videoPath + '" type="video/mp4; codecs=\'avc1.42E01E, mp4a.40.2\'" />' + 
						'<object id="flash_fallback_1" class="vjs-flash-fallback" width="720" height="400" type="application/x-shockwave-flash" data="fileadmin/templates/swf/flowplayer.swf">' + 
						'<param name="movie" value="fileadmin/templates/swf/flowplayer.swf" />' + 
						'<param name="allowfullscreen" value="true" />' + 
						'<param name="flashvars" value="' + videoConfig + '" />' + 
						'Zum Abspielen des Videos wird ein aktueller Browser oder das <a href="http://www.adobe.com/go/getflashplayer_de">Flash Plug-In</a> benötigt.' + 
						'</object>' + 
						'</video>' + 
				    	'</div>';
			});
			window.setTimeout(function(){

				VideoJS.setup("videocontent", {    
					flashVersion: 10
				});
			}, 200);


				// videolayer anzeigen
			videoLayer.load();
			return false;
		});
	}

});

