

var VideoHeight = 450;
var VideoWidth = 800;

var AutoSizePercent = 70; // Werte 0 - 100

var Vorschaubild = ""; //URL
var PlayerAutoStart = false; //Werte true , false


var ShadowOpacity = 0.9; //Werte 0.0 - 1

var Rand = 0; // Werte 0 - 100

var RandFarbe = "#000000";
var ShadowFarbe = "#000000";

var SpeedTransition = 1500;		// Werte 0 - unendlich

var PlayerStrechingMode = "fill";   //uniform,fill,exactfit,bestfit,none 
var AutoSize = false;  //Werte true , false




//-----------------------------------------------------------------------------------------------------

function DocumentHeight() {

	var body = document.body,
    	html = document.documentElement;

	var DocHeight = Math.max( body.scrollHeight, body.offsetHeight, 
    	html.clientHeight, html.scrollHeight, html.offsetHeight );

	return DocHeight;

};


function DocumentWidth() {

	var body = document.body,
    	html = document.documentElement;

	var DocWidth = Math.max( body.scrollWidth, body.offsetWidth, 
    	html.clientWidth, html.scrollWidth, html.offsetWidth );

	return DocWidth;

};

function WindowWidth() {

	var body = document.body,
    	html = document.documentElement;

	var WinWidth = Math.max(html.clientWidth);

	return WinWidth;

};



function WindowHeight() {
    var WinHeight = 0;
 
    if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
       
        WinHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
       
        WinHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
       
        WinHeight = document.body.clientHeight;
    }
    return WinHeight;
}






function getScrollY() {
    var scrOfX = 0, scrOfY = 0;
 
    if( typeof( window.pageYOffset ) == 'number' ) {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    return scrOfY;
}





	

function ShadowEnd() {

	
	
	
	function fade (endVolume, percent, interval) {
  		
  		if (jwplayer("JWPlayer").getVolume() < 11){
			jwplayer("JWPlayer").pause(true);
    		return;
  		}
  		
  		
  		
 		jwplayer("JWPlayer").setVolume(jwplayer("JWPlayer").getVolume() - percent);
  		setTimeout(function () {
    		fade(endVolume, percent, interval);
  		}, interval);
	}
	
	fade(0,20,1);


	$('#FadeBlack').fadeOut(1000);
		
	$('#VideoWindow').fadeOut(1000, function() {
		$('#VideoBox').css('height', 0);
		$('#VideoBox').css('width', 0);
		jwplayer("JWPlayer").remove();
		$('body,html').animate({scrollTop: ScrollPosition}, 800, function () {
			$('body').css({overflow:'inherit'});
		});
	
		
		
	
			
		
		SlideShowPlay = true;	
		TICKER_PAUSED_VIDEO = false;
		
	});
}	
	
	//file,VideoWidth,VideoHeight,PlayerStrechingMode,Vorschaubild,PlayerAutoStart


function VideoShow(file,VideoWidth,VideoHeight,AutoSize,PlayerStrechingMode,Vorschaubild,PlayerAutoStart) {
	
	//clearInterval(_timer[0]);
	SlideShowPlay = false;	
	
	var AutoSizer = AutoSize;
	var FirstPlay = true;
	var BoxActive = 0;
	
	ScrollPosition = getScrollY();
	
	
	
	var DocHeight2 = DocumentHeight();
	var DocWidth2 = DocumentWidth();
	var WinWidth2 = WindowWidth();
	var WinHeight2 = WindowHeight();
	var RandPixel = Rand + "px";
	
	var VideoW = VideoWidth;
	var VideoH = VideoHeight;
	
	var Aspect = VideoWidth / VideoHeight;
	
	
	
	if(AutoSizer){
		VideoW = Math.floor(WinWidth2 * (AutoSizePercent / 100));
		VideoH = Math.floor(VideoW/Aspect);
		
		if (VideoW > VideoWidth){
			VideoW = VideoWidth;
			VideoH = VideoHeight;
		};
		
	};
	
	
	
	
	var PlayerVerticalCenter = (WinHeight2 / 2)- ((VideoH/2)+Rand);
	
	if(PlayerVerticalCenter < 10){
		PlayerVerticalCenter = 10;
	}

	
	
	
	if (file == "" || file == undefined) {
		alert('Bitte geben Sie einen gültigen Pfad zu den Videoclips ohne Punkt und Suffix an!');
		return;
	};
	
	if ( !isNaN( parseFloat(VideoHeight) ) ) { 
   
	} else {
    	alert('Bitte geben Sie eine gültige Höhe für den Videoclip ein!');
    	return;
	};
	
	if ( !isNaN( parseFloat(VideoWidth) ) ) { 
   
	} else {
   		alert('Bitte geben Sie eine gültige Breite für den Videoclip ein!');
    	return;
	};
	
	
	if (PlayerAutoStart == true || PlayerAutoStart == false) {
		alert('Bitte geben Sie für den Autostart des Video entweder "true" oder "false" ein!');
		return;
	};
	
	

	//Ticker und Slideshow pausieren
	TICKER_PAUSED_VIDEO = true;
	
	
	
	var URLMP4 = file + ".mp4";
	var URLWEBM = file + ".webm";
	
	
	
	/*if(PlayerAutoStart){
		Vorschaubild = "";
	};*/
	
	
	
	if(iPhoneBrowser || iPadBrowser){		
		DocHeight2 = DocHeight2+300+"px";
		DocWidth2 = DocWidth2+"px";
		
	
	}else{
		DocHeight2 = DocHeight2+"px";
		DocWidth2 = DocWidth2+15+"px";
		
		
		
	};
	
	$('body').css({overflow:'hidden'});
	
	$('body,html').animate({scrollTop: 0}, 400);
	
	
	
	
	
	
	$('#FadeBlack').css({
		'height': DocHeight2,
		'width': DocWidth2,
		'background': ShadowFarbe
	});
	
	$('#FadeBlack').fadeTo(SpeedTransition,ShadowOpacity);
	
	
	$('#VideoWindow').fadeIn(0);
	
	$('#VideoHolder').css({'margin-top':PlayerVerticalCenter});
	
	
	$('#CloseBTN').fadeOut(0);
	$('#JWPlayer').css('height', VideoH);
	$('#JWPlayer').css('min-width', VideoW);
	$('#VideoRand').css({
		'margin-left': RandPixel,
		'top':Rand		
	
	});
	
	$('#VideoBox').css('background', RandFarbe);
	
	
	$("#VideoBox").animate({width: (VideoW+(2*Rand)),height: (VideoH+(2*Rand))},SpeedTransition, function() {
			
		$('#VideoLoader').fadeIn(500);
		
		
		$('#VideoBox').mouseover(function() {
			BoxActive = 1;
			
		});
		
		$('#VideoBox').mouseout(function() {
			BoxActive = 0;
			
		});
		if(!iPhoneBrowser && !iPadBrowser){
			
			$('#FadeBlack').css({
				'height': '100%',
				'width': '100%'
			});
		};
		
    	jwplayer("JWPlayer").setup({
			events: {
				onReady: function() {$('#VideoLoader').fadeOut(200);if(PlayerAutoStart) {jwplayer("JWPlayer").play(true);};},
				onComplete: function() {ShadowEnd();},
				onPlay: function() {if(FirstPlay){FirstPlay = false;jwplayer("JWPlayer").setVolume(80);};},
				
		
			},
		
			stretching: PlayerStrechingMode,
			flashplayer: "http://www.buehnenfilm.de/swf/player-licensed.swf",
			image: Vorschaubild,
			width: VideoW,
			height:VideoH,
			levels: [
    	   		{file: URLMP4},
       	     	{file: URLWEBM}
	    	    
                        ]
  	  	});
  	  	
  	  	
  	  	$('#CloseBTN').css({
			'top': (-Rand-15)+'px',
			'left':(VideoW-15+Rand)+'px'		
	
		});
  	  	
  	  	
  	  	$('#CloseBTN').fadeIn(2000);
  	  	
  	  	document.getElementById('VideoWindow').onclick = function() { 
		 	if(BoxActive == 0) {
		 		ShadowEnd();
			 };
		 };
		 
		 document.getElementById('CloseBTN').onclick = function() { 
		 	
		 	ShadowEnd();
			 
		 };
		 
		document.onkeydown = function(e){
   			if (e == null) { // ie
    			keycode = event.keyCode;
    		} else { // mozilla
   				keycode = e.which;
    		}
   			if(keycode == 27){ 
    			ShadowEnd();
   			}
    	};
		 
 	});
		
	

}



