// SCROLLPOSITION
function scroll_PosX () {

	if (window.innerHeight && window.scrollMaxY) {
		return document.body.scrollWidth;
	// alle ausser Explorer auf Mac
	} else if (document.body.scrollHeight > document.body.offsetHeight) {
		return document.body.scrollWidth;
	// Explorer auf Mac (würde auch im Explorer 6 strict, Mozilla und Safari funktionieren)
	} else {
		return document.body.offsetWidth;
	}

}

// SCROLLPOSITION
function scroll_PosY () {

	if (window.innerHeight && window.scrollMaxY) {
		return window.innerHeight + window.scrollMaxY;
	// alle ausser Explorer auf Mac
	} else if (document.body.scrollHeight > document.body.offsetHeight) {
		return document.body.scrollHeight;
	// Explorer auf Mac (würde auch im Explorer 6 strict, Mozilla und Safari funktionieren)
	} else {
		return document.body.offsetHeight;
	}

}

// FENSTERBREITE
function window_Width () {

	// Alle ausser Explorer
	if (self.innerHeight) {
		return self.innerWidth;
	// Explorer 6 im Strict Mode
	} else if (document.documentElement && document.documentElement.clientHeight) {
		return document.documentElement.clientWidth;
	// Andere Explorer
	} else if (document.body) {
		return document.body.clientWidth;
	}

}

// FENSTERBREITE
function window_Height () {

	// Alle ausser Explorer
	if (self.innerHeight) {
		return self.innerHeight;
	// Explorer 6 im Strict Mode
	} else if (document.documentElement && document.documentElement.clientHeight) {
		return document.documentElement.clientHeight;
	// Andere Explorer
	} else if (document.body) {
		return document.body.clientHeight;
	}

}

// SEITENGROESSE ERRECHNEN
function getPageSize (){

	var xScroll = scroll_PosX();
	var yScroll = scroll_PosY();

	var windowWidth = window_Width();
	var windowHeight = window_Height();

	// Für Seiten deren Höhe kleiner ist als die des Viewports
	if(yScroll < windowHeight){

		pageHeight = windowHeight;

	} else {

		pageHeight = yScroll;

	}

	// Für Seiten deren Breite kleiner ist als die des Viewports
	if(xScroll < windowWidth){

		pageWidth = windowWidth;

	} else {

		pageWidth = xScroll;

	}

	// Array zusamensetzen
	arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight);

	//alert(arrayPageSize);

	return arrayPageSize;

}

// OVERLAY SETZEN
function overlay (arrayPageSize, id, video) {

	var overlayDiv = document.createElement('div');
	overlayDiv.id = 'overlay';
	overlayDiv.style.height = arrayPageSize[1] + 'px';

	var bdy = document.getElementsByTagName('body').item(0);

	bdy.appendChild(overlayDiv);

	overlayDiv.onclick = function () {
		hide_popup(id, video);
	}

}

// ZENTRIERTE NACHRICHT SETZEN
function show_popup (id, video) {

	arrayPageSize = getPageSize();

	overlay (arrayPageSize, id, video);

	var bdy = document.getElementsByTagName('body').item(0);

	var offsetX = document.all? document.documentElement.scrollLeft: pageXOffset;
	var offsetY = document.all? document.documentElement.scrollTop: pageYOffset;

	container = document.getElementById(id);

	container.style.display = 'block';

	if (!document.getElementById(id + 'closelink')) {

		var closeLink = document.createElement('a');
		closeLink.id = id + 'closelink';
		closeLink.href = '#';
		closeLink.className = 'closelink';
		closeLink.onclick = function () { hide_popup(id, video); return false; }
		//closeLink.firstChild.nodeValue = 'Fenster schlie&szlig;en';

		container.appendChild(closeLink);

	}

	var containerWidth = container.offsetWidth;
	var containerHeight = container.offsetHeight;

	//alert('height: ' + containerWidth + '\r\n' + 'width: ' + containerHeight + '\r\n' + 'margin: ' + '-' + Math.round(containerHeight / 2) + 'px 0 0 -' + Math.round(containerWidth / 2) + 'px' + '\r\n' + 'left: ' + Math.round((arrayPageSize[2] / 2) + offsetX) + 'px' + '\r\n');

	container.style.margin = '-' + Math.round(containerHeight / 2) + 'px 0 0 -' + Math.round(containerWidth / 2) + 'px';
	container.style.left = Math.round((arrayPageSize[2] / 2) + offsetX) + 'px';
	container.style.top = Math.round((arrayPageSize[3] / 2) + offsetY) + 'px';

}

function hide_popup (id, video) {

	var overlayDiv = document.getElementById('overlay');
	var bdy = document.getElementsByTagName('body').item(0);

	bdy.removeChild(overlayDiv);

	container = document.getElementById(id);
	container.innerHTML = '';
	container.style.display = 'none';

	/*
	if (typeof video != 'undefined') {
		var videoplayer = document.getElementById(video);
		videoplayer.sendEvent('STOP');
	}
	*/

}

// Ein- oder Ausblenden -------------------------------------------------------------------------------------------------------------------
function fade (id, fadeFrom, fadeTo, ms) {

	//Quelle: http://brainerror.net/scripts/javascript/blendtrans/

	//speed for each frame
	var speed = Math.round(ms / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(fadeFrom > fadeTo) {
		var i = fadeFrom;
		while(i >= fadeTo) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
			i--;
		}
	} else if(fadeFrom < fadeTo) {
		for(i = fadeFrom; i <= fadeTo; i++) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}

}

// Dekckrakt (opacity) setzen -------------------------------------------------------------------------------------------------------------
function changeOpac(opacity, id) {

    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";

}

function show_trailer (containerID, res_x, res_y, duration, file, logotype) {

	container = document.getElementById(containerID);
	container.style.width = res_x + 'px';
	container.style.height = res_y + 'px';

	var so = new SWFObject('md.static/video/player-licensed.swf','mpl', res_x , res_y, '9');
	so.addParam('allowscriptaccess','always');
	so.addParam('allowfullscreen','true');
	so.addParam('flashvars','&volume=50&duration=' + duration + '&file=../../' + file + '&image=image.jpg&backcolor=141414&frontcolor=dcdcdc&lightcolor=f08c1e&screencolor=000000&logo=md.static/video/video-logo-' + logotype + '.png&skin=md.static/video/modieus.swf&bufferlength=' + duration/4 + '&controlbar=over&autostart=true');
	so.write(containerID);

	show_popup(containerID, 'mpl');

}

function show_youtubevideo (containerID, res_x, res_y, url) {

	container = document.getElementById(containerID);
	container.style.width = res_x + 'px';
	container.style.height = res_y + 'px';

	var html = '<object width="' + res_x + '" height="' + res_y + '"><param name="movie" value="' + url + '"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="' + url + '" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="' + res_x + '" height="' + res_y + '"></embed></object>';
	container.innerHTML = html;

	show_popup(containerID, 'mpl');

}

