var falk = function() {
	var
	
	activeTab,
	
	checkCurrent = function() {
		var that = $(this);
		
		if(typeof topmenupoint == "undefined") {
			topmenupoint = "none-";
		}
		
		that.find("a").each(function() {
			if($(this).attr("href") == window.location.pathname.toString() || $(this).attr("href").indexOf(topmenupoint) != -1) {
				$(this).addClass("current");
			}
		});
	},
	
	init = function() {
		
		$("#menu li").each(checkCurrent);
	    
	    $("#sortiment-wrapper .container .title").bind("click", function() {
	    	var $this = $(this);
	    	
	    	var ul = $this.parent().find("ul");
	    	
	    	$("#sortiment-wrapper .container ul").slideUp();
	    	$("#sortiment-wrapper .container .title").removeClass("active");
	    	
	    	if(ul.css("display") == "block") {
	    		ul.slideUp();
	    	} else {
	    		ul.slideDown();
	    		$this.addClass("active");
	    	}
	    });
	    
	    var uri = window.location + "";
	    
	    var matches = uri.match(/sortiment\/([^\/]*)\/?(?:category\/(.*))?/);
	     
	    if(matches != null) {
	    	var category = matches[1];
	    	var subcategory = "";
	    	
	    	var curUL = $("#sortiment-wrapper .container ." + category);
	    	curUL.css("display", "block");
	    	curUL.parent().find(".title").addClass("active");
	    	
	    	
	    	
	    	if(typeof matches[2] !== "undefined") {
	    		subcategory = matches[2];	    		
	    		curUL.find("." + subcategory).addClass("active");
	    	}
	    }
	}
	;

	return {
		init: init
	};
}();


$(document).ready(function() {
	falk.init();
});

