if (document.getElementById && document.getElementsByTagName)
{
	document.write('<style type="text/css">li ul { display: none; }</style>');
}

window.onload = function()
{
	Navi.init();
};

var Navi = new Object();
Navi.contentURL = null;
Navi.levels = null;
Navi.items = [];
Navi.openItem = null;
Navi.activeItem = null;
Navi.probableItem = null;
Navi.highestProbability = 0;

Navi.init = function()
{
	if (document.getElementById && document.getElementsByTagName)
	{
		var key = 'contenturl=';
		var searches = parent.location.search.toLowerCase().split('&');
		var i = searches.length;

		while (i--)
		{
			if (searches[i].indexOf(key) != -1)
			{
				this.url = searches[i].split('=')[1];
				contentURL = this.url.replace(/http:\/\/(([-\w])+\.){1,3}(\w){2,4}/, '');
				contentURL = contentURL.replace(/^\//, '');
				contentURL = contentURL.replace(/\/$/, '');
				contentURL = contentURL.replace(/\.([a-z]){3,4}$/, '');
				this.contentURL = contentURL;

				this.levels = this.contentURL.split('/');

				break;
			}
		}

		var list = document.getElementsByTagName('ul')[0];
		var listItems = list.getElementsByTagName('li');
		var i = listItems.length;

		while (i--)
		{
			var listItem = listItems[i];
			if (listItem.parentNode == list)
			{
				this.items[listItem.id] = new NaviItem(this, listItem);
			}
		}

		this.hilite();
	}
};
Navi.hilite = function()
{
	if (this.probableItem && this.probableItem.container)
	{
		this.probableItem.container.text.onclick();
		this.probableItem._link.onclick();
	}
}
Navi.update = function()
{
	this.reset();

	for (var id in this.items)
	{
		var items = this.items[id].items;
		var i = items.length;

		while(i--)
		{
			var item = items[i];
			this.checkProbability(item, item._link.href);
		}
	}

	this.hilite();
};
Navi.reset = function()
{
	if (this.openItem)
	{
		this.openItem.className = '';
		this.openItem.text.onmouseout();
		this.openItem = null;
	}

	if (this.activeItem)
	{
		this.activeItem.className = '';
		this.activeItem = null;
	}
};
Navi.checkProbability = function(item, href)
{
	if (href.replace(/http:\/\/(([-\w])+\.){1,3}(\w){2,4}/, '') == this.url)
	{
		this.probableItem = item;
	}
	else if (this.levels)
	{
		var url = href.replace(/([a-z]){3,4}:(\/){2,3}/, '');
		url = url.replace(/\.([a-z]){3,4}$/, '');

		var levels = url.split('/');
		var probability = 0;

		for (var i = 0, ii = this.levels.length; i < ii; i++)
		{
			if (levels[i] != this.levels[i])
			{
				for (var k = i, kk = ii - 1; k < kk; k++)
				{
					levels[k] = levels[k + 1];
				}

				levels.length = levels.length - 1;
			}
			else
			{
				probability++;
			}
		}

		if (probability > this.highestProbability)
		{
			this.highestProbability++;
			this.probableItem = this;
		}
	}
};

var NaviItem = function(navi, container)
{
	this.navi = navi;
	this.container = container;
	this.items = [];

	this.text = this.container.getElementsByTagName('h2')[0];
	this.text.navi = this.navi;
	this.text.container = this.container;
	this.container.text = this.text;
	this.text.item = this;
	this.container.item = this;

	this.text.style.cursor = 'hand';
	if (!this.text.style.cursor)
	{
		this.text.style.cursor = 'pointer';
	}

	this.text.onclick = this._switch;
	this.text.onmouseover = this._hilite;
	this.text.onmouseout = this._clear;

	this._links = this.container.getElementsByTagName('a');
	var i = this._links.length;

	while (i--)
	{
		var a = this._links[i];

		if (a.parentNode != this.text)
		{
			this.items[i] = new SubNaviItem(this.navi, this.container, a);
		}
	}
};
NaviItem.prototype._switch = function()
{
	this.navi.reset();

	this.navi.openItem = this.container;
	this.navi.openItem.className = 'open';

	if ('produkte' == this.container.id)
	{
		try
		{
			var contentURL = parent.content.location.href;

			if ('default_content.asp' == contentURL.substring(contentURL.lastIndexOf('/') + 1, contentURL.length))
			{
				var a = this.item.items[0]._link;
				a.onclick();
				parent.content.location.href = a.href;
			}
		}
		catch (e) { }
	}
};
NaviItem.prototype._hilite = function()
{
	this.className = 'hilite';
};
NaviItem.prototype._clear = function()
{
	this.className = '';
};

var SubNaviItem = function(navi, container, link)
{
	this.navi = navi;
	this.container = container;
	this._link = link;
	this._link.navi = this.navi;

	this._link.clickHandler = this._activate;

	if (this._link.onclick)
	{
		this._link.oldHandler = this._link.onclick;

		this._link.onclick = function()
		{
			this.oldHandler();
			this.clickHandler();

			return false;
		}
	}
	else
	{
		this._link.onclick = this._link.clickHandler;
	}

	this.navi.checkProbability(this, this._link.href);
};
SubNaviItem.prototype._activate = function()
{
	if (this.navi.activeItem)
	{
		this.navi.activeItem.className = '';
		this.navi.activeItem = null;
	}

	this.navi.activeItem = this;
	this.navi.activeItem.className = 'hilite';
};

var popWin;

function popWinGrillen(url, width, height)
{
	if (popWin)
	{
		popWin.close();
	}

	popWin = window.open(url, 'popWin', 'top=100, left=400, menubar=0, location=0, toolbar=0, scrollbars=0, status=0, resizable=0, width=' + width + ', height=' + height);

	if (popWin)
	{
		popWin.focus();
	}
}
