topMenu = function (theme) {
	//массив открытыэ эл-тов по уровню
	this.submenu_shown = new Array ();
	//document.onmouseover = this.test;

	this.hide_timeout = null;

	//предзагрузка картинок меню
	this.pointer_selected = new Image ();
	this.pointer_selected.src = 'images/menu/pointer_' + theme + '_selected.gif';
	this.pointer = new Image ();
	this.pointer.src = 'images/menu/pointer.gif';

	this.preloaded_images = new Object;
}

topMenu.prototype.hoverRoot = function (alias, state) {
	if (state == true) {
		document.images['top_menu_pointer_' + alias].src = this.pointer_selected.src;
		this.showSubMenu (alias);
	} else if (state == false) {
		document.images['top_menu_pointer_' + alias].src = this.pointer.src;
	}
}


topMenu.prototype.hoverSub = function (alias, level) {
	//if (this.hide_timeout != null)
	//	clearTimeout (this.hide_timeout);

	this.hideSubMenusUpToLevel (level);

	if (this.showSubMenu (alias))
		this.submenu_shown[level] = alias;
}

topMenu.prototype.hoverSubTdOn = function (node, level) {
	var alias = node.firstChild.firstChild.id;
	if (level < 2)
		this.hoverSub (alias, level);

	node.style.backgroundColor = '#9B9FA1';
	node.firstChild.firstChild.src = this.preloaded_images[alias].src;

	window.status = node.firstChild.firstChild.alt;
}

topMenu.prototype.hoverSubTdOff = function (node) {
	node.style.backgroundColor = '';
	node.firstChild.firstChild.src = 'images/menu/sub/' + node.firstChild.firstChild.id + '.gif';

	window.status = '';
}

topMenu.prototype.hideSubMenusUpToLevel = function (level) {
	/* скрываем все до текущего уровня ключительно */
	if (this.submenu_shown.length > level) {
		for (var i = level; i < this.submenu_shown.length; i++) {
			this.hideSubMenu (i);
		}
		this.submenu_shown.splice (level, this.submenu_shown.length - level);
	}
}

topMenu.prototype.showSubMenu = function (alias) {
	var a = document.getElementById ('top_menu_sub_' + alias);
	if (a) {
		a.style.display = '';
		return true;
	} else {
		return false;
	}
}

topMenu.prototype.test = function () {
	var on_menu = false
	var tmp = event.srcElement;
	while (tmp.tagName != 'BODY') {
		if (tmp.id.indexOf ('top_menu') != -1)
			on_menu = true;
		tmp = tmp.parentNode;
	}

	if (on_menu == false && top_menu.submenu_shown.length > 0) {
		//если мы не в меню - скрываем все нафиг...
		top_menu.hide_timeout = setTimeout ('top_menu.hideSubMenusUpToLevel (0);', 500)
	} else {
		clearTimeout (top_menu.hide_timeout);
		top_menu.hide_timeout = null;
	}
}

topMenu.prototype.hideSubMenu = function (i) {
	if (document.getElementById ('top_menu_sub_' + this.submenu_shown[i]))
		document.getElementById ('top_menu_sub_' + this.submenu_shown[i]).style.display = 'none';
}

topMenu.prototype.preloadSubMenuImages = function (aliases) {
	for (var i in aliases)
	{
		this.preloaded_images[aliases[i]] = new Image;
		this.preloaded_images[aliases[i]].src = 'images/menu/sub/' + aliases[i] + '_s.gif';
	}
}