function forward_timer(c){
	document.getElementById('forward_timer').innerHTML = c;
	if(c > 0)	window.setTimeout("forward_timer("+(c-1)+");", 1000);
	else window.location.href = document.getElementById('forward_timer').title ;
}
	

(function($){
	$().ready(function(){
		$("a").css("text-decoration", "none");
	
		$("a, #b2 a").hover(
			function() {
				$(this).css("text-decoration", "underline");
			},
			function() {
				$(this).css("text-decoration", "none");
			}
		);
		
		$("#nav li.item").hover(
			function() {
				$(this).css("background-image", "url('images/design/nav_item_hover.jpg')");
			},
			function() {
				$(this).css("background-image", "none");
			}
		);
		
		$("#box #inner ul#subnav li.allow_hover").hover(
			function() {
				$(this).css("background-image", "url('images/design/sub_nav_item_hover.jpg')");
			},
			function() {
				$(this).css("background-image", "url('images/design/sub_nav_item_bg.jpg')");
			}
		);
		
		// Prüfen ob Subnavi überhaupt verfügbar
		if($("#box #inner ul#subnav li.allow_hover").size() == 0){
			$("#box #inner ul#subnav li").css("visibility", "hidden");
		}
	});
	
	$("span#forward_timer").ready(function(){
		if(isNaN(parseInt($("span#forward_timer").text())) === false) forward_timer(parseInt($("span#forward_timer").text()));
	});
	
	$("#studium #semester").ready(function(){
		$("#studium #semester ul").css("display", "none");
		$("#studium #semester h2").css("display", "inline");
	
		$("#studium #semester h2").after(' (<a href="#" id="link_' + $(this).next().attr("id") + '">+</a>)<br />');
		$("#studium #semester a").css("text-decoration", "none");	
			
		$("#studium #semester a").click(function() {
			if($(this).nextAll("ul").filter(":first").css("display") == "block"){
				$(this).html("+");
				$(this).nextAll("ul").filter(":first").css("display", "none");
			} else {
				$(this).html("-");
				$(this).nextAll("ul").filter(":first").css("display", "block");
			}
			return false;
		});	
	});
		
	$("#Delicious").ready(function(){
		$("#Delicious").hover(
			function() {
				document.body.style.cursor = 'pointer';
				$(this).attr("src", "images/design/del_ani.gif");
			},
			function() {
				document.body.style.cursor = 'default';
				$(this).attr("src", "images/design/del.gif");
			}
		);
		$("#Delicious").click(function() {
				window.open('http://del.icio.us/post?v=2&amp;url='+encodeURIComponent(location.href)+'&amp;notes=&amp;tags=&amp;title='+encodeURIComponent(document.title));
			}
		);
	});	
	
	$("#Google").ready(function(){
		$("#Google").hover(
			function() {
				document.body.style.cursor = 'pointer';
				$(this).attr("src", "images/design/google_ani.gif");
			},
			function() {
				document.body.style.cursor = 'default';
				$(this).attr("src", "images/design/google.gif");
			}
		);
		$("#Google").click(function() {
				window.open('http://www.google.com/bookmarks/mark?op=add&amp;hl=de&amp;bkmk='+encodeURIComponent(location.href)+'&amp;annotation=&amp;labels=&amp;title='+encodeURIComponent(document.title));
			}
		);
	});	
	
	$("ul#web li a").ready(function(){
		$("ul#web li a").click(function(){
			window.open(this.href); 
			return false;
		});
	});
	
	$("#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));
			    })
			    
			    if($("#kontakt #vielendank")){
			    	$("#kontakt #vielendank").remove();
			    }
			    
			    $("#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: 100000,
			      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 (" + data + ")");
			      	} else {
			      		$("#kontakt").prepend('<p style="color: red" id="vielendank">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)