document.write("<div id=\"vxMediaOverlay\"></div>");
document.write("<div id=\"vxMediaContent\"></div>");

function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}


function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}


function showOverlay() {  
	var objOverlay = document.getElementById("vxMediaOverlay");
	var arrPageSize = getPageSize();
	
	objOverlay.style.height = arrPageSize[1] + "px";
	objOverlay.style.width = "100%";
  objOverlay.style.display = "block";
} // showOverlay


function vxMediaImage(imgHref) {
	
	var objContainer = document.getElementById("vxMediaContent");	
	var arrPageScroll = getPageScroll();
	var arrPageSize = getPageSize();
	var imgGallery = new Image();
	
	// Loader	
	objContainer.innerHTML = "<img src=\"/images/vxGallery/loader.gif\" />";
	
	// Background
	showOverlay();
	
	imgGallery.src = imgHref;
	objContainer.style.marginLeft = (imgGallery.width / 2)*-1 + "px";
	objContainer.style.top = arrPageScroll[1] + 200 + "px";
	

	// mittig positionieren
	imgGallery.onload = function() {
												objContainer.innerHTML = "<img src=\"" + imgGallery.src + "\" /><br><a href=\"#\" onClick=\"vxMediaClose()\">Schliessen</a>";
											};
	
	objContainer.style.display = "block";
	
} // vxMediaImage


// ----------------------------------------------------------------------------------------------
function vxMediaVideo(id) {
  vxMediaStart('video',id, 245);
} // vxMediaVideo


// ----------------------------------------------------------------------------------------------
function vxMediaAudio(id) {
  vxMediaStart('audio',id, 245);
} // vxMediaVideo


// ----------------------------------------------------------------------------------------------
function vxMediaStart(type, id, objWidth) {
	
  req1create();
	
	var objContainer = document.getElementById("vxMediaContent");	
	var arrPageScroll = getPageScroll();
	var arrPageSize = getPageSize();
							
	// Background
	showOverlay();	
	objContainer.innerHTML = "<img src=\"/images/vxGallery/loader.gif\" />";
	objContainer.style.marginLeft = (objWidth / 2)*-1 + "px";
	objContainer.style.top = arrPageScroll[1] + 200 + "px";
	
  req1.onreadystatechange = function () {	  
		if (req1.readyState == 4) {
	    if (req1.status == 200) {	
							
					// mittig positionieren
					objContainer.innerHTML = req1.responseText;					
					objContainer.style.display = "block";
				
	    } // if
		} // if		
	};
  req1.open('POST', '/vxMedia/' + type + '.html', true);
  req1.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  req1.setRequestHeader("Connection", "close");
  req1.send('control=true&id=' +id);
} // vxMediaVideo


function vxMediaClose() {
	
	var objContainer = document.getElementById("vxMediaOverlay");	
	var objOverlay = document.getElementById("vxMediaContent");	
	objContainer.style.display = "none";
	objOverlay.style.display = "none";
	
}
