/* collapsible paragraph stuff ********************************************************************/
function toggleCollapsibleParagraph(id) {
	var paragraph = document.getElementById(id);
	if (paragraph) {
		var currentClass = paragraph.getAttribute("class");
		if (!currentClass) {
			currentClass = paragraph.getAttribute("className");
		}
		if (currentClass == "closed") {
			paragraph.setAttribute("class", "open"); 
			paragraph.setAttribute("className", "open");
		} else {
			paragraph.setAttribute("class", "closed"); 
			paragraph.setAttribute("className", "closed");
		}
	}
}

function openCollapsibleParagraph(id) {
	var paragraph = document.getElementById(id);
	if (paragraph) {
		var currentClass = paragraph.getAttribute("class");
		if (!currentClass) {
			currentClass = paragraph.getAttribute("className");
		}
		if (currentClass == "closed") {
			paragraph.setAttribute("class", "open"); 
			paragraph.setAttribute("className", "open");
		}
		window.location.hash=id;
	}
}

/* noyb stuff *************************************************************************************/
function dcmadr(nnnn) {
	var a = "";
	for(i=0,m=nnnn.length;i < m;i++){
		if(i%3==0){
			a += String.fromCharCode(nnnn.substr(i, 3)-37);
		}
	}
	return a;
}

function dcmt(nnnn) {
	var a = dcmadr(nnnn);
	location.href=('m'+'ail'+'t'+'o:'+a);
}

/* calendar image on homepage **********************************************************************/
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function setTitleFromThumb(thumbId) {
	if (thumbId) {
		var thumb = document.getElementById(thumbId);
		if (thumb) {
			var bigPicture = document.getElementById('calendar');
			if (bigPicture) {
				bigPicture.setAttribute("title", thumb.getAttribute("title"));
				bigPicture.setAttribute("alt", thumb.getAttribute("alt"));
			}
		} else {
			alert("no thumb for id "+thumbId);
		}
	}
}

function resizeImage(image, width, height, isMax, center) {
	if (image) {
		var origWidth = image.width;
		var origHeight = image.height;
		var scaleFactor = 1;
		if (width && width > 0 && height && height > 0) {
			// Bild-Seitenverhältnis
			var ratioImage = origWidth / origHeight;
			// Box-Seitenverhältnis
			var ratioBox = width / height;			
			if (isMax) {
				if (ratioBox > ratioImage) {
					// Wenn das Box-Seiten-Verhältnis > Bild-Seitenverhältnis muss die Höhe übereinstimmen
					scaleFactor = height / origHeight;
				} else {
					// Wenn das Box-Seiten-Verhältnis < Bild-Seitenverhältnis muss die Breite übereinstimmen
					scaleFactor = width / origWidth;
				}
			} else {
				if (ratioBox < ratioImage) {
					// Wenn das Box-Seiten-Verhältnis < Bild-Seitenverhältnis muss die Höhe übereinstimmen
					scaleFactor = height / origHeight;
				} else {
					// Wenn das Box-Seiten-Verhältnis > Bild-Seitenverhältnis muss die Breite übereinstimmen
					scaleFactor = width / origWidth;
				}
			}
			var newWidth = Math.ceil(origWidth * scaleFactor);
			var newHeight = Math.ceil(origHeight * scaleFactor);
			$(image).css("width", "" + newWidth + "px");
			$(image).css("height", "" + newHeight + "px");
			$(image).css("position", "relative");
			if (isMax && center) {
				if (newWidth < width) {
					$(image).css("left", Math.round((width - newWidth) / 2) + "px");
				}
				if (newHeight < height) {
					$(image).css("top", Math.round((height - newHeight) / 2) + "px");
				}
			}
			if (!isMax && center) {
				if (newWidth > width) {
					$(image).css("left", "-" + Math.round((newWidth - width) / 2) + "px");
				}
				if (newHeight > height) {
					$(image).css("top", "-" + Math.round((newHeight - height) / 2) + "px");
				}
			}
		}
/*		} else if (width && width > 0) {
			ratio = width / origWidth;
		} else if (height && height > 0) {
			ratio = height / origHeight;
		}*/
//		percentage = ratio*100;
	}
}