// O'range 2001 Ilya Muzukin ilya@iep.uran.ru
var ns ;
var ie ;
var n6;
var W;
function BrowserCheck() {
	if (document.layers) ns=true;
	if (document.all) ie=true;
	if(!ie&&document.getElementById){ns=false;n6=true;};
	if(ns||n6){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=false;
this.bckColor="#f0f0f0";
this.fntColor="#ffffff";
this.selFntColor="#00ffff";
this.fntSize=2;
this.css=null;
this.face="arial";
this.selBckColor="#a0a0a0";
this.alinkColor="#ffff00";
this.arrIm="list-img0.gif";
this.arrIm1="list-img1.gif";
this.iob=null;this.iob1=null;
this.xpos=0;
this.ypos=0;
this.selected=0;
this.height=600;
this.width=150;
this.iHeight=21;
this.imWidth=18;
this.focus=-1;
this.bSize=1;
this.tW=0;
this.tH=0;
this.bColor="#000000"
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.outHandler=TIMout;
this.downHandler=TreeItemDown;
this.active=false;
this.Reset=TreeItemReset;
this.EventInit=TIEventInit;
this.MoveTo=TIMoveTo;
this.Write=TreeItemWrite;
this.Toggle=TIToggle;
this.normText="";
this.selText=""
eval(this.vname + "=this");
}
function TIMoveTo(x,y)
{
if(this.itemCount<1) return;
this.xpos=x;this.ypos=y;
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;
It=this.Get(item.parid);
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.arrIm1=this.arrIm1;
item.selFntColor=this.selFntColor;
this.items[this.itemCount]=item;
item.parentItem=this;
item.boxspacing=this.boxspacing;
item.bSize=this.bSize;
item.face=this.face;
item.bColor=this.bColor;
item.visibility="hidden";
this.itemCount++;
return;
}
if(It!=null) {It.Add(item);return;}
}

function TreeItemWriteDiv()
{preload(this.vname+".iob",this.arrIm);preload(this.vname+".iob1",this.arrIm1);
if(this.itemCount<1) return false;
document.write("<DIV ID='"+this.vname+"'><table border='"+this.bSize+"' width='"+this.tW+"' height='"+this.tH+"' bordercolor='"+this.bColor+"'  ><tr><td >");
for(var i=0;i<this.itemCount;i++)
{
ref=this.items[i].name;
im="";im1="";cl="";scl="";im2="";
cl=" color='"+this.fntColor+"'";scl=" color='"+this.selFntColor+"'";
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 name='"+this.items[i].vname+"im' src='"+this.iob.src+"' height='"+this.iHeight+"' width='"+this.iHeight+"' border=0>";im2="<img name='"+this.items[i].vname+"im' src='"+this.iob1.src+"' height='"+this.iHeight+"' width='"+this.iHeight+"' border=0>";}

t1="<table xborder='2' width='"+this.width+"' cellspacing='0' height='"+this.iHeight+"' cellpadding='0' class=menubox><tr><td width ="+this.imWidth+">"+im1+"</td><td width= '"+this.width+"'  ><zfont ";tc=" size='"+this.fntSize+"' face='"+this.face+"'>";

t2="</font></td><td width=0 "+this.iHeight+"  >";

t3="</td></tr></table>";

this.items[i].normText=t1+cl+tc+"<div id='"+this.items[i].vname+"t' >"+ref+"</div>"+t2+im+t3;
this.items[i].selText=t1+scl+tc+ref+t2+im2+t3;
document.write("<DIV ID='"+this.items[i].vname+"i' >"+this.items[i].normText+"</DIV>");
if(ie){this.items[i].ilayer=document.all[this.items[i].vname+"i"];this.items[i].tlayer=document.all[this.items[i].vname+"t"];}
if(n6){this.items[i].ilayer=document.getElementById(this.items[i].vname+"i");
this.items[i].tlayer=document.getElementById(this.items[i].vname+"t");
var tl=this.items[i].tlayer.style;
tl.color=this.items[i].fntColor;tl.fontFamily=this.face;
tl.fontSize=6+2*this.items[i].fntSize+"pt";
};
if(ns)this.items[i].ilayer=eval("document."+this.vname+".document."+this.items[i].vname+"i");
}
document.write("</td></tr></table></DIV>");
for(var i=0;i<this.itemCount;i++)
{
this.items[i].WriteDiv();
}
if(ie){this.layer=document.all[this.vname];this.css=this.layer.style;}
if(n6){this.layer=document.getElementById(this.vname);this.css=this.layer.style;}
if(ns){this.layer=eval("document."+this.vname);this.css=this.layer;}
}
function TIEventInit()
{
var oinit=true;
 for(var i=0;i<this.itemCount;i++)
 {
 this.items[i].EventInit();
 }
for(var i=0;i<this.itemCount;i++){
var style=this.items[i].ilayer;
if(oinit)this.layer.onmouseout=new Function(this.vname+".outHandler();return false;");
oinit=false;
style.onmouseover=new Function(this.vname+".moveHandler("+i+");return false;");
style.onmousedown=new Function(this.vname+".downHandler("+i+");return false;");
if(ns)style.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
}
}
function TreeItemWriteCSS()
{
var dx;
var dy;
var bCol=(ns)?"layer-background-color:" : "background-color:";
if(this.align=="vert"){
Height=this.itemCount*this.iHeight+2*this.bSize;
Width=this.width+2*this.bSize;
dx=0;
dy=this.iHeight;
}else
{
Height=this.iHeight+2*this.bSize;Width=(this.width+2)*this.itemCount+2*this.bSize;
dy=0;
dx=this.width+this.boxspacing;
}
this.tH=Height; this.tW=Width;
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("visibility: "+this.visibility+"; cursor: hand; 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+this.bSize)+"px;left:"+(i*dx+this.bSize)+"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)
{
this.focus=-1;
if(this.itemCount<1) return;
if(o==1)
{
this.css.visibility=(ns)? "show":"visible";
}
else
{
for(var i=0;i<this.itemCount;i++)this.items[i].Show(0);
this.css.visibility=(ns)? "hide":"hidden";
}
}
function TIToggle(mod)
{
this.Opened=mod;
var c1=this.bckColor;var c2=this.selBckColor;
if(ie||n6)
{
if(document.images[this.vname+"im"])document.images[this.vname+"im"].src=(mod)? this.iob1.src:this.iob.src;
this.ilayer.style.backgroundColor=(mod)? c2 : c1;
this.ilayer.style.background=(mod)? c2:c1;
this.tlayer.style.color=(mod)? this.selFntColor:this.fntColor; 
}
if(ns)
{
var txt=(mod)? this.selText:this.normText;
this.ilayer.document.bgColor=(mod)? c2 : c1;
this.Write(txt);
}
}
function TreeItemMove(i)
{
if(this.itemCount<1)return;
sel=i;
this.active=true;
if(this.parentItem!=null)this.parentItem.active=true;
this.items[this.selected].active=true;
var nxpos=this.xpos+this.width;
var nypos=this.ypos+i*this.iHeight;
if(this.align!="vert")
{
nxpos=this.xpos+i*this.width+i*this.boxspacing;
nypos=this.ypos+this.iHeight;
}
if(nxpos+this.width>W) nxpos=nxpos-2*this.width;
this.items[sel].MoveTo(nxpos,nypos);
this.items[this.selected].Show(0);
this.items[sel].Show(1);
if(sel!=this.focus){this.items[this.selected].Toggle(false);
this.items[sel].Toggle(true);status=this.items[sel].link;
}
this.selected=sel;this.focus=sel;

}

function TreeItemDown(i)
{
sel=i;
if(this.items[sel].link!=""){
if(this.items[sel].target!="")parent.frames[this.items[sel].target].location=this.items[sel].link;else location.href=this.items[sel].link;
}
}
function TreeItemReset()
{if(this.active)return;
for(var i=0;i<this.itemCount;i++)this.items[i].Show(0);
this.focus=-1;
if(this.parentItem!=null){this.parentItem.active=false;this.parentItem.Reset();}
this.items[this.selected].Toggle(false);
}
function TreeItemWrite(text)
{
var style=this.ilayer;
style.document.open();
style.document.write(text);
style.document.close();
}
function TIMout(e)
{
if(ie){
mx=window.event.clientX;if(document.body.scrollLeft)mx+=document.body.scrollLeft;
my=window.event.clientY;if(document.body.scrollTop)my+=document.body.scrollTop;
if((mx>this.xpos+1&&mx<this.xpos+this.tW)&&(my>this.ypos+1&&my<this.ypos+this.tH)) return;
}
this.active=false;

setTimeout(this.vname+".Reset()",300);
}
function preload(imgObj,imgSrc) {
	if (document.images) {
		eval(imgObj+' = new Image()')
		eval(imgObj+'.src = "'+imgSrc+'"')
	}
}


TreeItem.dmcount=0;