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.itemByURL = false;
Navi.itemByExceptions = null;
Navi.exceptions = (exceptions) ? exceptions : false;
Navi.possibleItems = [];
Navi.rating = 0;
Navi.highestRating = 0;

Navi.init = function()
{
	if (document.getElementById && document.getElementsByTagName)
	{
		this.setURLs();

		var list = document.getElementsByTagName('ul')[0];
		var listItem = list.getElementsByTagName('li')[0];
		var i = 0;

		do
		{
			if (listItem.tagName && listItem.tagName.toLowerCase() == 'li')
			{
				this.items[i++] = new NaviItem(this, listItem);
			}
		}
		while (listItem = listItem.nextSibling);

		this.hilite();
	}
};
Navi.setURLs = function()
{
	var key = 'contenturl=';
	var searches = parent.location.search.toLowerCase().split('&');

	for (i = 0, ii = searches.length; i < ii; i++)
	{
		if (searches[i].indexOf(key) != -1)
		{
			this.contentURL = searches[i].split('=')[1];
			this.contentURL = this.contentURL.split('?')[0];

			this.cleanURL = this.contentURL.replace(/http:\/\/(([-\w])+\.){1,3}(\w){2,4}/, '');
			this.cleanURL = this.cleanURL.replace(/^\/isapi\/|^\//, '');
			this.cleanURL = this.cleanURL.replace(/\/$/, '');
			this.cleanURL = this.cleanURL.replace(/\.([a-z]){3,4}$/, '');

			this.levels = this.cleanURL.split('/');

			this.rating = Math.pow(2, this.levels.length - 1);

			break;
		}
	}
};
Navi.hilite = function()
{
	var item = this.itemByURL;

	if (!item)
	{
		if (this.possibleItems.length)
		{
			item = this.possibleItems[0];
		}
		else if (this.itemByExceptions)
		{
			item = this.items[this.itemByExceptions[0] - 1].items[this.itemByExceptions[1] - 1];
		}
	}

	if (item)
	{
		if (item.container && item.container.txt)
		{
			item.container.txt.onclick();
		}

		if (item._link)
		{
			item._link.onclick();
		}
	}
};
Navi.update = function()
{
	this.reset();

	for (var id in this.items)
	{
		var items = this.items[id].items;

		for (var i = 0, ii = items.length; i < ii; i++)
		{
			var item = items[i];
			item.checkURLs();
		}
	}

	this.hilite();
};
Navi.reset = function()
{
	if (this.openItem)
	{
		this.openItem.className = '';
		this.openItem.txt.onmouseout();
		this.openItem = null;
	}

	if (this.activeItem)
	{
		this.activeItem.className = '';
		this.activeItem = null;
	}
};

var NaviItem = function(navi, container)
{
	this.navi = navi;
	this.container = container;
	this.items = [];

	this.txt = this.container.getElementsByTagName('h2')[0];
	this.txt.navi = this.navi;
	this.txt.container = this.container;
	this.container.txt = this.txt;
	this.txt.item = this;
	this.container.item = this;

	this.txt.style.cursor = 'hand';
	if (!this.txt.style.cursor)
	{
		this.txt.style.cursor = 'pointer';
	}

	this.txt.onclick = this._switch;
	this.txt.onmouseover = this._hilite;
	this.txt.onmouseout = this._clear;

	this._links = this.container.getElementsByTagName('a');

	for (var i = 0, ii = this._links.length; i < ii; i++)
	{
		var a = this._links[i];

		if (a.parentNode != this.txt)
		{
			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.rating = 0;
	this.setURLs();

	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;
	}
};
SubNaviItem.prototype.setURLs = function()
{
	this.realURL = this._link.href.replace(/http:\/\/(([-\w])+\.){1,3}(\w){2,4}/, '');

	this.cleanURL = this.realURL.replace(/^\/isapi\/|^\//, '');
	this.cleanURL = this.cleanURL.replace(/\.([a-z]){3,4}$/, '');

	this.levels = this.cleanURL.split('/');

	this.checkURLs();
};
SubNaviItem.prototype.checkURLs = function()
{
	if (this.navi.itemByURL || this.navi.itemByExceptions)
	{
		return;
	}

	var exceptions = this.navi.exceptions;
	var contentURL = this.navi.contentURL;

	if (this.cleanURL == this.navi.cleanURL)
	{
		this.navi.itemByURL = this;
	}
	else if (exceptions && exceptions[contentURL])
	{
		this.navi.itemByExceptions = exceptions[contentURL];
	}
	else if (this.levels && this.navi.levels)
	{
		this._rate();
	}
};
SubNaviItem.prototype._rate = function(step)
{
	var step = (step) ? step : 0;

	if (this.levels[step] && this.navi.levels[step] && this.levels[step] == this.navi.levels[step])
	{
		this.rating += this.navi.rating - step * this.navi.rating / 2;

		if (this.navi.highestRating < this.rating)
		{
			this.navi.highestRating = this.rating;
			this.navi.possibleItems = [];
			this.navi.possibleItems[this.navi.possibleItems.length] = this;
		}
		else if (this.navi.highestRating == this.rating)
		{
			this.navi.possibleItems[this.navi.possibleItems.length] = this;
		}

		this._rate(++step);
	}
};
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 openPopWin(url, left, top, width, height)
{
	popWin = window.open(url, 'popWin', 'menubar=0, location=0, toolbar=0, scrollbars=0, status=0, resizable=0, left=' + left + ', top=' + top + ', width=' + width + ', height=' + height);

	if (popWin)
	{
		popWin.focus();
	}
}
