$(function() {
	/** FLYOUT MENU FOR IE 6 (suckerfish technique) **/
	$("#flyout.ie6 #main-nav > li").hover(function() {
		$(this).addClass("sfhover");
	}, function() {
		$(this).removeClass("sfhover");
	});

	/** INFORMATION LAYER FOR IE 6 & 7 **/
	$(".ie6 .info-layer, .ie7 .info-layer").hover(function() {
		// alternative solution because there can be overlay bugs (especially near forms)
		var pos = $(this).offset();
		$(".info-layer-container", this).clone().addClass("cloned").appendTo("body").css({
			left: pos.left + 24,
			top: pos.top
		});
	}, function() {
		$(".info-layer-container.cloned").remove();
	});

	/** SOME MODIFICATIONS FOR iOS **/
	if (navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod') {
		// no fixed height for news module (because it won't be scrollable)
		$(".module-news ul").css("height", "auto");

		// no fixed position for bottom links (because they will not be positioned as wanted)
		$("#bottom-links").css("position", "static");
	}

	/** TABS **/
	$(".tabs").tabs();

	/** FLAPS **/
	$(".flap").each(function() {
		$(this).not(".flap-open").find(".flap-body", this).hide();
		$(".flap-header", this).css("cursor", "pointer").click(function() {
			var flap$ = $(this).closest(".flap");
			if ($(".flap-body", flap$).is(":visible")) {
				flap$.removeClass("flap-open").find(".flap-body").slideUp();
			} else {
				flap$.addClass("flap-open").find(".flap-body").slideDown();
			}
			return false;
		});
	});

	/** SEARCH **/
	$("#N_TopNavigation_search").focus(function() {
		$(this).select();
	}).mouseup(function(e) {
		e.preventDefault(); // this is for Safari and Chrome
	});

	/** LOGIN **/
	$("#login > button.btn").click(function() {
		if ($("span", this).hasClass("btn-icon-arrow-down")) {
			$("span", this).attr("class", "btn-icon-arrow-up");
			$(this).next("form").show();
		} else {
			$("span", this).attr("class", "btn-icon-arrow-down");
			$(this).next("form").hide();
		}
		return false;
	});

	/** FUNCTION BAR **/
	$("#function-bar-print").click(function() {
		window.print();
		return false;
	});

	/** MULTILINK MODULE **/
	$(".module-multilink .multilink-title").click(function() {
		$(this).parents("ul").find("li.active").removeClass("active");
		$(this).parent("li").addClass("active");
		return false;
	});

	/** MULTITEASER MODULE **/
	$(".module-multiteaser li:gt(0)").hide();
	$(".module-multiteaser .multiteaser-next").click(function() {
		$(this).closest(".module-multiteaser").find("ul").each(function() {
			var visibleItem$ = $(this).find("li:visible");
			visibleItem$.hide();
			if (visibleItem$.next("li").size() == 0) {
				$("li:eq(0)", this).show();
			} else {
				visibleItem$.next("li").show();
			}
		});
		return false;
	});
});
