// Author: Sergey A Zakharov, sergey@kraft-sp.ru
// Copyright: (c)2002 Sergey A Zakharov
// Small JavaScript Menu: v1.0
ua=navigator.userAgent;
OP=ua.match(/Opera.[5-9]/i)!=null;
IE=!OP&&ua.match(/msie.[4-9]/i)!=null;N4=!OP&&!IE&&ua.match(/mozilla.4/i)!=null;
ofsH=14;
nbsp="&nbsp;";
rt="<!--el-->";
mi=[];
c=0;
d=document;

function Item(m,w)
{
 this.l;
 this.m=m;this.w=w
}

function Menu(n)
{
 this.n=n;
 this.m="<table border=0 width=800 cellpadding=0 cellspacing=0><tr>"+rt+"</tr></table>";
 this.sm="";
 this.bg=["#9999CC","#6699ff","#9999CC","#6699ff"];
 this.cl=["#ffffff","#FFFFFF","#ffffff","#FFFFFF"];
 this.mf="Verdana,Arial";
 this.mfs="10px";
 this.mfw="bold";
 this.smf=this.mf;
 this.smfs=this.mfs;
 this.smfw=this.mfw;
 this.bc="#ffffff";
 this.bw=0
}

function addM(mo,mid,text,url,w)
{
 mi[mid]=new Item(mo,w);
 mo.m=mo.m.replace(rt,item(mid,mo.bg[0],mo.n,url,nbsp+text+nbsp,w)+rt)
}


function addSM(mo,mid,text,url)
{
 mi[mid+"sub"+c]=new Item(mo,0);
 ls="<!--"+mid+"-->";
 
 if(mo.sm.indexOf(ls)<0)mo.sm+=(N4?"<layer":"<div")+" id="+mid+"sub onmouseover=sE(this,1) onmouseout=sE(this,0) "+(N4?"visibility=hide  width="+mi[mid].w:"style=position:absolute;visibility:hidden")+"><table width="+mi[mid].w+"  border=0 cellpadding=0 cellspacing=0><tr><td bgcolor="+mo.bc+"><table width=100% border=0 cellpadding=0 cellspacing="+mo.bw+">"+ls+"</table></td></tr></table>"+(N4?"</layer>":"</div>");mo.sm=mo.sm.replace(ls,"<tr>"+item(mid+"sub"+c,mo.bg[2],mo.n+"sub",url,nbsp+text+nbsp)+"</tr>"+ls);
 c++
}


function writeStyle(o)
{
 s=IE?"cursor:pointer":N4?"text-decoration:none; padding:2px":"cursor:pointer";
 d.write('<style>.'+o.n+',.'+o.n+'n{font-family:'+o.mf+';font-size:'+o.mfs+';font-weight:'+o.mfw+';'+s+'}.'+o.n+'sub,.'+o.n+'subn{font-family:'+o.smf+';font-size:'+o.smfs+';font-weight:'+o.smfw+';'+s+'}.'+o.n+'{color:'+o.cl[0]+'}.'+o.n+'sub{color:'+o.cl[2]+'}</style>')
}


function hl(o,t)
{
 e=mi[o.id];
 c=(e.w>0)<<1|t;
 bg=e.m.bg[c];
 cl=e.m.cl[c];
 if(N4)
 { 
  w=o.clip.width;
  with(o.document) {
   linkColor=cl;
   vlinkColor=cl;
   alinkColor=cl;
   bgColor=bg;
   open();
   write(e.l);
   close()
  }
  
  o.clip.width=w
 } else { 
  OP?o.style.background=bg:o.style.backgroundColor=bg;
  o.style.color=cl
 }
 
 sm=gE(o.id+"sub");
 
 if(e.w && sm) {
  if(t) {
   if(N4) {
    sm.left=o.pageX;
	sm.top=o.pageY+o.clip.height;
   } else { 
    mnp=o;ofsL=0;
	ofsT=0;
	do { 
	  ofsL+=mnp.offsetLeft;
	  ofsT+=mnp.offsetTop;
	  mnp=mnp.offsetParent
	} while(mnp!=null);
	
	s=sm.style;
	s.left=ofsL;
	s.top=ofsT+(OP?ofsH:o.offsetHeight)
   }
   
   sE(sm,1)
  } else  sE(sm,0)
 }
}


function item(id,bg,cl,u,t,w)
{
 mi[id].l=a(cl+"n",u,t);
 return "<td "+(N4?"":" style=\"border: solid 1px #003366; text-align: center; padding: 3px; cursor: pointer;\"") +"bgcolor="+bg+(N4?"><ilayer><layer width="+w:"  class="+cl+(u?" onmousedown=document.location='"+u+"'":""))+" id="+id+" onmouseover=hl(this,1) onmouseout=hl(this,0)>"+(N4?a(cl,u,t)+"</layer></ilayer>":t)+"</td>"
}


function a(cl,u,t)
{
 var link = '<a class="' +cl+ '" href="' +(u ? u : "#")+ '"> '+t+' </a>';
 return link; //document.write(link+"<br>");

}


function gE(e,f)
{
 if(N4) {
  f=(f)?f:self;var V=f.document.layers;
  if(V[e]) return V[e];
  for(var W=0;W<V.length;) t=gE(e,V[W++]);
  return t
 }
 
 if(IE) return d.all[e];
 return d.getElementById(e)
}


function gS(e)
{
 return N4? gE(e):gE(e).style
}


function sE(e,v)
{ 
 (N4?e:e.style).visibility=v?N4?'show':'visible':N4?'hide':'hidden'
}


