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

function swapImage(element, newimage) {
	var oldsrc = element.src
	element.src = newimage
	if (!element.onmouseout)
		element.onmouseout = function (event) { swapImage(this, oldsrc); };
}




// 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, '');
}

//checkEmail - needed for forms
function checkEmail(val) {
	if (val) {
		var usr = "([a-zA-Z0-9][a-zA-Z0-9_.-]*|\"([^\\\\\x80-\xff\015\012\"]|\\\\[^\x80-\xff])+\")";
		var domain = "([a-zA-Z0-9][a-zA-Z0-9._-]*\\.)*[a-zA-Z0-9][a-zA-Z0-9._-]*\\.[a-zA-Z]{2,5}";
		var regex = "^"+usr+"\@"+domain+"$";
		var myrxp = new RegExp(regex);
		var check = (myrxp.test(val));
		if (check!=true) {
			return false;
		}
		else {
			return true;
		}
	}
}

/*
validates formfields if they have a value or not
to check for other options do the following
specialfields = new Object();
specialfields.fieldname = new Object();
specialfields.fieldname.check1 = 'function_to_call,error_message';
specialfields.fieldname.check2 = 'second_function_to_call,second_error_message';
specialfields.another_fieldname = new Object();
specialfields.another_fieldname.check1 = 'function_to_call,error_message';
*/
function validateForm(form,specialfields) {
	var errors = new Array();
	var fields = form.getElementsByTagName('label');
	for (i = 0; i < fields.length; i++) {
		var span = fields[i].getElementsByTagName('span')[0];
		if (span && span.firstChild) {
			var label = span.firstChild.data;
			label = label.trim();
			// if there is a '*' in the label - this indicates the inputfield has to be filled
			if (label.charAt(label.length - 1) == '*') {
				label = label.substring(0, label.length - 1).trim();
				// get the inputfield
				var obj_input = fields[i].getElementsByTagName('input');
				if (!obj_input[0])
					obj_input = fields[i].getElementsByTagName('select');
				if (!obj_input[0])
					obj_input = fields[i].getElementsByTagName('textarea');

				// if there is an inputfield
				if (obj_input && obj_input[0]) {
					input = obj_input[0];
					error = false;
					
					// check if the inputfield has a value
					if (!input.value || input.value.trim().length==0) {
						error = true;
						errors.push(label + ' nicht eingegeben');
					}
					
					// check the inputfield for special things (email, ...)
					if (!error && specialfields[input.name]){
						specialfield = specialfields[input.name];
						for (check in specialfield){
							check_function = specialfield[check].split(',')[0];
							check_message = specialfield[check].split(',')[1];
							if (!eval(check_function)(input.value)){
								error = true;
								errors.push(label + ' ' + check_message);
							}
						}
					}

					// on error give the label the className 'error' otherwise delete the className 'error' (if exists)
					if (error) {
						className = fields[i].className;
						if (className.length>0){
							className = className + ' ';
						}
						fields[i].className = className + 'error';
					} else {
			            	className = fields[i].className;
						if (className.indexOf('error')>-1){
								className = className.replace(' error', '');
								className = className.replace('error', '');
								fields[i].className = className;
						}
					}
				}
			}
		}
	}

	return errors;
}

function showFormErrors (errors) {
	error_message = '';
	for (i=0;i<errors.length;i++){
		error_message += errors[i] + '\n';
	}
	alert(error_message);
}


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

var bubbleClosed = false;
function closeBubble()
{
	var bubble = document.getElementById('bubble');
	if(bubble && bubbleClosed == false)
	{
		//fx = new Fx.Style(bubble, 'opacity', {duration: 400, wait: false}).start(1,0);
		var newMorph = new Fx.Morph($(bubble), {
			duration: 400,
			wait: false
		}).start({
			opacity: [1, 0]
		});

		bubbleClosed = true;
	}
}

/* Gallery Inside */
/*Fx.Morph = Fx.Styles.extend({
	start: function(className){
		var to = {};
		$each(document.styleSheets, function(style){
			var rules = style.rules || style.cssRules;
			$each(rules, function(rule){
				if (!rule.selectorText.test('\.' + className + '$')) return;
				Fx.CSS.Styles.each(function(style){
					if (!rule.style || !rule.style[style]) return;
					var ruleStyle = rule.style[style];
					to[style] = (style.test(/color/i) && ruleStyle.test(/^rgb/)) ? ruleStyle.rgbToHex() : ruleStyle;
				});
			});
		});
		return this.parent(to);
	}
});

Fx.CSS.Styles = ["width", "height", "marginTop"];

Fx.CSS.Styles.extend(Element.Styles.padding);
Fx.CSS.Styles.extend(Element.Styles.margin);

Element.Styles.border.each(function(border){
	['Width', 'Color'].each(function(property){
		Fx.CSS.Styles.push(border + property);
	});
});
*/

var galleryPage = 0;
var activeID = '';

function galleryInsideHover(obj)
{
	var id = obj.number;
	var gallery_inside = document.getElementById('gallery_inside');
	if(gallery_inside)
	{
		var beforeImg = (id*1)-1;
		var nextImg = (id*1)+1;
		var galleryStart = galleryPage*6;
		var galleryEnd = galleryStart + 6;

		var imgs = gallery_inside.getElementsByTagName('img');

/*		for(i=galleryStart; i<imgs.length && i<galleryEnd; i++)
		{
			if(i == beforeImg || i == nextImg)
			{
				imgs[i].className = 'gallery_inside_img_trampling';
				//var newMorph = new Fx.Morph(imgs[i].id, {duration: 100, wait: false}).start('gallery_inside_img_trampling');
				var newMorph = new Fx.Morph($(imgs[i]), {
					duration: 100,
					wait: false
				}).start({
					width: 150
				});
			}
			else if(i == id)
			{
				imgs[i].className = 'gallery_inside_img_attraction';
				//var newMorph = new Fx.Morph(imgs[i].id, {duration: 100, wait: false}).start('gallery_inside_img_attraction');
				var newMorph = new Fx.Morph($(imgs[i]), {
					duration: 100,
					wait: false
				}).start({
					width: 130
				});
			}
			else
			{
				imgs[i].className = 'gallery_inside_img';
				var newMorph = new Fx.Morph($(imgs[i]), {
					duration: 100,
					wait: false
				}).start({
					width: 50
				});
			}
		}*/
		activeID = id;
	}
}

window.addEvent('domready', function() {
	var subnav = document.getElementById('subnav');
	var subnav_background = document.getElementById('subnav_background');
	var bubble = document.getElementById('bubble');

	if(subnav)
	{
		var fx = new Fx.Morph($(subnav), {duration: 400, wait: false}).start({ opacity: [0 , 1] });
		var fx2 = new Fx.Morph($(subnav_background), {duration: 400, wait: false}).start({ opacity: [0 , 0.7] });
		if(bubble) {
			var fx3 = new Fx.Morph($(bubble), {duration: 800, wait: false}).start({ opacity: [0 , 1] });
		}
	}

	var gallery_inside = document.getElementById('gallery_inside');

	if(gallery_inside)
	{
		var safetycount = 0;
		var imgs = gallery_inside.getElementsByTagName('img');
		var img_to_add = '';

		var imgs_needed = Math.floor(gallery_inside.offsetWidth / 115);
		var img_count = 0;
		while(imgs.length < imgs_needed && safetycount < 5)
		{
			var idcount = imgs.length;
			var img_count = imgs.length;

			img_to_add = '';
			for(i=0; i<imgs.length; i++)
			{
				if(img_count < imgs_needed)
				{
					img_to_add = img_to_add + '<img id="imginside' + idcount + '" src="' + imgs[i].src + '" alt="" />';
					img_count++;
					idcount++;
				}
			}

			gallery_inside.innerHTML = gallery_inside.innerHTML + img_to_add;

			imgs = gallery_inside.getElementsByTagName('img');
			safetycount++;
		}

		for(i=0; i<imgs.length; i++)
		{
			imgs[i].number = i;
			imgs[i].onmouseover = function() { galleryInsideHover(this); };
			imgs[i].onclick = function() { showImagePopup('imgcloseup' + this.number); };
			if(i > 5)
			{
				imgs[i].style.display='none';
			}
		}
	}

	if($('bubble_content')) {
		var content = $$('#bubble_content div');
		content[Math.floor(Math.random()*content.length)].style.display = 'block';

		setTimeout('closeBubble()', 5000);
	}
});



/** IMAGE GALLERY **/
function nextImage(obj, go) {
	var id = obj.className;
	var container = $(id).parentNode;
	var divs = container.getElementsByTagName('div');

	var activeImage = 0;
	for(i=0; i<divs.length; i++) {
		if(divs[i].id == id)
			activeImage = i;
	}

	var nextImage = activeImage + go;
	if(nextImage == divs.length)
		nextImage = 0;

	if(nextImage < 0)
		nextImage = divs.length - 1;

	showImagePopup(divs[nextImage].id);
}

function showImagePopup(id) {
	var a  = $(id).getElementsByTagName('a')[0];
	var span = $(id).getElementsByTagName('span')[0];
	var dimensions = span.innerHTML.split("x");

	var container = $(id).parentNode;
	var divs = container.getElementsByTagName('div');

	var activeImage = 0;
	for(i=0; i<divs.length; i++) {
		if(divs[i].id == id)
			activeImage = i;
	}

	activeImage++;

	showPopup(a.id, dimensions[0]-0, dimensions[1]-0, '<img src="' + a.href + '" alt="" /><br/>[ <a class="' + id + '" href="#" onclick="nextImage(this, -1)">Voriges Bild</a> ] [ <b>' + activeImage + '</b> / ' + divs.length + ' ] [ <a class="' + id + '" href="#" onclick="nextImage(this, 1)">Nächstes Bild</a> ]');
}

/** IMAGE GALLERY END **/



// BO Popup
function hideSelectBoxes(){
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) { selects[i].style.visibility = "hidden";}

	if(!window.ie)
		document.getElementById('content').style.overflow='hidden';
}

function showSelectBoxes(){
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) { selects[i].style.visibility = "visible";}

	if(!window.ie)
		document.getElementById('content').style.overflow='auto';
}

var popupOldOnResize = window.onresize;
var popupOldOnLoad = window.onload;
function showPopup(id, width, height, popupinnerHTML)
{
	hideSelectBoxes();
	if(document.getElementById('popup_background')) {
		objTemp = document.getElementById('popup_background');
	}
	else
	{
		objTemp = document.createElement("div");
		objTemp.id = 'popup_background';
		objTemp.style.visibility='hidden';
		objTemp.onclick=function() { }
	}

	if(objTemp.style.display != 'block')
	{
		objTemp.style.display='block';

		popupBackground = document.body.appendChild(objTemp);
		//$(popupBackground).effects({duration:400,onComplete:function(){      $(popupBackground).effects({}).set({'opacity':[0.5]}); showPopupContent(id, width, height, popupinnerHTML);     }}).start({'opacity':[0,0.5]});
		new Fx.Morph($(popupBackground), {
			duration: 400,
			onComplete: function() {
				showPopupContent(id, width, height, popupinnerHTML);
			}
		}).start({
			opacity: [0, 0.5]
		});
	}
	else
	{
		showPopupContent(id, width, height, popupinnerHTML);
	}
}

function showPopupContent(id, width, height, popupinnerHTML)
{
	width += 60;
	height += 50;
	if(popupinnerHTML == undefined)
		popupinnerHTML = '';

	if(document.getElementById('popup_content')) {
		objTemp = document.getElementById('popup_content');
	}
	else
	{
		objTemp = document.createElement("div");
		objTemp.id = 'popup_content';
	}

	$('popup_background').onclick=function() { popupClose(); }

	objTemp.innerHTML= '<div id="popup_close"><a href="javascript:popupClose()"><span>X</span></a></div><div id="popup_text">' + document.getElementById(id).innerHTML + '' + popupinnerHTML + '</div>';

	if(width > 0 && height > 0) {
		objTemp.style.width=width+'px';
		objTemp.style.height=height+'px';
		objTemp.style.marginLeft='-' + Math.floor(width/2) +'px';
		objTemp.style.marginTop='-' + Math.floor(height/2) +'px';
	}

	objTemp.style.display='block';

	popupContent =  document.body.appendChild(objTemp);
}

function popupClose()
{
	popupContent = document.getElementById('popup_content');
	popupContent.style.display='none';

	popupBackground = $('popup_background');
	popupBackground.onclick=function() { }

	//$(popupBackground).effects({duration:400,onComplete:function(){      	popupBackground.style.display='none'; showSelectBoxes();    }}).start({'opacity':[0.5,0]});
	new Fx.Morph($(popupBackground), {
		duration: 400,
		onComplete: function() {
			popupBackground.style.display='none';
			showSelectBoxes();
		}
	}).start({
		opacity: [0.5, 0]
	});

}
// EO Popup (div einblenden)