$(function() {
	//Newsletter Input
	$("#newsletter_signup_input").focus(function(){
		var $t=$(this);
		$t.removeClass("input_default");
		if($t.val()==$t.data("defaultval")) $t.val("");
	}).blur(function(){
		var $t=$(this);
		if($t.val()=="") $t.val($t.data("defaultval")).addClass("input_default");
	}).addClass("input_default").data("defaultval",$("#newsletter_signup_input").val());
	
	
	//Slider
	$('.anythingSlider').anythingSlider({
		easing: "easeInOutExpo",        // Anything other than "linear" or "swing" requires the easing plugin
		autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
		delay: 12000,                    // How long between slide transitions in AutoPlay mode
		startStopped: false,            // If autoPlay is on, this can force it to start stopped
		animationTime: 600,             // How long the slide transition takes
		hashTags: true,                 // Should links change the hashtag in the URL?
		buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
		pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
		startText: "Go",                // Start text
		stopText: "Stop",               // Stop text
		navigationFormatter: formatText // Details at the top of the file on this use (advanced use)
	});
           	
	$("#teaserbox_navigation ul li a").mouseover(function() {
		$(".cur").removeClass("cur");

		var item_name=$(this).attr("id");

		$(this).addClass("cur");

		item_ar=item_name.split("-");
		item_id=parseInt(item_ar[1]);

		$('.anythingSlider').anythingSlider(item_id);
	});

	$("#teaserbox_navigation li:last").css({"background":"none"}); //removes the last navigation seperator (right-hand side)
	
	//buttons
	$(".button").mousedown(function() {
		$(this).css({"opacity":"0.8"});
	});
	$(".button").mouseleave(function() {
		$(this).css({"opacity":"0.9"});
	});
	
	//Kalender
	var er=$(".event > .calnk");
	er.addClass("ereignis");
	er.removeClass("calnk");
	
	var e_heading;
	var e_date;
	var e_time;
	var e_text;
	var e_cat;
	var e_info;
	var e_id;
	
	$('.ereignis > a').click(function() {
		details=$(this).next();
		e_heading=details.find(".event-title").html();
		e_date=details.find(".event-date").html();
		e_time=details.find(".event-time").html();
		e_text=details.find(".event-content").html();
		
		e_info=details.attr("title").split("|");
		e_cat=e_info[0];
		e_id=e_info[1];
		
		$("#lightbox_heading").html(e_heading);
		$("#lightbox_date").html(e_date+" - "+e_time);
		$("#lightbox_text").html(e_text);
		
		//buttons
		e_heading=e_heading.replace(/ /g,"-");
		e_heading=e_heading.toLowerCase();
		var regb_url="'anmeldung?event="+e_heading+"&id="+e_id+"'";
		
		$("#gotoregister_button").live("click",function(regb_url) {
			console.log(regb_url);
			document.location.href=regb_url;
		});
		
		
		e_cat=e_cat.replace(/ /g,"-");
		e_cat=e_cat.toLowerCase();
		var sprti_url="document.location.href='"+e_cat+"'";
		
		$("#sportinfo_button").click(function(sprti_url) {
			document.location.href=sprti_url;
		});
		$("#sportinfo_button").attr("onclick",sprti_url);
		
		
		var mid = $(window).scrollTop() + Math.floor($(window).height() / 2);
		$("#lightbox").css("top",mid-300+"px");
		
		$("#lightbox").fadeIn();
		$("#dark").fadeIn();
		return false;
	});
	
	/* Lightbox */
	var lightbox_hide=function() {
		$("#dark").fadeOut();
		$("#lightbox").fadeOut();
	}

	//hide lightbox by esc
	$(window).keyup(function(event) {
		if (event.keyCode == '27') {
			lightbox_hide();
		}
	});

	$("#dark").click(function() {
		lightbox_hide();
	});
	$("#lightbox_top a").click(function() {
		lightbox_hide();
		return false;
	});
	
	//Betreff bei der Anmeldung einfügen
	if ($.getURLParam("kurs")!=null) {
		var anmeldung_kurs = $.getURLParam("kurs");
		var anmeldung_id = $.getURLParam("kurs_id");
		
		$("#anmeldung_betreff").attr("value","Anmeldung: "+anmeldung_kurs+" | Kurs-ID: "+anmeldung_id);
		$("#anmeldung_betreff").attr("disabled","disabled");
	}
	
	// jQuery SmoothScroll
	$('#goto_top a[href*=#]').click(function() {
		// duration in ms
		var duration=500;

		// easing values: swing | linear
		var easing='swing';


		// get parameters
		var hash=this.hash;
		var target=$(hash).offset().top;

		// animate to target and set the hash to the window.location after the animation
		$("html:not(:animated),body:not(:animated)").animate({ scrollTop: target }, duration, easing, function() { location.hash=hash; });

		// cancel default click action
		return false;
	});
});
