// SEITENGROESSE ERRECHNEN
function getPageSize (){

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {

		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;

	// alle ausser Explorer auf Mac
	} else if (document.body.scrollHeight > document.body.offsetHeight) {

		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;

	// Explorer auf Mac (würde auch im Explorer 6 strict, Mozilla und Safari funktionieren)
	} else {

		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;

	}

	var windowWidth, windowHeight;

	// Alle ausser Explorer
	if (self.innerHeight) {

		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;

	// Explorer 6 im Strict Mode
	} else if (document.documentElement && document.documentElement.clientHeight) {

		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;

	// Andere Explorer
	} else if (document.body) {

		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;

	}

	// 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 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;

	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) {

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

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

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

	bdy.removeChild(overlayDiv);
	bdy.removeChild(container);

}

// 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 + ",'" + 'startani_1' + "')",(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 imgPop (res_x, res_y, img, highresimg) {

	var bdy = document.getElementsByTagName('body').item(0);
	var container = document.createElement('div');
	container.id = 'imagepopup';
	container.style.width = res_x + 'px';
	container.style.height = res_y + 'px';
	container.style.position = 'absolute';
	container.style.zIndex = '600';
	bdy.appendChild(container);


	var html;
	html = '<img src="' + img + '" />';
	if (typeof highresimg != 'undefined') {
		html += '<a href="' + highresimg + '" target="_blank" class="highreslink" onfocus="blur()"><strong>Hochaufl&ouml;sende Version</strong></a>';
	}
	container.innerHTML = html;

	show_popup(container.id);

}