// JavaScript Document

$(document).ready(
	function() {
					
		if( ($(window).width()-1000)/2 < 0 ) {
			var zinnenbreite = 0;
			$("#footer_background").css("margin-left", 0);
			$("#footer_background").css("width", $(window).width());	
		}
		else {
			var zinnenbreite = ($(window).width()-1000)/2;
			$("#footer_background").css("margin-left", 0-(($(window).width()-1000)/2));
			$("#footer_background").css("width", $(window).width());	
		}
		
		$("#zinnen").css("width", zinnenbreite);
		
		if( $(window).height() > ($("#design").height()+66) ) {
			$("#footer_background").css("margin-top", $(window).height()-$("#design").height()-66);	
		}
		
		$("ul.header_navigation_box").each(
			function() {
				var countli = $(this).children().size();
				$(this).css("height", countli*31);
			}
		);
		
		$(".header_navigation_button").hover(
			function() {
				$(this).find("ul").show();
				$(this).find("ul li").slideDown("fast");
			},
			function() {
				$(this).find("ul li").slideUp("fast", function() {$(this).parent().hide();});
				
			}
		);
		
		$("a[href*='http://'], a[href*='www.']").addClass("externalURL");
		
		$("a[href*='http://'], a[href*='www.']").hover(
			function() {
				$(this).addClass("externalURLHover");	
			},
			function() {
				$(this).removeClass("externalURLHover");	
			}
		);
				
		$("ul.header_navigation_box li").hover(
			function() {
				$(this).addClass("hover");	
			},
			function() {
				$(this).removeClass("hover");	
			}
		);
				
		$("#footer_background").css("margin-left", 0-(($(window).width()-1000)/2));
		$("#footer_background").css("width", $(window).width());
		
		
		if( $(document).width() % 2 != 0 ) {
			$("#spaltelinks_background").css("width", "189px");	
		}
		
		function replaceUmlauts(string, index){
		    var anArray = new Array(2);
		    anArray[0] = new Array("Ö", "ö", "Ä", "ä", "Ü", "ü", "ß", "» ", " ");
		    anArray[1] = new Array("Oe", "oe", "Ae", "ae", "Ue", "ue", "ss", "", "_");
		    
		    for (var i=0; i<anArray[index].length; i++){
				myRegExp = new RegExp(anArray[index][i],"g");
				string = string.replace(myRegExp, anArray[(index==0?1:0)][i]);
			}
			
			if( string.slice(string.length-1, string.length) == "_" ) {
				string = string.slice(0, string.length-1);
			}
			
		    return string.toLowerCase().replace(/\./, "").replace(/\./, "").replace(/\./, "").replace(/\./, "").replace(/\./, "");
		}
			
		$("#unternavigation li, #unternavigation2 li").click(
			function() {
				if( $(this).attr("id") != "" ) {
					window.location.href = replaceUmlauts($(this).attr("id"), 0);
				}
				else {
					window.location.href = replaceUmlauts($(this).text(), 0);		
				}	
			}
		);
		
		$("#logo").click(
			function() {
				window.location.href = "terminkalender";	
			}
		);
		
		$(".header_navigation_box li").click(
			function() {
				if( $(this).attr("id") != "" ) {
					window.location.href = replaceUmlauts($(this).attr("id"), 0);
				}
				else if( $(this).attr("title") != "" ) {
					window.location.href = replaceUmlauts($(this).attr("title"), 0);					
				}
				else {
					window.location.href = replaceUmlauts($(this).text(), 0);		
				}
			}
		);
		
		$(".accordion p").each(
			function() {
				$(this).next("ol, ul").hide();
			}
		);
		
		$(".accordion p").click(
			function() {
				$(".accordion ul, .accordion ol").hide();
				$(this).next("ol, ul").show();
			}
		);
		
		$("#adminaccordion p").click(
			function() {
				$.post("includes/adminaccordion.php", { admin_text: $(this).attr("id") } );
			}
		);
		
		$('.tooltip').tooltip({ 
			track: true, 
			delay: 0, 
			showURL: false, 
			showBody: "::", 
			fade: 250,
			extraClass: "tooltip"
		});
		
		$(".colorize").each(
			function() {
				$(this).find("tr:even").addClass("even");
				$(this).find("tr:odd").addClass("odd");
			}
		);
		
		$("a:contains('löschen'), .confirm").click(
			function() {
				Check = confirm("Wollen Sie das ausgewählte Objekt wirklich löschen?");
				if (Check == false) {
					return false;
				}
				else {
					return true;	
				}
			}
		);
		
		$(".datepicker").datepicker();
		
		$("#search").click(
			function() {
				$("#searchform").submit();
			}
		);
		
		$("#highlight_stop").click(
			function() {
				$(".hilite1, .hilite2, .hilite3, .hilite4, .hilite5").each(
					function() {
						$(this).after($(this).html());
					}
				);
				$(".hilite1, .hilite2, .hilite3, .hilite4, .hilite5").remove();
				
				$("#hightlight_span").remove();
				if( $(".warningmessage").text() == "Hinweis!" ) {
					$(".warningmessage").hide();
				}
			}
		);
		
		$("#pagecontent img[class!='nobox']").each(
			function() {
				$(this).wrap("<a class='group' rel='group' title='"+$(this).attr("src").replace("/downloads/bildergalerien/bilderpool/", "")+"' href='"+$(this).attr("src")+"'></a>");
				$(this).attr("border", "0");
			}
		);
		
		$(".hider").hover(
			function() {
				$(this).css("overflow","");
				$(this).css("height","auto");
			},
			function() {
				$(this).css("overflow","hidden");
				$(this).css("height","25px");
			}
		);
		
		setTimeout(doSomething, 1);

	}
);
function doSomething() {

	if( $(window).height() > ($("#design").height()+66) ) {
		$("#footer_background").css("margin-top", $(window).height()-$("#design").height()-66);	
	}
	
	if( ($(window).width()-1000)/2 < 0 ) {
		var zinnenbreite = 0;
		$("#footer_background").css("margin-left", 0);
		$("#footer_background").css("width", $(window).width());	
	}
	else {
		var zinnenbreite = ($(window).width()-1000)/2;
		$("#footer_background").css("margin-left", 0-(($(window).width()-1000)/2));
		$("#footer_background").css("width", $(window).width());	
	}
	$("#zinnen").css("width", zinnenbreite);
	
	if( $(document).width() % 2 != 0 ) {
		$("#spaltelinks_background").css("width", "189px");	
	}
		
}

var resizeTimer = null;
$(window).bind('resize',
	function() {
		if (resizeTimer) clearTimeout(resizeTimer);
		resizeTimer = setTimeout(doSomething, 1);
	}
);