/* VARIABLEN */


function newDimensions(dimension) {
	
	if (dimension == "small") {
		var header_width = "733px";
		var content_right_width = "136px";
	} else {
		var header_width = "862px";
		var content_right_width = "250px";
	}
	$("#header").animate({ width: header_width });
	$("#content-right").animate({ width: content_right_width });
	
}

function resizeContent() {
	
	var header_height = $("#header").outerHeight();
	var content_height = $("#content-left-wrapper").outerHeight();
	var content_right_height = $("#content-right-wrapper").outerHeight();
	if (content_height < content_right_height) content_height = content_right_height;
	var body_height = $(document).height() - header_height - 35;
	
	if (body_height > content_height) {
		content_height = body_height;
	} 
	
	if (content_height < 520) { 
		content_height = 520; 
	}
	
	$("#content-left").height(content_height);
	$("#content-right").height(content_height);
	
	if ($("#content-right-wrapper").hasClass("wide")) { dimension = "wide" } else { dimension = "small"  }
	
	newDimensions(dimension);
	
	//$("#content-right-wrapper").css("border","solid 1px red");
	
	/* BREITE */
	
}

var active_nav_id = "";
var active_subnav_id = "";

function leftNavClick(link_id) {
	handleLoader("start");
	resetArrows();
	var el_link = $('#'+link_id);
	var el_link_sub = $('#'+link_id+'_sub');
	var el_link_arrow = $('#'+link_id+'_arrow');
	if (active_nav_id != link_id) { activate_level_one(link_id); }
	el_link_arrow.animate({ backgroundPosition:'47px 0px', opacity:1 }, 500);
	if (!el_link.hasClass('justright')) {
		$("#content-left").load("content/"+lang+"/"+nav[link_id]+".php?lang="+lang, new Date().getTime(), function() { });
	}
	$("#content-right").load("content/"+lang+"/"+nav[link_id]+"_right.php?lang="+lang, new Date().getTime(), function() { resizeContent(); handleLoader("stop"); });
	
}
function leftSubNavClick(link_id) {
	
	handleLoader("start");
	
	resetArrows();
	
	var el_link = $('#'+link_id);
	var el_link_arrow = $('#'+link_id+'_arrow');
	
	if (active_nav_id != link_id) {
		
		el_link.blur();
		
		active_subnav_id = link_id;
	}
	
	el_link_arrow.animate({ backgroundPosition:'47px 0px', opacity:1 }, 500);
	
	if (!el_link.hasClass('justright')) {
		$("#content-left").load("content/"+lang+"/"+nav[link_id]+".php?lang="+lang, new Date().getTime(), function() {  });
	}
	$("#content-right").load("content/"+lang+"/"+nav[link_id]+"_right.php?lang="+lang, new Date().getTime(), function() { resizeContent(); handleLoader("stop"); });
}

function linkto(link_id) {
	if (link_id.substr(link_id.length-1,1) == "0") { // LVL 1
		leftNavClick(link_id);
	} else { // LVL 2
		var parent_link_id = link_id.substring(0,link_id.length-1) + "0";
		resetArrows();
		activate_level_one(parent_link_id);
		leftSubNavClick(link_id);
	}
	
}
function linktocontent(link_id) {
	
	handleLoader("start");
	
	resetArrows();
	
	var el_link = $('#'+link_id);
	var el_link_sub = $('#'+link_id+'_sub');
	var el_link_arrow = $('#'+link_id+'_arrow');
	
	if (active_nav_id != link_id) {
		
		activate_level_one(link_id);
	}
	
	el_link_arrow.animate({ backgroundPosition:'47px 0px', opacity:1 }, 500);
	
	//$("#content-right").load("content/"+lang+"/"+nav[link_id]+"_right.php", new Date().getTime(), function() {  });
	$("#content-left").load("content/"+lang+"/"+nav[link_id]+".php?lang="+lang, new Date().getTime(), function() { resizeContent(); handleLoader("stop"); });
	
}

function activate_level_one (link_id) {
	
	var el_link = $('#'+link_id);
	var el_link_sub = $('#'+link_id+'_sub');
	
	if (active_nav_id != "") { $("#"+active_nav_id).removeClass("active"); }
	$("#"+active_nav_id+"_sub").hide("normal");
	el_link.addClass("active").blur();;
	el_link_sub.show("slow");
	active_nav_id = link_id;
}

function resetArrows() {
	$("#"+active_nav_id+"_arrow").css({ backgroundPosition:'0px 0px', opacity:0 });
	$("#"+active_subnav_id+"_arrow").css({ backgroundPosition:'0px 0px', opacity:0 });	
}

function handleLoader(action) {
	if (action == "start") {
		$('#loader').show();
	} else {
		$('#loader').hide();
	}
}

function contentClick(contentright) {
	$("#content-right").load("content/"+lang+"/"+contentright+".php?lang="+lang, new Date().getTime(), function() { 
		if ($("#content-right-wrapper").hasClass("wide")) { dimension = "wide" } else { dimension = "small" }
		resizeContent();
	});
	
}

function contentClick2Left(contentleft) {
	$("#content-left").load("content/"+lang+"/"+contentleft+".php?lang="+lang, new Date().getTime(), function() { 
		if ($("#content-right-wrapper").hasClass("wide")) { dimension = "wide" } else { dimension = "small" }
		resizeContent();
	});
	
}

function openLayer(contentlayer) {
	$("#layer-bg").css({opacity:0.50}).fadeIn("slow");
	$("#layer-content").show("slow");
	$("#layer-content").load("content/"+lang+"/"+contentlayer+".php?lang="+lang, new Date().getTime(), function() {  });
}

function closeLayer(contentlayer) {
	$("#layer-content").text("");
	$("#layer-content").hide("slow");
	$("#layer-bg").fadeOut("slow");
}

function openLayerSmall(contentlayer) {
	$("#layer-bg").css({opacity:0.50}).fadeIn("slow");
	$("#layer-content-small").show("slow");
	$("#layer-content-small").load("content/"+lang+"/"+contentlayer+".php?lang="+lang, new Date().getTime(), function() {  });
}

function closeLayerSmall(contentlayer) {
	$("#layer-content-small").text("");
	$("#layer-content-small").hide("slow");
	$("#layer-bg").fadeOut("slow");
}

window.onload = function(){ 

	$("ul.leftnav li a.lvl_1").click(function() { leftNavClick(this.id) });
	$("ul.leftnav li a.lvl_2").click(function() { leftSubNavClick(this.id) });
	$("ul.metanav li a").click(function() { leftNavClick(this.id) });
		
	leftNavClick("link_1_0");
	
}