// Copyright 2008 Lars Madsen, daleif@imf.au.dk
// 
// feel to use the code for what ever you want.
// THIS IS CURRENTLY JUST A PLACEHOLDER SCRIPT WILL CONTAIN BRANCH-FOLDING (AND SPECIAL SIAB VERSION ALSO BREADCRUMB)
var navItems = new Array();

function build_sublist(id,List,extra) {
    var DIV = document.createElement('div');
    DIV.id = id;
    if ( extra != '' ) {
	var H2 = document.createElement('h2');
	H2.appendChild(document.createTextNode(extra));
	DIV.appendChild(H2);
    }
    var UL = document.createElement('ul');
    for (var i=0; i<List.length; i++ ) {
	var LI = document.createElement('li');
	LI.id = List[i][2];
	LI.appendChild( make_link(List[i][3],List[i][4]) )
	UL.appendChild(LI);
    }
    DIV.appendChild(UL);
    return DIV;
}

function make_link(URL,TXT) {
    var AA = document.createElement('a');
    AA.href = URL;
    AA.title = TXT ? TXT : URL;
    AA.appendChild(document.createTextNode(TXT == '' ? URL:  TXT));
    return AA;
}

function make_linkX(URL,TXT) {
    var AA = document.createElement('a');
    AA.href = URL;
    AA.title = TXT ? TXT : URL;
    AA.appendChild(document.createTextNode(TXT == '' ? URL:  TXT));
    jQuery(AA).click( function(){ return false });
    return AA;
}

function auMenuStructure(A,Conf) {
    this.Data = A;
    var that = this;




    this.mostForContainer       = Conf.mostForContainer           ? Conf.mostForContainer : '';
    this.mostForArray           = Conf.mostForArray.length >0     ? Conf.mostForArray : new Array() ;
    this.navGrenKeyword         = Conf.navGrenKeyword             ? Conf.navGrenKeyword : '';
    this.navUndersideKeyword    = Conf.navUndersideKeyword        ? Conf.navUndersideKeyword  :'';
    this.currentItemClass       = Conf.currentItemClass           ? Conf.currentItemClass : '';
    this.selectedItemClass      = Conf.selectedItemClass          ? Conf.selectedItemClass : '';
    this.mainNavContainer       = Conf.mainNavContainer           ? Conf.mainNavContainer : '';
    this.leftNavContainer       = Conf.leftNavContainer           ? Conf.leftNavContainer : '';
    this.leftNavPaddingClass    = Conf.leftNavPaddingClass        ? Conf.leftNavPaddingClass : '';
    this.leftNavInnerContainer  = Conf.leftNavInnerContainer      ? Conf.leftNavInnerContainer : '';
    this.altBodyClassArray      = Conf.altBodyClassArray.length>0 ? Conf.altBodyClassArray : new Array();
    this.branchClass            = Conf.branchClass                ? Conf.branchClass : '';
    this.selectedBranchClass    = Conf.selectedBranchClass        ? Conf.selectedBranchClass : '';
    this.navMostForKeyword      = Conf.navMostForKeyword          ? Conf.navMostForKeyword : '';
    this.navBreadcrumbKeyword   = Conf.navBreadcrumbKeyword       ? Conf.navBreadcrumbKeyword : '';
    this.breadcrumbContainer    = Conf.breadcrumbContainer        ? Conf.breadcrumbContainer : '';
    this.pageTitleKeyword       = Conf.pageTitleKeyword           ? Conf.pageTitleKeyword : '';
    this.navBreadcrumbSeparator = Conf.navBreadcrumbSeparator     ? Conf.navBreadcrumbSeparator : ''; 
    this.selectedSpecialMainItemClass = Conf.selectedSpecialMainItemClass ? Conf.selectedSpecialMainItemClass : '';



    // some variables
    this.navGren           = '';
    this.navUnderside      = '';
    this.navGranMother     = ''; 
    this.navMostForWord    = '';
    this.navBreadcrumbWord = '';
    this.pageTitle         = '';
 
    var CC = new Array();

    var latestParent = '';
    var latestChildURL = '';

    // start by filtering out branches without leaves, and setting the
    // URLS on 1-items (and nav headlines) to the URL of the leaf
    // found by a depth first search
    LOOP:
    for (var i=navItems.length-1;i>=0;i--) {
	if ( navItems[i][0] == 0 && /^\*+jQuery/.test( navItems[i][2] ) ) {
	    // menu headline
	    CC.push( navItems[i] );
	    CC[CC.length-1][3] = latestChildURL;
	    continue LOOP;
	}
	if ( navItems[i][0] == 0 ) {
	    CC.push( navItems[i] );
	    latestParent = navItems[i][1];
	    latestChildURL = navItems[i][3];
	    continue LOOP;
	}
	if ( navItems[i][0] == 1 ) {
	    if ( navItems[i][2] == latestParent ) {
		CC.push( navItems[i] );
		CC[CC.length-1][3] = latestChildURL;
		latestParent = navItems[i][1];
		continue LOOP;
	    }
	    // i.e. if latestParent does not fit, the branch is ignored
	}
    }
    
    CC.reverse();

    this.Data = CC;
    CC = null;

    var cntr = 0;
    var prefix = 'xyzxxyzzxxderssff';
    CC = new Array();
    var special = false;
    var O = '';

    // filter the array such that we get each menu as an array item of its own
    // we also provide
    LOOP:
    for (var i=0; i<this.Data.length; i++) {
	if ( this.Data[i][0] == 0 && this.Data[i][1] == '' && /^\*+jQuery/.test( this.Data[i][2] ) ) {
	    if ( O ) {
		CC.push ( O );
	    }
	    cntr++;
	    O = new Array();
	    O.push( this.Data[i] );
	    if ( ! /^\s*information\s+(om|about)\s*$/i.test( this.Data[i][4] ) 
		 && 
		 ! /^\s*information\s+(til|for)\s*$/i.test( this.Data[i][4] ) ) {
		special = true;
	    }
	    else {
		special = false;
	    }
	    if ( special ) {
		// now the header item for this nav looks like a branch
		O[O.length-1][2] = prefix + cntr;
		O[O.length-1][0] = 1;
	    }
	    continue LOOP;
	}
	O.push( this.Data[i] );
	if ( special && this.Data[i][1] == '' ) { 
	    O[O.length-1][1] = prefix + cntr;
	}
    }
    // remember to push the last nav
    if ( O ) {
	CC.push ( O );
    }
    
    // next we would like to add the non 'mest til' navigations as branches
    // inside the main navigation, known as 'information om|about'
    
    X = new Array(); // main nav
    O = new Array(); // mest til
    
    for (var i=0;i<CC.length;i++) {
	if ( /^\s*information\s+(til|for)\s*$/i.test( CC[i][0][4] ) ) {
	    O = O.concat( CC[i] );
	}
	else {
	    if ( /^\s*information\s+(om|about)\s*$/i.test( CC[i][0][4] ) ) {
		CC[i].shift();
	    }
	    X = X.concat( CC[i] );
	}
    }

    O.shift(); // getting rid of the first element, i.e the header

    CC = null;

    // structure object
    // Main:
    // navItems = array of the arrays that make up the navigation
    // 
    // MostFor:
    // navItems = same
    //
    // LookUp = array where keys are the unique ids for all the nav items, 
    // and the value is 1 for Main and -2 for MostFor (and thus undefined for 
    // elements not in the menues)

    this.Structure = new Object();

    this.Structure.Main = new Object();
    this.Structure.Main.navItems = X;

    this.Structure.MostFor = new Object();
    this.Structure.MostFor.navItems = O;
    this.Structure.LookUp = new Array();

    for (var i=0;i< this.Structure.Main.navItems.length;i++) {
	this.Structure.LookUp[ this.Structure.Main.navItems[i][2] ] = 1;
    }
    for (var i=0;i< this.Structure.MostFor.navItems.length;i++) {
	this.Structure.LookUp[ this.Structure.MostFor.navItems[i][2] ] = -1;
    }

    X = null;
    O = null;


    // this is special in jquery, so we use that instead
    jQuery.each( jQuery('meta') , function(i,item) {
	if ( jQuery(item).attr('name') == that.navGrenKeyword ) {
	    that.navGren = jQuery(item).attr('content');
	}
	if ( jQuery(item).attr('name') == that.navUndersideKeyword ) {
	    that.navUnderside = jQuery(item).attr('content');
	}
	if ( jQuery(item).attr('name') == that.navMostForKeyword ) {
	    that.navMostForWord = jQuery(item).attr('content');
	}
	if ( jQuery(item).attr('name') == that.navBreadcrumbKeyword ) {
	    that.navBreadcrumbWord = jQuery(item).attr('content');
	}
	if ( jQuery(item).attr('name') == that.pageTitleKeyword ) {
	    that.pageTitle = jQuery(item).attr('content');
	}
    });


    // methods

    this.itemInSpecialNav = function (Child) {
	return  this.Structure.LookUp[ Child ] < 0;
    }

    this.findGranMotherOfChild = function (Child) {
	if ( Child == '' ) {
	    return '';
	}
	var found = false;
	var mother = '';
	
	if ( this.Structure.LookUp[ Child ] > 0 ) {
	    LOOP:
	    for (var i = this.Structure.Main.navItems.length-1; i>=0; i--) {
		if ( this.Structure.Main.navItems[i][2] == Child ) {
		    found = true;
		    if ( this.Structure.Main.navItems[i][1] == '' ) {
			return Child;
		    }
		    continue LOOP;
		}
		if ( found 
		     //&& this.Structure.Main.navItems[i][0] == 1 
		     && 
		     this.Structure.Main.navItems[i][1] == ''
		   ) {
//		    mother = this.Structure.Main.navItems[i][2];
//		    break LOOP;
		    return this.Structure.Main.navItems[i][2];
		}
	    }
	}
	if (  this.Structure.LookUp[ Child ] < 0 ) {
	    LOOP:
	    for (var i = this.Structure.MostFor.navItems.length-1; i>=0; i--) {
		if ( this.Structure.MostFor.navItems[i][2] == Child ) {
		    found = true; 
		    if ( this.Structure.MostFor.navItems[i][1] == '' ) {
			return Child;
		    }
		    continue LOOP;
		}
		if ( found 
		     //&& this.Structure.MostFor.navItems[i][0] == 1 
		     && this.Structure.MostFor.navItems[i][1] == '' ) {
// 		    mother = this.Structure.MostFor.navItems[i][2];
// 		    break LOOP;
 		    return this.Structure.MostFor.navItems[i][2];
		}
	    }
	}
	return mother;
    }

    this.navGranMother = this.findGranMotherOfChild(this.navGren);

    this.buildMestTilList = function() {
	var C = this.Structure.MostFor.navItems;
	var header = this.navMostForWord;
	if ( C == '' ) { return null; }


	var K = jQuery('#' + this.mostForContainer );
	// first add header (and remove the extraparam from build_sublist below)
	var H2 = document.createElement('h2');
	if ( C.length < 3 ) {
		jQuery(K).addClass(this.mostForArray[0]);
	}
	else if  ( C.length < 5 ) {
		jQuery(K).addClass(this.mostForArray[1]);
	}
	else {
		jQuery(K).addClass(this.mostForArray[2]);
	}
	H2.appendChild(document.createTextNode(header));
	jQuery(K).append(H2);


	// we fill up right to left
	if ( C.length < 3 ) {
	    jQuery(K).append(build_sublist(this.mostForArray[0],C,''));
	}
	else if ( C.length < 5 ) {
	    if ( C.length % 2 == 1 ) {
		jQuery(K).append(build_sublist(this.mostForArray[1],C.slice(Math.floor(C.length/2)+1,C.length),''));
		jQuery(K).append(build_sublist(this.mostForArray[0],C.slice(0,Math.floor(C.length/2)+1),''));
	    }
	    else {
		jQuery(K).append(build_sublist(this.mostForArray[1],C.slice(Math.floor(C.length/2),C.length),''));
		jQuery(K).append(build_sublist(this.mostForArray[0],C.slice(0,Math.floor(C.length/2)),''));
	    }
	}
	else { // >=5
	    var X = C.length % 3;
	    if ( X  == 0 ) {
		jQuery(K).append(build_sublist(this.mostForArray[0],C.slice(C.length/3*2,C.length),''));
		jQuery(K).append(build_sublist(this.mostForArray[1],C.slice(C.length/3,C.length/3*2),''));
		jQuery(K).append(build_sublist(this.mostForArray[2],C.slice(0,C.length/3),''));
	    }
	    else if ( X  == 1 ) {
		jQuery(K).append(build_sublist(this.mostForArray[0],C.slice(Math.floor(C.length/3)*2+1,C.length),''));
		jQuery(K).append(build_sublist(this.mostForArray[1],C.slice(Math.floor(C.length/3)+1,Math.floor(C.length/3)*2+1),''));
		jQuery(K).append(build_sublist(this.mostForArray[2],C.slice(0,Math.floor(C.length/3)+1),''));
	    }
	    else if ( X  == 2 ) {
		jQuery(K).append(build_sublist(this.mostForArray[0],C.slice(Math.floor(C.length/3)*2+2,C.length),''));
		jQuery(K).append(build_sublist(this.mostForArray[1],C.slice(Math.floor(C.length/3)+1,Math.floor(C.length/3)*2+2),''));
		jQuery(K).append(build_sublist(this.mostForArray[2],C.slice(0,Math.floor(C.length/3)+1),''));
	    }
	}
	return;
    }


    this.unfoldToItem = function() {
	// the id is the navGren from init
	var that = this;
	var id = this.navGren

	jQuery('#' + id).parents('ul').show();
	jQuery('#' + id).parents('ul').each( function(i,item) {
	    jQuery(item).parent('li').removeClass(this.branchClass).addClass(that.selectedBranchClass);
	});
	if ( this.navUnderside != '' ) {
	    jQuery('#' + id).addClass(that.selectedItemClass);
	}
	else {
	    jQuery('#' + id).addClass(that.currentItemClass);
	    jQuery('#' + id + ' a').click( function(){return false});
	}
	
	if ( this.Structure.LookUp[id] < 0 ) { // i.e. most for item 
	    // find the top most item in the most for nav that corresponds to id
	    var parent = '';
	    var found = false;
	    LOOP:
	    for (var i = this.Structure.MostFor.navItems.length-1; i>=0; i--) {
		if ( this.Structure.MostFor.navItems[i][2] == id ) {
		    found = true;
		    parent = this.Structure.MostFor.navItems[i][1];
		    if ( ! parent ) {
			parent = id; // already at the top
			break LOOP;
		    }
		}
		if ( found ) {
		    if ( this.Structure.MostFor.navItems[i][2] == parent && this.Structure.MostFor.navItems[i][1] != '' ) {
			parent = this.Structure.MostFor.navItems[i][1];
		    }
		}
	    }
	    if ( parent ) {
		found = jQuery('#' + parent).attr('class');
		if ( found.indexOf(that.currentItemClass) == -1 ) {
		    jQuery('#' + parent).removeClass(this.branchClass).addClass(that.selectedBranchClass);
		}
	    }
	}
    }

    this.generateMainMenu = function() {
	var UL =document.createElement('ul');
	var is_bad = this.itemInSpecialNav(this.navGren);
	var navMother = this.findGranMotherOfChild(this.navGren);
	LOOP:
	for (var i=0; i<this.Structure.Main.navItems.length;i++) {
	    
	    if (  this.Structure.Main.navItems[i][1] == '' 
		//  && this.Structure.Main.navItems[i][0] == 1  // leaves can live on the main trunk
	       ) {
		var LI = document.createElement('li');
		var AA = document.createElement('a');
		AA.href= this.Structure.Main.navItems[i][3];
		AA.appendChild(document.createTextNode(this.Structure.Main.navItems[i][4]));
		AA.title = this.Structure.Main.navItems[i][4];
		if ( navMother && this.Structure.Main.navItems[i][2] == navMother && ! is_bad) {
		    jQuery(LI).addClass(this.selectedItemClass);
		    // if this is comming from a special menu, we also add another class when it is selected.
		    if ( this.Structure.Main.navItems[i][2].indexOf(prefix) != -1  ) {
			jQuery(LI).addClass(this.selectedSpecialMainItemClass);
		    }
		}
		LI.appendChild(AA);
		UL.appendChild(LI);
	    }

	}
	jQuery('#' + this.mainNavContainer).append(UL);
	jQuery('#' + this.mainNavContainer).append('<br />');
    }

    this.generateLeftMenu = function() {
	var collecting = false;
	var headingMother = '';
	var menu = new Array();
	var A;

	// first figure out which nav we need to look at.
	if ( this.itemInSpecialNav(this.navGren) ) {
	    A = this.Structure.MostFor.navItems;
	}
	else {
	    A = this.Structure.Main.navItems;
	}

	// we now have two possibilities
	// (1) this.navGren has no parent and we may need to change the body class
	// (2) this.navGren has a parent, so we handle it as normal and the left 
	//     menu should reflect the content of the GranMother of this item

//	alert('granny: ' + this.navGranMother + "\n" + 'gren: ' + this.navGren);


	if ( this.navGranMother == this.navGren  || ! this.Structure.LookUp[ this.navGren ] ) {
	    var bodyClass = jQuery('body').attr('class');
	    if ( bodyClass.indexOf(this.altBodyClassArray[0]) > -1 ) {
		jQuery('body').removeClass(this.altBodyClassArray[0]).addClass(this.altBodyClassArray[2]);
		return;
	    } 
	    if ( bodyClass.indexOf(this.altBodyClassArray[1]) > -1 ) {
		jQuery('body').removeClass(this.altBodyClassArray[1]).addClass(this.altBodyClassArray[3]);
		return;
	    }
	}

	// we are in case (2)
	// create an array of all the items belonging to navGranMother
	LOOP:
	for (var i=0;i<A.length;i++) {
	    if ( !collecting && A[i][0] == 1 && A[i][1] == '' && A[i][2] == this.navGranMother ) {
		collecting = true;
		headingMother = A[i][4];
		continue LOOP;
	    }
	    // we stop at the next main item
	    if ( collecting 
		 //&& A[i][0] == 1 // removed because a main item can also be 0
		 && A[i][1] == '' ) {
		break LOOP;
		// the end
	    }
	    if ( collecting ) {	menu.push(A[i]); }
	} 
	
	if ( menu.length == 0 ) { return; }


	var UL = document.createElement('ul');
	UL.id = this.leftNavInnerContainer;

	var mystack = new Array;
	mystack.push([this.navGranMother,'',UL]);
	// the idea is to use a stack to create the list structure, when
	// an item is popped of the list it is added to the item below it
	for (var i=0;i<menu.length;i++) {
	    // we always needs to create a li for each item
	    var LI = document.createElement('li');
//	    LI.appendChild(make_linkX(menu[i][3],menu[i][4]));
	    LI.appendChild(make_link(menu[i][3],menu[i][4]));

	    LI.id = menu[i][2];
	    if ( menu[i][0] == 1 ) { // i.e. a branch
		LI.className = this.branchClass;
	    }



	    // next we have three situations:
	    // (1) new list underneath the current item
	    // (2) new list under a lower stack item
	    // (3) a regular item

	    // (1) menu[i][0] == 1 && mystack[mystack.length-1][0] ==
	    // menu[i][1], i.e. the mother label is the same as the label
	    // at the top of the stack

	    // (2) menu[i][0] == 1 && menu[i][1] matches an item lower in the stack

	    // (3) menu[i][0] == 0, just add it to the item at the top of the stack



	    if ( menu[i][0] == 1 && mystack[mystack.length-1][0] == menu[i][1] ) {
		// this is the start of a new list, under the current list item
		// first the just created LI has to be added 
		mystack[mystack.length-1][2].appendChild(LI);
		// next add the new list to the stack
		mystack.push([menu[i][2],LI,document.createElement('ul')]);
	    }
	    else {
		// here are two situations
		// (1) menu[i][0] == 1 but we are not in the current item
		
		if ( menu[i][0] == 1 && mystack[mystack.length-1][0] != menu[i][1] ) {
		    // new list under another item, we need to pop of the stack until we find it
		    // but along the way the items on the stack has to be finished of
		    //		jQuery(LI).attr('haschildren','1');

		    while ( mystack[mystack.length-1][1] != '' && mystack[mystack.length-1][0] != menu[i][1] ) {
			var L = mystack.pop();
			L[1].appendChild(L[2]);
// 			jQuery(L[1]).find('a:first').click(function() {
// 			    jQuery(this).parent().find('ul:first').toggle();
// 			    return false;
// 			});
			mystack[mystack.length-1][2].appendChild(L[1]);
		    }
		    
		    // the just created LI has to be added 
		    mystack[mystack.length-1][2].appendChild(LI);
		    // next add the new list to the stack
		    mystack.push([menu[i][2],LI,document.createElement('ul')]);
		}
		
		// (2) menu[i][0] == 0
		else {
		    // it is an error if we end up back at [navMother,'',UL]
		    while ( mystack[mystack.length-1][1] != '' && mystack[mystack.length-1][0] != menu[i][1] ) {
			var L = mystack.pop();
			L[1].appendChild(L[2]);
// 			jQuery(L[1]).find('a:first').click(function() {
// 			    jQuery(this).parent().find('ul:first').toggle();
// 			    return false;
// 			});
			mystack[mystack.length-1][2].appendChild(L[1]);
		    }
		    mystack[mystack.length-1][2].appendChild(LI);
		}
	    }
	}

	// flatten the stack
	if ( mystack[mystack.length-1][1] != '' ) {
	    while ( mystack[mystack.length-1][1] != '' ) {
		var L = mystack.pop();
		L[1].appendChild(L[2]);
// 		jQuery(L[1]).find('a:first').click(function() {
// 		    jQuery(this).parent().find('ul:first').toggle();
// 		    return false;
// 		});
		mystack[mystack.length-1][2].appendChild(L[1]);
	    }
	}

	jQuery('#' + this.leftNavContainer).find('.' + this.leftNavPaddingClass).empty().append('<h3>' + headingMother + '</h3>');
	jQuery('#' + this.leftNavContainer).find('.' + this.leftNavPaddingClass).append(UL);
    }


    this.makeFoldable = function() {
	var start = this.leftNavInnerContainer;
	jQuery('#' + start + '  li ').each( 
	    function(i,item) {
		if ( jQuery(item).find('ul:first').length > 0 ) {
		    // item is a li tag that is a branch
//		    jQuery(item).find('a:first').attr('href','http://clickto expand');
		    jQuery(item).find('a:first').click( 
			function(e) {
			    jQuery(this).parent().siblings().find('ul').hide();
			    jQuery(this).parent().find('ul:first').toggle();
			    if ( jQuery('#' + start + ' > li').find('ul:visible').length == 0 ) {
				that.unfoldToItem(); // that because this is special
			    }
			    e.preventDefault();
 			    return false;
 			});
		}
	    });
    }


    this.breadcrumb = function() {
	var found = false;
	var crumb = new Array();
	var A;
	
	if ( this.itemInSpecialNav(this.navGren) ) {
	    A = this.Structure.MostFor.navItems;
	}
	else {
	    A = this.Structure.Main.navItems;
	}
	
	LOOP:
	for (var i = A.length-1;i>=0;i--) {
	    if ( ! found && A[i][2] == this.navGren ) {
		crumb.push( A[i] );
		found = true;
		continue LOOP;
	    }
	    if ( found && A[i][0] == 1 && A[i][2] == crumb[crumb.length-1][1] ) {
		crumb.push( A[i] );
		if ( A[i][1] == '' ) { break LOOP; }
	    }
	}
	
	var S = ''; 
	var T = ''; 
	if ( crumb.length > 1 ) {
	    S += '  ' + '<a href="' + crumb[crumb.length-1][3] + '">'+   crumb[crumb.length-1][4] +'</a>';
	    for (var i = crumb.length-2;i>=1; i--) {
		S += this.navBreadcrumbSeparator + '<a href="' + crumb[i][3] + '">'+   crumb[i][4] +'</a>';
	    }
	    if ( this.navUnderside && this.pageTitle) {
		S += this.navBreadcrumbSeparator + '<a href="' + crumb[0][3] + '">'+   crumb[0][4] +'</a>';
//		S +=  this.navBreadcrumbSeparator + this.pageTitle ;
		S += ' ';
		T = this.navBreadcrumbSeparator + this.pageTitle ;
	    }
	    else {
		S +=  this.navBreadcrumbSeparator + crumb[0][4] ;
	    }
	}
	else if ( crumb.length == 1 ) {
	    if ( this.navUnderside && this.pageTitle) {
		S += ' <a href="' + crumb[0][3] + '">'+   crumb[0][4] +'</a>';
//		S +=  this.navBreadcrumbSeparator + this.pageTitle ;
		S += ' ';
		T =  this.navBreadcrumbSeparator + this.pageTitle ;
	    }
	    else {
		S +=  ' ' + crumb[0][4] ;
	    }
	}
	else { // no left nav
	    if ( this.pageTitle) {
//		S +=  ' ' + this.pageTitle ;
		S += ' ';
		T = this.pageTitle ;
	    }
	}
	
	if ( S ) {
//	    jQuery('#' + this.breadcrumbContainer).empty().append(this.navBreadcrumbWord).append(S);
	    jQuery('#' + this.breadcrumbContainer).prepend(S).prepend(this.navBreadcrumbWord).append(T);
	}
	else {
	    jQuery('#' + this.breadcrumbContainer).remove();
	}
    }

    this.run = function() {
//	this.buildMestTilList();
//	this.generateMainMenu();
//	this.breadcrumb();
//	this.generateLeftMenu();
	this.makeFoldable();
	this.unfoldToItem();
    }


} // end object definition



function myinit() {
    // we do not like to hard code names into the functions, thus we give them via the constructor
    var X = new auMenuStructure(navItems, {
	mostForContainer : 'au_nav_shortcuts',
	mostForArray : new Array('au_nav_shortcuts_1','au_nav_shortcuts_2','au_nav_shortcuts_3'),
	navGrenKeyword : 'au-navgren',
	navUndersideKeyword : 'au-navunderside',
	navMostForKeyword: 'au-navtil',
	navBreadcrumbKeyword: 'au-navkrumme',
	currentItemClass : 'au_current',
	selectedItemClass : 'au_selected',
	branchClass : 'au_branch',
	selectedBranchClass : 'au_selected_branch',
	mainNavContainer : 'au_header_nav',
	leftNavContainer : 'au_section_nav',
	leftNavPaddingClass : 'au_padding',
	leftNavInnerContainer : 'au_section_nav_inner_list',
	altBodyClassArray : new Array('au_layout_1','au_layout_2','au_layout_3','au_layout_4'),
	breadcrumbContainer : 'au_breadcrumb',
	pageTitleKeyword : 'DC.Title',
	navBreadcrumbSeparator : ' &#187; ',
	selectedSpecialMainItemClass : 'au_extra'
    });
    X.run();
}




jQuery(document).ready(function() {
    myinit();
});


