var $j = jQuery.noConflict();

function removePlayer() {
	$j("#videoplayerMask").fadeTo(600,0, function() {
		$j("#videoplayerMask").stop();
		$j("#videoplayerMask").remove();
		$j("#videoplayerContainer").remove();
	});
}

$j(document).ready(function() {
	$j(".swfplayer").bind("click", function() {
		var videoFile = $j(this).attr("href");
		if(videoFile.search(/http/) == -1) {
			videoFile = 'http://www.charles-voegele.ch/' + videoFile;
		}
		$j(document).keyup(function(e) {
			if (e.keyCode == 27) { removePlayer(); } 
		});
                $j("html, body").animate( { scrollTop: 0 }, 0 );
		$j("body").append("<div id='videoplayerMask'></div><div id='videoplayerContainer'><div id='videoplayerBox'></div></div>");
		$j("#videoplayerContainer").bind("click", function() {		
			removePlayer();
		});
		$j("#videoplayerMask").hide();
		$j("#videoplayerMask").fadeTo(600,0.8, function() {
			flashembed(
				'videoplayerBox',
				{
					src: 'fileadmin/templates/swf/VideoLayerLightBox.swf',
					wmode:'transparent'
				},{
					autoPlay: '1',
					videoURL: videoFile,
					videoWidth: '780',
					showCloseButton: '1',
					jsCloseFunction: 'removePlayer',
					lightboxAlpha: '0'
				}
			);
		});
		return false;
	});
});
