// JavaScript Document

//Accordion
$(document).ready(function(){

  $(".begegnungen div").eq(1).addClass("active");
  $(".begegnungen table").eq(0).show();
  
  $(".begegnungen div").click(function(){
  		$(this).next("table").slideToggle("slow")
  		.siblings("table:visible").slideUp("slow");
  		$(this).toggleClass("active");
  		$(this).siblings("div").removeClass("active");
  	});

	
	$(".kommentareeintragen h3:first").addClass("active");
	$(".kommentareeintragen form:not(:first)").hide();

	$(".kommentareeintragen h3").click(function(){
		$(this).next("form").slideToggle("slow")
		.siblings("form:visible").slideUp("slow");
		$(this).toggleClass("active");
		$(this).siblings("h3").removeClass("active");
	});

	$(".kommentareanzeigen h3:first").addClass("active");
	$(".kommentareanzeigen table:not(:first)").hide();

	$(".kommentareanzeigen h3").click(function(){
		$(this).next("table").slideToggle("slow")
		.siblings("table:visible").slideUp("slow");
		$(this).toggleClass("active");
		$(this).siblings("h3").removeClass("active");
	});

});



//Shadowbox

Shadowbox.loadSkin('classic', 'shadowbox/skin');
Shadowbox.loadLanguage('de', 'shadowbox/lang');
Shadowbox.loadPlayer(['html', 'iframe', 'img'], 'shadowbox/player');


//Resize-Images

var imageMaxWidth = 400;
var imageMaxHeight = 400;

function resizeImages() {
	for (var i = 0; i < document.images.length ;i++){
		if (document.images[i].className == 'newsimage') {
			var imageWidth = document.images[i].width;
			var imageHeight = document.images[i].height;
			
			if ((imageMaxWidth != 0 && imageWidth > imageMaxWidth) || (imageMaxHeight != 0 && imageHeight > imageMaxHeight)) {
				if (imageMaxWidth != 0) var div1 = imageMaxWidth / imageWidth;
				else var div1 = 1;
				if (imageMaxHeight != 0) var div2 = imageMaxHeight / imageHeight;
				else var div2 = 1;
							
				if (div1 < div2) {
					document.images[i].width = imageMaxWidth;
					document.images[i].height = Math.round(imageHeight * div1);
				}
				else {
					document.images[i].height = imageMaxHeight;
					document.images[i].width = Math.round(imageWidth * div2);
				}
				
			}
		}
	}
}

function loadit() {

Shadowbox.init();
resizeImages();

}

window.onload = loadit;
