function getAdr(prefix, postfix, text) {
        document.write('<a href="mailto:' + prefix + '@' + postfix + '">' + (text ? text.replace(/&quot;/g, '"').replace(/%EMAIL%/, prefix + '@' + postfix) : prefix + '@' + postfix) + '</a>');
}

// deletes leading and trailing spaces in a string - adds the function directly to the String Object, so that all strings inherit this method
String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, '');
}

function popup(url, typ, para1, width, height) {
	attrib = "";
	Y = (screen.height - width) / 2;
	X = (screen.width - height) / 2;
	X = Math.round(X);
	Y = Math.round(Y);
	if (para1 == 'CENTER') attrib += 'height=' + height + ',width=' + width + ',top=' + Y + ',left=' + X;
	if (typ == 'TYP1') attrib += ",scrollbars=no";
	if (typ == 'TYP2') attrib += ",scrollbars=yes";
	if (typ == 'TYP3') attrib += ",scrollbars=yes,menubar=yes";
	fenster = window.open(url, 'win', attrib);
	return false;
}

function displayfaq(id) {
	var divisions = document.getElementsByTagName('div');
	for (i=0;i<divisions.length;i++) {
		if (divisions[i].className.indexOf('faqitem') > -1) {
			divisions[i].style.display = 'none';
		}
	}
	document.getElementById('question_'+id).style.display='block';
}

// Sujetchanger

function changesujet() {

    var spancount = document.getElementById('sujet').getElementsByTagName('span').length;
    var sujetlist = document.getElementById('sujetlist').getElementsByTagName('a');
    sujetlistnew = new Array;

    for(i=0; i<sujetlist.length; i++) {
        sujetlistnew[i] = sujetlist[i].href;
    }

    for(i=0; i<spancount; i++) {
        var randomindex = Math.floor(Math.random() * sujetlistnew.length);
        var sujetrandom = sujetlistnew.splice(randomindex, 1)[0];
        document.getElementById('sujet').getElementsByTagName('span')[i].style.background = "url(" + sujetrandom + ")";
    }

}



// Doomready
	var doomready = new Object();
	doomready = {
		add: function(fn) {
			if (doomready.loaded) return fn();
			var observers = doomready.observers;
			if (!observers) observers = doomready.observers = [];
			observers[observers.length] = fn; // Arraypush is not supported by Mac IE 5
			if (doomready.callback) return;
			doomready.callback = function() {
				if (doomready.loaded) return;
				doomready.loaded = true;
				if (doomready.timer) {
					clearInterval(doomready.timer);
					doomready.timer = null;
				}
				var observers = doomready.observers;
				for (var i = 0, length = observers.length; i < length; i++) {
					var fn = observers[i];
					observers[i] = null;
					fn(); // make 'this' as window
				}
				doomready.callback = doomready.observers = null;
			};
	
			var ie = !!(window.attachEvent && !window.opera);
			var webkit = navigator.userAgent.indexOf('AppleWebKit/') > -1;
			if (document.readyState && webkit) { // Apple WebKit (Safari, OmniWeb, ...)
				doomready.timer = setInterval(function() {
					var state = document.readyState;
					if (state == 'loaded' || state == 'complete') {
						doomready.callback();
					}
				}, 50);
			}
			else if (document.readyState && ie) { // Windows IE
				var src = (window.location.protocol == 'https:') ? '://0' : 'javascript:void(0)';
				document.write(
					'<script type="text/javascript" defer="defer" src="' + src + '" ' +
					'onreadystatechange="if (this.readyState == \'complete\') doomready.callback();"' +
					'><\/script>');
			}
			else {
				if (window.addEventListener) { // for Mozilla browsers, Opera 9
					document.addEventListener("DOMContentLoaded", doomready.callback, false);
					window.addEventListener("load", doomready.callback, false); // Fail safe
				}
				else if (window.attachEvent) {
				window.attachEvent('onload', doomready.callback);
				}
				else { // Legacy browsers (e.g. Mac IE 5)
					var fn = window.onload;
					window.onload = function() {
						doomready.callback();
						if (fn) fn();
					}
				}
			}
		}
	}

doomready.add(function() {
	changesujet();
	initDatevGallery('smoothbox');
});

function ShowGallery(id) {
	for(i=0;i<gallerypix.length;i++) {
		document.getElementById('galpic_'+gallerypix[i]).style.display = 'none';
		document.getElementById('galnav_'+gallerypix[i]).style.display = 'none';
	}

	document.getElementById('galpic_'+gallerypix[id]).style.display = 'block';
	document.getElementById('galnav_'+gallerypix[id]).style.display = 'block';
}

/* set opacity of any object */
function opacity(obj, value) {
	obj.style.opacity = value;
	obj.style.filter = 'alpha(opacity=' + value*100 + ')';
}

/* fader functions */
var faderQueue = new Array();
var faderInterval;
function fader(options) {
	var obj = options.obj;
	var inout = options.inorout;
	var maxopacity = options.maxopacity;
	var alphastep = options.alphastep;
	var oncomplete = options.oncomplete;

	obj.oncomplete = oncomplete;
	obj.alphastep = alphastep;
	obj.maxopacity = maxopacity;
	if(!obj.currentopacity) {
		if(inout == 'in') {
			obj.currentopacity = 0;
			opacity(obj, 0);
		}
		else {
			obj.currentopacity = maxopacity;
			opacity(obj, maxopacity);
		}
	}
	obj.fade = inout;
	obj.style.display = 'block';

	faderQueue.push(obj);
	if(!faderInterval) {
		faderInterval = window.setInterval('darthFader()', 20);
	}
}

function darthFader() {
	if(faderQueue.length > 0) {
		for(i=0; i<faderQueue.length; i++) {
			var obj = faderQueue[i];

			if(obj.fade == 'in') {
				obj.currentopacity += obj.alphastep;
				opacity(obj, obj.currentopacity);

				if(obj.currentopacity >= obj.maxopacity) {
					if(obj.oncomplete) {
						obj.oncomplete(obj);
					}
					faderQueue.splice(i, 1); // remove object from queue
				}
			}
			else {
				obj.currentopacity -= obj.alphastep;
				opacity(obj, obj.currentopacity);

				if(obj.currentopacity <= 0 ) {
					obj.style.display = 'none';
					if(obj.oncomplete) {
						obj.oncomplete(obj);
					}
					faderQueue.splice(i, 1); // remove object from queue
				}
			}
		}

		if(faderQueue.length <= 0) {
			window.clearInterval(faderInterval);
			faderInterval = undefined;
		}
	}
}

/* init gallery */
var galleryObjects = new Array();
var activeGalleryObj;
function initDatevGallery(galleryclass) {
	var eles = document.getElementsByTagName('*');
	var container = document.getElementById(galleryclass + '_container');
	if(!container) {
		container = document.createElement('div');
		container.id = galleryclass + '_container';
		container.className = "gallerycontainer";
		opacity(container, 0);
		document.body.appendChild(container);
	}
	var loading = document.getElementById(galleryclass + '_loading');
	if(!loading) {
		loading = document.createElement('div');
		loading.id = galleryclass + '_loading';
		loading.className = "galleryloading";
		document.body.appendChild(loading);
	}
	var content = document.getElementById(galleryclass + '_content');
	if(!content) {
		content = document.createElement('div');
		content.id = galleryclass + '_content';
		content.className = "gallerycontent";
		content.style.position = 'absolute';
		content.style.top = '50%';
		content.style.left = '50%';
		content.style.width = 800 + 'px';
		content.style.height = 600 + 'px';
		content.style.marginTop = -400 + 'px';
		content.style.marginLeft = -300 + 'px';
		content.style.background = '#fff';
		content.style.display = 'none';
		content.style.overflow = 'hidden';
		opacity(content, 0);
		document.body.appendChild(content);
	}
	for(i=0; i<eles.length; i++) {
		if(eles[i].className.indexOf(galleryclass) > -1) {
			eles[i].number = i;
			eles[i].galleryclass = galleryclass;
			galleryObjects.push(eles[i]);
			eles[i].onclick = function() {
				activeGalleryObj = this;
				fader({
					obj: document.getElementById(activeGalleryObj.galleryclass + '_container'), 
					inorout: 'in',
					maxopacity: 0.7,
					alphastep: 0.1,
					oncomplete: function(container) {
						var content = document.getElementById(activeGalleryObj.galleryclass + '_content');
						content.innerHTML = '<a class="closer" href="#"><span>Schließen</span></a>';
						if(activeGalleryObj.className.indexOf('iframe') > -1) {
							var title = activeGalleryObj.title;
							if(title) {
								content.innerHTML += '<div class="title">' + title + '</div>';
							}
							content.innerHTML += '<iframe frameborder="0" src="' + activeGalleryObj.href + '"></iframe>';
							var iframe = content.getElementsByTagName('iframe')[0];
							content.style.display = 'block';
							content.style.width = (iframe .offsetWidth+40) + 'px';
							content.style.height = (iframe.offsetHeight+40) + 'px';
							content.style.marginTop = 0-Math.round((iframe.offsetHeight+40)/2) + 'px';
							content.style.marginLeft = 0-Math.round((iframe .offsetWidth+40)/2) + 'px';
							fader({
								obj: content, 
								inorout: 'in',
								maxopacity: 1,
								alphastep: 0.1,
								oncomplete: function() {
									var closer = document.getElementById(activeGalleryObj.galleryclass + '_content').getElementsByTagName('a')[0];
									closer.onclick = document.getElementById(activeGalleryObj.galleryclass + '_container').onclick;
								}
							});
						}
						else {
							content.innerHTML += '<div class="text"><img src="#" alt="" /></div>';
							var img = content.getElementsByTagName('img')[0];
							if(img) {
								img.onload = function() {
									document.getElementById(activeGalleryObj.galleryclass + '_loading').style.display = 'none';
									var content = document.getElementById(activeGalleryObj.galleryclass + '_content');
									content.style.display = 'block';
									var imgwidth = this.offsetWidth + 40;
									var imgheight = this.offsetHeight + 40;
									content.style.width = imgwidth + 'px';
									content.style.height = imgheight + 'px';
									content.style.marginTop = 0-Math.round(imgheight/2) + 'px';
									content.style.marginLeft = 0-Math.round(imgwidth/2) + 'px';
									content.style.textAlign =  'center';
									fader({
										obj: content, 
										inorout: 'in',
										maxopacity: 1,
										alphastep: 0.1,
										oncomplete: function() {
											var closer = document.getElementById(activeGalleryObj.galleryclass + '_content').getElementsByTagName('a')[0];
											closer.onclick = document.getElementById(activeGalleryObj.galleryclass + '_container').onclick;
										}
									});
								}
								img.src = activeGalleryObj.href;
							}
						}
						container.onclick = function() {
							document.getElementById(activeGalleryObj.galleryclass + '_content').innerHTML = "";
							fader({
								obj: document.getElementById(activeGalleryObj.galleryclass + '_content'), 
								inorout: 'out',
								maxopacity: 1,
								alphastep: 0.1,
								oncomplete: function() {
								}
							});
							fader({
								obj: document.getElementById(activeGalleryObj.galleryclass + '_container'), 
								inorout: 'out',
								maxopacity: 0.7,
								alphastep: 0.1,
								oncomplete: function() {
									document.getElementById(activeGalleryObj.galleryclass + '_container').onclick = function() {};
								}
							});
							document.getElementById(activeGalleryObj.galleryclass + '_loading').style.display = 'none';
						}
						var loading = document.getElementById(activeGalleryObj.galleryclass + '_loading');
						loading.style.display = 'block';
						loading.onclick = container.onclick;
					}
				});
				return false;
			}
		}
	}
}
