
/*  ---------------------------------------------------------------------------
 *  MENU
 *  ---------------------------------------------------------------------------
 *  These scripts handle the data background for the menu
 *  It's not much more than a linked list manager
 *  ---------------------------------------------------------------------------
 */

// the constructor for the main menu (virtual node)
function menu(name)
{
	this.name = name;
	this.toplevels = new Array();
	this.collection = new Array();
	this.namedcollection = new Array();
}

// get a menuitem by its id
menu.prototype.getById = function(id)
{
	return this.collection[id];
}

// get a menuitem by its name
menu.prototype.getByName = function(name)
{
	return this.namedcollection[name];
}

// add a toplevel item
menu.prototype.addToplevel = function(toplevel)
{
	this.toplevels[this.toplevels.length] = toplevel;
	toplevel.level = 0;
	this.append(toplevel);
}

// append a menuitem to the collection of a menu
menu.prototype.append = function(item)
{
	this.collection[item.id] = item;
	this.namedcollection[item.name] = item;
	item.menu = this;
}

// constructor for the menuitems
function menuItem(id,name,url)
{
	this.id = id;
	this.link = url;
	this.name = name;
	this.level = 0;
	this.children = new Array();
	this.parent = null;
}

// link two items together
menuItem.prototype.addChild = function(child)
{
	this.children[this.children.length] = child;
	child.level = this.level+1;
	this.menu.append(child);
	child.parent = this;
}

// get all items with the same parent item, exclusive the
// item itself
menuItem.prototype.getBrothers = function()
{
	var coll = new Array();
	var items = new Array();
	if (this.parent)
	{
		coll = this.parent.children;
	}
	else
	// top-level item
	{
		coll = this.menu.toplevels;
	}
	for (i=0;i<coll.length;i++)
	{
		if (coll[i].id != this.id)
		{
			items[items.length] = coll[i];
		}
	}
	return items;
}

// get all elements to the top (inclusive the item itself) in reverse order
// (mainmenu first)
menuItem.prototype.getPath = function()
{
	var curitem = this;
	var path = new Array();
	while (curitem)
	{
		path[path.length] = curitem;
		curitem = curitem.parent;
	}
	path.reverse();
	return path;
}

//mouseover in imagechanger js
function roll_over(imgNr, state, imgName, imgType)
{
	if(typeof imgType == 'undefined')
		imgType = "jpg";
	if(imgNr)
		eval("document.getElementById('wechsel_" + imgNr + "').src = 'images/startseite/" + imgName + "_" + state + "_" + imgNr + "." + imgType + "'");
	else
		eval("document.getElementById('wechsel_" + imgNr + "').src = 'images/startseite/" + imgName + "_" + state +"." + imgType + "'");
}

function roll_over_name(imgNr, state, imgName, imgType)
{
	if(typeof imgType == 'undefined')
		imgType = "jpg";

	eval("document.getElementById('wechsel_" + imgNr + "').src = '../images/" + imgName + "_" + state +"." + imgType + "'");
}