$(function() {
	var bodyh=parseInt($("body").css("height"));
	var winh=$(window).height();
	if(bodyh<winh) {
		$("#mainbackground").css("height",(winh)+"px");
	}

	$(".menufinger").each(function() {
		var classes=$(this).attr("class").split(" ");
		for(var i=0; i<classes.length; i++) {
			if(classes[i]!="menufinger") $(this).data("delta",parseInt(classes[i].substr(1)));
		}
		$(this).data("top",parseInt($(this).css("top")));
		$(this).data("left",parseInt($(this).css("left")));
	});

	$(".ajaxlink").click(function(event) {
		event.preventDefault();
		if($(this).attr("href")=="saxofonschule") $(".brandmask").css("background", "transparent url('"+$("#metahttpbase").attr("content")+"images/saxmask.png') no-repeat")
		else if($(this).attr("href")=="bandschule") $(".brandmask").css("background", "transparent url('"+$("#metahttpbase").attr("content")+"images/bandmask.png') no-repeat")
		$.post(
			$("#metahttpbase").attr("content")+$(this).attr("href"),
			{
				ajaxrequest:"getContent"
			},
			function(result){
				$("#ajaxcontentcontainer").fadeOut(500, function() {
					$(this).html(result);
					$(this).fadeIn(500, function() {});
					initAfterAjax();
				});
			}
		);

	})

	$(".ajaxlink").mouseover(function() {
		var el=$("#"+$(this).attr("id")+"finger");
		var delta=220;
		if(el.data("delta")!=undefined) delta=el.data("delta");
		el.stop().animate({"left": (delta*(-1)+el.data("left"))+"px","top": (el.data("top")+delta)+"px"},400,"swing");
	});
	$(".ajaxlink").mouseout(function() {
		var el=$("#"+$(this).attr("id")+"finger");
		el.stop().animate({"left": el.data("left")+"px","top": el.data("top")+"px"},200,"swing");

	});
	$("#popupclose a").click(function(event) {
		event.preventDefault();
		hidePopup();
	})
	$("#popupcanv").click(function() {
		hidePopup();
	})


	
	$('dl').addClass('enabled').timetabs({
		defaultIndex: 0,
		interval: 5000,
		continueOnMouseLeave: true,
		animated: 'fade',
		animationSpeed: 500
	});    
    
	initAfterAjax();

	function initAfterAjax() {
		if($('.marqueeSlow').length>0) $('.marqueeSlow').marquee({speed:2});
		if($('.marqueeFast').length>0) $('.marqueeFast').marquee({speed:3});
		if($('.popup').length>0) {
			$('.popup').hide();
			$('.popuplink').each(function() {
//				$(this).before("<a href='#' class='popuplink'>"+$(this).children("a.popuplink").html()+"</a>");
//				$(this).children("a.popuplink").remove();
				$(this).next(".popup").hide();
				var str=$(this).next(".popup").html();
				$(this).children("a").click(function(event) {
					event.preventDefault();
					showPopup(str);
				});
			});
		}
	}

	function showPopup(str) {
		$("#popupcontent").html(str);
		$("#popupcanv").fadeIn(500);
		if($("#brownmask").height()>$("body").height()) $("#popupcanv").height($("#brownmask").height());
		else $("#popupcanv").height($("body").height());
		$("#popupcontent").fadeIn();

	}
	function hidePopup() {
		$("#popupcontent").html("");
		$("#popupcanv").fadeOut(500,function() {
			$("#popupcontent").html("");
		});
	}

});

