var lastSubnav='buerstmaschienen';

$(document).ready(function(){
	var location = window.location.hash;
	slide($("ul li"));
	navi($("#head ul li"));
	navi($('.navigator li'));
	linkMe($('.link_box'));
	linkMe($('.linkMe'));

	
		
		/*if(window.location.href.indexOf("index.html") != -1 ){
			setTimeout(function() {
				var temp = window.location.href.substr(0, window.location.href.indexOf("testserver/")+11) + window.location.href.substr(window.location.href.indexOf("testserver/")+21, window.location.href.length);
				window.location.href = temp;
			  }, 200);
		}*/
		
	if(location != ""){
		if(location.indexOf("/") != -1){
			$('.sub_nav .sub_navigation .'+window.location.hash.substr(window.location.hash.indexOf("/")+1,window.location.hash.length)).click();
		}
		else{	
			$('#content').children().hide();
			$('#navigation .'+window.location.hash.substr(1,window.location.hash.length)).click();
		}
	}else{
		$('#content').children().hide();
		$('#head ul li:first').click();	
	}

});

function linkMe(obj){
	$(obj).click(function(){
			setTimeout(function() {
				window.location.reload();
			}, 200);
	});
}

function slide(obj){
	if(!obj.length) return;

	$(obj).find("ul").css({display: "none"});
	$(obj).hover(function(){
		
	},function(){
		$(this).find('ul').stop(true, true).slideUp(500);
	});
	
	$(obj).click(function(){
		$(this).find('ul').stop(true, true).slideDown(500);
	});
}

function navi(obj){
	$(obj).click(function(){
		
		if($(this).hasClass('selected') || $(this).hasClass('slide')){
			return;
		}
		$('#content').children().hide();
		var classe = $(this).attr('class');
		if($("."+classe).parent().attr('class') == $('#navigation').attr('class')){
			
			window.location.hash = '#' + classe;
			if(window.location.hash == '#produkte'){
					
					$('#content .produkte').show();
					$('#content .produkte .sub_cont').show();
					$('#content .produkte .sub_cont:not(.'+lastSubnav+')').hide();
					$('.sub_nav .sub_navigation .'+lastSubnav).addClass('selected').siblings().removeClass('selected');
					window.location.hash = '#produkte/'+lastSubnav;
			}
			else
				$("."+classe).show();
			
		}	
		else{
			
			window.location.hash = '#produkte/' + classe;
			$('#navigation .produkte').addClass('selected');
			$('#content .produkte').show();
			//$("#content .produkte .sub_nav").show();
			$("#content .produkte .sub_cont").hide();
			$("."+classe).show();
			$('.sub_navigation').children().removeClass('selected');
			lastSubnav=classe;
		}
		$(this).addClass('selected').siblings().removeClass('selected');
		
	});
}



