var accordion_displayFirstItem = true;	// erstes Element im Accordion steht per default offen

var myFontsize = 0;
var myFontsizeModifikation = 1;
var myFontsizeRate = 30;
var maxFontsize = 1;

function setFontsizeOnElement(element, faktor) {
	curSize = $(element).css('font-size');
	if (curSize) {
		myUnit = curSize.substr((curSize.length-2), 2);
		newSize = (curSize.substr(0, (curSize.length-2)) * faktor);
		$(element).css('font-size', newSize + myUnit);
	}
}

function setFontsize(modifikation) {
	if (modifikation != 0) {
		//modifikation = (modifikation < 0) ? 0.90909090909 : 1.1;
		modifikation = (modifikation < 0) ? (100/(100+myFontsizeRate)) : ((100+myFontsizeRate)/100);
		setFontsizeOnElement('#contentContainer #content', modifikation)
		setFontsizeOnElement('#contentContainer #content h1', modifikation)
		setFontsizeOnElement('#contentContainer #content h2', modifikation)
		setFontsizeOnElement('#contentContainer #content h3', modifikation)
		setFontsizeOnElement('#contentContainer #content h4', modifikation)
		setFontsizeOnElement('#contentContainer #content p.headline', modifikation)
		$('#contentContainer #content a').each(function(){
			setFontsizeOnElement($(this), modifikation);
		});
		$('#contentContainer #content span.metadata').each(function(){
			setFontsizeOnElement($(this), modifikation);
		});
		$('#contentContainer #content th').each(function(){
			setFontsizeOnElement($(this), modifikation);
		});
		$('#contentContainer #content td').each(function(){
			setFontsizeOnElement($(this), modifikation);
		});
	}
}
function incFontsize() {
	myFontsizeModifikation = (myFontsize < maxFontsize) ? 1 : 0;
	myFontsize = myFontsize + myFontsizeModifikation;
	setFontsize(myFontsizeModifikation);
}
function decFontsize() {
	myFontsizeModifikation = (myFontsize > 0) ? -1 : 0;
	myFontsize = myFontsize + myFontsizeModifikation;
	setFontsize(myFontsizeModifikation);
}

$(document).ready(function(){

// ############################
// Accordion-Effekt fuer H3

	if (accordion_displayFirstItem == true) {
		$("div.divAccordion h3.accordionHeadline:first").addClass("active");
		$("div.divAccordion div.accordionContent:not(:first)").hide();
	} else {
		$("div.divAccordion div.accordionContent").hide();
	}

	$("div.divAccordion h3.accordionHeadline").click(function(){
		// klappe alle sichtbaren Elemente ein und entferne bei h3 die klasse active
		$("div.divAccordion h3.accordionHeadline").siblings("div.accordionContent:visible").slideUp("slow").prev().removeClass("active");
		// fahre aus
		$(this).next("div.accordionContent").slideToggle("slow");
		// setze klasse aktiv fuer aktuelles h3
		$(this).toggleClass("active");
		
		if (PAGE_ID == 515) {
			$("div.divAccordion").each(function(){
				// alle hr nach einem Accordion werden grau
				$(this).next("hr").removeClass('dottedRed').addClass('dottedGray');
			});
			// vor und nach einen Accordion werden die hr rot
			$(this).parent().next("hr").removeClass('dottedGray').addClass('dottedRed');
			$(this).parent().prev("hr").removeClass('dottedGray').addClass('dottedRed');
		}
	});

	
	
	
	// LIGHTBOX
	$('a[rel=gallery]').lightBox({
		overlayBgColor: '#7f7f7f',
		imageLoading:'./img/lightbox/lightbox-ico-loading.gif',
		imageBtnClose:'./img/lightbox/lightbox-btn-close.gif',
		imageBtnPrev:'./img/lightbox/lightbox-btn-prev.gif',
		imageBtnNext:'./img/lightbox/lightbox-btn-next.gif',
		imageBlank:'./img/lightbox/lightbox-blank.gif',
		txtImage: 'Bild',
		txtOf: 'von'
	});
	$('a[rel=gallery2]').lightBox({
		overlayBgColor: '#7f7f7f',
		imageLoading:'./img/lightbox/lightbox-ico-loading.gif',
		imageBtnClose:'./img/lightbox/lightbox-btn-close.gif',
		imageBtnPrev:'./img/lightbox/lightbox-btn-prev.gif',
		imageBtnNext:'./img/lightbox/lightbox-btn-next.gif',
		imageBlank:'./img/lightbox/lightbox-blank.gif',
		txtImage: 'Bild',
		txtOf: 'von'
	});
	
	// die Lupe an alle Lighbox-Bilder
	$('a[rel=gallery] img').each(function(){
		if (PAGE_ID != 504) {
			offsetX = 3;
			offsetY = 6;
			if (PAGE_ID == 811 || PAGE_ID == 817 || PAGE_ID == 812 || PAGE_ID == 813) {
				offsetX = 27;
				offsetY = 31;
				if ($.browser.msie) {
					offsetX = 23;
					offsetY = 27;
				}
			}
			myPos = $(this).position();
			myLeft = myPos.left + $(this).width() - offsetX;
			myTop = myPos.top + $(this).height() - offsetY;
			//$(this).after("<img src='./img/lupe.gif' class='lupe' style='position:absolute; left: "+myLeft+"px; top:"+myTop+"px;' />");
		}
	});
	
/*	$('a#btn15Jahre').live('click', function(){
		removeTrans();
		showTrans();
		$('.div15Jahre').show();
		$('.div15JahreSlide1').show();
		$('.div15JahreSlide2').hide();
		$('.div15JahreSlide3').hide();
	});

	$('a#btn15JahreSlide2').live('click', function(){
		removeTrans();
		showTrans();
		$('.div15Jahre').show();
		$('.div15JahreSlide1').hide();
		$('.div15JahreSlide2').show();
		$('.div15JahreSlide3').hide();
	});

	$('a#btn15JahreSlide3').live('click', function(){
		removeTrans();
		showTrans();
		$('.div15Jahre').show();
		$('.div15JahreSlide1').hide();
		$('.div15JahreSlide2').hide();
		$('.div15JahreSlide3').show();
	});

	$('a#btn15JahreClose').live('click', function(){
		removeTrans();
		$('.div15Jahre').hide();
		$('.div15JahreSlide1').hide();
		$('.div15JahreSlide2').hide();
		$('.div15JahreSlide3').hide();
	});
*/
});

// ###############################################################################

// Wartehinweis horizontal und vertikal mittig ausrichten und anzeigen
// verlangt das dimensions-plugin
function showWaiting() {
	$('#waitingDiv').css('top', function(){
		return (($(window).height()-$(this).height()) / 2) + $(window).scrollTop() - $(this).height() + 'px'
	}).css('left', function(){
		return (($(window).width()-$(this).width()) / 2) + $(window).scrollLeft() + 'px'
	}).show();
}

// Wartehinweis entfernen
function removeWaiting() {
	$('#waitingDiv').hide();
}

// ###############################################################################

// Transparente Flaeche anzeigen
function showTrans() {
	$('#transDiv').css({
		width: function(){return $(document).width() + 'px'}, 
		height: function(){return $(document).height() + 'px'}, 
		opacity: 0.5
	}).show();
}

// Transparente Flaeche entfernen
function removeTrans() {
	$('#transDiv').hide();
}

// ###############################################################################

function showNotice(json) {
	if (json.text) {
		showTrans();
		$('#noticeDiv #noticeHead').empty().append(json.head);
		$('#noticeDiv #noticeText').empty().append(json.text);
		
		hrefString = 'javascript:removeTrans();removeNotice();';
		if (json.success && json.reload) {
			if (typeof json.reloadpage != "undefined" && json.reloadpage != "") {
				hrefString = json.reloadpage;
			} else {
				hrefString += 'location.reload();'; 
			}
		}
		$('#noticeDiv #noticeFoot a').attr('href', hrefString);
		
		if (json.success) $('#noticeDiv > div').removeClass('error').addClass('success');
		else $('#noticeDiv > div').removeClass('success').addClass('error');
		
		$('#noticeDiv').hide()
		.css('top', function(){
			return (($(window).height()-$(this).height()) / 2) + $(window).scrollTop() - $(this).height() + 'px'
			//return ((getBrowserHeight()-$(this).height()) / 2) + $(document).scrollTop() + 'px'
		})
		.css('left', function(){
			return (($(document).width()-$(this).width()) / 2) + $(document).scrollLeft() + 'px'
		})
		.fadeIn('slow');
	} else if (typeof json.reloadpage != "undefined" && json.reloadpage != "") {
		document.location.href = json.reloadpage;
	} else {
		if (json.success && json.reload) location.reload();
	}
}

function removeNotice() {
	$('#noticeDiv').hide();
}

// ###############################################################################

