//-----------------------------------------------------------------------------
//	Project:	NOSE WEB NAVIGATOR
//	Authors:	Stefan Tan, Walter Stulzer, Alexandra Papadopoulos
//	(c):		1998-1999, Nose GmbH Interactive Media
//	(c):		1999-2000, Perspectix-Nose AG, Digital Business Intelligence
//	(c):		2001, Nose Applied Intelligence
//	History:
//	[04/99]		Rel. 1.0.0 [WS/AP]
//	[04/99]		Rel. 1.0.1 'Debugging Programmlogik, NEW: Powerfunctions' [WS]
//	[04/99]		Rel. 1.0.2 'Kompatibilitaet HTML 3.0' [WS]
//	[04/99]		Rel. 1.0.3 'Reaktion des Menues auf Links im Hauptfenster' [WS]
//	[01/00]		Rel. 1.0.4 'generische Ordnungsnummer, oparent' [WS]
//	[01/00]		Rel. 1.1.0 'generischer expanded-Wert' [WS/MH/NS]
//	[02/00]		Rel. 1.1.1 'Neuer Menueintrag' [WS]
//	[07/00]		Rel. 1.1.2 'Korrektur für Mac-Explorer 5.0' [ST]
//	[08/00]		Rel. 2.0.0 'CSS-capability' [ST]
//	[03/01]		Rel. 2.0.1 'Rewriting refresh(), debugging' [ST/SA]
//	[12/01]		Rel. 2.1.0 'Codewashing' [ST/FS]
//  [06/02]     Rel. 2.2.0 'Redirect von ausserhalb'-Bug behoben [FS/ST]
//-----------------------------------------------------------------------------
//  Navigator Logic
//-----------------------------------------------------------------------------

var aMain = new Array();					// main working array containing the total information
var bMain = new Array();					// temporary copy of aMain
var actLevel = new Array(10);				// number of maximum levels allowed (e.g. 10)
var actLength = 0;							// internal count of menu entries
var waitSec = 0;							// timeout var for refresh function
var actMother = 0;							// var for counting number of top levels (level 0 and -1)
var actParent = 0;							// var for saving order number of direct mother level
var defaultFolder = "pages/";				// default folder of the content pages	
var navigatorHTMFile = "navigation.htm";	// name of file where the navigator menu is beeing written
var basisURL = top.window.location.href;	// get initial path (url)
var actLink = "nose@2775731.htm";			// don't change this var! init only
var redirect = false;						// don't change this var! init only
var redirectsite = "";						// don't change this var! init only
var intURL = 0;								// don't change this var! init only
                                    
function init()
{
	if (basisURL.lastIndexOf("?") >= 0)
	{    
		redirect = true;
		redirectvar = location.href;
		redirectpoint = redirectvar.indexOf("?")+1;
		redirectlength = redirectvar.length;
		redirectsite = redirectvar.substring(redirectpoint,redirectlength);
		//actLink = redirectsite; das war ein fehler
	}
	
	if (basisURL.lastIndexOf("?") >= 0) 
	{
		basisURL = basisURL.substring(0, basisURL.lastIndexOf("?"));
	}
	var i = basisURL.lastIndexOf("\\")+2;
	if (i < basisURL.lastIndexOf("/")+1)
	{
		i = basisURL.lastIndexOf("/")+1;
	}
	basisURL = basisURL.substr(0,i);
	intURL = basisURL.length;
}

function makeLevel(level,descr,menulink,tooltip)
{  
	bMain[actLength] = new makeVals(actLength,level,descr,menulink,tooltip);
	actLength++;
}

function makeVals(order,level,descr,menulink,tooltip)
{
	if (level < 0)
	{
		actLevel[0] = order;
	} else
	{
		actLevel[level] = order;
	}
	this.order = order;
	this.level = level;
	this.descr = descr;
	this.tooltip = tooltip;
	this.activ = false;
	
	if(menulink == "none")
	{
		this.menulink = menulink;
	} else
    {
		this.menulink = makeLink(descr, menulink, level, order);
	}
	
	if (order > 0)
	{
	    if (bMain[order-1].level < level)
		{
			if (bMain[order-1].level <= 0)
			{
				bMain[order-1].expand = 0;
			} else
			{
				bMain[order-1].expand = 3;
			}
		} else
		{
			if (bMain[order-1].level <= 0)
			{
				bMain[order-1].expand = 2;
			} else
			{
				bMain[order-1].expand = 4;
			}
		}
	}
	
	if (level <= 0)
	{
		this.expand = 2;
		this.oparent = null;
	} else
	{
		this.expand = 4;
		this.oparent = actLevel[level-1];
	}
	this.mother = actLevel[0];
	return this;
}

function makeLink(descr, menulink, level, order)
{  		
	var myLink = "";
	if ((menulink).lastIndexOf(actLink) >= 0)
	{
		myLink = "";
	} else
	{
		if (level < 0)		
		{ 
		  myLink = menulink + " target=_top";
		} else
		{
		  myLink = "\"javascript:top.goLink(\'" + menulink + "\'," + level + "," + order + ");\"";
		}
	}  
	return myLink;
}

function goLink(myLink, myLevel, myOrder)
{
	window.clearTimeout(waitSec);
	actLink = myLink;
	actMother = aMain[myOrder].mother;
	actParent = aMain[myOrder].oparent;
	top.botr.window.location = myLink;
	expandLevel(myLevel, myOrder);
}

function expandLevel(level, order)
{
	window.clearTimeout(waitSec);
	actLength = 0;
	makeTree();
	expandDown(level, order);
}

function expandDown(level, order)
{	
	window.clearTimeout(waitSec);
	var oparent = 0;
	for (i = 0 ; i < bMain.length ; i++)
	{   
		if (bMain[i].level == level)
		{
			if (bMain[i].order == order)
			{
				if (bMain[i].expand == 0) bMain[i].expand = 1;
				if (bMain[i].expand == 2) bMain[i].expand = 2;
				if (bMain[i].expand == 3) bMain[i].expand = 1;
				if (bMain[i].expand == 4) bMain[i].expand = 2;
				oparent = bMain[i].oparent;
			}
		} else
		{
			if (bMain[i].oparent == order)
			{
				if (bMain[i].expand == 3) bMain[i].expand = 0;
				if (bMain[i].expand == 4) bMain[i].expand = 2;
			}
		}
	}
	
	if (level == 0) 
	{
		aMain = bMain;
		markPath(actParent);
		top.botl.window.location = navigatorHTMFile;
		waitSec = window.setTimeout("refreshTree()", 1000);
	} else
	{   
		expandDown(level - 1, oparent);
	}
}

function contractLevel(level, order)
{
	window.clearTimeout(waitSec);
	for (i = 0 ; i < bMain.length ; i++)
	{
		var testVal = bMain[i].level - level
		if (i == order)
        { 
        	bMain[i].expand = 0;
        }
        
		if ((i > order) && (((bMain[i].oparent == order) && (testVal == 1)) || ((testVal > 1) && (testVal < 5))))
		{
			if (bMain[i].expand == 0) bMain[i].expand = 3;    
 			if (bMain[i].expand == 1) bMain[i].expand = 3;
			if (bMain[i].expand == 2) bMain[i].expand = 3;
		} 
	}
	aMain = bMain;
	markPath(actParent);
	top.botl.window.location = navigatorHTMFile;
	waitSec = window.setTimeout("refreshTree()", 1000);
}

function markPath(nextParent)
{ 
	while (nextParent >= actMother && nextParent != null)
	{
		if (aMain[nextParent].expand == 0)
		{
			aMain[nextParent].activ =  true;
		}
		nextParent = aMain[nextParent].oparent;
	}
}


function refreshTree()
{
	window.clearTimeout(waitSec);
	var newPathname = top.botr.window.location.href;
	newLink = newPathname.substring(intURL, newPathname.length);
	if (actLink != newLink)
	{
		for ( i = 0 ; i < aMain.length; i++ )
		{
			if (aMain[i].menulink.lastIndexOf(newLink) >= 0)
			{
				actLink = newLink;
				actMother = aMain[i].mother;
				actParent = aMain[i].oparent;
				expandLevel(aMain[i].level, aMain[i].order);
				break;
			}
		}
	}
	waitSec = window.setTimeout("refreshTree()", 2000);

    if (redirect)
	{
		top.botr.window.location.href = redirectsite;
		redirect = false;
	}
}

//-----------------------------------------------------------------------------
// initialization													   
//-----------------------------------------------------------------------------
init();
makeTree();
aMain = bMain;
if (redirect)
{
	waitSec = window.setTimeout("refreshTree()", 1000);
} else
{
	waitSec = window.setTimeout("refreshTree()", 400);
}