$(document).ready(function(){


	
	var myurl = String(window.location.pathname);
	var parts_url = myurl.split('/');
	var activeCat = parts_url[1];
	
	$("#menu a").each(function() {
		if ($(this).metadata().path == activeCat){
			$(this).addClass("active");
		}
	});
	
    
    $("#home-center a").click(function(e){
    	e.preventDefault();
    	var target = $(this).attr("href");
    	$("#home-center").fadeOut(2000, function() {
    		location.href = target;
    	});
    });
    
	$("#langswitch").click(function(e){
		e.preventDefault();
		
		var currentURL = location.href;
		var full = window.location.host;
		var parts = full.split('.');
		var sub = parts[0];
		if (sub === "de" || sub === "www") {
			var switchURL = currentURL.replace("de.", "en.");
			switchURL = switchURL.replace("www.", "en.");
		} else {
			var switchURL = currentURL.replace("en.", "de.");
		}
	
		location.href = switchURL;	
	});
	
    jQuery.fn.center = function () {
	    this.css("position","absolute");
	    this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
	    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
    	return this;
	}

	$("#wrapper").center();
	$(window).resize(function() {
		$("#wrapper").center();	
	});
	
	var lang = "de";
	$("#sl").click(function(e){
		if (lang === "de") {
			$(".lang_de").hide();
			$(".lang_en").show();
			lang = "en";
		} else {
			$(".lang_de").show();
			$(".lang_en").hide();
			lang = "de";
		}
	});
	
});	
