var pop = null;

//***************************
// Popup-Fenster für Dateien
//***************************

function popup(obj, name, width, height) {
	var url = (obj.getAttribute) ? obj.getAttribute('href') : obj.href;
	if(!url) return true;
	
	// Fenster generieren
	if(navigator.appName == "Microsoft Internet Explorer") {
		if(pop) pop.close();
		pop = window.open(url, "name", "left=" + (screen.width - width) / 2 + ", top="+ (screen.height - height) / 2 + ", width=" + width + ", height=" + height + ", menubar=no, locationbar=no, scrollbars=yes, resizable=yes, status=no");
	}
		else pop = window.open(url, name, "left=" + (screen.width - width) / 2 + ", top="+ (screen.height - height) / 2 + ", width=" + width + ", height=" + height + ", menubar=no, locationbar=no, scrollbars=yes, resizable=yes, status=no");

	pop.focus();
	return (pop) ? false : true;
}

// *************************
// Popup-Fenster für Bilder
// *************************

function imagePopup(obj, name, width, height) {
	var url = (obj.getAttribute) ? obj.getAttribute('href') : obj.href;
	if(!url) return true;

	imageWidth = width;
	imageHeight = height;
	
	// Einstellung: Abstand zum Bildschirmrand in Prozent
	resizeToPercent = 20;
	
	// Bildschirmauflösung feststellen
	screenWidthDeviation = screen.width * resizeToPercent / 100;
	screenHeightDeviation = screen.height * resizeToPercent / 100;
	screenWidth = screen.width - screenWidthDeviation;
	screenHeight = screen.height - screenHeightDeviation;

	// Bild skalieren
	if(imageWidth > screenWidth || imageHeight > screenHeight) {
		(imageWidth > imageHeight) ? deviationInPercent = 100 * screenWidth / imageWidth :	deviationInPercent = 100 * screenHeight / imageHeight;
		imageWidth = imageWidth * deviationInPercent / 100;
		imageHeight = imageHeight * deviationInPercent / 100;
	}
	
	// Fenster zentrieren
	positionLeft = (screen.width - imageWidth) / 2;
	positionTop = (screen.height - imageHeight) / 2;
	
	// Fenster generieren
	if(navigator.appName == "Microsoft Internet Explorer") {
		if(pop) pop.close();
		pop = window.open("sources/popups/popup.php?src=" + obj, "name", "width=" + imageWidth + ", height=" + imageHeight + ", left=" + positionLeft + ", top=" + positionTop + ", resizable=no, status=no, toolbar=no, menubar=no, locationbar=no, directories=0, scrollbars=no");
	}
		else pop = window.open("sources/popups/popup.php?src=" + obj, name, "width=" + imageWidth + ", height=" + imageHeight + ", left=" + positionLeft + ", top=" + positionTop + ", resizable=no, status=no, toolbar=no, menubar=no, locationbar=no, directories=0, scrollbars=no");

	pop.moveTo(positionLeft, positionTop);   
	pop.focus();
	
	return (pop) ? false : true;
}
