var FirstLineFrame=top.frames['KISTERS_TOP'];
var SecLineFrame=top.frames['KISTERS_MAIN'];
var FstLoc,SecLoc;
var menuHeadLeft=200;
var menuMaxRight=0;
var sliderWidth=20;
var root=null;
var overMenu=false;
var closeTimer=null;
var reposTimer=null;
var yTopPosition=0;
var HorCorrect=0;
var subOverlap=10;
var subOffsetWidth=20;
var subOffsetTop=5;
//MenuTopLoaded=true;
isMenuCreated=false;
function Go()
{
	if(MenuTopLoaded&&NoOffFirstLineMenus)
	{
		isMenuCreated=false;
		SecLoc=SecLineFrame?SecLineFrame:window;
		if(!root)
		{
			FstLoc=FirstLineFrame;
			var Element=FstLoc.document.getElementById("menuTop");
			root=createMenuStructure("Menu", NoOffFirstLineMenus, 1, Element);
		}
		else
		{
			recreateSecondMenuStructur();
			closeTree(root);
		}
		SecLoc.onunload=unLoaded;
		menuMaxRight=800+HorCorrect-sliderWidth;
		isMenuCreated=true;
	}
	else
	{
		//alert("go");
		setTimeout("Go()", 100);
	}
}
function unLoaded()
{
	if(closeTimer) clearTimeout(closeTimer);
	if(reposTimer) clearTimeout(reposTimer);
	isMenuCreated=false;
}
function closeTree(divNode)
{
	try
	{
		if(divNode)
		{
			var mbr=divNode.first;
			while(mbr)
			{
				mbr.style.fontWeight='';
				mbr.style.backgroundColor='';
				if(mbr.child)
				{
					divNode=mbr.child;
					if(divNode.isOn)
					{
						divNode.style.visibility='hidden';
						divNode.isOn=0;
					}
					closeTree(divNode);
				}
				mbr=mbr.next;
			}
		}
	}
	catch(e)	{ }
}
function positionTree(divNode, yOffset)
{
	try
	{
		if(divNode)
		{
			var mbr=divNode.first;
			while(mbr)
			{
				if(mbr.child)
				{
					divNode=mbr.child;
					if(divNode.isOn)
						if(divNode.level==2)
							divNode.style.top=yOffset;
						else
							divNode.style.top=mbr.offsetTop+subOffsetTop+yOffset;
					positionTree(divNode, yOffset);
				}
				mbr=mbr.next;
			}
		}
	}
	catch(e) { }
}
function reposTree()
{
	var y=getPageYOffset();
	if(yTopPosition!=y)
	{
		positionTree(root,y);
		yTopPosition=y;
	}
	reposTimer=setTimeout("reposTree()", 10);
}
function getPageYOffset()
{
	var y;
	try
	{
		if (SecLoc.pageYOffset) // all except Explorer
			y=SecLoc.pageYOffset;
		else if (SecLoc.document.documentElement && SecLoc.document.documentElement.scrollTop) // Explorer 6 Strict
			y=SecLoc.document.documentElement.scrollTop;
		else if (SecLoc.document.body) // all other Explorers
			y=SecLoc.document.body.scrollTop;
	}
	catch(e)
	{
		y=0;
	}
	return(y);
}
function setChildWidth(divNode)
{
	var node=divNode.first;
	if(!node.style.width)
		while(node)
		{
			node.style.width='100%';
			node=node.next;	
		}
}
function openMenu()
{
	if(!isMenuCreated) return;
	closeTree(this.parent);
	var child = this.child;
	this.style.fontWeight='bold';
	this.style.backgroundColor='#7C7E81';
  // this.style.cursor='pointer';
	if(child)
	{
		yTopPosition=getPageYOffset();
		if(child.level==2)
		{
			var left=this.parent.offsetLeft+this.offsetLeft+HorCorrect;
			if(left+child.offsetWidth>menuMaxRight)
				left=menuMaxRight-child.offsetWidth;
			child.style.left=left;
			child.style.top=yTopPosition;
		}
		else
		{
			var left=this.parent.offsetLeft+this.parent.offsetWidth-subOverlap;
			if(left+child.offsetWidth>menuMaxRight)
			{
				left=this.parent.offsetLeft-child.offsetWidth+subOverlap;
				if(left<0)
					left=menuMaxRight-child.offsetWidth;
			}
			child.style.left=left;
			child.style.top=this.offsetTop+subOffsetTop+yTopPosition;
		}
		setChildWidth(child);
		child.style.visibility='visible';
     //child.style.cursor='pointer';
		child.isOn=1;
		if(reposTimer) clearTimeout(reposTimer);
		reposTree();
	}
}
function enterMenu()
{
	if(closeTimer) clearTimeout(closeTimer);
	overMenu=true;
}
function closeImmediate()
{
	if(closeTimer) clearTimeout(closeTimer);
	if(reposTimer) clearTimeout(closeTimer);
	overMenu=false;
	closeTree(root);
}
function closeAll()
{
	if(!overMenu)
	{
		if(reposTimer) clearTimeout(reposTimer);
		closeTree(root);
	}
	else
	{
		closeTimer=setTimeout("closeAll()", 1000);
		overMenu=false;
	}
}
function getTopMenuWidth()
{
	var aNode=root.first;
	var width=0;
	while(aNode)
	{
		width+=aNode.offsetWidth;
		aNode=aNode.next;
	}
	return(width);
}
function deleteTopMenu()
{
	var element=FirstLineFrame.document.getElementById("menuTop");
	while(element.firstChild)
	{
		element.removeChild(element.firstChild);
		root=null;
	}
}
function createMenuStructure(MName, NumberOf, Level, Element)
{
	var prevNode=null;
	var Location=Level==1?FstLoc:SecLoc;
	for(var i=1; i<NumberOf+1; i++)
	{
		var WMnu=MName+eval(i);
		if(i==1)
		{
			var divNode=Location.document.createElement("div");
			var divClass=Location.document.createAttribute("class");
			divClass.nodeValue="TopMenu";
			divNode.setAttributeNode(divClass);
			if(Level!=1)
			{
				divNode.style.position='absolute';
				divNode.style.visibility='hidden';
				divNode.style.top=0;
				divNode.style.left=0;
				divNode.style.zindex=Level*10;
				Location.document.body.appendChild(divNode);
			}
			else
			{
				divNode.style.position='relative';
				divNode.style.left=menuHeadLeft;
				Element.appendChild(divNode);
			}
			divNode.onmouseout=closeAll;
			divNode.onmouseover=enterMenu;
			divNode.level=Level;
		}
		var text=eval(WMnu+'[0]');
		if(text=="#Delimiter#")
		{
			var node=Location.document.createElement("hr");
			var attr=Location.document.createAttribute("width");
			attr.nodeValue="";
			node.setAttributeNode(attr);
			divNode.appendChild(node);
		}
		else
		{
			var node=Location.document.createElement("a");
			var href=eval(WMnu+'[1]');
			var attr=Location.document.createAttribute("href");
			attr.nodeValue=(href!=""?href:"javascript:return;");
if(href!="")
			node.setAttributeNode(attr);
			attr=Location.document.createAttribute("target");
			attr.nodeValue=eval(WMnu+'[3]');
			node.setAttributeNode(attr);
			var txtNode=Location.document.createTextNode(text);
			node.appendChild(txtNode);
			divNode.appendChild(node);
/*
		if(i<NumberOf)
		{
			if(Level!=1)
			{
				brNode=Location.document.createElement("br");
				divNode.appendChild(brNode);
			}
		}
*/
			NoOffSubs=eval(WMnu+'[2]');
			if(NoOffSubs>0)
				node.child=createMenuStructure(WMnu+'_',NoOffSubs,Level+1,divNode);
			node.onmouseover=openMenu;
			node.onclick=closeImmediate;
		}
		node.parent=divNode;
		if(i==1)
			divNode.first=node;
		if(prevNode)
			prevNode.next=node;
		prevNode=node;
	}
	if(Level!=1&&divNode)
		divNode.style.width=divNode.offsetWidth+subOffsetWidth;
	return(divNode);
}
function recreateSecondMenuStructur()
{
	var i=1;
	var aNode=root.first;
	while(aNode)
	{
		var WMnu="Menu"+eval(i);
		noOffSubs=eval(WMnu+'[2]');
		if(noOffSubs>0)
		{
			aNode.child=createMenuStructure(WMnu+'_',noOffSubs,2,null);
		}
		i++;
		aNode=aNode.next;
	}
}

