
$(document).ready(function() {
	$("#mainnavi > ul li").each(function () {
		var elem = $(this);
		var submenu = elem.children(".subnavi");
		var off = elem.position();
		var width = elem.width();
		var subwidth = submenu.width();
		submenu.hide();
		if (width+70 > subwidth) subwidth = width+70;
		
		subwidth = subwidth;
		
		if (submenu.size() > 0) {
			submenu.prepend('<img class="submenu_top" src="tl_files/images/global/submenu_top.png">');
			elem.hover(function() {
				submenu.css("width", subwidth+"px");
				submenu.css("left", (off.left+width/2-subwidth/2+6)+"px");
				submenu.css("top", (off.top+elem.height())+"px");
				$("#mainnavi .subnavi").stop(false, true);
				submenu.fadeIn(300);
			}, function() {
				submenu.fadeOut(200);
			});
		}
	});

	$(".mod_weine_navi").each(function() {
		var elem = $(this);
		$("ul.level2, ul.level3", this).hide();
		$("ul.level3 li.selected").each(function() {
			$(this).parent().show();
			$(this).parent().parent().parent().show();
		});
		$("ul.level1 .caption a", this).each(function () {
			var submenu = $(this).parent().next()
			$(this).click(function() {
				submenu.parent().siblings().children("ul").not(submenu).slideUp(200);
				submenu.slideDown(200);
				
			});
		});
	});
	
	$("#overlaypictures").each(function() {
		$("td.picture", this).hover(function() {
			$(".inactive", this).hide();
			$(".active", this).show();
		}, function() {
			$(".active", this).hide();
			$(".inactive", this).show();
		});
	});
	
	$("#diashow").each(function() {
		var elem = $(this);
		var pos = elem.position();
		
		elem.find("tr").css("position", "absolute").css("top", pos.top+"px")
		elem.css("marginBottom", "210px");
		
		timer = function() {
			var current = elem.find("tr:visible");
			var next = elem.find("tr:visible + tr");
			if (next.length == 0) {
				next = elem.find("tr:first");
			}
			next.fadeIn(1000);
			current.fadeOut(1500);
			
			setTimeout("timer()", 10000);
		}
		
		setTimeout("timer()", 5000);
	});
	
});


if (typeof(ddaccordion) != "undefined") {
	ddaccordion.init({
		headerclass: "acsubmenuheader", //Shared CSS class name of headers group
		contentclass: "acsubmenu", //Shared CSS class name of contents group
		revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click", "clickgo", or "mouseover"
		mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
		collapseprev: true, //Collapse previous content (so only one open at any time)? true/false 
		defaultexpanded: [], //index of content(s) open by default [index1, index2, etc] [] denotes no content
		onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed)
		animatedefault: false, //Should contents open by default be animated into view?
		persiststate: false, //persist state of opened contents within browser session?
		toggleclass: ["", ""], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
		togglehtml: ["suffix", "<img src='tl_files/images/global/pfeil_rechts.png' class='statusicon' width='15' height='15' />", "<img src='tl_files/images/global/pfeil_down.png' width='15' height='15' class='statusicon' />"], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
		animatespeed: "200" //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
	});
}