function resizeImage(image, width, height, isMax) {
	if (image) {
		var origWidth = image.width;
		var origHeight = image.height;
		var ration = 1;
		if (width && width > 0 && height && height > 0) {
			if (isMax) {
				if (origWidth > origHeight) {
					ratio = width / origWidth;
				} else {
					ratio = height / origHeight;
				}
			} else {
				if (origWidth < origHeight) {
					ratio = width / origWidth;
				} else {
					ratio = height / origHeight;
				}
			}
		} else if (width && width > 0) {
			ratio = width / origWidth;
		} else if (height && height > 0) {
			ratio = height / origHeight;
		}
		percentage = ratio*100;
		var newWidth = Math.ceil(origWidth * ratio) + 3;
		var newHeight = Math.ceil(origHeight * ratio) + 3;
		$(image).css("width", "" + newWidth + "px");
		$(image).css("height", "" + newHeight + "px");
		$(image).css("position", "relative");
		if (!isMax) {
			if (newWidth > width) {
				$(image).css("left", "-" + Math.round((newWidth - width) / 2) + "px");
			}
			if (newHeight > height) {
				$(image).css("top", "-" + Math.round((newHeight - height) / 2) + "px");
			}
		}
	}
}
/* 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);
}
/* staff ******************************************************************************************/
var currentFloatingWindow;

function showStaffDetails(staffid) {
	$(function() {
		// de-highlight all staff links
		$("a.staffLink").removeClass("active");
		$("#" + staffid + ">a").addClass("active");
		currentFloatingWindow = staffid;
		var position = findPosition($("#" + staffid).get(0));
		$("#floatingWindow").remove();
		if ($("#backdrop").size() == 0) {
			$("#container").after("<div id=\"backdrop\"><!-- --></div>");
		}
		$("#backdrop").click(function () { 
			hideStaffDetails(); 
		});
		positionBackdrop();
		$(window).resize(function() {
			positionBackdrop();
		});
		$(window).scroll(function() {
			positionBackdrop();
		});
		if ($("#floatingWindow").size() == 0) {
			$("#backdrop").after("<div id=\"floatingWindow\"></div>");
		}
		$("#floatingWindow").html($("#" + staffid + " div.staffdetails").html());
		$("#floatingWindow").draggable();
		$("#floatingWindow").css('left', position[0] + 230);
		//$("#floatingWindow").css('left', 527);
		//$("#floatingWindow").css('top', position[1] - 5);
		//$("#floatingWindow").css('top', 249); wird ca. 10px zu tief dargstellt, deshalb:
		var staffDetailHeight = $("#floatingWindow").height();
		$("#floatingWindow").css('top', ($(window).height() - staffDetailHeight) / 2);
		$("#floatingWindow").show("slow");
	});
}

function hideStaffDetails() {
	$("#floatingWindow").hide("slow", function() {
		$("#floatingWindow").remove();
		$("#backdrop").remove();
		$("a.staffLink").removeClass("active");
	});
}


function findPosition( oElement ) {
  if( typeof( oElement.offsetParent ) != 'undefined' ) {
    for( var posX = 0, posY = 0; oElement; oElement = oElement.offsetParent ) {
      posX += oElement.offsetLeft;
      posY += oElement.offsetTop;
    }
    return [ posX, posY ];
  } else {
    return [ oElement.x, oElement.y ];
  }
}

function positionBackdrop() {
	if ($("#backdrop").size() > 0) {
		$("#backdrop").css("top", $(window).scrollTop());
	}
}
/* projects file list *****************************************************************************/
function initFileList() {
//	$("div.project_downloads ul.fileList").addClass("hidden");
//	$("div.project_downloads ul.level1").removeClass("hidden");
	$("div.project_downloads ul.fileList a.folder").click(function() {
		var listItem = $(this).parent();
		var subList = $(listItem).children("ul");
		if ($(listItem).hasClass("closed")) {
			$(subList).slideDown("fast", function() {
				$(listItem).removeClass("closed");
				$(listItem).addClass("open");
			});
		} else {
			$(subList).slideUp("fast", function() {
				$(listItem).removeClass("open");
				$(listItem).addClass("closed");
			});
		}
	});
}