(function($){
	$(document).ready(function(){
		/* Navigation */
		$("#Navigation").ready(function(){
			$("#Navigation li a").hover(
				function(){;
					$(this.parentNode).css("background-image", "url(images/li_hover.jpg)")
					$("#submenus ul").css("display", "none");
					$("#sub_" + $(this.parentNode).attr("id").replace(/nav_/, "")).css("display", "block");
				},
				function(){
					$(this.parentNode).css("background-image", "url(images/li_"+$(this.parentNode).attr("id").replace(/nav_/, "")+".jpg)")
				}
			);	
		});
		
		$("#submenus").ready(function(){
			$("#submenus li a").hover(
				function(){;
					$(this).css("text-decoration", "underline");
				},
				function(){
					$(this).css("text-decoration", "none");
				}
			);
		});	

		/* Kurse */
		
		// Parser hinzufügen
		$j.tablesorter.addParser({
			// Datumsparser.
			// Hier verwendet: '[Wochentag]s, UhrzeitVon - UhrzeitBis';
			// Idee: 	Wochentag durch zahl von 0-6 ersetzen
			// 			Uhrzeit als rein Zahl
			// => Leichtes numerisches Sortieren möglich
			// Skript kann sehr leicht auf andere Daten übertragen werden...   
	        id: 'wochentage', 
	        is: function(s) { 
	            return false; 
	        }, 
	        format: function(s) { 
	        	Wochentage = new Array("Montags", "Dienstags", "Mittwochs", "Donnerstags", "Freitags", "Samstags", "Sonntags");
	        	
	        	// Wochentag durch entsprechende Zahl ersetzen
	        	for(var i = 0; i < Wochentage.length; i++){
	        		s = s.replace(Wochentage[i], i);
	        	}
	        	
	        	// Alles auser Zahlen entfernen
	        	s = s.replace(/\D/ig, "");
	        	
	        	return s;
	        }, 
	        type: 'numeric' 
	    });

	    // Sicherstellen, dass Thickbox updates mitbekommt...     	
			$j(".tablesorter thead tr th").click(function () {
				tb_remove();
				$j("a.thickbox").unbind("click");
				tb_init('a.thickbox');
		});
		
		$j(".tablesorter").each(function(i){
			if($j(this).children("tbody").children("tr").length != 0){
				// Tablesorting initalisieren
				$j(this).tablesorter({
					sortList: [[0,0]],
					headers: { 
			               2: {  sorter:'wochentage'  } ,          
			               3: {  sorter: false 	    } 
			           }
			     } );
			}
		});
		/* Kursbilder */
		if($(".kursebilderfader").length != 0){
			$(".kursebilderfader").hover(
				function(){;
					$(this).css("text-decoration", "none");
				},
				function(){
					$(this).css("text-decoration", "underline");
				}
			);
			$(".kursebilderfader").click(function(){
				if($(this).next().css("display") == "none"){
					$(this).next().fadeIn();
					$(this).text("Bilder ausblenden");
				} else {
					$(this).next().fadeOut();
					$(this).text("Bilder einblenden");
				}
			});
		}
		
	  	/* Hobbies & Bilder */
		if($("#gallerytab").length != 0){
	    	$('#gallerytab ul:first').tabs({ fxFade: true, fxSpeed: 500 });
	    	/*
	    	var hobbies = $('#gallerytab ul ~ div');
	
	    	for (var i=0;i<hobbies.length;i++){
	    		$("#"+ hobbies[i].id + " .bilder li").click( function(){
			  		hobbie = $(this.parentNode.parentNode).attr("id");
					
					$("#"+ hobbie + " .show .text").css("display", "none");
					$("#"+ hobbie + " .show .image").css("display", "none");
					$("#"+ hobbie + " .show .loading").css("display", "block");
					$("#"+ hobbie + " .show").css("height", "352px");
					
					var src = "big-" + this.firstChild.src.match(/.+\/(.+)$/i).pop().replace(/thumb-/, "");
			
					$("#"+ hobbie + " .show .image").html('<img src="'+src+'" alt="'+this.firstChild.alt+'" id="' + src + '"/>');
			
					var image = new Image();
					image.onload = function(){
						$("#"+ hobbie + " .show .image").css("display", "block");
						$("#"+ hobbie + " .show .loading").css("display", "none");	
						jQuery.scrollTo( 0, {speed:1000} );	
					}
					image.src = src;
					
					$(src).attr("src", image.src);  		
	    		});
	    	}
	    	*/
		};
	});
	
		$("#kontakt form").ready(function(){
		$("#kontakt form").validate({
			rules: {
				name: {
					required: true,
					minLength: 10
				},
				email: {
					required: true,
					email: true
				},
				nachricht: {
					required: true,
					minLength: 10
				}
			},
			messages: {
				name: {
					required: "Bitte geben Sie ihren Namen an.",
					minLength: "Ihr Name wird doch wohl l&auml;nger als 10 Zeichen sein?"
				},
				nachricht: {
					required: "Haben Sie nichts zu sagen?",
					minLength: "Etwas mehr muss schon sein..."
				},
				email: "Bitte geben Sie ihre E-Mail Adresse an."
			},
			submitHandler: function(form) {
			    var inputs = [];
			    $(':input', form).each(function() {
			      inputs.push(this.name + '=' + escape(this.value));
			    })
			    
			    $("#kontakt div.formular").css("display", "none");
				$("#kontakt div.adresse").css("display", "none");
				$("#kontakt #kontakt_loader").css("display", "block");
				
			    jQuery.ajax({
			      type: "POST",
			      data: inputs.join('&'),
			      url: "kontakt.php",
			      timeout: 10000,
			      error: function(a,b,c) {
			        alert("Mail konnte nicht gesendet werden (" + b + ")");
			        $("#kontakt div.formular").css("display", "block");
					$("#kontakt div.adresse").css("display", "block");
					$("#kontakt #kontakt_loader").css("display", "none");
			      },
			      success: function(data, textStatus){
			      	if(data != "gesendet"){
			      		alert("Mail konnte nicht gesendet werden");
			      	} else {
			      		$("#kontakt").prepend('<p style="color: red">Vielen Dank f&uuml;r Ihre Nachricht!</p>');
			      	}
				    $("#kontakt div.formular").css("display", "block");
					$("#kontakt div.adresse").css("display", "block");
					$("#kontakt #kontakt_loader").css("display", "none");
			      }
			    }); 
			    

			    return false;
			}
		})
	});
	
})(jQuery)
