$(document).ready(
		function() {
			// Lawyer Teaser
			$(".lawyer_teaser span").click(function() {
				if ($(this).next().is(":hidden")) {
					$(this).addClass("open");
					$(this).next().slideDown();
				} else if ($(this).next().is(":visible")) {
					$(this).next().slideUp();
					$(this).removeClass("open");
				}
			});
			// Meta Navigation
			$("div#meta_navi ul li").mouseenter(function() {
				$(this).children().next("ul").show();
			});
			$("div#meta_navi ul li").mouseleave(function() {
				$(this).children().next("ul").hide();
			});
			$("div#meta_navi ul li ul li").mouseenter(function() {
				$(this).addClass("active");
			});
			$("div#meta_navi ul li ul li").mouseleave(function() {
				$(this).removeClass("active");
			});
			// Main Navigation
			// Level 1
			$("li.level1").mouseenter(function() {
				$("div.inner_navi_description").height("auto");
				$("div#navigation ul li ul").height("auto");
				$(this).addClass("active");
				$(this).children().next(".ul_border").css("display", "block");
				$(this).children().next("ul").css("display", "block");
				$("div#navigation ul li.level1 a").css("z-index", 36);
				$.maxHeight = getMaximumHeight($(this));
			});
			$("li.level1").mouseleave(function() {
				$(this).removeClass("active");
				$(this).children().next(".ul_border").css("display", "none");
				$(this).children().next("ul").css("display", "none");
				$("div#navigation ul li.level1 a").css("z-index", 31);
			});
			// Level 2
			$("li.level2").mouseenter(
					function() {
						$(this).children().addClass("active");
						$(this).children().next("ul").css("display", "block");
						$(this).parent().parent().children().next("div").css(
								"z-index", 30);
						$(this).parent().parent().children().next(".ul_border")
								.css("z-index", 35);
					});
			$("li.level2").mouseleave(
					function() {
						$(this).children().removeClass("active");
						$(this).children().next("ul").css("display", "none");
						$(this).parent().parent().children().next("div").css(
								"z-index", 34);
						// $(this).parent().parent().children().next(".ul_border").css("z-index",
						// 30);
					});
			// Left Navigation
			/*
			 * $("div#left_navi ul li ul li").click(function() {
			 * $(this).parent().children().removeClass("active");
			 * $(this).addClass("active"); });
			 */
			// Anchors
			/*
			$("div#inner_content ul li a").mouseenter(function() {
				$(this).addClass("active");
			});
			$("div#inner_content ul li a").mouseleave(function() {
				$(this).removeClass("active");
			});
			*/
			// Side Teaser Slider
			$(".teaser_slider .teaser_slider_elements div:not(.news_teaser) h4").click(function() {
				if ($(this).next().size() > 0) {
					if ($(this).next().is(":hidden")) {
						$(this).addClass("open");
						$(this).next().slideDown();
					} else if ($(this).next().is(":visible")) {
						$(this).next().slideUp();
						$(this).removeClass("open");
					}
					return false;
				}
			});
			// Lawyer Detail Slider
			$("#inner_content_left h4.lawyer_slider").click(function() {
				if ($(this).next(".lawyer_1").is(":hidden")) {
					$(this).addClass("open");
					$(this).next(".lawyer_1").slideDown();
				} else if ($(this).next(".lawyer_1").is(":visible")) {
					$(this).next(".lawyer_1").slideUp();
					$(this).removeClass("open");
				}
			});
		});

function getMaximumHeight(level1ListItem) {
	$.maxHeight = 271;
	level1ListItem.find("ul").each(function(i) {
		if ($(this).height() > $.maxHeight) {
			$.maxHeight = $(this).height();
		}
	});
	level1ListItem.find(".inner_navi_description").each(function(i) {
		if ($(this).height() > $.maxHeight) {
			$.maxHeight = $(this).height();
		}
	});
	return $.maxHeight;
}


function getRandomNumber(maxNumber) {
	return Math.floor(Math.random()*maxNumber);
}

function initializeStageBoxes_OLD() {
	$("div.stage_boxes div").hide();
	var nr1 = getRandomNumber(10);
	var nr2 = getRandomNumber(10);
	while(nr2 == nr1)
	{
		nr2 = getRandomNumber(10);
	}
	var nr3 = getRandomNumber(10);
	while((nr3 == nr1)||(nr3 == nr2))
	{
		nr3 = getRandomNumber(10);
	}
	var nr4 = getRandomNumber(10);
	while((nr4 == nr1)||(nr4 == nr2)||(nr4 == nr3))
	{
		nr4 = getRandomNumber(10);
	}
	// Set 4 absolute positions
	document.getElementById("sb_" + nr1).style.left = "0";
	document.getElementById("sb_" + nr2).style.left = "240px";
	document.getElementById("sb_" + nr3).style.left = "480px";
	document.getElementById("sb_" + nr4).style.left = "720px";
	document.getElementById("sb_" + nr1).style.display = "block";
	document.getElementById("sb_" + nr2).style.display = "block";
	document.getElementById("sb_" + nr3).style.display = "block";
	document.getElementById("sb_" + nr4).style.display = "block";
}

function getRandomStageBox_OLD() {
	// Set timer
	// Fill array with the 4 currently shown box numbers
	var shownBoxes = new Array();
	$("div.stage_boxes div.stage_box").each(function() {
		if($(this).is(':visible')) {
			shownBoxes.push($(this).attr("id").substr(3, $(this).attr("id").length-3));
			//alert("shown: " + shownBoxes[i]);
		}
	});
	// Fill array with the 6 remaining box numbers
	var hiddenBoxes = new Array();
	$("div.stage_boxes div.stage_box").each(function() {
		if($(this).is(':hidden')) {
			hiddenBoxes.push($(this).attr("id").substr(3, $(this).attr("id").length-3));
			//alert("hidden: " + hiddenBoxes[i]);
		}
	});
	// Randomly decide which box number from the 4 currently shown should be hidden
	i = getRandomNumber(4);
	var left = document.getElementById("sb_" + shownBoxes[i]).style.left;
	document.getElementById("sb_" + shownBoxes[i]).style.display = "none";
	//$("div.stage_boxes div#" + "sb_" + shownBoxes[i]).fadeOut();
	// Randomly decide which box number of the 6 remaining should be shown
	i = getRandomNumber(6);
	document.getElementById("sb_" + hiddenBoxes[i]).style.left = left;
	document.getElementById("sb_" + hiddenBoxes[i]).style.display = "block";
	//$("div.stage_boxes div#" + "sb_" + hiddenBoxes[i]).fadeIn();
	t=setTimeout("getRandomStageBox()",5000);
	
}

// Number of complete and shown boxes is variable
// Please set the hidden boxes on display: none; in stylesheet
// Variables that can be set
var numberOfShownBoxes = 3;
var distanceBetweenBoxes = 320;
var secondsBetweenChange = 5;
// Additional variables
var t;
var boxToHide = -1;
var boxToShow = boxToHide + numberOfShownBoxes;
var left = -distanceBetweenBoxes;

function initializeStageBoxes() {
	$stageBoxes = $("div.stage_boxes div.stage_box");
	$stageBoxes.each(function(i) {
		$(this).attr("id", "sb_"+ i);
	});
	// Show only first 3 boxes
	$stageBoxes.hide();
	$stageBoxes.eq(0).show();
	$stageBoxes.eq(1).show();
	$stageBoxes.eq(2).show();
	var numberOfBoxes = $("div.stage_boxes div.stage_box").size();
	if(numberOfBoxes>3) {
		changeStageBoxes();
	}
}

function changeStageBoxes() {
	if(boxToHide > -1) {
		//alert(boxToHide + " wird gegen " + boxToShow + " ausgetauscht!");
			$("#" + "sb_" + boxToHide).slideUp();
			$("#" + "sb_" + boxToShow).css("left", left);
			$("#" + "sb_" + boxToShow).slideDown();
	}
	var numberOfBoxes = $("div.stage_boxes div.stage_box").size();
	if(boxToHide == (numberOfBoxes-1)) {
		boxToHide = -1;
	}
	if(boxToShow == (numberOfBoxes - 1)) {
		boxToShow = -1;
	}
	boxToHide++;
	boxToShow++;
	left = left + distanceBetweenBoxes;
	if(left > (distanceBetweenBoxes * (numberOfShownBoxes - 1))) {
		left = 0;
	}
	t=setTimeout("changeStageBoxes()", secondsBetweenChange * 1000);
}

 jQuery(document).ready(function($){
        $("div#navigation ul li.level1").each(function(){ 
            $(this).hover(function(){
                $(this).find("ul").css("margin-left","-" + ($(this).find("ul").outerWidth() - $(this).outerWidth() + 1) / 2 +"px");
        });});
});

