// remap jQuery to $
(function($){})(window.jQuery);

function _initFullscreen()
{
	$('div.wrapperX').videoBG({
		position:"fixed",
		zIndex:-1,
		mp4:'TYPO_Animation_Elemente.mp4',
		ogv:'TYPO_Animation_Elemente.ogv',
		webm:'TYPO_Animation_Elemente.webm',
		poster:'Image02.jpg',
		opacity:1,
		height: '100%',
		autoplay:true,
		scale:true
	});

	//var dim = $('#videobg').getVideoDimensions();
//alert(getVideoDimensions());
	var dim = getVideoDimensions();
	var h = dim[1];
	var w = dim[0];
	$('#videobg').css({width:Math.ceil(w), height:Math.ceil(h)});
	$('#videobg2').css({width:Math.ceil(w), height:Math.ceil(h)});
	$('#videobg').attr('loop',true);

	var h2 = $(window).innerHeight();
	var w2 = $(window).innerWidth();
	$('#imprint').css({left:Math.ceil((w2-($('#imprint').width()))/2), top:((h2-$('#imprint').height())/2)});
}

function imprint()
{
	$('#imprint').toggle();
}

function getVideoDimensions() {
		var windowWidth = $(window).innerWidth();
		var windowHeight = $(window).innerHeight();
		windowProportion = windowWidth / windowHeight;
		var origWidth = 1280;
		origHeight = 720;
		var origProportion = origWidth / origHeight;
		var newWidth = 0; var newHeight = 0;
		if (windowProportion >= origProportion) {
			proportion = windowWidth / origWidth;
		} else {
			proportion = windowHeight / origHeight;
		}
		newWidth = proportion * origWidth;
		newHeight = proportion * origHeight;
		//console.log('Window Height:%s, newWidth: %s, newHeight: %s',windowHeight,newWidth,newHeight);
		return [newWidth,newHeight]
}
var t;
function loopVideo() {
t = window.setInterval(function() {
	$('#videobg').on('ended',function(e){ this.play() });},500);
}

/* trigger when page is ready */
$(document).ready(function (){
	_initFullscreen();
	loopVideo();
});
$(window).resize(function() {
	_initFullscreen()
});

/* optional triggers

$(window).load(function() {

});

$(window).resize(function() {

});

*/

