$(document).ready(function() {
	/* Tabs */
	var aboutHeight = $("div#about").height();
	var portfolioHeight = $("div#portfolio").height();
	var socialHeight = $("div#social").height();
	var kontaktHeight = $("div#kontakt").height();
	$("div.content").height(0);
	
	var current = "about";
	$("div#" + current).height( eval(current+"Height") );
	
	$("a.tablink").click( function() {
		var toShow = $(this).attr("rel");
		if(toShow!=$("a.tablink.selected").attr("rel")){
			$("a.tablink").removeClass("selected");
			$(this).addClass("selected");
			$("div#" + current).animate({ height: 0 }, 500, function() { $(this).hide(); });
			if( toShow == "kontakt" ) toAdd = 30;
			else toAdd = 0;
			$("div#" + toShow).show().animate({ height: eval(toShow+"Height") + toAdd }, 500);
			current = toShow;
		}
		return false;
	});
	
	/* Portfolio */
	$("a.break").click( function() { return false; });
	$("#slider").scrollable({ size: 1, clickable: false, keyboard: false });
	$('#slider div.work' ).tooltip({
		tip: '#tooltip', 
		effect: 'slide',
	    predelay:200, 
	    delay:200
	});
	
	/* Social Networks */
	$('#socialnetworks ul li').hover(
		function() {
			$(this).animate({
			    left: '-=10'
			  }, 200, function() {
			    // Animation complete.
			  });
		},
		function() {
			$(this).animate({
			    left: '+=10'
			  }, 200, function() {
			    // Animation complete.
			  });
		}
	);
	
	/* Contact Form */
	$('.required').hide();
	$("#sendform").click( function() {
		$('.required').hide();  
	    var name = $("input#contact_name").val();  
	    if (name == "") {  
	      $("label#name_error").show();  
	      $("input#contact_name").focus();  
	      return false;  
	    }  
	    var email = $("input#contact_email").val();  
	    if (email == "") {  
	      $("label#email_error").show();  
	      $("input#contact_email").focus();  
	      return false;  
	    }  
	    var message = $("textarea#contact_message").val();  
	    if (message == "") {  
	      $("label#message_error").show();  
	      $("textarea#contact_message").focus();  
	      return false;  
	    }
	    
	    var dataString = 'name='+ name + '&email=' + email + '&message=' + message;
		
		$.ajax({
		    type: "POST",
		    url: "mail.php",
		    data: dataString,
		    success: function() {
		      $('#contactform form').html("<div id='message'></div>");
		      $('#message').html("<h2>Nachricht verschickt</h2>")
		      .append("<p>Danke für die Nachricht. Ich werde Ihnen umgehend antworten.</p>")
		      .hide()
		      .fadeIn(1500);
		    }
		}); 
		
		return false;
	});
	
	$("#themes a").click( function() {
		$("body").removeClass();
		$("body").addClass( $(this).attr("rel") );
		return false;
	});
});
