// O'range 2001 Ilya Muzukin ilya@iep.uran.ru
var ns ;
var ie ;
var W;
function BrowserCheck() {
	var b = navigator.appName
	if (b=="Netscape") {this.b = "ns";ns=true;}
	else if (b=="Microsoft Internet Explorer") {this.b = "ie";ie=true;}
	else this.b = b
	this.version = navigator.appVersion
	this.v = parseInt(this.version);
	if(ns){W=window.innerWidth-16;}
	else{W=document.body.offsetWidth-20;}
}

function TreeItem(id,parid,name,link,target,image)
{
this.vname="DdMenu"+TreeItem.dmcount;
TreeItem.dmcount++;
this.image=image;
this.name=name;
this.frname="";
this.id=id;
this.parentItem=null;
this.parid=parid;
this.link=link;
this.target=target;
this.items=new Array();
this.itemCount=0;
this.Opened=true;
this.bckColor="#f0f0f0";
this.fntColor="#ffffff";
this.selFntColor="#00ffff";
this.fntSize=2;
this.css=null;
this.selBckColor="#a0a0a0";
this.alinkColor="#ffff00";
this.arrIm="list-img0.gif";
this.xpos=0;
this.ypos=0;
this.selected=0;
this.height=600;
this.width=150;
this.iHeight=21;
this.imWidth=18;
this.focus=-1;
if(ie){
this.visibility="hidden";
};
if(ns){this.visibility="hide";
};
this.WriteCSS = TreeItemWriteCSS;
this.Show = TreeItemShow;
this.Add = TreeItemAdd;
this.WriteDiv = TreeItemWriteDiv;
this.Get = TreeItemGet;
this.A = TreeItemA;
this.align="vert";
this.moveHandler=TreeItemMove;

this.downHandler=TreeItemDown;

this.Reset=TreeItemReset;
this.EventInit=TIEventInit;
this.MoveTo=TIMoveTo;
this.Write=TreeItemWrite;
this.normText="";
this.selText=""
eval(this.vname + "=this");
}
function TIMoveTo(x,y)
{
if(this.itemCount<1) return;
this.xpos=x;
this.ypos=y;
if(ns) {this.css.left=this.xpos;
this.css.top=this.ypos;}
if(ie) {this.css.left=this.xpos;
this.css.top=this.ypos;};
}
function TreeItemGet(id)
{
if(id==this.id) return this;
for(var i=0;i<this.itemCount;i++)
{
It=this.items[i].Get(id);
if(It!=null) return It;
}
return null;
}
function TreeItemA(id,parid,name,link,target,image)
{
It=new TreeItem(id,parid,name,link,target,image);
this.Add(It);
}
function TreeItemAdd(item)
{
item.Opened=false;
status="adding "+item.id; 
It=this.Get(item.parid);
status="item got "+item.id;
if(item.parid==this.id)
{item.width=this.width;
item.bckColor=this.bckColor;
item.selBckColor=this.selBckColor;
item.fntColor=this.fntColor;
item.fntSize=this.fntSize;
item.iHeight=this.iHeight;
item.imWidth=this.imWidth;
item.arrIm=this.arrIm;
item.selFntColor=this.selFntColor;
this.items[this.itemCount]=item;
item.parentItem=this;
if(ie)item.visibility="hidden";
if(ns)item.visibility="hide";
this.itemCount++;
return;
}
if(It!=null) {It.Add(item);return;}
}

function TreeItemWriteDiv()
{
if(this.itemCount<1) return false;
document.write("<DIV ID='"+this.vname+"'>");
for(var i=0;i<this.itemCount;i++)
{
ref=this.items[i].name;
im="";im1="";
if(this.items[i].image!="")im1="<img src='"+this.items[i].image+"' width='"+this.imWidth+"' height='"+this.iHeight+"' border=0>";
w=this.width-this.imWidth-this.iHeight;
if(this.items[i].itemCount>0&&this.arrIm!="")im="<img src='"+this.arrIm+"' height='"+this.iHeight+"' width='"+this.iHeight+"' border=0>";
this.items[i].normText="<table border='0' width='"+this.width+"' cellspacing='0' height='"+this.iHeight+"' cellpadding='0'><tr><td width ="+this.imWidth+">"+im1+"</td><td width= '"+this.width+"' ><font color='"+this.fntColor+"' size='"+this.fntSize+"'>"+ref+"</font></td><td width="+this.iHeight+">"+im+"</td></tr></table>";
this.items[i].selText="<table border='0' width='"+this.width+"' cellspacing='0' height='"+this.iHeight+"' cellpadding='0'><tr><td width ="+this.imWidth+">"+im1+"</td><td width= '"+this.width+"' ><font color='"+this.selFntColor+"' size='"+this.fntSize+"'>"+ref+"</font></td><td width="+this.iHeight+">"+im+"</td></tr></table>";
document.write("<DIV ID='"+this.items[i].vname+"i' >");
document.write(this.items[i].normText);
document.write("</DIV>\r\n");
}
document.write("</DIV>\r\n");
for(var i=0;i<this.itemCount;i++)
{
this.items[i].WriteDiv();
}


}
function TIEventInit()
{
for(var i=0;i<this.itemCount;i++)
{
this.items[i].EventInit();
}
if(ns)
{
if(this.itemCount>0)this.css=document.layers[this.vname];
for(var i=0;i<this.itemCount;i++){
var style=eval("document."+this.vname+".document."+this.items[i].vname+"i");
style.onmousemove=new Function(this.vname+".moveHandler("+i+");return false;");
style.onmousedown=new Function(this.vname+".downHandler("+i+");return false;");
style.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);

}
}
if(ie)
{
if(this.itemCount>0)this.css=document.all[this.vname].style;
for(var i=0;i<this.itemCount;i++){
document.all[this.items[i].vname+"i"].onmousemove=new Function(this.vname+".moveHandler("+i+");return false;");
document.all[this.items[i].vname+"i"].onmousedown=new Function(this.vname+".downHandler("+i+");return false;");

}
}
status="Menu inited"+this.id;
}
function TreeItemWriteCSS()
{
var dx;
var dy;
var bCol=(ns)?"layer-background-color:" : "background-color:";
if(this.align=="vert"){
Height=this.itemCount*this.iHeight;
Width=this.width+10;
dx=0;
dy=this.iHeight;
}else
{
Height=this.iHeight;Width=(this.width+1)*this.itemCount;
dy=0;
dx=this.width+2;
}
if(this.itemCount>0){
if(this.parentItem==null)document.write("<STYLE TYPE='text/css'><!--");
document.write("#"+this.vname+" {position:absolute;"); 
document.write(";left:"+this.xpos+"px;top:"+this.ypos+"px;width:"+Width+"px;");
document.write("visiblity:'"+this.visibility+"'; z-index:1;}\r\n");
for(var i=0;i<this.itemCount;i++)
{
 document.write("#"+this.items[i].vname+"i {position:absolute;"+bCol+this.items[i].bckColor); 
document.write(";top:"+i*dy+"px;left:"+i*dx+"px"+";width:"+this.width+"px;");
document.write("height:"+this.iHeight+"px; z-index:1;}\r\n");

this.items[i].WriteCSS();
}
if(this.parentItem==null)document.write("--></STYLE>\r\n");
}
}
function TreeItemShow(o)
{
if(this.itemCount<1) return;
this.focus=-1;
if(o==1)
{
if(ns)
{document.layers[this.vname].visibility = "show";
}
if(ie)
{document.all[this.vname].style.visibility = "visible";
}
}
else
{
for(var i=0;i<this.itemCount;i++)this.items[i].Show(0);
if (ns) {document.layers[this.vname].visibility = "hide";

}
else if (ie) {document.all[this.vname].style.visibility = "hidden";

}
}
}


function TreeItemMove(i)
{
if(this.itemCount<1)return;
sel=i;
if(sel!=this.focus||sel==0)
{
var nxpos=this.xpos+this.width;
var nypos=this.ypos+sel*this.iHeight;
if(this.align!="vert")
{
nxpos=this.xpos+sel*this.width;
nypos=this.ypos+this.iHeight;
}
if(nxpos+this.width>W) nxpos=nxpos-2*this.width;
this.items[this.selected].Show(0);

this.items[this.selected].MoveTo(0,0);
this.items[sel].Show(1);

this.items[sel].MoveTo(nxpos,nypos);
if(sel!=this.focus){
var c1=this.items[this.selected].bckColor;
var c2=this.items[sel].selBckColor
if(ie){
document.all[this.items[this.selected].vname+"i"].style.backgroundColor=c1;
document.all[this.items[sel].vname+"i"].style.backgroundColor =c2;

}
if(ns)
{
var style=eval("document."+this.vname+".document."+this.items[this.selected].vname+"i");
var style1=eval("document."+this.vname+".document."+this.items[sel].vname+"i");
style.document.bgColor=c1;
style1.document.bgColor=c2; 
}
this.Write(this.selected,this.items[this.selected].normText);
this.Write(sel,this.items[sel].selText);}
this.selected=sel;this.focus=sel;
}
}

function TreeItemDown(i)
{
sel=i;
if(this.items[sel].link!=""){
if(this.items[sel].target=="")location.href=this.items[sel].link;
else{top.frames[this.items[sel].target].location.href=this.items[sel].link;}
}
}
function TreeItemReset()
{
for(var i=0;i<this.itemCount;i++)this.items[i].Show(0);
this.focus=-1;
}
function TreeItemWrite(i,text)
{
if(ie) document.all[this.items[i].vname+"i"].innerHTML = text;
if(ns){
var style=eval("document."+this.vname+".document."+this.items[i].vname+"i");
style.document.open();
style.document.write(text);
style.document.close();
}
}
TreeItem.dmcount=0;