//defining const for better performance
var L1active = $('#subNav_L1 li a.active');
var L2active = $('#subNav_L2 li a.active');
var L3active = $('#subNav_L3 li a.active');

//if children in list, add a edge downwards - sure
if( L2active.length > 0) {
	L1active.css({'background' : 'url("fileadmin/layout/images/edge_down.png") no-repeat -0.455em 0.364em'}); 
};

//clean up
L1active.nextAll().children().children().css("background", "none");
L2active.css("background", "url('fileadmin/layout/images/edge_up.png') no-repeat");
L2active.parent().nextAll().children().css("background", "none");

//if only <a> in Level 2 is active but not in L3, make:
if (L2active) {
	$('#subNav_L2 li ul li a').css("background", "none"); 
};

//if there is a reference (next Level) for this <a> in <li> add a cross and add to all <a> before <a class="active"> a line.png, if it's the least add edge_up.png - sure
if ((L2active.parent().children().length > 1) && (L3active.length > 0)) { 
	L2active.css("background", "url('fileadmin/layout/images/cross.png') no-repeat -0.455em 0");
	$('#subNav_L3 li a').css("background", "url('fileadmin/layout/images/line.png') repeat-y -0.455em  0");
} else {
	L2active.css("background", "url('fileadmin/layout/images/edge_up.png') no-repeat -0.455em  0");
};

//following <a> in <li> in Level 2 getting no background
if (L2active.parent().children().length == 0) {
	$('ul#subNav_L2 li a.active').css("background", "none"); 
};

//Creates outer Line downwards, checks several conditions which <a> is class="active" and in which #subNav Level
if (((L1active.length > 1) && (L2active.length > 0 )) && ($('#subNav_L3').children().length == 0)) { 
L2active.parent().prevAll().children().css("background", "url('fileadmin/layout/images/line.png') repeat-y -1.364em 0");
};

if (((L1active.length > 1) && (L2active.length > 0 )) && ($('#subNav_L3').children().length > 0)) { 
L2active.parent().parent().parent().prevAll().children().css("background", "url('fileadmin/layout/images/line.png') repeat-y -1.364em 0");
	if (L3active.length == 0) {
	L2active.parent().prevAll().children().css("background", "url('fileadmin/layout/images/line.png') repeat-y -1.364em 0");
	}
};

//add standard edge_up.png to each <a> in Level 3 - surely, clean up all in DOM
L3active.css("background", "url('fileadmin/layout/images/edge_up.png') no-repeat 0.455em 0"); 
L3active.parent().nextAll().children().css("background", "none");
L2active.parent().css("background", "none");
L2active.parent().nextAll().css("background", "none");
L3active.parent().nextAll().css("background", "none");
//delete line.png where 2 or more Elements in Level1 are present and not the first one is class="active"
$('#subNav_L1 > li > a.active').parent().prevAll().children().css("background", "none");
